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