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: 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 | **********************************************************************/ | |
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; | |
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; | |
27 | ||
28 | /** | |
29 | * @author sveyrier | |
30 | */ | |
31 | public 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 | } |