Fix static analysis warnings for UML2SD
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / ShowNodeEnd.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 ShowNodeEnd extends Action {
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
df0b8ff4
BH
40 /**
41 * The sequence diagram view reference
42 */
43 protected SDView fView = null;
73005152 44
df0b8ff4
BH
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48 /**
49 * Default constructor
50 */
51 public ShowNodeEnd() {
52 this(null);
53 }
73005152 54
df0b8ff4
BH
55 /**
56 * Constructor
57 *
eb63f5ff 58 * @param view The sequence diagram view reference
df0b8ff4 59 */
eb63f5ff 60 public ShowNodeEnd(IViewPart view) {
73005152 61 super();
eb63f5ff
BH
62 if (view instanceof SDView) {
63 fView = (SDView)view;
73005152
BH
64 }
65 setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END));
66 }
67
68 // ------------------------------------------------------------------------
69 // Operations
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 80 }
73005152
BH
81
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;
df0b8ff4 91
73005152 92 Iterator it = ((StructuredSelection) sel).iterator();
df0b8ff4 93 while (it.hasNext()) {
73005152 94 selectedNode = it.next();
df0b8ff4
BH
95 }
96
73005152
BH
97 if (selectedNode != null) {
98 GraphNode node = (GraphNode) selectedNode;
df0b8ff4 99 if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
73005152 100 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor()) - sdWidget.getVisibleWidth() / 2, Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
df0b8ff4 101 } else {
73005152 102 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
df0b8ff4 103 }
73005152
BH
104 }
105 }
106
df0b8ff4
BH
107 /**
108 * Sets the active SD view.
109 *
110 * @param view The SD view.
111 */
112 public void setView(SDView view) {
73005152
BH
113 fView = view;
114 }
115}
This page took 0.033941 seconds and 5 git commands to generate.