tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.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.viewers.ISelection;
18 import org.eclipse.jface.viewers.ISelectionProvider;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
21 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
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;
25
26 /**
27 * Action class implementation to show end of a graph node.
28 *
29 * @version 1.0
30 * @author sveyrier
31 */
32 public class ShowNodeStart extends BaseSDAction {
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
37
38 /**
39 * Default constructor
40 */
41 public ShowNodeStart() {
42 this(null);
43 }
44
45 /**
46 * Constructor
47 *
48 * @param view
49 * The sequence diagram view reference
50 * @since 2.0
51 */
52 public ShowNodeStart(SDView view) {
53 super(view);
54 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_START));
55 }
56
57 // ------------------------------------------------------------------------
58 // Methods
59 // ------------------------------------------------------------------------
60
61 @Override
62 public void run() {
63 if (getView() == null) {
64 return;
65 }
66
67 SDWidget sdWidget = getView().getSDWidget();
68
69 if (sdWidget == null) {
70 return;
71 }
72
73 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
74 ISelection sel = selProvider.getSelection();
75 Object selectedNode = null;
76 Iterator<Object> it = ((StructuredSelection) sel).iterator();
77 while (it.hasNext()) {
78 selectedNode = it.next();
79 }
80 if (selectedNode != null) {
81 GraphNode node = (GraphNode) selectedNode;
82 if (node.getX() * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
83 sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() - sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor()));
84 } else {
85 sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor()));
86 }
87 }
88 }
89 }
This page took 0.031795 seconds and 5 git commands to generate.