Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
73005152 BH |
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 | |
64636df8 BH |
7 | * |
8 | * Contributors: | |
c8422608 AM |
9 | * IBM - Initial API and implementation |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers; |
14 | ||
15 | import java.util.Iterator; | |
16 | ||
73005152 BH |
17 | import org.eclipse.jface.viewers.ISelection; |
18 | import org.eclipse.jface.viewers.ISelectionProvider; | |
19 | import org.eclipse.jface.viewers.StructuredSelection; | |
8fd82db5 | 20 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
cab6c8ff | 21 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
73005152 BH |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView; |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage; | |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessageReturn; | |
28 | ||
29 | /** | |
df0b8ff4 | 30 | * Action Class implementation to move to selected message |
64636df8 | 31 | * |
df0b8ff4 | 32 | * @version 1.0 |
73005152 | 33 | * @author sveyrier |
64636df8 | 34 | * |
73005152 | 35 | */ |
cab6c8ff | 36 | public class MoveToMessage extends BaseSDAction { |
73005152 BH |
37 | |
38 | // ------------------------------------------------------------------------ | |
df0b8ff4 | 39 | // Constants |
73005152 | 40 | // ------------------------------------------------------------------------ |
df0b8ff4 BH |
41 | /** |
42 | * The action ID. | |
43 | */ | |
73005152 | 44 | public final static String ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$ |
df0b8ff4 | 45 | |
73005152 BH |
46 | // ------------------------------------------------------------------------ |
47 | // Constructors | |
48 | // ------------------------------------------------------------------------ | |
df0b8ff4 BH |
49 | /** |
50 | * Default Constructor | |
51 | */ | |
73005152 BH |
52 | public MoveToMessage() { |
53 | this(null); | |
54 | } | |
64636df8 | 55 | |
df0b8ff4 BH |
56 | /** |
57 | * Constructor | |
64636df8 | 58 | * |
df0b8ff4 BH |
59 | * @param view a sequence diagram view reference |
60 | */ | |
73005152 | 61 | public MoveToMessage(SDView view) { |
cab6c8ff | 62 | super(view); |
73005152 BH |
63 | setId(ID); |
64 | setActionDefinitionId(ID); | |
8fd82db5 | 65 | setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_MATCH)); |
73005152 BH |
66 | } |
67 | ||
68 | // ------------------------------------------------------------------------ | |
df0b8ff4 | 69 | // Methods |
73005152 BH |
70 | // ------------------------------------------------------------------------ |
71 | ||
73005152 BH |
72 | @Override |
73 | public void run() { | |
cab6c8ff | 74 | if (getView() == null) { |
73005152 BH |
75 | return; |
76 | } | |
77 | ||
cab6c8ff | 78 | SDWidget sdWidget = getView().getSDWidget(); |
73005152 BH |
79 | |
80 | if (sdWidget == null) { | |
81 | return; | |
82 | } | |
83 | ||
84 | ISelectionProvider selProvider = sdWidget.getSelectionProvider(); | |
85 | ISelection sel = selProvider.getSelection(); | |
86 | Object selectedNode = null; | |
73005152 BH |
87 | Iterator<Object> it = ((StructuredSelection) sel).iterator(); |
88 | while (it.hasNext()) { | |
89 | Object node = it.next(); | |
90 | if (node instanceof BaseMessage) { | |
91 | selectedNode = node; | |
92 | } | |
93 | } | |
df0b8ff4 BH |
94 | |
95 | if (selectedNode == null) { | |
73005152 | 96 | return; |
df0b8ff4 | 97 | } |
73005152 BH |
98 | |
99 | if (selectedNode instanceof SyncMessageReturn) { | |
100 | GraphNode node = ((SyncMessageReturn) selectedNode).getMessage(); | |
101 | sdWidget.clearSelection(); | |
102 | sdWidget.addSelection(node); | |
103 | sdWidget.ensureVisible(node); | |
73005152 BH |
104 | sdWidget.redraw(); |
105 | } else if (selectedNode instanceof SyncMessage) { | |
106 | GraphNode node = ((SyncMessage) selectedNode).getMessageReturn(); | |
107 | sdWidget.clearSelection(); | |
108 | sdWidget.addSelection(node); | |
109 | sdWidget.ensureVisible(node); | |
73005152 BH |
110 | sdWidget.redraw(); |
111 | } | |
112 | } | |
73005152 | 113 | } |