Copyright header update, 2015 edition
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / uml2sd / handlers / ShowNodeStart.java
CommitLineData
73005152 1/**********************************************************************
ed902a2b 2 * Copyright (c) 2005, 2014 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
2bdf0193 13package org.eclipse.tracecompass.tmf.ui.views.uml2sd.handlers;
73005152
BH
14
15import java.util.Iterator;
16
73005152
BH
17import org.eclipse.jface.viewers.ISelection;
18import org.eclipse.jface.viewers.ISelectionProvider;
19import org.eclipse.jface.viewers.StructuredSelection;
2bdf0193
AM
20import org.eclipse.tracecompass.internal.tmf.ui.Activator;
21import org.eclipse.tracecompass.internal.tmf.ui.ITmfImageConstants;
22import org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView;
23import org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget;
24import org.eclipse.tracecompass.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 32public class ShowNodeStart extends BaseSDAction {
73005152
BH
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
11252342 37
df0b8ff4
BH
38 /**
39 * Default constructor
40 */
73005152
BH
41 public ShowNodeStart() {
42 this(null);
43 }
df0b8ff4
BH
44
45 /**
46 * Constructor
c8422608 47 *
11252342
AM
48 * @param view
49 * The sequence diagram view reference
cab6c8ff 50 * @since 2.0
df0b8ff4 51 */
cab6c8ff
BH
52 public ShowNodeStart(SDView view) {
53 super(view);
8fd82db5 54 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_START));
73005152
BH
55 }
56
57 // ------------------------------------------------------------------------
df0b8ff4 58 // Methods
73005152 59 // ------------------------------------------------------------------------
11252342
AM
60
61 @Override
73005152 62 public void run() {
cab6c8ff 63 if (getView() == null) {
73005152 64 return;
df0b8ff4
BH
65 }
66
cab6c8ff 67 SDWidget sdWidget = getView().getSDWidget();
73005152
BH
68
69 if (sdWidget == null) {
70 return;
71 }
df0b8ff4 72
73005152
BH
73 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
74 ISelection sel = selProvider.getSelection();
75 Object selectedNode = null;
5b5b7df5 76 Iterator<Object> it = ((StructuredSelection) sel).iterator();
df0b8ff4 77 while (it.hasNext()) {
73005152 78 selectedNode = it.next();
df0b8ff4 79 }
73005152
BH
80 if (selectedNode != null) {
81 GraphNode node = (GraphNode) selectedNode;
df0b8ff4 82 if (node.getX() * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
73005152 83 sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() - sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor()));
df0b8ff4 84 } else {
73005152 85 sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor()));
df0b8ff4 86 }
73005152
BH
87 }
88 }
73005152 89}
This page took 0.068621 seconds and 5 git commands to generate.