1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
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
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
;
16 import java
.util
.Iterator
;
18 import org
.eclipse
.jface
.action
.Action
;
19 import org
.eclipse
.jface
.viewers
.ISelection
;
20 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDWidget
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
27 import org
.eclipse
.ui
.IViewPart
;
30 * Action class implementation to show end of a graph node.
35 public class ShowNodeStart
extends Action
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 * The sequence diagram view reference
43 protected SDView fView
= null;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
51 public ShowNodeStart() {
58 * @param view The sequence diagram view reference
60 public ShowNodeStart(IViewPart view
) {
62 if (view
instanceof SDView
) {
65 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NODE_START
));
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * @see org.eclipse.jface.action.Action#run()
76 @SuppressWarnings("rawtypes")
82 SDWidget sdWidget
= fView
.getSDWidget();
84 if (sdWidget
== null) {
88 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
89 ISelection sel
= selProvider
.getSelection();
90 Object selectedNode
= null;
91 Iterator it
= ((StructuredSelection
) sel
).iterator();
92 while (it
.hasNext()) {
93 selectedNode
= it
.next();
95 if (selectedNode
!= null) {
96 GraphNode node
= (GraphNode
) selectedNode
;
97 if (node
.getX() * sdWidget
.getZoomFactor() < sdWidget
.getContentsX() + sdWidget
.getVisibleWidth() / 2) {
98 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() - sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
100 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() + sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
106 * Sets the active SD view.
108 * @param view The SD view.
110 public void setView(SDView view
) {