Commit | Line | Data |
---|---|---|
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: ShowNodeStart.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 | **********************************************************************/ | |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers; | |
14 | ||
15 | import java.util.Iterator; | |
16 | ||
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; | |
d34665f9 FC |
21 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
22 | import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; | |
73005152 BH |
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; | |
27 | ||
28 | /** | |
29 | * @author sveyrier | |
30 | */ | |
31 | public class ShowNodeStart extends Action { | |
32 | ||
33 | // ------------------------------------------------------------------------ | |
34 | // Attributes | |
35 | // ------------------------------------------------------------------------ | |
36 | protected SDView fView = null; | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Constructors | |
40 | // ------------------------------------------------------------------------ | |
41 | public ShowNodeStart() { | |
42 | this(null); | |
43 | } | |
44 | ||
45 | public ShowNodeStart(IViewPart _view) { | |
46 | super(); | |
47 | if (_view instanceof SDView) { | |
48 | fView = (SDView)_view; | |
49 | } | |
50 | setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NODE_START)); | |
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 | SDWidget sdWidget = fView.getSDWidget(); | |
66 | ||
67 | if (sdWidget == null) { | |
68 | return; | |
69 | } | |
70 | ||
71 | ISelectionProvider selProvider = sdWidget.getSelectionProvider(); | |
72 | ISelection sel = selProvider.getSelection(); | |
73 | Object selectedNode = null; | |
74 | Iterator it = ((StructuredSelection) sel).iterator(); | |
75 | while (it.hasNext()) | |
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())); | |
81 | else | |
82 | sdWidget.ensureVisible(Math.round(node.getX() * sdWidget.getZoomFactor() + sdWidget.getVisibleWidth() / (float) 2), Math.round(node.getY() * sdWidget.getZoomFactor())); | |
83 | } | |
84 | } | |
85 | ||
86 | public void setView(SDView view) { | |
87 | fView = view; | |
88 | } | |
89 | } |