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