1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
19 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
20 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDWidget
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
27 * Action class implementation to show end of a graph node.
32 public class ShowNodeStart
extends BaseSDAction
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
41 public ShowNodeStart() {
49 * The sequence diagram view reference
52 public ShowNodeStart(SDView view
) {
54 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NODE_START
));
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
63 if (getView() == null) {
67 SDWidget sdWidget
= getView().getSDWidget();
69 if (sdWidget
== null) {
73 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
74 ISelection sel
= selProvider
.getSelection();
75 Object selectedNode
= null;
76 Iterator
<Object
> it
= ((StructuredSelection
) sel
).iterator();
77 while (it
.hasNext()) {
78 selectedNode
= it
.next();
80 if (selectedNode
!= null) {
81 GraphNode node
= (GraphNode
) selectedNode
;
82 if (node
.getX() * sdWidget
.getZoomFactor() < sdWidget
.getContentsX() + sdWidget
.getVisibleWidth() / 2) {
83 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() - sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));
85 sdWidget
.ensureVisible(Math
.round(node
.getX() * sdWidget
.getZoomFactor() + sdWidget
.getVisibleWidth() / (float) 2), Math
.round(node
.getY() * sdWidget
.getZoomFactor()));