Java Doc and API clean up of TMF UML Sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / KeyBindingsManager.java
CommitLineData
73005152 1/**********************************************************************
df0b8ff4 2 * Copyright (c) 2011, 2012 Ericsson
73005152
BH
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers;
13
14import java.util.HashSet;
15import java.util.List;
16import java.util.Set;
17import java.util.Vector;
18
19import org.eclipse.core.commands.AbstractHandler;
20import org.eclipse.core.commands.ExecutionEvent;
21import org.eclipse.core.commands.ExecutionException;
22import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
23import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
24import org.eclipse.ui.PlatformUI;
25import org.eclipse.ui.handlers.IHandlerActivation;
26import org.eclipse.ui.handlers.IHandlerService;
27
28/**
73005152
BH
29 * <p>
30 * Singleton class that manages key-bindings for certain commands across multiple sequence
31 * diagram view instances.
32 * </p>
df0b8ff4
BH
33 *
34 * @version 1.0
35 * @author Bernd Hufmann
36 *
73005152
BH
37 */
38public class KeyBindingsManager {
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
73005152 43
df0b8ff4
BH
44 /**
45 * The singleton instance.
46 */
47 private final static KeyBindingsManager fInstance = new KeyBindingsManager();
48 /**
49 * The list of view names.
50 */
73005152 51 private Set<String> fViews = new HashSet<String>();
df0b8ff4
BH
52 /**
53 * The list of activations Activations to store
54 */
73005152 55 private List<IHandlerActivation> fHandlerActivations = new Vector<IHandlerActivation>();
df0b8ff4
BH
56 /**
57 * The action reference for moving to a message in view.
58 */
73005152 59 private MoveToMessage fGoToMessageForKeyBinding;
df0b8ff4
BH
60 /**
61 * The action reference for opening the find dialog.
62 */
73005152 63 private OpenSDFindDialog fFindForKeyBinding;
df0b8ff4
BH
64 /**
65 * The action reference for moving up in view.
66 */
73005152 67 private MoveSDUp fMoveUpForKeyBinding;
df0b8ff4
BH
68 /**
69 * The action reference for moving down in view.
70 */
73005152 71 private MoveSDDown fMoveDownForKeyBinding;
df0b8ff4
BH
72 /**
73 * The action reference for moving left in view.
74 */
73005152 75 private MoveSDLeft fMoveLeftForKeyBinding;
df0b8ff4
BH
76 /**
77 * The action reference for moving right in view.
78 */
73005152 79 private MoveSDRight fMoveRightForKeyBinding;
df0b8ff4
BH
80 /**
81 * The action reference for showing node start.
82 */
73005152 83 private ShowNodeStart fShowNodeStartForKeyBinding;
df0b8ff4
BH
84 /**
85 * The action reference for showing node end.
86 */
73005152
BH
87 private ShowNodeEnd fShowNodeEndForKeyBinding;
88
89 // ------------------------------------------------------------------------
90 // Constructor
91 // ------------------------------------------------------------------------
df0b8ff4
BH
92
93 /**
94 * Private constructor
95 */
73005152
BH
96 private KeyBindingsManager() {
97 }
98
99 // ------------------------------------------------------------------------
df0b8ff4 100 // Methods
73005152 101 // ------------------------------------------------------------------------
df0b8ff4
BH
102 /**
103 * Returns the KeyBindingsManager singleton instance.
104 *
105 * @return the KeyBindingsManager singleton instance
106 */
107 public synchronized static KeyBindingsManager getInstance() {
73005152
BH
108 return fInstance;
109 }
110
111 /**
df0b8ff4
BH
112 * Adds a view list of managed view list.
113 *
73005152
BH
114 * @param viewId Id of SD view to add and to manage
115 */
116 public void add(String viewId) {
117
118 if (fViews.size() == 0) {
119 initialize();
120 }
121
122 if(!fViews.contains(viewId)) {
123 fViews.add(viewId);
124 }
125 }
126
127 /**
df0b8ff4
BH
128 * Removes a view from managed view list
129 *
73005152
BH
130 * @param viewId Id of SD view to remove
131 */
132 public void remove(String viewId) {
133 if (fViews.contains(viewId)) {
134 fViews.remove(viewId);
135 }
136 if (fViews.size() == 0) {
137 dispose();
138 }
139 }
140
df0b8ff4
BH
141 /*
142 * Initialized the KeyBindingsManager.
143 */
73005152
BH
144 private void initialize() {
145 fGoToMessageForKeyBinding = new MoveToMessage();
146 IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class);
147 AbstractHandler handler = new AbstractHandler() {
148 @Override
149 public Object execute(ExecutionEvent event) throws ExecutionException {
150 fGoToMessageForKeyBinding.run();
151 return null;
152 }
153 };
154 IHandlerActivation activation = service.activateHandler(fGoToMessageForKeyBinding.getActionDefinitionId(), handler);
155 fHandlerActivations.add(activation);
156
157 fMoveUpForKeyBinding = new MoveSDUp();
158 handler = new AbstractHandler() {
159 @Override
160 public Object execute(ExecutionEvent event) throws ExecutionException {
161 fMoveUpForKeyBinding.run();
162 return null;
163 }
164 };
165 activation = service.activateHandler(fMoveUpForKeyBinding.getActionDefinitionId(), handler);
166 fHandlerActivations.add(activation);
167
168 fMoveDownForKeyBinding = new MoveSDDown();
169 handler = new AbstractHandler() {
170 @Override
171 public Object execute(ExecutionEvent event) throws ExecutionException {
172 fMoveDownForKeyBinding.run();
173 return null;
174 }
175 };
176 activation = service.activateHandler(fMoveDownForKeyBinding.getActionDefinitionId(), handler);
177 fHandlerActivations.add(activation);
178
179 fMoveLeftForKeyBinding = new MoveSDLeft();
180 handler = new AbstractHandler() {
181 @Override
182 public Object execute(ExecutionEvent event) throws ExecutionException {
183 fMoveLeftForKeyBinding.run();
184 return null;
185 }
186 };
187 activation = service.activateHandler(fMoveLeftForKeyBinding.getActionDefinitionId(), handler);
188 fHandlerActivations.add(activation);
189
190 fMoveRightForKeyBinding = new MoveSDRight();
191 handler = new AbstractHandler() {
192 @Override
193 public Object execute(ExecutionEvent event) throws ExecutionException {
194 fMoveRightForKeyBinding.run();
195 return null;
196 }
197 };
198 activation = service.activateHandler(fMoveRightForKeyBinding.getActionDefinitionId(), handler);
199 fHandlerActivations.add(activation);
200
201 fFindForKeyBinding = new OpenSDFindDialog();
202 handler = new AbstractHandler() {
203 @Override
204 public Object execute(ExecutionEvent event) throws ExecutionException {
205 fFindForKeyBinding.run();
206 return null;
207 }
208 };
209 activation = service.activateHandler(fFindForKeyBinding.getActionDefinitionId(), handler);
210 fFindForKeyBinding.setEnabled(false);
211 fHandlerActivations.add(activation);
212
213 fShowNodeStartForKeyBinding = new ShowNodeStart();
214 fShowNodeStartForKeyBinding.setText(SDMessages.uml_25);
215
216 fShowNodeStartForKeyBinding.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
217 fShowNodeStartForKeyBinding.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
218
219 handler = new AbstractHandler() {
220 @Override
221 public Object execute(ExecutionEvent event) throws ExecutionException {
222 fShowNodeStartForKeyBinding.run();
223 return null;
224 }
225 };
226 activation = service.activateHandler(fShowNodeStartForKeyBinding.getActionDefinitionId(), handler);
227 fHandlerActivations.add(activation);
228
229 fShowNodeEndForKeyBinding = new ShowNodeEnd();
230 fShowNodeEndForKeyBinding.setText(SDMessages.uml_23);
231 fShowNodeEndForKeyBinding.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
232 fShowNodeEndForKeyBinding.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
233
234 handler = new AbstractHandler() {
235 @Override
236 public Object execute(ExecutionEvent event) throws ExecutionException {
237 fShowNodeEndForKeyBinding.run();
238 return null;
239 }
240 };
241 activation = service.activateHandler(fShowNodeEndForKeyBinding.getActionDefinitionId(), handler);
242 fHandlerActivations.add(activation);
243
244 }
245
df0b8ff4
BH
246 /*
247 * Disposes the KeyBindingsManager
248 */
73005152
BH
249 private void dispose() {
250 IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class);
251 for(IHandlerActivation activation : fHandlerActivations) {
252 service.deactivateHandler(activation);
253 }
254
255 fGoToMessageForKeyBinding = null;
256 fFindForKeyBinding = null;
257 fMoveUpForKeyBinding = null;
258 fMoveDownForKeyBinding = null;
259 fMoveLeftForKeyBinding = null;
260 fMoveRightForKeyBinding = null;
261 fShowNodeStartForKeyBinding = null;
262 fShowNodeEndForKeyBinding = null;
263 }
264
265 /**
df0b8ff4
BH
266 * Set the view in all supported actions
267 *
73005152
BH
268 * @param view to set in global actions
269 */
270 public void setSdView(SDView view) {
271 if (fViews.size() > 0) {
272 fGoToMessageForKeyBinding.setView(view);
273 fFindForKeyBinding.setView(view);
274 fMoveUpForKeyBinding.setView(view);
275 fMoveDownForKeyBinding.setView(view);
276 fMoveLeftForKeyBinding.setView(view);
277 fMoveRightForKeyBinding.setView(view);
278 fShowNodeStartForKeyBinding.setView(view);
279 fShowNodeEndForKeyBinding.setView(view);
280 }
281 }
282
283 /**
284 * Enable / disable find action
df0b8ff4
BH
285 *
286 * @param enabled <code>true</code> for enabling else <code>false</code>
73005152
BH
287 */
288 public void setFindEnabled(boolean enabled) {
289 if (fFindForKeyBinding != null) {
290 fFindForKeyBinding.setEnabled(enabled);
291 }
292 }
293}
This page took 0.03829 seconds and 5 git commands to generate.