Internalize some TMF APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / ShowNodeEnd.java
CommitLineData
73005152
BH
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: ShowNodeEnd.java,v 1.3 2006/09/20 20:56:26 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
14
15import java.util.Iterator;
16
17import org.eclipse.jface.action.Action;
18import org.eclipse.jface.viewers.ISelection;
19import org.eclipse.jface.viewers.ISelectionProvider;
20import org.eclipse.jface.viewers.StructuredSelection;
21import org.eclipse.linuxtools.tmf.ui.ITmfImageConstants;
22import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
23import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
24import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
25import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
26import org.eclipse.ui.IViewPart;
27
28/**
29 * @author sveyrier
30 */
31public class ShowNodeEnd extends Action {
32
33 // ------------------------------------------------------------------------
34 // Attributes
35 // ------------------------------------------------------------------------
36 protected SDView fView = null;
37
38 // ------------------------------------------------------------------------
39 // Constructors
40 // ------------------------------------------------------------------------
41 public ShowNodeEnd() {
42 this(null);
43 }
44
45 public ShowNodeEnd(IViewPart _view) {
46 super();
47 if (_view instanceof SDView) {
48 fView = (SDView)_view;
49 }
50 setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_END));
51 }
52
53 // ------------------------------------------------------------------------
54 // Operations
55 // ------------------------------------------------------------------------
56 /*
57 * (non-Javadoc)
58 * @see org.eclipse.jface.action.Action#run()
59 */
60 @Override
61 @SuppressWarnings("rawtypes")
62 public void run() {
63 if (fView == null)
64 return;
65
66 SDWidget sdWidget = fView.getSDWidget();
67
68 if (sdWidget == null) {
69 return;
70 }
71
72 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
73 ISelection sel = selProvider.getSelection();
74 Object selectedNode = null;
75 Iterator it = ((StructuredSelection) sel).iterator();
76 while (it.hasNext())
77 selectedNode = it.next();
78 if (selectedNode != null) {
79 GraphNode node = (GraphNode) selectedNode;
80 if ((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() < sdWidget.getContentsX() + sdWidget.getVisibleWidth() / 2)
81 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor()) - sdWidget.getVisibleWidth() / 2, Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
82 else
83 sdWidget.ensureVisible(Math.round((node.getX() + node.getWidth()) * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round((node.getY() + node.getHeight()) * sdWidget.getZoomFactor()));
84 }
85 }
86
87 public void setView(SDView view) {
88 fView = view;
89 }
90}
This page took 0.029795 seconds and 5 git commands to generate.