Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
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 | |
73005152 BH |
9 | * |
10 | * Contributors: | |
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 BH |
32 | * Action Class implementation to move to selected message |
33 | * | |
34 | * @version 1.0 | |
73005152 BH |
35 | * @author sveyrier |
36 | * | |
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 | } | |
65 | ||
df0b8ff4 BH |
66 | /** |
67 | * Constructor | |
68 | * | |
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; | |
102 | @SuppressWarnings("unchecked") | |
103 | Iterator<Object> it = ((StructuredSelection) sel).iterator(); | |
104 | while (it.hasNext()) { | |
105 | Object node = it.next(); | |
106 | if (node instanceof BaseMessage) { | |
107 | selectedNode = node; | |
108 | } | |
109 | } | |
df0b8ff4 BH |
110 | |
111 | if (selectedNode == null) { | |
73005152 | 112 | return; |
df0b8ff4 | 113 | } |
73005152 BH |
114 | |
115 | if (selectedNode instanceof SyncMessageReturn) { | |
116 | GraphNode node = ((SyncMessageReturn) selectedNode).getMessage(); | |
117 | sdWidget.clearSelection(); | |
118 | sdWidget.addSelection(node); | |
119 | sdWidget.ensureVisible(node); | |
120 | // sdWidget.setFocusNode(node); | |
121 | sdWidget.redraw(); | |
122 | } else if (selectedNode instanceof SyncMessage) { | |
123 | GraphNode node = ((SyncMessage) selectedNode).getMessageReturn(); | |
124 | sdWidget.clearSelection(); | |
125 | sdWidget.addSelection(node); | |
126 | sdWidget.ensureVisible(node); | |
127 | // sdWidget.setFocusNode(node); | |
128 | sdWidget.redraw(); | |
129 | } | |
130 | } | |
131 | ||
132 | /** | |
133 | * Sets the active SD view. | |
df0b8ff4 | 134 | * |
73005152 BH |
135 | * @param view The SD view. |
136 | */ | |
137 | public void setView(SDView view) { | |
138 | fView = view; | |
139 | } | |
140 | } |