tmf: API clean-up of sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / ShowNodeEnd.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 ShowNodeEnd extends BaseSDAction {
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
37 /**
38 * Default constructor
39 */
40 public ShowNodeEnd() {
41 this(null);
42 }
43
44 /**
45 * Constructor
46 *
47 * @param view The sequence diagram view reference
48 * @since 2.0
49 */
50 public ShowNodeEnd(SDView view) {
51 super(view);
52 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END));
53 }
54
55 // ------------------------------------------------------------------------
56 // Operations
57 // ------------------------------------------------------------------------
58
59 @Override
60 @SuppressWarnings("rawtypes")
61 public void run() {
62 if (getView() == null) {
63 return;
64 }
65
66 SDWidget sdWidget = getView().getSDWidget();
67
68 if (sdWidget == null) {
69 return;
70 }
71
72 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
73 ISelection sel = selProvider.getSelection();
74 Object selectedNode = null;
75
76 Iterator it = ((StructuredSelection) sel).iterator();
77 while (it.hasNext()) {
78 selectedNode = it.next();
79 }
80
81 if (selectedNode != null) {
82 GraphNode node = (GraphNode) selectedNode;
83 if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
84 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor()) - sdWidget.getVisibleWidth() / 2, Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
85 } else {
86 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
87 }
88 }
89 }
90 }
This page took 0.047522 seconds and 5 git commands to generate.