93ffafcd53e6d8ab551c24dd445142d3d77035bc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / ShowNodeStart.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
14
15 import java.util.Iterator;
16
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
22 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
24 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
25 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
26 import org.eclipse.ui.IViewPart;
27
28 /**
29 * Action class implementation to show end of a graph node.
30 *
31 * @version 1.0
32 * @author sveyrier
33 */
34 public class ShowNodeStart extends Action {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 /**
41 * The sequence diagram view reference
42 */
43 protected SDView fView = null;
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
49 /**
50 * Default constructor
51 */
52 public ShowNodeStart() {
53 this(null);
54 }
55
56 /**
57 * Constructor
58 *
59 * @param view
60 * The sequence diagram view reference
61 */
62 public ShowNodeStart(IViewPart view) {
63 super();
64 if (view instanceof SDView) {
65 fView = (SDView) view;
66 }
67 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_START));
68 }
69
70 // ------------------------------------------------------------------------
71 // Methods
72 // ------------------------------------------------------------------------
73
74 @Override
75 @SuppressWarnings("rawtypes")
76 public void run() {
77 if (fView == null) {
78 return;
79 }
80
81 SDWidget sdWidget = fView.getSDWidget();
82
83 if (sdWidget == null) {
84 return;
85 }
86
87 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
88 ISelection sel = selProvider.getSelection();
89 Object selectedNode = null;
90 Iterator it = ((StructuredSelection) sel).iterator();
91 while (it.hasNext()) {
92 selectedNode = it.next();
93 }
94 if (selectedNode != null) {
95 GraphNode node = (GraphNode) selectedNode;
96 if (node.getX() * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
97 sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() - sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor()));
98 } else {
99 sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor()));
100 }
101 }
102 }
103
104 /**
105 * Sets the active SD view.
106 *
107 * @param view
108 * The SD view.
109 */
110 public void setView(SDView view) {
111 fView = view;
112 }
113 }
This page took 0.058728 seconds and 4 git commands to generate.