tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / ShowNodeEnd.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2012 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
73005152
BH
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
14
15import java.util.Iterator;
16
17import org.eclipse.jface.action.Action;
18import org.eclipse.jface.viewers.ISelection;
19import org.eclipse.jface.viewers.ISelectionProvider;
20import org.eclipse.jface.viewers.StructuredSelection;
d34665f9 21import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
8fd82db5 22import org.eclipse.linuxtools.internal.tmf.ui.Activator;
73005152
BH
23import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
24import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
25import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
26import org.eclipse.ui.IViewPart;
27
28/**
df0b8ff4 29 * Action class implementation to show end of a graph node.
c8422608 30 *
df0b8ff4 31 * @version 1.0
73005152
BH
32 * @author sveyrier
33 */
34public class ShowNodeEnd extends Action {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
df0b8ff4
BH
39 /**
40 * The sequence diagram view reference
41 */
42 protected SDView fView = null;
73005152 43
df0b8ff4
BH
44 // ------------------------------------------------------------------------
45 // Constructors
46 // ------------------------------------------------------------------------
47 /**
48 * Default constructor
49 */
50 public ShowNodeEnd() {
51 this(null);
52 }
73005152 53
df0b8ff4
BH
54 /**
55 * Constructor
c8422608 56 *
eb63f5ff 57 * @param view The sequence diagram view reference
df0b8ff4 58 */
eb63f5ff 59 public ShowNodeEnd(IViewPart view) {
73005152 60 super();
eb63f5ff
BH
61 if (view instanceof SDView) {
62 fView = (SDView)view;
73005152 63 }
8fd82db5 64 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END));
73005152
BH
65 }
66
67 // ------------------------------------------------------------------------
68 // Operations
69 // ------------------------------------------------------------------------
70 /*
71 * (non-Javadoc)
72 * @see org.eclipse.jface.action.Action#run()
73 */
74 @Override
75 @SuppressWarnings("rawtypes")
76 public void run() {
df0b8ff4 77 if (fView == null) {
73005152 78 return;
df0b8ff4 79 }
73005152
BH
80
81 SDWidget sdWidget = fView.getSDWidget();
82
83 if (sdWidget == null) {
84 return;
85 }
df0b8ff4 86
73005152
BH
87 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
88 ISelection sel = selProvider.getSelection();
89 Object selectedNode = null;
df0b8ff4 90
73005152 91 Iterator it = ((StructuredSelection) sel).iterator();
df0b8ff4 92 while (it.hasNext()) {
73005152 93 selectedNode = it.next();
df0b8ff4 94 }
c8422608 95
73005152
BH
96 if (selectedNode != null) {
97 GraphNode node = (GraphNode) selectedNode;
df0b8ff4 98 if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2) {
73005152 99 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor()) - sdWidget.getVisibleWidth() / 2, Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
df0b8ff4 100 } else {
73005152 101 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
df0b8ff4 102 }
73005152
BH
103 }
104 }
105
df0b8ff4
BH
106 /**
107 * Sets the active SD view.
c8422608 108 *
df0b8ff4
BH
109 * @param view The SD view.
110 */
111 public void setView(SDView view) {
73005152
BH
112 fView = view;
113 }
114}
This page took 0.040008 seconds and 5 git commands to generate.