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
1 /**********************************************************************
2 * Copyright (c) 2005, 2012 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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
14
15 import java.util.Iterator;
16
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;
29
30 /**
31 * Action Class implementation to move to selected message
32 *
33 * @version 1.0
34 * @author sveyrier
35 *
36 */
37 public class MoveToMessage extends Action {
38
39 // ------------------------------------------------------------------------
40 // Constants
41 // ------------------------------------------------------------------------
42 /**
43 * The action ID.
44 */
45 public final static String ID = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.GoToMessage"; //$NON-NLS-1$
46
47 // ------------------------------------------------------------------------
48 // Attributes
49 // ------------------------------------------------------------------------
50 /**
51 * The sequence diagram view reference.
52 */
53 protected SDView fView = null;
54
55 // ------------------------------------------------------------------------
56 // Constructors
57 // ------------------------------------------------------------------------
58 /**
59 * Default Constructor
60 */
61 public MoveToMessage() {
62 this(null);
63 }
64
65 /**
66 * Constructor
67 *
68 * @param view a sequence diagram view reference
69 */
70 public MoveToMessage(SDView view) {
71 super();
72 setId(ID);
73 setActionDefinitionId(ID);
74 setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_MATCH));
75 fView = view;
76 }
77
78 // ------------------------------------------------------------------------
79 // Methods
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;
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 }
108
109 if (selectedNode == null) {
110 return;
111 }
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.
132 *
133 * @param view The SD view.
134 */
135 public void setView(SDView view) {
136 fView = view;
137 }
138 }
This page took 0.046926 seconds and 5 git commands to generate.