Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
64636df8 | 4 | * |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
64636df8 BH |
9 | * |
10 | * Contributors: | |
73005152 BH |
11 | * IBM - Initial API and implementation |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers; | |
15 | ||
16 | import java.util.Iterator; | |
17 | ||
18 | import org.eclipse.jface.action.Action; | |
19 | import org.eclipse.jface.viewers.ISelection; | |
20 | import org.eclipse.jface.viewers.ISelectionProvider; | |
21 | import org.eclipse.jface.viewers.StructuredSelection; | |
d34665f9 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
8fd82db5 | 23 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
73005152 BH |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView; |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; | |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
28 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
29 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessageReturn; | |
30 | ||
31 | /** | |
df0b8ff4 | 32 | * Action Class implementation to move to selected message |
64636df8 | 33 | * |
df0b8ff4 | 34 | * @version 1.0 |
73005152 | 35 | * @author sveyrier |
64636df8 | 36 | * |
73005152 BH |
37 | */ |
38 | public class MoveToMessage extends Action { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
df0b8ff4 | 41 | // Constants |
73005152 | 42 | // ------------------------------------------------------------------------ |
df0b8ff4 BH |
43 | /** |
44 | * The action ID. | |
45 | */ | |
73005152 | 46 | public final static String ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$ |
df0b8ff4 BH |
47 | |
48 | // ------------------------------------------------------------------------ | |
49 | // Attributes | |
50 | // ------------------------------------------------------------------------ | |
51 | /** | |
52 | * The sequence diagram view reference. | |
53 | */ | |
73005152 BH |
54 | protected SDView fView = null; |
55 | ||
56 | // ------------------------------------------------------------------------ | |
57 | // Constructors | |
58 | // ------------------------------------------------------------------------ | |
df0b8ff4 BH |
59 | /** |
60 | * Default Constructor | |
61 | */ | |
73005152 BH |
62 | public MoveToMessage() { |
63 | this(null); | |
64 | } | |
64636df8 | 65 | |
df0b8ff4 BH |
66 | /** |
67 | * Constructor | |
64636df8 | 68 | * |
df0b8ff4 BH |
69 | * @param view a sequence diagram view reference |
70 | */ | |
73005152 BH |
71 | public MoveToMessage(SDView view) { |
72 | super(); | |
73 | setId(ID); | |
74 | setActionDefinitionId(ID); | |
8fd82db5 | 75 | setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_MATCH)); |
73005152 BH |
76 | fView = view; |
77 | } | |
78 | ||
79 | // ------------------------------------------------------------------------ | |
df0b8ff4 | 80 | // Methods |
73005152 BH |
81 | // ------------------------------------------------------------------------ |
82 | ||
83 | /* | |
84 | * (non-Javadoc) | |
85 | * @see org.eclipse.jface.action.Action#run() | |
86 | */ | |
87 | @Override | |
88 | public void run() { | |
89 | if (fView == null) { | |
90 | return; | |
91 | } | |
92 | ||
93 | SDWidget sdWidget = fView.getSDWidget(); | |
94 | ||
95 | if (sdWidget == null) { | |
96 | return; | |
97 | } | |
98 | ||
99 | ISelectionProvider selProvider = sdWidget.getSelectionProvider(); | |
100 | ISelection sel = selProvider.getSelection(); | |
101 | Object selectedNode = null; | |
73005152 BH |
102 | Iterator<Object> it = ((StructuredSelection) sel).iterator(); |
103 | while (it.hasNext()) { | |
104 | Object node = it.next(); | |
105 | if (node instanceof BaseMessage) { | |
106 | selectedNode = node; | |
107 | } | |
108 | } | |
df0b8ff4 BH |
109 | |
110 | if (selectedNode == null) { | |
73005152 | 111 | return; |
df0b8ff4 | 112 | } |
73005152 BH |
113 | |
114 | if (selectedNode instanceof SyncMessageReturn) { | |
115 | GraphNode node = ((SyncMessageReturn) selectedNode).getMessage(); | |
116 | sdWidget.clearSelection(); | |
117 | sdWidget.addSelection(node); | |
118 | sdWidget.ensureVisible(node); | |
119 | // sdWidget.setFocusNode(node); | |
120 | sdWidget.redraw(); | |
121 | } else if (selectedNode instanceof SyncMessage) { | |
122 | GraphNode node = ((SyncMessage) selectedNode).getMessageReturn(); | |
123 | sdWidget.clearSelection(); | |
124 | sdWidget.addSelection(node); | |
125 | sdWidget.ensureVisible(node); | |
126 | // sdWidget.setFocusNode(node); | |
127 | sdWidget.redraw(); | |
128 | } | |
129 | } | |
130 | ||
131 | /** | |
132 | * Sets the active SD view. | |
64636df8 | 133 | * |
73005152 BH |
134 | * @param view The SD view. |
135 | */ | |
136 | public void setView(SDView view) { | |
137 | fView = view; | |
138 | } | |
139 | } |