1 /**********************************************************************
2 * Copyright (c) 2005, 2012 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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
;
15 import java
.util
.Iterator
;
17 import org
.eclipse
.jface
.action
.Action
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
20 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDWidget
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
26 import org
.eclipse
.ui
.IViewPart
;
29 * Action class implementation to show end of a graph node.
34 public class ShowNodeStart
extends Action
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 * The sequence diagram view reference
42 protected SDView fView
= null;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
50 public ShowNodeStart() {
57 * @param view The sequence diagram view reference
59 public ShowNodeStart(IViewPart view
) {
61 if (view
instanceof SDView
) {
64 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NODE_START
));
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * @see org.eclipse.jface.action.Action#run()
75 @SuppressWarnings("rawtypes")
81 SDWidget sdWidget
= fView
.getSDWidget();
83 if (sdWidget
== null) {
87 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
88 ISelection sel
= selProvider
.getSelection();
89 Object selectedNode
= null;
90 Iterator it
= ((StructuredSelection
) sel
).iterator();
91 while (it
.hasNext()) {
92 selectedNode
= it
.next();
94 if (selectedNode
!= null) {
95 GraphNode node
= (GraphNode
) selectedNode
;
96 if (node
.getX() * sdWidget
.getZoomFactor() < sdWidget
.getContentsX() + sdWidget
.getVisibleWidth() / 2) {
97 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() - sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
99 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() + sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
105 * Sets the active SD view.
107 * @param view The SD view.
109 public void setView(SDView view
) {