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 ShowNodeEnd
extends BaseSDAction
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
40 public ShowNodeEnd() {
47 * @param view The sequence diagram view reference
50 public ShowNodeEnd(SDView view
) {
52 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NODE_END
));
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 @SuppressWarnings("rawtypes")
62 if (getView() == null) {
66 SDWidget sdWidget
= getView().getSDWidget();
68 if (sdWidget
== null) {
72 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
73 ISelection sel
= selProvider
.getSelection();
74 Object selectedNode
= null;
76 Iterator it
= ((StructuredSelection
) sel
).iterator();
77 while (it
.hasNext()) {
78 selectedNode
= it
.next();
81 if (selectedNode
!= null) {
82 GraphNode node
= (GraphNode
) selectedNode
;
83 if ((node
.getX() + node
.getWidth()) * sdWidget
.getZoomFactor() < sdWidget
.getContentsX() + sdWidget
.getVisibleWidth() / 2) {
84 sdWidget
.ensureVisible(Math
.round((node
.getX() + node
.getWidth()) * sdWidget
.getZoomFactor()) - sdWidget
.getVisibleWidth() / 2, Math
.round((node
.getY() + node
.getHeight()) * sdWidget
.getZoomFactor()));
86 sdWidget
.ensureVisible(Math
.round((node
.getX() + node
.getWidth()) * sdWidget
.getZoomFactor() + sdWidget
.getVisibleWidth() / (float) 2), Math
.round((node
.getY() + node
.getHeight()) * sdWidget
.getZoomFactor()));