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 | |
a55887ca AM |
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; |
14 | ||
15 | import java.util.Iterator; | |
16 | ||
17 | import org.eclipse.jface.action.Action; | |
18 | import org.eclipse.jface.action.ActionContributionItem; | |
19 | import org.eclipse.jface.action.IAction; | |
20 | import org.eclipse.jface.action.IContributionItem; | |
21 | import org.eclipse.jface.action.IMenuListener; | |
22 | import org.eclipse.jface.action.IMenuManager; | |
23 | import org.eclipse.jface.action.IToolBarManager; | |
24 | import org.eclipse.jface.action.MenuManager; | |
25 | import org.eclipse.jface.action.Separator; | |
26 | import org.eclipse.jface.viewers.ISelection; | |
27 | import org.eclipse.jface.viewers.ISelectionProvider; | |
28 | import org.eclipse.jface.viewers.StructuredSelection; | |
8fd82db5 | 29 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
a55887ca | 30 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; |
73005152 BH |
31 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage; |
32 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame; | |
33 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
34 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
35 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessageReturn; | |
36 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax; | |
37 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.FirstPage; | |
38 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.KeyBindingsManager; | |
39 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.LastPage; | |
40 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveToMessage; | |
41 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NextPage; | |
42 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.OpenSDFiltersDialog; | |
43 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.OpenSDFindDialog; | |
44 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.OpenSDPagesDialog; | |
45 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.PrevPage; | |
46 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.Print; | |
47 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd; | |
48 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart; | |
49 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.Zoom; | |
50 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.Zoom.ZoomType; | |
51 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.IExtendedFilterProvider; | |
52 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.IExtendedFindProvider; | |
73005152 BH |
53 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider; |
54 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDCollapseProvider; | |
55 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDExtendedActionBarProvider; | |
56 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider; | |
57 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider; | |
8a95ce5a | 58 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter; |
73005152 BH |
59 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider; |
60 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPropertiesProvider; | |
61 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader; | |
62 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.LoadersManager; | |
92330441 | 63 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages; |
73005152 BH |
64 | import org.eclipse.swt.SWT; |
65 | import org.eclipse.swt.graphics.Cursor; | |
66 | import org.eclipse.swt.layout.GridData; | |
67 | import org.eclipse.swt.layout.GridLayout; | |
68 | import org.eclipse.swt.widgets.Composite; | |
69 | import org.eclipse.swt.widgets.Menu; | |
70 | import org.eclipse.ui.IActionBars; | |
71 | import org.eclipse.ui.IViewReference; | |
72 | import org.eclipse.ui.IWorkbenchPage; | |
73 | import org.eclipse.ui.PlatformUI; | |
74 | import org.eclipse.ui.actions.ActionFactory; | |
75 | import org.eclipse.ui.part.ViewPart; | |
ebf38fcc | 76 | import org.eclipse.ui.views.properties.IPropertySheetPage; |
73005152 BH |
77 | |
78 | /** | |
df0b8ff4 BH |
79 | * <p> |
80 | * This class is a generic sequence diagram view implementation. | |
81 | * </p> | |
82 | ||
a55887ca | 83 | * @version 1.0 |
73005152 | 84 | * @author sveyrier |
73005152 BH |
85 | */ |
86 | public class SDView extends ViewPart { | |
87 | ||
cab6c8ff BH |
88 | // ------------------------------------------------------------------------ |
89 | // Constants | |
90 | // ------------------------------------------------------------------------ | |
91 | /** | |
92 | * Name of menu separator for view modes | |
93 | * @since 2.0 | |
94 | */ | |
95 | public final static String UML2SD_VIEW_MODES_SEPARATOR = "UML2SD_VIEW_MODES"; //$NON-NLS-1$ | |
96 | /** | |
97 | * Name of menu separator for working set | |
98 | * @since 2.0 | |
99 | */ | |
100 | public final static String UML2SD_WORKING_SET_SEPARATOR = "UML2SD_WORKING_SET"; //$NON-NLS-1$ | |
101 | /** | |
102 | * Name of menu separator for sorting | |
103 | * @since 2.0 | |
104 | */ | |
105 | public final static String UML2SD_SORTING_SEPARATOR = "UML2SD_SORTING"; //$NON-NLS-1$ | |
106 | /** | |
107 | * Name of menu separator for filtering | |
108 | * @since 2.0 | |
109 | */ | |
110 | public final static String UML2SD_FILTERING_SEPARATOR = "UML2SD_FILTERING"; //$NON-NLS-1$ | |
111 | /** | |
112 | * Name of menu separator for view layout | |
113 | * @since 2.0 | |
114 | */ | |
115 | public final static String UML2SD_VIEW_LAYOUT_SEPARATOR = "UML2SD_VIEW_LAYOUT"; //$NON-NLS-1$ | |
116 | /** | |
117 | * Name of menu separator for link editor | |
118 | * @since 2.0 | |
119 | */ | |
120 | public final static String UML2SD_LINK_EDITOR_SEPARATOR = "UML2SD_LINK_EDITOR"; //$NON-NLS-1$ | |
121 | /** | |
122 | * Name of menu separator for other commands | |
123 | * @since 2.0 | |
124 | */ | |
125 | public final static String UML2SD_OTHER_COMMANDS_SEPARATOR = "UML2SD_OTHER_COMMANDS"; //$NON-NLS-1$ | |
126 | /** | |
127 | * Name of menu separator for other plug-in commands | |
128 | * @since 2.0 | |
129 | */ | |
130 | public final static String UML2SD_OTHER_PLUGINS_COMMANDS_SEPARATOR = "UML2SD_OTHER_PLUGINS_COMMANDS"; //$NON-NLS-1$ | |
131 | ||
df0b8ff4 BH |
132 | // ------------------------------------------------------------------------ |
133 | // Attributes | |
134 | // ------------------------------------------------------------------------ | |
135 | /** | |
136 | * The sequence diagram widget. | |
137 | */ | |
cab6c8ff | 138 | private SDWidget fSdWidget = null; |
df0b8ff4 BH |
139 | /** |
140 | * The time compression bar. | |
141 | */ | |
cab6c8ff | 142 | private TimeCompressionBar fTimeCompressionBar = null; |
df0b8ff4 BH |
143 | /** |
144 | * The sequence diagram find provider implementation. | |
145 | */ | |
cab6c8ff | 146 | private ISDFindProvider fSdFindProvider = null; |
df0b8ff4 BH |
147 | /** |
148 | * The sequence diagram paging provider implementation. | |
149 | */ | |
cab6c8ff | 150 | private ISDPagingProvider fSdPagingProvider = null; |
df0b8ff4 BH |
151 | /** |
152 | * The sequence diagram filter provider implementation. | |
153 | */ | |
cab6c8ff | 154 | private ISDFilterProvider fSdFilterProvider = null; |
df0b8ff4 BH |
155 | /** |
156 | * The extended sequence diagram filter provider implementation. | |
157 | */ | |
cab6c8ff | 158 | private IExtendedFilterProvider fSdExFilterProvider = null; |
df0b8ff4 BH |
159 | /** |
160 | * The extended sequence diagram find provider implementation. | |
161 | */ | |
cab6c8ff | 162 | private IExtendedFindProvider fSdExFindProvider = null; |
df0b8ff4 BH |
163 | /** |
164 | * The extended sequence diagram action bar provider implementation. | |
165 | */ | |
cab6c8ff | 166 | private ISDExtendedActionBarProvider fSdExtendedActionBarProvider = null; |
df0b8ff4 BH |
167 | /** |
168 | * The sequence diagram property provider implementation. | |
169 | */ | |
cab6c8ff | 170 | private ISDPropertiesProvider fSdPropertiesProvider = null; |
df0b8ff4 | 171 | /** |
a55887ca | 172 | * Button for executing the next page action. |
df0b8ff4 | 173 | */ |
cab6c8ff | 174 | private NextPage fNextPageButton = null; |
df0b8ff4 | 175 | /** |
a55887ca | 176 | * Button for executing the previous page action. |
df0b8ff4 | 177 | */ |
cab6c8ff | 178 | private PrevPage fPrevPageButton = null; |
df0b8ff4 | 179 | /** |
a55887ca | 180 | * Button for executing the first page page action. |
df0b8ff4 | 181 | */ |
cab6c8ff | 182 | private FirstPage fFirstPageButton = null; |
df0b8ff4 | 183 | /** |
a55887ca | 184 | * Button for executing the last page action. |
df0b8ff4 | 185 | */ |
cab6c8ff | 186 | private LastPage fLastPageButton = null; |
df0b8ff4 BH |
187 | /** |
188 | * The menu manager reference. | |
189 | */ | |
cab6c8ff | 190 | private MenuManager fMenuMgr = null; |
df0b8ff4 | 191 | /** |
a55887ca | 192 | * Flag to indicate whether view needs initialization or not. |
df0b8ff4 | 193 | */ |
cab6c8ff | 194 | private boolean fNeedInit = true; |
df0b8ff4 BH |
195 | /** |
196 | * WaitCursor is the cursor to be displayed when long tasks are running | |
197 | */ | |
cab6c8ff | 198 | private Cursor fWaitCursor; |
df0b8ff4 BH |
199 | |
200 | // ------------------------------------------------------------------------ | |
201 | // Methods | |
202 | // ------------------------------------------------------------------------ | |
73005152 | 203 | |
73005152 BH |
204 | @Override |
205 | public void createPartControl(Composite c) { | |
206 | Composite parent = new Composite(c, SWT.NONE); | |
207 | GridLayout parentLayout = new GridLayout(); | |
208 | parentLayout.numColumns = 2; | |
209 | parentLayout.marginWidth = 0; | |
210 | parentLayout.marginHeight = 0; | |
211 | parent.setLayout(parentLayout); | |
212 | ||
213 | GridData timeLayoutdata = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL); | |
214 | timeLayoutdata.widthHint = 10; | |
215 | GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL); | |
eb63f5ff BH |
216 | fTimeCompressionBar = new TimeCompressionBar(parent, SWT.NONE); |
217 | fTimeCompressionBar.setLayoutData(timeLayoutdata); | |
cab6c8ff | 218 | fSdWidget = new SDWidget(parent, SWT.NONE); |
eb63f5ff BH |
219 | fSdWidget.setLayoutData(seqDiagLayoutData); |
220 | fSdWidget.setSite(this); | |
221 | fSdWidget.setTimeBar(fTimeCompressionBar); | |
73005152 BH |
222 | |
223 | // Add this view to the key bindings manager | |
224 | KeyBindingsManager.getInstance().add(this.getSite().getId()); | |
a55887ca | 225 | |
73005152 BH |
226 | createCoolbarContent(); |
227 | ||
228 | hookContextMenu(); | |
229 | ||
eb63f5ff | 230 | fTimeCompressionBar.setVisible(false); |
73005152 BH |
231 | parent.layout(true); |
232 | ||
233 | Print print = new Print(this); | |
234 | getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.PRINT.getId(), print); | |
235 | ||
eb63f5ff | 236 | fNeedInit = restoreLoader(); |
73005152 BH |
237 | } |
238 | ||
239 | /** | |
df0b8ff4 | 240 | * Load a blank page that is supposed to explain that a kind of interaction must be chosen. |
73005152 BH |
241 | */ |
242 | protected void loadBlank() { | |
a55887ca | 243 | IUml2SDLoader loader = new BlankUml2SdLoader(); |
df0b8ff4 BH |
244 | loader.setViewer(this); |
245 | setContentDescription(loader.getTitleString()); | |
73005152 BH |
246 | } |
247 | ||
73005152 BH |
248 | @Override |
249 | public void setFocus() { | |
eb63f5ff | 250 | if (fSdWidget != null) { |
73005152 BH |
251 | // update actions for key bindings |
252 | KeyBindingsManager.getInstance().setSdView(this); | |
eb63f5ff | 253 | fSdWidget.setFocus(); |
73005152 | 254 | } |
eb63f5ff BH |
255 | if (isViewReady() && fNeedInit) { |
256 | fNeedInit = restoreLoader(); | |
73005152 BH |
257 | } |
258 | } | |
259 | ||
73005152 BH |
260 | @Override |
261 | public void dispose() { | |
262 | KeyBindingsManager.getInstance().remove(this.getSite().getId()); | |
263 | super.dispose(); | |
264 | } | |
265 | ||
266 | /** | |
df0b8ff4 | 267 | * Returns the SD widget. |
a55887ca | 268 | * |
73005152 BH |
269 | * @return The SD widget. |
270 | */ | |
271 | public SDWidget getSDWidget() { | |
eb63f5ff | 272 | return fSdWidget; |
73005152 | 273 | } |
df0b8ff4 | 274 | |
73005152 BH |
275 | /** |
276 | * Set the find provider for the opened sequence diagram viewer<br> | |
277 | * If the provider is not set, the find menu item will not be available in the viewer<br> | |
278 | * A find provider is called back when the user perform a find action<br> | |
a55887ca | 279 | * The find provider is responsible to move the sequence diagram to the GraphNode which match the |
73005152 | 280 | * find criteria as well as to highlight the GraphNode |
a55887ca | 281 | * |
73005152 BH |
282 | * @param provider the search provider |
283 | */ | |
284 | public void setSDFindProvider(ISDFindProvider provider) { | |
eb63f5ff BH |
285 | fSdFindProvider = provider; |
286 | fSdExFindProvider = null; | |
73005152 BH |
287 | createCoolbarContent(); |
288 | if (provider != null) { | |
289 | KeyBindingsManager.getInstance().setFindEnabled(true); | |
290 | } | |
291 | else { | |
292 | KeyBindingsManager.getInstance().setFindEnabled(false); | |
293 | } | |
294 | } | |
a55887ca | 295 | |
73005152 BH |
296 | /** |
297 | * Set the find provider for the opened sequence diagram viewer<br> | |
a55887ca AM |
298 | * If the provider is not set, the find menu item will not be available in |
299 | * the viewer<br> | |
73005152 | 300 | * A find provider is called back when the user perform a find action<br> |
a55887ca AM |
301 | * If the extended find provider is set, it replaces the regular find |
302 | * provider (sdFindProvider).<br> | |
303 | * | |
73005152 | 304 | * @param provider |
a55887ca | 305 | * The provider to set |
73005152 BH |
306 | */ |
307 | public void setExtendedFindProvider(IExtendedFindProvider provider) { | |
eb63f5ff BH |
308 | fSdExFindProvider = provider; |
309 | fSdFindProvider = null; | |
73005152 BH |
310 | createCoolbarContent(); |
311 | if (provider != null) { | |
312 | KeyBindingsManager.getInstance().setFindEnabled(true); | |
313 | } | |
314 | else { | |
315 | KeyBindingsManager.getInstance().setFindEnabled(false); | |
316 | } | |
317 | } | |
318 | ||
319 | /** | |
320 | * Returns the extended find provider | |
a55887ca | 321 | * |
73005152 BH |
322 | * @return extended find provider. |
323 | */ | |
324 | public IExtendedFindProvider getExtendedFindProvider() { | |
eb63f5ff | 325 | return fSdExFindProvider; |
73005152 BH |
326 | } |
327 | ||
328 | /** | |
329 | * Resets all providers. | |
330 | */ | |
331 | public void resetProviders() { | |
332 | KeyBindingsManager.getInstance().setFindEnabled(false); | |
eb63f5ff BH |
333 | fSdFindProvider = null; |
334 | fSdExFindProvider = null; | |
335 | fSdFilterProvider = null; | |
336 | fSdExFilterProvider = null; | |
337 | fSdPagingProvider = null; | |
338 | fSdExtendedActionBarProvider = null; | |
339 | fSdPropertiesProvider = null; | |
340 | if ((fSdWidget != null) && (!fSdWidget.isDisposed())) { | |
341 | fSdWidget.setCollapseProvider(null); | |
73005152 BH |
342 | } |
343 | } | |
344 | ||
345 | /** | |
346 | * Set the filter provider for the opened sequence diagram viewer<br> | |
347 | * If the provider is not set, the filter menu item will not be available in the viewer<br> | |
348 | * A filter provider is called back when the user perform a filter action<br> | |
a55887ca | 349 | * |
73005152 BH |
350 | * @param provider the filter provider |
351 | */ | |
352 | public void setSDFilterProvider(ISDFilterProvider provider) { | |
eb63f5ff | 353 | fSdFilterProvider = provider; |
73005152 | 354 | // Both systems can be used now, commenting out next statement |
73005152 BH |
355 | createCoolbarContent(); |
356 | } | |
a55887ca | 357 | |
73005152 | 358 | /** |
a55887ca AM |
359 | * Sets the extended filter provider for the opened sequence diagram viewer. |
360 | * | |
73005152 | 361 | * @param provider |
a55887ca | 362 | * The provider to set |
73005152 BH |
363 | */ |
364 | public void setExtendedFilterProvider(IExtendedFilterProvider provider) { | |
eb63f5ff | 365 | fSdExFilterProvider = provider; |
73005152 | 366 | // Both systems can be used now, commenting out next statement |
73005152 BH |
367 | createCoolbarContent(); |
368 | } | |
369 | ||
370 | /** | |
371 | * Returns the extended find provider. | |
a55887ca | 372 | * |
73005152 BH |
373 | * @return The extended find provider. |
374 | */ | |
375 | public IExtendedFilterProvider getExtendedFilterProvider() { | |
eb63f5ff | 376 | return fSdExFilterProvider; |
73005152 BH |
377 | } |
378 | ||
379 | /** | |
a55887ca | 380 | * Register the given provider to support Drag and Drop collapsing. This provider is |
73005152 | 381 | * responsible of updating the Frame. |
a55887ca | 382 | * |
73005152 BH |
383 | * @param provider - the provider to register |
384 | */ | |
385 | public void setCollapsingProvider(ISDCollapseProvider provider) { | |
eb63f5ff BH |
386 | if ((fSdWidget != null) && (!fSdWidget.isDisposed())) { |
387 | fSdWidget.setCollapseProvider(provider); | |
73005152 BH |
388 | } |
389 | } | |
390 | ||
391 | /** | |
392 | * Set the page provider for the opened sequence diagram viewer<br> | |
393 | * If the sequence diagram provided (see setFrame) need to be split in many parts, a paging provider must be | |
394 | * provided in order to handle page change requested by the user<br> | |
395 | * Set a page provider will create the next and previous page buttons in the viewer coolBar | |
a55887ca | 396 | * |
73005152 BH |
397 | * @param provider the paging provider |
398 | */ | |
399 | public void setSDPagingProvider(ISDPagingProvider provider) { | |
eb63f5ff | 400 | fSdPagingProvider = provider; |
73005152 BH |
401 | createCoolbarContent(); |
402 | } | |
403 | ||
404 | /** | |
405 | * Returns the current page provider for the view | |
a55887ca | 406 | * |
73005152 BH |
407 | * @return the paging provider |
408 | */ | |
409 | public ISDPagingProvider getSDPagingProvider() { | |
eb63f5ff | 410 | return fSdPagingProvider; |
73005152 BH |
411 | } |
412 | ||
413 | /** | |
414 | * Returns the current find provider for the view | |
a55887ca | 415 | * |
73005152 BH |
416 | * @return the find provider |
417 | */ | |
418 | public ISDFindProvider getSDFindProvider() { | |
eb63f5ff | 419 | return fSdFindProvider; |
73005152 BH |
420 | } |
421 | ||
422 | /** | |
423 | * Returns the current filter provider for the view | |
a55887ca | 424 | * |
73005152 BH |
425 | * @return the filter provider |
426 | */ | |
427 | public ISDFilterProvider getSDFilterProvider() { | |
eb63f5ff | 428 | return fSdFilterProvider; |
73005152 BH |
429 | } |
430 | ||
431 | /** | |
432 | * Set the extended action bar provider for the opened sequence diagram viewer<br> | |
433 | * This allow to add programmatically actions in the coolbar and/or in the drop-down menu | |
a55887ca | 434 | * |
73005152 BH |
435 | * @param provider the search provider |
436 | */ | |
437 | public void setSDExtendedActionBarProvider(ISDExtendedActionBarProvider provider) { | |
eb63f5ff | 438 | fSdExtendedActionBarProvider = provider; |
73005152 BH |
439 | createCoolbarContent(); |
440 | } | |
441 | ||
442 | /** | |
443 | * Returns the current extended action bar provider for the view | |
a55887ca | 444 | * |
73005152 BH |
445 | * @return the extended action bar provider |
446 | */ | |
447 | public ISDExtendedActionBarProvider getSDExtendedActionBarProvider() { | |
eb63f5ff | 448 | return fSdExtendedActionBarProvider; |
73005152 BH |
449 | } |
450 | ||
451 | /** | |
df0b8ff4 | 452 | * Set the properties view provider for the opened sequence diagram viewer |
a55887ca | 453 | * |
73005152 BH |
454 | * @param provider the properties provider |
455 | */ | |
456 | public void setSDPropertiesProvider(ISDPropertiesProvider provider) { | |
eb63f5ff | 457 | fSdPropertiesProvider = provider; |
73005152 BH |
458 | } |
459 | ||
460 | /** | |
df0b8ff4 | 461 | * Returns the current extended action bar provider for the view. |
a55887ca | 462 | * |
73005152 BH |
463 | * @return the extended action bar provider |
464 | */ | |
465 | public ISDPropertiesProvider getSDPropertiesProvider() { | |
eb63f5ff | 466 | return fSdPropertiesProvider; |
73005152 BH |
467 | } |
468 | ||
cab6c8ff BH |
469 | /** |
470 | * Sets the sdWidget. | |
471 | * | |
472 | * @param sdWidget | |
473 | * A sdWidget to set | |
474 | * @since 2.0 | |
475 | */ | |
476 | protected void setSDWidget(SDWidget sdWidget) { | |
477 | fSdWidget = sdWidget; | |
478 | } | |
479 | ||
480 | /** | |
481 | * Sets the time compression bar. | |
482 | * | |
483 | * @param timeCompressionbar | |
484 | * A sdWidget to set | |
485 | * @since 2.0 | |
486 | */ | |
487 | protected void setTimeBar(TimeCompressionBar timeCompressionbar) { | |
488 | fTimeCompressionBar = timeCompressionbar; | |
489 | } | |
490 | ||
491 | /** | |
492 | * Sets the initialization flag. | |
493 | * | |
494 | * @param needInit | |
495 | * flag value to set | |
496 | * @since 2.0 | |
497 | */ | |
498 | protected void setNeedInit(boolean needInit) { | |
499 | fNeedInit = needInit; | |
500 | } | |
501 | ||
73005152 BH |
502 | /** |
503 | * Creates the basic sequence diagram menu | |
504 | */ | |
505 | protected void hookContextMenu() { | |
eb63f5ff BH |
506 | fMenuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
507 | fMenuMgr.setRemoveAllWhenShown(true); | |
508 | fMenuMgr.addMenuListener(new IMenuListener() { | |
73005152 BH |
509 | @Override |
510 | public void menuAboutToShow(IMenuManager manager) { | |
511 | fillContextMenu(manager); | |
512 | } | |
513 | }); | |
eb63f5ff BH |
514 | Menu menu = fMenuMgr.createContextMenu(fSdWidget.getViewControl()); |
515 | fSdWidget.getViewControl().setMenu(menu); | |
516 | getSite().registerContextMenu(fMenuMgr, fSdWidget.getSelectionProvider()); | |
73005152 BH |
517 | } |
518 | ||
519 | /** | |
520 | * Returns the context menu manager | |
a55887ca | 521 | * |
73005152 BH |
522 | * @return the menu manager |
523 | */ | |
524 | public MenuManager getMenuManager() { | |
eb63f5ff | 525 | return fMenuMgr; |
73005152 BH |
526 | } |
527 | ||
528 | /** | |
529 | * Fills the basic sequence diagram menu and define the dynamic menu item insertion point | |
a55887ca | 530 | * |
73005152 BH |
531 | * @param manager the menu manager |
532 | */ | |
533 | protected void fillContextMenu(IMenuManager manager) { | |
534 | manager.add(new Separator("Additions")); //$NON-NLS-1$ | |
cab6c8ff | 535 | if (getSDWidget() != null && getSDWidget().getCurrentGraphNode() != null) { |
eb63f5ff | 536 | ISelectionProvider selProvider = fSdWidget.getSelectionProvider(); |
73005152 BH |
537 | ISelection sel = selProvider.getSelection(); |
538 | int nbMessage = 0; | |
539 | Iterator<?> it = ((StructuredSelection) sel).iterator(); | |
540 | while (it.hasNext()) { | |
541 | Object node = it.next(); | |
542 | if (node instanceof BaseMessage) { | |
543 | nbMessage++; | |
544 | } | |
545 | } | |
546 | if (nbMessage != 1) { | |
547 | return; | |
548 | } | |
cab6c8ff | 549 | GraphNode node = getSDWidget().getCurrentGraphNode(); |
eb63f5ff BH |
550 | if ((node instanceof SyncMessageReturn) && (((SyncMessageReturn) node).getMessage() != null)) { |
551 | Action goToMessage = new MoveToMessage(this); | |
92330441 | 552 | goToMessage.setText(Messages.SequenceDiagram_GoToMessage); |
eb63f5ff | 553 | manager.add(goToMessage); |
73005152 | 554 | } |
eb63f5ff BH |
555 | if ((node instanceof SyncMessage) && (((SyncMessage) node).getMessageReturn() != null)) { |
556 | Action goToMessage = new MoveToMessage(this); | |
92330441 | 557 | goToMessage.setText(Messages.SequenceDiagram_GoToMessageReturn); |
eb63f5ff | 558 | manager.add(goToMessage); |
73005152 BH |
559 | } |
560 | } | |
561 | manager.add(new Separator("MultiSelectAdditions")); //$NON-NLS-1$ | |
562 | } | |
563 | ||
564 | /** | |
565 | * Enables/Disables an action with given name. | |
a55887ca | 566 | * |
73005152 BH |
567 | * @param actionName The action name |
568 | * @param state true or false | |
569 | */ | |
570 | public void setEnableAction(String actionName, boolean state) { | |
571 | IActionBars bar = getViewSite().getActionBars(); | |
572 | if (bar != null) { | |
573 | IContributionItem item = bar.getMenuManager().find(actionName); | |
574 | if ((item != null) && (item instanceof ActionContributionItem)) { | |
575 | IAction action = ((ActionContributionItem) item).getAction(); | |
576 | if (action != null) { | |
577 | action.setEnabled(state); | |
578 | } | |
579 | item.setVisible(state); | |
580 | bar.updateActionBars(); | |
581 | } | |
582 | } | |
583 | } | |
584 | ||
585 | /** | |
586 | * Creates the coolBar icon depending on the actions supported by the Sequence Diagram provider<br> | |
587 | * - Navigation buttons are displayed if ISDPovider.HasPaging return true<br> | |
588 | * - Navigation buttons are enabled depending on the value return by ISDPovider.HasNext and HasPrev<br> | |
a55887ca | 589 | * |
73005152 BH |
590 | * @see ISDGraphNodeSupporter Action support definition |
591 | * @see SDView#setSDFilterProvider(ISDFilterProvider) | |
592 | * @see SDView#setSDFindProvider(ISDFindProvider) | |
593 | * @see SDView#setSDPagingProvider(ISDPagingProvider) | |
594 | */ | |
595 | protected void createCoolbarContent() { | |
596 | IActionBars bar = getViewSite().getActionBars(); | |
597 | ||
598 | bar.getMenuManager().removeAll(); | |
599 | bar.getToolBarManager().removeAll(); | |
600 | ||
601 | createMenuGroup(); | |
602 | ||
603 | Zoom resetZoom = new Zoom(this, ZoomType.ZOOM_RESET); | |
cab6c8ff BH |
604 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, resetZoom); |
605 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, resetZoom); | |
73005152 BH |
606 | |
607 | Zoom noZoom = new Zoom(this, ZoomType.ZOOM_NONE); | |
608 | noZoom.setChecked(true); | |
cab6c8ff BH |
609 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, noZoom); |
610 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, noZoom); | |
73005152 BH |
611 | |
612 | Zoom zoomIn = new Zoom(this, ZoomType.ZOOM_IN); | |
cab6c8ff BH |
613 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomIn); |
614 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomIn); | |
73005152 BH |
615 | |
616 | Zoom zoomOut = new Zoom(this, ZoomType.ZOOM_OUT); | |
cab6c8ff BH |
617 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomOut); |
618 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomOut); | |
73005152 | 619 | |
92330441 | 620 | MenuManager navigation = new MenuManager(Messages.SequenceDiagram_Navigation); |
73005152 BH |
621 | |
622 | ShowNodeStart showNodeStart = new ShowNodeStart(this); | |
92330441 | 623 | showNodeStart.setText(Messages.SequenceDiagram_ShowNodeStart); |
73005152 BH |
624 | |
625 | showNodeStart.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$ | |
626 | showNodeStart.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$ | |
627 | navigation.add(showNodeStart); | |
628 | ||
629 | ShowNodeEnd showNodeEnd = new ShowNodeEnd(this); | |
92330441 | 630 | showNodeEnd.setText(Messages.SequenceDiagram_ShowNodeEnd); |
73005152 BH |
631 | |
632 | showNodeEnd.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$ | |
633 | showNodeEnd.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$ | |
634 | navigation.add(showNodeEnd); | |
635 | ||
cab6c8ff | 636 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, navigation); |
73005152 BH |
637 | |
638 | ConfigureMinMax minMax = new ConfigureMinMax(this); | |
92330441 | 639 | minMax.setText(Messages.SequenceDiagram_ConfigureMinMax); |
73005152 | 640 | minMax.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax");//$NON-NLS-1$ |
cab6c8ff | 641 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, minMax); |
73005152 | 642 | |
eb63f5ff | 643 | if ((fSdWidget.getFrame() != null) && (fSdWidget.getFrame().hasTimeInfo())) { |
73005152 | 644 | minMax.setEnabled(true); |
df0b8ff4 | 645 | } else { |
73005152 | 646 | minMax.setEnabled(false); |
df0b8ff4 | 647 | } |
73005152 BH |
648 | |
649 | // Do we need to display a paging item | |
eb63f5ff BH |
650 | if (fSdPagingProvider != null) { |
651 | fNextPageButton = new NextPage(this); | |
cab6c8ff | 652 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fNextPageButton); |
eb63f5ff | 653 | fNextPageButton.setEnabled(fSdPagingProvider.hasNextPage()); |
cab6c8ff | 654 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fNextPageButton); |
eb63f5ff BH |
655 | |
656 | fPrevPageButton = new PrevPage(this); | |
cab6c8ff | 657 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fPrevPageButton); |
eb63f5ff | 658 | fPrevPageButton.setEnabled(fSdPagingProvider.hasPrevPage()); |
cab6c8ff | 659 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fPrevPageButton); |
a55887ca | 660 | |
eb63f5ff | 661 | fFirstPageButton = new FirstPage(this); |
cab6c8ff | 662 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fFirstPageButton); |
eb63f5ff | 663 | fFirstPageButton.setEnabled(fSdPagingProvider.hasPrevPage()); |
cab6c8ff | 664 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fFirstPageButton); |
eb63f5ff BH |
665 | |
666 | fLastPageButton = new LastPage(this); | |
cab6c8ff | 667 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fLastPageButton); |
eb63f5ff | 668 | fLastPageButton.setEnabled(fSdPagingProvider.hasNextPage()); |
cab6c8ff | 669 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fLastPageButton); |
73005152 BH |
670 | } |
671 | ||
eb63f5ff BH |
672 | if (fSdExFilterProvider != null) { |
673 | Action action = fSdExFilterProvider.getFilterAction(); | |
73005152 BH |
674 | if (action != null) { |
675 | if (action.getId() == null) | |
a55887ca | 676 | { |
73005152 | 677 | action.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFilter"); //$NON-NLS-1$ |
a55887ca AM |
678 | } |
679 | if (action.getImageDescriptor() == null) { | |
8fd82db5 | 680 | action.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FILTERS)); |
a55887ca AM |
681 | } |
682 | if (action.getText() == null || action.getText().length() == 0) { | |
92330441 | 683 | action.setText(Messages.SequenceDiagram_EditFilters); |
a55887ca | 684 | } |
cab6c8ff BH |
685 | bar.getMenuManager().prependToGroup(UML2SD_FILTERING_SEPARATOR, action); |
686 | bar.getToolBarManager().prependToGroup(UML2SD_FILTERING_SEPARATOR, action); | |
73005152 BH |
687 | } |
688 | } | |
689 | // Both systems can be used now: commenting out else keyword | |
cab6c8ff BH |
690 | if (fSdFilterProvider != null) { |
691 | bar.getMenuManager().appendToGroup(UML2SD_FILTERING_SEPARATOR, new OpenSDFiltersDialog(this, fSdFilterProvider)); | |
73005152 | 692 | } |
eb63f5ff | 693 | if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) { |
73005152 BH |
694 | IContributionItem sdPaging = bar.getMenuManager().find(OpenSDPagesDialog.ID); |
695 | if (sdPaging != null) { | |
696 | bar.getMenuManager().remove(sdPaging); | |
697 | sdPaging = null; | |
698 | } | |
cab6c8ff | 699 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, new OpenSDPagesDialog(this, (ISDAdvancedPagingProvider) fSdPagingProvider)); |
73005152 BH |
700 | updatePagesMenuItem(bar); |
701 | } | |
702 | ||
eb63f5ff BH |
703 | if (fSdExFindProvider != null) { |
704 | Action action = fSdExFindProvider.getFindAction(); | |
73005152 | 705 | if (action != null) { |
df0b8ff4 | 706 | if (action.getId() == null) { |
73005152 | 707 | action.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFind"); //$NON-NLS-1$ |
df0b8ff4 BH |
708 | } |
709 | if (action.getImageDescriptor() == null) { | |
8fd82db5 | 710 | action.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_SEQ)); |
df0b8ff4 BH |
711 | } |
712 | if (action.getText() == null) { | |
92330441 | 713 | action.setText(Messages.SequenceDiagram_Find + "..."); //$NON-NLS-1$ |
df0b8ff4 | 714 | } |
cab6c8ff BH |
715 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, action); |
716 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, action); | |
73005152 | 717 | } |
eb63f5ff | 718 | } else if (fSdFindProvider != null) { |
cab6c8ff BH |
719 | bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, new OpenSDFindDialog(this)); |
720 | bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, new OpenSDFindDialog(this)); | |
73005152 BH |
721 | } |
722 | ||
eb63f5ff BH |
723 | if (fSdExtendedActionBarProvider != null) { |
724 | fSdExtendedActionBarProvider.supplementCoolbarContent(bar); | |
73005152 BH |
725 | } |
726 | ||
727 | bar.updateActionBars(); | |
728 | } | |
729 | ||
730 | /** | |
731 | * Updates the view coolbar buttons state according to the value return by: - | |
732 | * ISDExtendedActionBarProvider.hasNextPage()<br> | |
733 | * - ISDExtendedActionBarProvider.hasPrevPage()<br> | |
a55887ca | 734 | * |
73005152 BH |
735 | */ |
736 | public void updateCoolBar() { | |
eb63f5ff | 737 | if (fSdPagingProvider != null) { |
73005152 | 738 | IActionBars bar = getViewSite().getActionBars(); |
df0b8ff4 | 739 | if (bar == null) { |
73005152 | 740 | return; |
df0b8ff4 | 741 | } |
73005152 | 742 | IToolBarManager barManager = bar.getToolBarManager(); |
df0b8ff4 | 743 | if (barManager == null) { |
73005152 | 744 | return; |
df0b8ff4 | 745 | } |
73005152 | 746 | IContributionItem nextPage = barManager.find(NextPage.ID); |
eb63f5ff | 747 | if (nextPage instanceof ActionContributionItem) { |
73005152 | 748 | IAction nextPageAction = ((ActionContributionItem) nextPage).getAction(); |
eb63f5ff BH |
749 | if (nextPageAction instanceof NextPage) { |
750 | ((NextPage) nextPageAction).setEnabled(fSdPagingProvider.hasNextPage()); | |
73005152 BH |
751 | } |
752 | } | |
753 | ||
754 | IContributionItem prevPage = barManager.find(PrevPage.ID); | |
eb63f5ff | 755 | if (prevPage instanceof ActionContributionItem) { |
73005152 | 756 | IAction prevPageAction = ((ActionContributionItem) prevPage).getAction(); |
eb63f5ff BH |
757 | if (prevPageAction instanceof PrevPage) { |
758 | ((PrevPage) prevPageAction).setEnabled(fSdPagingProvider.hasPrevPage()); | |
73005152 BH |
759 | } |
760 | } | |
761 | ||
762 | IContributionItem firstPage = barManager.find(FirstPage.ID); | |
eb63f5ff | 763 | if (firstPage instanceof ActionContributionItem) { |
73005152 | 764 | IAction firstPageAction = ((ActionContributionItem) firstPage).getAction(); |
eb63f5ff BH |
765 | if (firstPageAction instanceof FirstPage) { |
766 | ((FirstPage) firstPageAction).setEnabled(fSdPagingProvider.hasPrevPage()); | |
73005152 BH |
767 | } |
768 | } | |
769 | ||
770 | IContributionItem lastPage = barManager.find(LastPage.ID); | |
eb63f5ff | 771 | if (lastPage instanceof ActionContributionItem) { |
73005152 | 772 | IAction lastPageAction = ((ActionContributionItem) lastPage).getAction(); |
eb63f5ff BH |
773 | if (lastPageAction instanceof LastPage) { |
774 | ((LastPage) lastPageAction).setEnabled(fSdPagingProvider.hasNextPage()); | |
73005152 BH |
775 | } |
776 | } | |
a55887ca | 777 | |
73005152 BH |
778 | updatePagesMenuItem(bar); |
779 | } | |
780 | } | |
781 | ||
782 | /** | |
783 | * Enables or disables the Pages... menu item, depending on the number of pages | |
a55887ca | 784 | * |
73005152 BH |
785 | * @param bar the bar containing the action |
786 | */ | |
787 | protected void updatePagesMenuItem(IActionBars bar) { | |
eb63f5ff | 788 | if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) { |
73005152 BH |
789 | IMenuManager menuManager = bar.getMenuManager(); |
790 | ActionContributionItem contributionItem = (ActionContributionItem) menuManager.find(OpenSDPagesDialog.ID); | |
791 | IAction openSDPagesDialog = null; | |
792 | if (contributionItem != null) { | |
793 | openSDPagesDialog = contributionItem.getAction(); | |
794 | } | |
795 | ||
eb63f5ff BH |
796 | if (openSDPagesDialog instanceof OpenSDPagesDialog) { |
797 | openSDPagesDialog.setEnabled(((ISDAdvancedPagingProvider) fSdPagingProvider).pagesCount() > 1); | |
73005152 BH |
798 | } |
799 | } | |
800 | } | |
801 | ||
802 | /** | |
803 | * The frame to render (the sequence diagram) | |
a55887ca | 804 | * |
73005152 BH |
805 | * @param frame the frame to display |
806 | */ | |
807 | public void setFrame(Frame frame) { | |
808 | setFrame(frame, true); | |
809 | } | |
810 | ||
811 | /** | |
812 | * The frame to render (the sequence diagram) | |
a55887ca | 813 | * |
73005152 | 814 | * @param frame the frame to display |
df0b8ff4 | 815 | * @param resetPosition boolean Flag whether to reset the position or not. |
73005152 BH |
816 | */ |
817 | protected void setFrame(Frame frame, boolean resetPosition) { | |
8a95ce5a | 818 | if (getSDWidget() == null) { |
73005152 | 819 | return; |
a55887ca | 820 | } |
73005152 BH |
821 | |
822 | if (frame == null) { | |
823 | loadBlank(); | |
824 | return; | |
825 | } | |
826 | ||
df0b8ff4 | 827 | IUml2SDLoader loader = LoadersManager.getInstance().getCurrentLoader(getViewSite().getId(), this); |
4b4a1525 BH |
828 | if (loader == null) { |
829 | return; | |
830 | } | |
73005152 | 831 | |
4b4a1525 | 832 | if (loader.getTitleString() != null) { |
df0b8ff4 | 833 | setContentDescription(loader.getTitleString()); |
73005152 BH |
834 | } |
835 | ||
8a95ce5a | 836 | getSDWidget().setFrame(frame, resetPosition); |
73005152 | 837 | |
eb63f5ff BH |
838 | if (fTimeCompressionBar != null) { |
839 | fTimeCompressionBar.setFrame(frame); | |
df0b8ff4 | 840 | } |
73005152 | 841 | updateCoolBar(); |
8a95ce5a BH |
842 | if (fTimeCompressionBar != null) { |
843 | if (!frame.hasTimeInfo()) { | |
844 | Composite parent = fTimeCompressionBar.getParent(); | |
845 | fTimeCompressionBar.setVisible(false); | |
846 | parent.layout(true); | |
847 | } else { | |
848 | Composite parent = fTimeCompressionBar.getParent(); | |
849 | fTimeCompressionBar.setVisible(true); | |
850 | parent.layout(true); | |
851 | } | |
73005152 BH |
852 | } |
853 | IContributionItem shortKeysMenu = getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$ | |
854 | MenuManager shortKeys = (MenuManager) shortKeysMenu; | |
855 | if (shortKeys != null) { | |
856 | IContributionItem[] items = shortKeys.getItems(); | |
857 | for (int i = 0; i < items.length; i++) { | |
858 | if (items[i] instanceof ActionContributionItem) { | |
859 | IAction action = ((ActionContributionItem) items[i]).getAction(); | |
df0b8ff4 | 860 | if (action != null) { |
73005152 | 861 | action.setEnabled(true); |
df0b8ff4 | 862 | } |
73005152 BH |
863 | } |
864 | } | |
865 | } | |
866 | createCoolbarContent(); | |
867 | } | |
868 | ||
869 | /** | |
870 | * Activate or deactivate the short key command given in parameter (see plugin.xml) | |
a55887ca | 871 | * |
73005152 BH |
872 | * @param id the command id defined in the plugin.xml |
873 | * @param value the state value | |
874 | */ | |
875 | public void setEnableCommand(String id, boolean value) { | |
876 | IContributionItem shortKeysMenu = getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$ | |
877 | MenuManager shortKeys = (MenuManager) shortKeysMenu; | |
df0b8ff4 | 878 | if (shortKeys == null) { |
73005152 | 879 | return; |
df0b8ff4 | 880 | } |
73005152 BH |
881 | IContributionItem item = shortKeys.find(id); |
882 | if ((item != null) && (item instanceof ActionContributionItem)) { | |
883 | IAction action = ((ActionContributionItem) item).getAction(); | |
df0b8ff4 | 884 | if (action != null) { |
73005152 | 885 | action.setEnabled(value); |
df0b8ff4 | 886 | } |
73005152 BH |
887 | } |
888 | } | |
889 | ||
890 | /** | |
891 | * Set the frame from an other thread than the one executing the main loop | |
a55887ca | 892 | * |
df0b8ff4 | 893 | * @param frame The frame to set (and display) |
73005152 BH |
894 | */ |
895 | public void setFrameSync(final Frame frame) { | |
896 | if (getSDWidget() == null || getSDWidget().isDisposed()) { | |
897 | return; | |
898 | } | |
899 | getSDWidget().getDisplay().syncExec(new Runnable() { | |
900 | @Override | |
901 | public void run() { | |
8a95ce5a BH |
902 | if (getSDWidget() == null || getSDWidget().isDisposed() || |
903 | ((fTimeCompressionBar != null) && fTimeCompressionBar.isDisposed())) { | |
73005152 BH |
904 | return; |
905 | } | |
906 | setFrame(frame); | |
907 | } | |
908 | }); | |
909 | ||
910 | } | |
911 | ||
912 | /** | |
913 | * Ensure an object is visible from an other thread than the one executing the main loop | |
a55887ca | 914 | * |
df0b8ff4 | 915 | * @param sm The node to make visible in view |
73005152 BH |
916 | */ |
917 | public void ensureVisibleSync(final GraphNode sm) { | |
918 | getSDWidget().getDisplay().syncExec(new Runnable() { | |
919 | @Override | |
920 | public void run() { | |
921 | if (getSDWidget() == null || getSDWidget().isDisposed()) { | |
922 | return; | |
923 | } | |
924 | getSDWidget().ensureVisible(sm); | |
925 | } | |
926 | }); | |
927 | } | |
928 | ||
929 | /** | |
930 | * Set the frame and ensure an object is visible from an other thread than the one executing the main loop | |
a55887ca | 931 | * |
df0b8ff4 BH |
932 | * @param sm The node to make visible in view |
933 | * @param frame Frame The frame to set | |
73005152 BH |
934 | */ |
935 | public void setFrameAndEnsureVisibleSync(final Frame frame, final GraphNode sm) { | |
936 | if (getSDWidget() == null || getSDWidget().isDisposed()) { | |
937 | return; | |
938 | } | |
939 | getSDWidget().getDisplay().syncExec(new Runnable() { | |
940 | @Override | |
941 | public void run() { | |
942 | if (getSDWidget() == null || getSDWidget().isDisposed()) { | |
943 | return; | |
944 | } | |
945 | setFrameAndEnsureVisible(frame, sm); | |
946 | } | |
947 | }); | |
948 | } | |
949 | ||
950 | /** | |
951 | * Set the frame and ensure an object is visible | |
a55887ca | 952 | * |
df0b8ff4 BH |
953 | * @param sm The node to make visible in view |
954 | * @param frame Frame The frame to set | |
73005152 BH |
955 | */ |
956 | public void setFrameAndEnsureVisible(Frame frame, GraphNode sm) { | |
957 | getSDWidget().clearSelection(); | |
958 | setFrame(frame, false); | |
959 | getSDWidget().ensureVisible(sm); | |
960 | } | |
961 | ||
962 | /** | |
963 | * Set the frame and ensure an object is visible from an other thread than the one executing the main loop | |
a55887ca | 964 | * |
df0b8ff4 BH |
965 | * @param frame The frame to set. |
966 | * @param x The x coordinate to make visible. | |
967 | * @param y The y coordinate to make visible. | |
73005152 BH |
968 | */ |
969 | public void setFrameAndEnsureVisibleSync(final Frame frame, final int x, final int y) { | |
970 | if (getSDWidget() == null || getSDWidget().isDisposed()) { | |
971 | return; | |
972 | } | |
a55887ca | 973 | |
73005152 BH |
974 | getSDWidget().getDisplay().syncExec(new Runnable() { |
975 | @Override | |
976 | public void run() { | |
977 | setFrameAndEnsureVisible(frame, x, y); | |
978 | } | |
979 | }); | |
980 | } | |
981 | ||
982 | /** | |
983 | * Set the frame and ensure an object is visible | |
a55887ca | 984 | * |
df0b8ff4 BH |
985 | * @param frame The frame to set. |
986 | * @param x The x coordinate to make visible. | |
987 | * @param y The y coordinate to make visible. | |
73005152 BH |
988 | */ |
989 | public void setFrameAndEnsureVisible(Frame frame, int x, int y) { | |
990 | getSDWidget().clearSelection(); | |
991 | setFrame(frame, false); | |
992 | getSDWidget().ensureVisible(x, y); | |
993 | getSDWidget().redraw(); | |
994 | } | |
995 | ||
73005152 BH |
996 | /** |
997 | * Toggle between default and wait cursors from an other thread than the one executing the main loop | |
a55887ca AM |
998 | * |
999 | * @param wait <code>true</code> for wait cursor else <code>false</code> for default cursor. | |
73005152 | 1000 | */ |
eb63f5ff | 1001 | public void toggleWaitCursorAsync(final boolean wait) { |
73005152 BH |
1002 | if (getSDWidget() == null || getSDWidget().isDisposed()) { |
1003 | return; | |
1004 | } | |
1005 | ||
1006 | getSDWidget().getDisplay().asyncExec(new Runnable() { | |
1007 | @Override | |
1008 | public void run() { | |
1009 | if (getSDWidget() == null || getSDWidget().isDisposed()) { | |
1010 | return; | |
1011 | } | |
eb63f5ff BH |
1012 | if (wait) { |
1013 | if (fWaitCursor != null && !fWaitCursor.isDisposed()) { | |
1014 | fWaitCursor.dispose(); | |
73005152 | 1015 | } |
eb63f5ff BH |
1016 | fWaitCursor = new Cursor(getSDWidget().getDisplay(), SWT.CURSOR_WAIT); |
1017 | getSDWidget().setCursor(fWaitCursor); | |
73005152 BH |
1018 | getSDWidget().getDisplay().update(); |
1019 | } else { | |
eb63f5ff BH |
1020 | if (fWaitCursor != null && !fWaitCursor.isDisposed()) { |
1021 | fWaitCursor.dispose(); | |
73005152 | 1022 | } |
eb63f5ff | 1023 | fWaitCursor = null; |
73005152 BH |
1024 | getSDWidget().setCursor(null); |
1025 | getSDWidget().getDisplay().update(); | |
1026 | } | |
1027 | } | |
1028 | }); | |
1029 | } | |
1030 | ||
1031 | /** | |
1032 | * Return the time compression bar widget | |
a55887ca AM |
1033 | * |
1034 | * @return the time compression bar | |
73005152 BH |
1035 | */ |
1036 | public TimeCompressionBar getTimeCompressionBar() { | |
eb63f5ff | 1037 | return fTimeCompressionBar; |
73005152 BH |
1038 | } |
1039 | ||
1040 | /** | |
1041 | * Returns the current Frame (the sequence diagram container) | |
a55887ca AM |
1042 | * |
1043 | * @return the current frame | |
73005152 BH |
1044 | */ |
1045 | public Frame getFrame() { | |
1046 | if (getSDWidget() != null) { | |
1047 | return getSDWidget().getFrame(); | |
1048 | } | |
abbdd66a | 1049 | return null; |
73005152 BH |
1050 | } |
1051 | ||
cab6c8ff BH |
1052 | /** |
1053 | * Gets the initialization flag. | |
1054 | * @return the value of the initialization flag. | |
1055 | * @since 2.0 | |
1056 | */ | |
1057 | private boolean isNeedInit() { | |
1058 | return fNeedInit; | |
1059 | } | |
1060 | ||
df0b8ff4 BH |
1061 | /** |
1062 | * Restores the loader for the view based on the view ID. | |
a55887ca | 1063 | * |
df0b8ff4 BH |
1064 | * @return boolean <code>true</code> if initialization is needed else <code>false</code>. |
1065 | */ | |
73005152 BH |
1066 | protected boolean restoreLoader() { |
1067 | String id = getViewSite().getId(); | |
73005152 BH |
1068 | if (id == null) { |
1069 | return true; | |
1070 | } | |
df0b8ff4 | 1071 | IUml2SDLoader loader = LoadersManager.getInstance().getCurrentLoader(id, this); |
cab6c8ff | 1072 | if ((loader != null)) { |
df0b8ff4 | 1073 | loader.setViewer(this); |
73005152 | 1074 | return false; |
73005152 | 1075 | } |
abbdd66a AM |
1076 | loadBlank(); |
1077 | return true; | |
73005152 BH |
1078 | } |
1079 | ||
df0b8ff4 BH |
1080 | /** |
1081 | * Checks if current view is ready to be used. | |
a55887ca | 1082 | * |
df0b8ff4 BH |
1083 | * @return boolean <code>true</code> if view is ready else <code>false</code>. |
1084 | */ | |
73005152 | 1085 | protected boolean isViewReady() { |
df0b8ff4 BH |
1086 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
1087 | if (page == null) { | |
73005152 | 1088 | return false; |
df0b8ff4 | 1089 | } |
73005152 | 1090 | |
df0b8ff4 | 1091 | IViewReference[] ref = page.getViewReferences(); |
73005152 BH |
1092 | for (int i = 0; i < ref.length; i++) { |
1093 | if (ref[i].getView(false) == this) { | |
1094 | return true; | |
1095 | } | |
1096 | } | |
1097 | return false; | |
1098 | } | |
1099 | ||
df0b8ff4 BH |
1100 | /** |
1101 | * Creates the menu group. | |
1102 | */ | |
73005152 BH |
1103 | protected void createMenuGroup() { |
1104 | IActionBars bar = getViewSite().getActionBars(); | |
1105 | if (bar == null) { | |
1106 | return; | |
1107 | } | |
cab6c8ff BH |
1108 | bar.getToolBarManager().add(new Separator(UML2SD_VIEW_MODES_SEPARATOR)); |
1109 | bar.getToolBarManager().add(new Separator(UML2SD_WORKING_SET_SEPARATOR)); | |
1110 | bar.getToolBarManager().add(new Separator(UML2SD_SORTING_SEPARATOR)); | |
1111 | bar.getToolBarManager().add(new Separator(UML2SD_FILTERING_SEPARATOR)); | |
1112 | bar.getToolBarManager().add(new Separator(UML2SD_VIEW_LAYOUT_SEPARATOR)); | |
1113 | bar.getToolBarManager().add(new Separator(UML2SD_LINK_EDITOR_SEPARATOR)); | |
1114 | bar.getToolBarManager().add(new Separator(UML2SD_OTHER_COMMANDS_SEPARATOR)); | |
1115 | bar.getToolBarManager().add(new Separator(UML2SD_OTHER_PLUGINS_COMMANDS_SEPARATOR)); | |
1116 | bar.getMenuManager().add(new Separator(UML2SD_VIEW_MODES_SEPARATOR)); | |
1117 | bar.getMenuManager().add(new Separator(UML2SD_WORKING_SET_SEPARATOR)); | |
1118 | bar.getMenuManager().add(new Separator(UML2SD_SORTING_SEPARATOR)); | |
1119 | bar.getMenuManager().add(new Separator(UML2SD_FILTERING_SEPARATOR)); | |
1120 | bar.getMenuManager().add(new Separator(UML2SD_VIEW_LAYOUT_SEPARATOR)); | |
1121 | bar.getMenuManager().add(new Separator(UML2SD_LINK_EDITOR_SEPARATOR)); | |
1122 | bar.getMenuManager().add(new Separator(UML2SD_OTHER_COMMANDS_SEPARATOR)); | |
1123 | bar.getMenuManager().add(new Separator(UML2SD_OTHER_PLUGINS_COMMANDS_SEPARATOR)); | |
73005152 BH |
1124 | } |
1125 | ||
73005152 | 1126 | @Override |
eb63f5ff BH |
1127 | public Object getAdapter(Class adapter) { |
1128 | Object obj = super.getAdapter(adapter); | |
1129 | if (fSdPropertiesProvider != null && adapter.equals(IPropertySheetPage.class)) { | |
1130 | return fSdPropertiesProvider.getPropertySheetEntry(); | |
73005152 BH |
1131 | } |
1132 | ||
1133 | return obj; | |
1134 | } | |
a55887ca | 1135 | |
3145ec83 | 1136 | /** |
3145ec83 | 1137 | * Loader for a blank sequence diagram. |
a55887ca | 1138 | * |
dbd4432d | 1139 | * @version 1.0 |
3145ec83 BH |
1140 | */ |
1141 | public static class BlankUml2SdLoader implements IUml2SDLoader { | |
3145ec83 BH |
1142 | @Override |
1143 | public void setViewer(SDView viewer) { | |
1144 | // Nothing to do | |
1145 | Frame f = new Frame(); | |
1146 | f.setName(""); //$NON-NLS-1$ | |
1147 | viewer.setFrame(f); | |
1148 | } | |
1149 | ||
3145ec83 BH |
1150 | @Override |
1151 | public String getTitleString() { | |
1152 | return ""; //$NON-NLS-1$ | |
1153 | } | |
1154 | ||
3145ec83 BH |
1155 | @Override |
1156 | public void dispose() { | |
1157 | } | |
a55887ca | 1158 | } |
73005152 | 1159 | } |