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