1 /**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
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 * $Id: ShowNodeStart.java,v 1.3 2006/09/20 20:56:26 ewchan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
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
.tmf
.ui
.ITmfImageConstants
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
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
;
31 public class ShowNodeStart
extends Action
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
36 protected SDView fView
= null;
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
41 public ShowNodeStart() {
45 public ShowNodeStart(IViewPart _view
) {
47 if (_view
instanceof SDView
) {
48 fView
= (SDView
)_view
;
50 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NODE_START
));
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * @see org.eclipse.jface.action.Action#run()
61 @SuppressWarnings("rawtypes")
65 SDWidget sdWidget
= fView
.getSDWidget();
67 if (sdWidget
== null) {
71 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
72 ISelection sel
= selProvider
.getSelection();
73 Object selectedNode
= null;
74 Iterator it
= ((StructuredSelection
) sel
).iterator();
76 selectedNode
= it
.next();
77 if (selectedNode
!= null) {
78 GraphNode node
= (GraphNode
) selectedNode
;
79 if (node
.getX() * sdWidget
.getZoomFactor() < sdWidget
.getContentsX() + sdWidget
.getVisibleWidth() / 2)
80 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() - sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
82 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() + sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
86 public void setView(SDView view
) {