Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
73005152 BH |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
c8422608 AM |
7 | * |
8 | * Contributors: | |
9 | * IBM - Initial API and implementation | |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers; |
14 | ||
15 | import java.util.Iterator; | |
16 | ||
73005152 BH |
17 | import org.eclipse.jface.viewers.ISelection; |
18 | import org.eclipse.jface.viewers.ISelectionProvider; | |
19 | import org.eclipse.jface.viewers.StructuredSelection; | |
8fd82db5 | 20 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
cab6c8ff | 21 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
73005152 BH |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView; |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
73005152 BH |
25 | |
26 | /** | |
df0b8ff4 | 27 | * Action class implementation to show end of a graph node. |
c8422608 | 28 | * |
df0b8ff4 | 29 | * @version 1.0 |
73005152 BH |
30 | * @author sveyrier |
31 | */ | |
cab6c8ff | 32 | public class ShowNodeEnd extends BaseSDAction { |
73005152 | 33 | |
df0b8ff4 BH |
34 | // ------------------------------------------------------------------------ |
35 | // Constructors | |
36 | // ------------------------------------------------------------------------ | |
37 | /** | |
38 | * Default constructor | |
39 | */ | |
40 | public ShowNodeEnd() { | |
41 | this(null); | |
42 | } | |
73005152 | 43 | |
df0b8ff4 BH |
44 | /** |
45 | * Constructor | |
c8422608 | 46 | * |
eb63f5ff | 47 | * @param view The sequence diagram view reference |
cab6c8ff | 48 | * @since 2.0 |
df0b8ff4 | 49 | */ |
cab6c8ff BH |
50 | public ShowNodeEnd(SDView view) { |
51 | super(view); | |
8fd82db5 | 52 | setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END)); |
73005152 BH |
53 | } |
54 | ||
55 | // ------------------------------------------------------------------------ | |
56 | // Operations | |
57 | // ------------------------------------------------------------------------ | |
11252342 | 58 | |
73005152 | 59 | @Override |
73005152 | 60 | public void run() { |
cab6c8ff | 61 | if (getView() == null) { |
73005152 | 62 | return; |
df0b8ff4 | 63 | } |
73005152 | 64 | |
cab6c8ff | 65 | SDWidget sdWidget = getView().getSDWidget(); |
73005152 BH |
66 | |
67 | if (sdWidget == null) { | |
68 | return; | |
69 | } | |
df0b8ff4 | 70 | |
73005152 BH |
71 | ISelectionProvider selProvider = sdWidget.getSelectionProvider(); |
72 | ISelection sel = selProvider.getSelection(); | |
73 | Object selectedNode = null; | |
df0b8ff4 | 74 | |
5b5b7df5 | 75 | Iterator<Object> it = ((StructuredSelection) sel).iterator(); |
df0b8ff4 | 76 | while (it.hasNext()) { |
73005152 | 77 | selectedNode = it.next(); |
df0b8ff4 | 78 | } |
c8422608 | 79 | |
73005152 BH |
80 | if (selectedNode != null) { |
81 | GraphNode node = (GraphNode) selectedNode; | |
df0b8ff4 | 82 | if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) { |
73005152 | 83 | sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor()) - sdWidget.getVisibleWidth() / 2, Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor())); |
df0b8ff4 | 84 | } else { |
73005152 | 85 | sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor())); |
df0b8ff4 | 86 | } |
73005152 BH |
87 | } |
88 | } | |
73005152 | 89 | } |