1 /**********************************************************************
2 * Copyright (c) 2005, 2008, 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: MoveToMessage.java,v 1.3 2008/01/24 02:28:52 apnan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
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
.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
.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
;
34 public class MoveToMessage
extends Action
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
39 public final static String ID
= "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$
41 protected SDView fView
= null;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
46 public MoveToMessage() {
50 public MoveToMessage(SDView view
) {
53 setActionDefinitionId(ID
);
54 setImageDescriptor(TmfUiPlugin
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SEARCH_MATCH
));
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
64 * @see org.eclipse.jface.action.Action#run()
72 SDWidget sdWidget
= fView
.getSDWidget();
74 if (sdWidget
== null) {
78 ISelectionProvider selProvider
= sdWidget
.getSelectionProvider();
79 ISelection sel
= selProvider
.getSelection();
80 Object selectedNode
= null;
81 @SuppressWarnings("unchecked")
82 Iterator
<Object
> it
= ((StructuredSelection
) sel
).iterator();
83 while (it
.hasNext()) {
84 Object node
= it
.next();
85 if (node
instanceof BaseMessage
) {
89 if (selectedNode
== null)
92 if (selectedNode
instanceof SyncMessageReturn
) {
93 GraphNode node
= ((SyncMessageReturn
) selectedNode
).getMessage();
94 sdWidget
.clearSelection();
95 sdWidget
.addSelection(node
);
96 sdWidget
.ensureVisible(node
);
97 // sdWidget.setFocusNode(node);
99 } else if (selectedNode
instanceof SyncMessage
) {
100 GraphNode node
= ((SyncMessage
) selectedNode
).getMessageReturn();
101 sdWidget
.clearSelection();
102 sdWidget
.addSelection(node
);
103 sdWidget
.ensureVisible(node
);
104 // sdWidget.setFocusNode(node);
110 * Sets the active SD view.
111 * @param view The SD view.
113 public void setView(SDView view
) {