1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
;
15 import java
.util
.Iterator
;
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
.internal
.tmf
.ui
.ITmfImageConstants
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
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
.BaseMessage
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessage
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessageReturn
;
31 * Action Class implementation to move to selected message
37 public class MoveToMessage
extends Action
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
45 public final static String ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 * The sequence diagram view reference.
53 protected SDView fView
= null;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
61 public MoveToMessage() {
68 * @param view a sequence diagram view reference
70 public MoveToMessage(SDView view
) {
73 setActionDefinitionId(ID
);
74 setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SEARCH_MATCH
));
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
88 SDWidget sdWidget
= fView
.getSDWidget();
90 if (sdWidget
== null) {
94 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
95 ISelection sel
= selProvider
.getSelection();
96 Object selectedNode
= null;
97 Iterator
<Object
> it
= ((StructuredSelection
) sel
).iterator();
98 while (it
.hasNext()) {
99 Object node
= it
.next();
100 if (node
instanceof BaseMessage
) {
105 if (selectedNode
== null) {
109 if (selectedNode
instanceof SyncMessageReturn
) {
110 GraphNode node
= ((SyncMessageReturn
) selectedNode
).getMessage();
111 sdWidget
.clearSelection();
112 sdWidget
.addSelection(node
);
113 sdWidget
.ensureVisible(node
);
114 // sdWidget.setFocusNode(node);
116 } else if (selectedNode
instanceof SyncMessage
) {
117 GraphNode node
= ((SyncMessage
) selectedNode
).getMessageReturn();
118 sdWidget
.clearSelection();
119 sdWidget
.addSelection(node
);
120 sdWidget
.ensureVisible(node
);
121 // sdWidget.setFocusNode(node);
127 * Sets the active SD view.
129 * @param view The SD view.
131 public void setView(SDView view
) {