1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
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
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
;
16 import java
.util
.Iterator
;
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
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
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
;
32 * Action Class implementation to move to selected message
38 public class MoveToMessage
extends Action
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
46 public final static String ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * The sequence diagram view reference.
54 protected SDView fView
= null;
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
62 public MoveToMessage() {
69 * @param view a sequence diagram view reference
71 public MoveToMessage(SDView view
) {
74 setActionDefinitionId(ID
);
75 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SEARCH_MATCH
));
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
85 * @see org.eclipse.jface.action.Action#run()
93 SDWidget sdWidget
= fView
.getSDWidget();
95 if (sdWidget
== null) {
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
) {
111 if (selectedNode
== null) {
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);
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);
133 * Sets the active SD view.
135 * @param view The SD view.
137 public void setView(SDView view
) {