tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / MoveToMessage.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2012 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
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
14
15import java.util.Iterator;
16
17import org.eclipse.jface.action.Action;
18import org.eclipse.jface.viewers.ISelection;
19import org.eclipse.jface.viewers.ISelectionProvider;
20import org.eclipse.jface.viewers.StructuredSelection;
d34665f9 21import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
8fd82db5 22import org.eclipse.linuxtools.internal.tmf.ui.Activator;
73005152
BH
23import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
24import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
25import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage;
26import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
27import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage;
28import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessageReturn;
29
30/**
df0b8ff4 31 * Action Class implementation to move to selected message
64636df8 32 *
df0b8ff4 33 * @version 1.0
73005152 34 * @author sveyrier
64636df8 35 *
73005152
BH
36 */
37public class MoveToMessage extends Action {
38
39 // ------------------------------------------------------------------------
df0b8ff4 40 // Constants
73005152 41 // ------------------------------------------------------------------------
df0b8ff4
BH
42 /**
43 * The action ID.
44 */
73005152 45 public final static String ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$
df0b8ff4
BH
46
47 // ------------------------------------------------------------------------
48 // Attributes
49 // ------------------------------------------------------------------------
50 /**
51 * The sequence diagram view reference.
52 */
73005152
BH
53 protected SDView fView = null;
54
55 // ------------------------------------------------------------------------
56 // Constructors
57 // ------------------------------------------------------------------------
df0b8ff4
BH
58 /**
59 * Default Constructor
60 */
73005152
BH
61 public MoveToMessage() {
62 this(null);
63 }
64636df8 64
df0b8ff4
BH
65 /**
66 * Constructor
64636df8 67 *
df0b8ff4
BH
68 * @param view a sequence diagram view reference
69 */
73005152
BH
70 public MoveToMessage(SDView view) {
71 super();
72 setId(ID);
73 setActionDefinitionId(ID);
8fd82db5 74 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_MATCH));
73005152
BH
75 fView = view;
76 }
77
78 // ------------------------------------------------------------------------
df0b8ff4 79 // Methods
73005152
BH
80 // ------------------------------------------------------------------------
81
82 /*
83 * (non-Javadoc)
84 * @see org.eclipse.jface.action.Action#run()
85 */
86 @Override
87 public void run() {
88 if (fView == null) {
89 return;
90 }
91
92 SDWidget sdWidget = fView.getSDWidget();
93
94 if (sdWidget == null) {
95 return;
96 }
97
98 ISelectionProvider selProvider = sdWidget.getSelectionProvider();
99 ISelection sel = selProvider.getSelection();
100 Object selectedNode = null;
73005152
BH
101 Iterator<Object> it = ((StructuredSelection) sel).iterator();
102 while (it.hasNext()) {
103 Object node = it.next();
104 if (node instanceof BaseMessage) {
105 selectedNode = node;
106 }
107 }
df0b8ff4
BH
108
109 if (selectedNode == null) {
73005152 110 return;
df0b8ff4 111 }
73005152
BH
112
113 if (selectedNode instanceof SyncMessageReturn) {
114 GraphNode node = ((SyncMessageReturn) selectedNode).getMessage();
115 sdWidget.clearSelection();
116 sdWidget.addSelection(node);
117 sdWidget.ensureVisible(node);
118 // sdWidget.setFocusNode(node);
119 sdWidget.redraw();
120 } else if (selectedNode instanceof SyncMessage) {
121 GraphNode node = ((SyncMessage) selectedNode).getMessageReturn();
122 sdWidget.clearSelection();
123 sdWidget.addSelection(node);
124 sdWidget.ensureVisible(node);
125 // sdWidget.setFocusNode(node);
126 sdWidget.redraw();
127 }
128 }
129
130 /**
131 * Sets the active SD view.
64636df8 132 *
73005152
BH
133 * @param view The SD view.
134 */
135 public void setView(SDView view) {
136 fView = view;
137 }
138}
This page took 0.039341 seconds and 5 git commands to generate.