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