tmf: API clean-up of sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / SDView.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd;
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;
29 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
30 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
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;
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;
58 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
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;
63 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
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;
76 import org.eclipse.ui.views.properties.IPropertySheetPage;
77
78 /**
79 * <p>
80 * This class is a generic sequence diagram view implementation.
81 * </p>
82
83 * @version 1.0
84 * @author sveyrier
85 */
86 public class SDView extends ViewPart {
87
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
132 // ------------------------------------------------------------------------
133 // Attributes
134 // ------------------------------------------------------------------------
135 /**
136 * The sequence diagram widget.
137 */
138 private SDWidget fSdWidget = null;
139 /**
140 * The time compression bar.
141 */
142 private TimeCompressionBar fTimeCompressionBar = null;
143 /**
144 * The sequence diagram find provider implementation.
145 */
146 private ISDFindProvider fSdFindProvider = null;
147 /**
148 * The sequence diagram paging provider implementation.
149 */
150 private ISDPagingProvider fSdPagingProvider = null;
151 /**
152 * The sequence diagram filter provider implementation.
153 */
154 private ISDFilterProvider fSdFilterProvider = null;
155 /**
156 * The extended sequence diagram filter provider implementation.
157 */
158 private IExtendedFilterProvider fSdExFilterProvider = null;
159 /**
160 * The extended sequence diagram find provider implementation.
161 */
162 private IExtendedFindProvider fSdExFindProvider = null;
163 /**
164 * The extended sequence diagram action bar provider implementation.
165 */
166 private ISDExtendedActionBarProvider fSdExtendedActionBarProvider = null;
167 /**
168 * The sequence diagram property provider implementation.
169 */
170 private ISDPropertiesProvider fSdPropertiesProvider = null;
171 /**
172 * Button for executing the next page action.
173 */
174 private NextPage fNextPageButton = null;
175 /**
176 * Button for executing the previous page action.
177 */
178 private PrevPage fPrevPageButton = null;
179 /**
180 * Button for executing the first page page action.
181 */
182 private FirstPage fFirstPageButton = null;
183 /**
184 * Button for executing the last page action.
185 */
186 private LastPage fLastPageButton = null;
187 /**
188 * The menu manager reference.
189 */
190 private MenuManager fMenuMgr = null;
191 /**
192 * Flag to indicate whether view needs initialization or not.
193 */
194 private boolean fNeedInit = true;
195 /**
196 * WaitCursor is the cursor to be displayed when long tasks are running
197 */
198 private Cursor fWaitCursor;
199
200 // ------------------------------------------------------------------------
201 // Methods
202 // ------------------------------------------------------------------------
203
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);
216 fTimeCompressionBar = new TimeCompressionBar(parent, SWT.NONE);
217 fTimeCompressionBar.setLayoutData(timeLayoutdata);
218 fSdWidget = new SDWidget(parent, SWT.NONE);
219 fSdWidget.setLayoutData(seqDiagLayoutData);
220 fSdWidget.setSite(this);
221 fSdWidget.setTimeBar(fTimeCompressionBar);
222
223 // Add this view to the key bindings manager
224 KeyBindingsManager.getInstance().add(this.getSite().getId());
225
226 createCoolbarContent();
227
228 hookContextMenu();
229
230 fTimeCompressionBar.setVisible(false);
231 parent.layout(true);
232
233 Print print = new Print(this);
234 getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.PRINT.getId(), print);
235
236 fNeedInit = restoreLoader();
237 }
238
239 /**
240 * Load a blank page that is supposed to explain that a kind of interaction must be chosen.
241 */
242 protected void loadBlank() {
243 IUml2SDLoader loader = new BlankUml2SdLoader();
244 loader.setViewer(this);
245 setContentDescription(loader.getTitleString());
246 }
247
248 @Override
249 public void setFocus() {
250 if (fSdWidget != null) {
251 // update actions for key bindings
252 KeyBindingsManager.getInstance().setSdView(this);
253 fSdWidget.setFocus();
254 }
255 if (isViewReady() && fNeedInit) {
256 fNeedInit = restoreLoader();
257 }
258 }
259
260 @Override
261 public void dispose() {
262 KeyBindingsManager.getInstance().remove(this.getSite().getId());
263 super.dispose();
264 }
265
266 /**
267 * Returns the SD widget.
268 *
269 * @return The SD widget.
270 */
271 public SDWidget getSDWidget() {
272 return fSdWidget;
273 }
274
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>
279 * The find provider is responsible to move the sequence diagram to the GraphNode which match the
280 * find criteria as well as to highlight the GraphNode
281 *
282 * @param provider the search provider
283 */
284 public void setSDFindProvider(ISDFindProvider provider) {
285 fSdFindProvider = provider;
286 fSdExFindProvider = null;
287 createCoolbarContent();
288 if (provider != null) {
289 KeyBindingsManager.getInstance().setFindEnabled(true);
290 }
291 else {
292 KeyBindingsManager.getInstance().setFindEnabled(false);
293 }
294 }
295
296 /**
297 * Set the find provider for the opened sequence diagram viewer<br>
298 * If the provider is not set, the find menu item will not be available in
299 * the viewer<br>
300 * A find provider is called back when the user perform a find action<br>
301 * If the extended find provider is set, it replaces the regular find
302 * provider (sdFindProvider).<br>
303 *
304 * @param provider
305 * The provider to set
306 */
307 public void setExtendedFindProvider(IExtendedFindProvider provider) {
308 fSdExFindProvider = provider;
309 fSdFindProvider = null;
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
321 *
322 * @return extended find provider.
323 */
324 public IExtendedFindProvider getExtendedFindProvider() {
325 return fSdExFindProvider;
326 }
327
328 /**
329 * Resets all providers.
330 */
331 public void resetProviders() {
332 KeyBindingsManager.getInstance().setFindEnabled(false);
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);
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>
349 *
350 * @param provider the filter provider
351 */
352 public void setSDFilterProvider(ISDFilterProvider provider) {
353 fSdFilterProvider = provider;
354 // Both systems can be used now, commenting out next statement
355 createCoolbarContent();
356 }
357
358 /**
359 * Sets the extended filter provider for the opened sequence diagram viewer.
360 *
361 * @param provider
362 * The provider to set
363 */
364 public void setExtendedFilterProvider(IExtendedFilterProvider provider) {
365 fSdExFilterProvider = provider;
366 // Both systems can be used now, commenting out next statement
367 createCoolbarContent();
368 }
369
370 /**
371 * Returns the extended find provider.
372 *
373 * @return The extended find provider.
374 */
375 public IExtendedFilterProvider getExtendedFilterProvider() {
376 return fSdExFilterProvider;
377 }
378
379 /**
380 * Register the given provider to support Drag and Drop collapsing. This provider is
381 * responsible of updating the Frame.
382 *
383 * @param provider - the provider to register
384 */
385 public void setCollapsingProvider(ISDCollapseProvider provider) {
386 if ((fSdWidget != null) && (!fSdWidget.isDisposed())) {
387 fSdWidget.setCollapseProvider(provider);
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
396 *
397 * @param provider the paging provider
398 */
399 public void setSDPagingProvider(ISDPagingProvider provider) {
400 fSdPagingProvider = provider;
401 createCoolbarContent();
402 }
403
404 /**
405 * Returns the current page provider for the view
406 *
407 * @return the paging provider
408 */
409 public ISDPagingProvider getSDPagingProvider() {
410 return fSdPagingProvider;
411 }
412
413 /**
414 * Returns the current find provider for the view
415 *
416 * @return the find provider
417 */
418 public ISDFindProvider getSDFindProvider() {
419 return fSdFindProvider;
420 }
421
422 /**
423 * Returns the current filter provider for the view
424 *
425 * @return the filter provider
426 */
427 public ISDFilterProvider getSDFilterProvider() {
428 return fSdFilterProvider;
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
434 *
435 * @param provider the search provider
436 */
437 public void setSDExtendedActionBarProvider(ISDExtendedActionBarProvider provider) {
438 fSdExtendedActionBarProvider = provider;
439 createCoolbarContent();
440 }
441
442 /**
443 * Returns the current extended action bar provider for the view
444 *
445 * @return the extended action bar provider
446 */
447 public ISDExtendedActionBarProvider getSDExtendedActionBarProvider() {
448 return fSdExtendedActionBarProvider;
449 }
450
451 /**
452 * Set the properties view provider for the opened sequence diagram viewer
453 *
454 * @param provider the properties provider
455 */
456 public void setSDPropertiesProvider(ISDPropertiesProvider provider) {
457 fSdPropertiesProvider = provider;
458 }
459
460 /**
461 * Returns the current extended action bar provider for the view.
462 *
463 * @return the extended action bar provider
464 */
465 public ISDPropertiesProvider getSDPropertiesProvider() {
466 return fSdPropertiesProvider;
467 }
468
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
502 /**
503 * Creates the basic sequence diagram menu
504 */
505 protected void hookContextMenu() {
506 fMenuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
507 fMenuMgr.setRemoveAllWhenShown(true);
508 fMenuMgr.addMenuListener(new IMenuListener() {
509 @Override
510 public void menuAboutToShow(IMenuManager manager) {
511 fillContextMenu(manager);
512 }
513 });
514 Menu menu = fMenuMgr.createContextMenu(fSdWidget.getViewControl());
515 fSdWidget.getViewControl().setMenu(menu);
516 getSite().registerContextMenu(fMenuMgr, fSdWidget.getSelectionProvider());
517 }
518
519 /**
520 * Returns the context menu manager
521 *
522 * @return the menu manager
523 */
524 public MenuManager getMenuManager() {
525 return fMenuMgr;
526 }
527
528 /**
529 * Fills the basic sequence diagram menu and define the dynamic menu item insertion point
530 *
531 * @param manager the menu manager
532 */
533 protected void fillContextMenu(IMenuManager manager) {
534 manager.add(new Separator("Additions")); //$NON-NLS-1$
535 if (getSDWidget() != null && getSDWidget().getCurrentGraphNode() != null) {
536 ISelectionProvider selProvider = fSdWidget.getSelectionProvider();
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 }
549 GraphNode node = getSDWidget().getCurrentGraphNode();
550 if ((node instanceof SyncMessageReturn) && (((SyncMessageReturn) node).getMessage() != null)) {
551 Action goToMessage = new MoveToMessage(this);
552 goToMessage.setText(Messages.SequenceDiagram_GoToMessage);
553 manager.add(goToMessage);
554 }
555 if ((node instanceof SyncMessage) && (((SyncMessage) node).getMessageReturn() != null)) {
556 Action goToMessage = new MoveToMessage(this);
557 goToMessage.setText(Messages.SequenceDiagram_GoToMessageReturn);
558 manager.add(goToMessage);
559 }
560 }
561 manager.add(new Separator("MultiSelectAdditions")); //$NON-NLS-1$
562 }
563
564 /**
565 * Enables/Disables an action with given name.
566 *
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>
589 *
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);
604 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, resetZoom);
605 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, resetZoom);
606
607 Zoom noZoom = new Zoom(this, ZoomType.ZOOM_NONE);
608 noZoom.setChecked(true);
609 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, noZoom);
610 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, noZoom);
611
612 Zoom zoomIn = new Zoom(this, ZoomType.ZOOM_IN);
613 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomIn);
614 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomIn);
615
616 Zoom zoomOut = new Zoom(this, ZoomType.ZOOM_OUT);
617 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomOut);
618 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, zoomOut);
619
620 MenuManager navigation = new MenuManager(Messages.SequenceDiagram_Navigation);
621
622 ShowNodeStart showNodeStart = new ShowNodeStart(this);
623 showNodeStart.setText(Messages.SequenceDiagram_ShowNodeStart);
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);
630 showNodeEnd.setText(Messages.SequenceDiagram_ShowNodeEnd);
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
636 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, navigation);
637
638 ConfigureMinMax minMax = new ConfigureMinMax(this);
639 minMax.setText(Messages.SequenceDiagram_ConfigureMinMax);
640 minMax.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax");//$NON-NLS-1$
641 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, minMax);
642
643 if ((fSdWidget.getFrame() != null) && (fSdWidget.getFrame().hasTimeInfo())) {
644 minMax.setEnabled(true);
645 } else {
646 minMax.setEnabled(false);
647 }
648
649 // Do we need to display a paging item
650 if (fSdPagingProvider != null) {
651 fNextPageButton = new NextPage(this);
652 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fNextPageButton);
653 fNextPageButton.setEnabled(fSdPagingProvider.hasNextPage());
654 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fNextPageButton);
655
656 fPrevPageButton = new PrevPage(this);
657 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fPrevPageButton);
658 fPrevPageButton.setEnabled(fSdPagingProvider.hasPrevPage());
659 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fPrevPageButton);
660
661 fFirstPageButton = new FirstPage(this);
662 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fFirstPageButton);
663 fFirstPageButton.setEnabled(fSdPagingProvider.hasPrevPage());
664 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fFirstPageButton);
665
666 fLastPageButton = new LastPage(this);
667 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fLastPageButton);
668 fLastPageButton.setEnabled(fSdPagingProvider.hasNextPage());
669 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, fLastPageButton);
670 }
671
672 if (fSdExFilterProvider != null) {
673 Action action = fSdExFilterProvider.getFilterAction();
674 if (action != null) {
675 if (action.getId() == null)
676 {
677 action.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFilter"); //$NON-NLS-1$
678 }
679 if (action.getImageDescriptor() == null) {
680 action.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FILTERS));
681 }
682 if (action.getText() == null || action.getText().length() == 0) {
683 action.setText(Messages.SequenceDiagram_EditFilters);
684 }
685 bar.getMenuManager().prependToGroup(UML2SD_FILTERING_SEPARATOR, action);
686 bar.getToolBarManager().prependToGroup(UML2SD_FILTERING_SEPARATOR, action);
687 }
688 }
689 // Both systems can be used now: commenting out else keyword
690 if (fSdFilterProvider != null) {
691 bar.getMenuManager().appendToGroup(UML2SD_FILTERING_SEPARATOR, new OpenSDFiltersDialog(this, fSdFilterProvider));
692 }
693 if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) {
694 IContributionItem sdPaging = bar.getMenuManager().find(OpenSDPagesDialog.ID);
695 if (sdPaging != null) {
696 bar.getMenuManager().remove(sdPaging);
697 sdPaging = null;
698 }
699 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, new OpenSDPagesDialog(this, (ISDAdvancedPagingProvider) fSdPagingProvider));
700 updatePagesMenuItem(bar);
701 }
702
703 if (fSdExFindProvider != null) {
704 Action action = fSdExFindProvider.getFindAction();
705 if (action != null) {
706 if (action.getId() == null) {
707 action.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFind"); //$NON-NLS-1$
708 }
709 if (action.getImageDescriptor() == null) {
710 action.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_SEQ));
711 }
712 if (action.getText() == null) {
713 action.setText(Messages.SequenceDiagram_Find + "..."); //$NON-NLS-1$
714 }
715 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, action);
716 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, action);
717 }
718 } else if (fSdFindProvider != null) {
719 bar.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, new OpenSDFindDialog(this));
720 bar.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR, new OpenSDFindDialog(this));
721 }
722
723 if (fSdExtendedActionBarProvider != null) {
724 fSdExtendedActionBarProvider.supplementCoolbarContent(bar);
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>
734 *
735 */
736 public void updateCoolBar() {
737 if (fSdPagingProvider != null) {
738 IActionBars bar = getViewSite().getActionBars();
739 if (bar == null) {
740 return;
741 }
742 IToolBarManager barManager = bar.getToolBarManager();
743 if (barManager == null) {
744 return;
745 }
746 IContributionItem nextPage = barManager.find(NextPage.ID);
747 if (nextPage instanceof ActionContributionItem) {
748 IAction nextPageAction = ((ActionContributionItem) nextPage).getAction();
749 if (nextPageAction instanceof NextPage) {
750 ((NextPage) nextPageAction).setEnabled(fSdPagingProvider.hasNextPage());
751 }
752 }
753
754 IContributionItem prevPage = barManager.find(PrevPage.ID);
755 if (prevPage instanceof ActionContributionItem) {
756 IAction prevPageAction = ((ActionContributionItem) prevPage).getAction();
757 if (prevPageAction instanceof PrevPage) {
758 ((PrevPage) prevPageAction).setEnabled(fSdPagingProvider.hasPrevPage());
759 }
760 }
761
762 IContributionItem firstPage = barManager.find(FirstPage.ID);
763 if (firstPage instanceof ActionContributionItem) {
764 IAction firstPageAction = ((ActionContributionItem) firstPage).getAction();
765 if (firstPageAction instanceof FirstPage) {
766 ((FirstPage) firstPageAction).setEnabled(fSdPagingProvider.hasPrevPage());
767 }
768 }
769
770 IContributionItem lastPage = barManager.find(LastPage.ID);
771 if (lastPage instanceof ActionContributionItem) {
772 IAction lastPageAction = ((ActionContributionItem) lastPage).getAction();
773 if (lastPageAction instanceof LastPage) {
774 ((LastPage) lastPageAction).setEnabled(fSdPagingProvider.hasNextPage());
775 }
776 }
777
778 updatePagesMenuItem(bar);
779 }
780 }
781
782 /**
783 * Enables or disables the Pages... menu item, depending on the number of pages
784 *
785 * @param bar the bar containing the action
786 */
787 protected void updatePagesMenuItem(IActionBars bar) {
788 if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) {
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
796 if (openSDPagesDialog instanceof OpenSDPagesDialog) {
797 openSDPagesDialog.setEnabled(((ISDAdvancedPagingProvider) fSdPagingProvider).pagesCount() > 1);
798 }
799 }
800 }
801
802 /**
803 * The frame to render (the sequence diagram)
804 *
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)
813 *
814 * @param frame the frame to display
815 * @param resetPosition boolean Flag whether to reset the position or not.
816 */
817 protected void setFrame(Frame frame, boolean resetPosition) {
818 if (getSDWidget() == null) {
819 return;
820 }
821
822 if (frame == null) {
823 loadBlank();
824 return;
825 }
826
827 IUml2SDLoader loader = LoadersManager.getInstance().getCurrentLoader(getViewSite().getId(), this);
828 if (loader == null) {
829 return;
830 }
831
832 if (loader.getTitleString() != null) {
833 setContentDescription(loader.getTitleString());
834 }
835
836 getSDWidget().setFrame(frame, resetPosition);
837
838 if (fTimeCompressionBar != null) {
839 fTimeCompressionBar.setFrame(frame);
840 }
841 updateCoolBar();
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 }
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();
860 if (action != null) {
861 action.setEnabled(true);
862 }
863 }
864 }
865 }
866 createCoolbarContent();
867 }
868
869 /**
870 * Activate or deactivate the short key command given in parameter (see plugin.xml)
871 *
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;
878 if (shortKeys == null) {
879 return;
880 }
881 IContributionItem item = shortKeys.find(id);
882 if ((item != null) && (item instanceof ActionContributionItem)) {
883 IAction action = ((ActionContributionItem) item).getAction();
884 if (action != null) {
885 action.setEnabled(value);
886 }
887 }
888 }
889
890 /**
891 * Set the frame from an other thread than the one executing the main loop
892 *
893 * @param frame The frame to set (and display)
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() {
902 if (getSDWidget() == null || getSDWidget().isDisposed() ||
903 ((fTimeCompressionBar != null) && fTimeCompressionBar.isDisposed())) {
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
914 *
915 * @param sm The node to make visible in view
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
931 *
932 * @param sm The node to make visible in view
933 * @param frame Frame The frame to set
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
952 *
953 * @param sm The node to make visible in view
954 * @param frame Frame The frame to set
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
964 *
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.
968 */
969 public void setFrameAndEnsureVisibleSync(final Frame frame, final int x, final int y) {
970 if (getSDWidget() == null || getSDWidget().isDisposed()) {
971 return;
972 }
973
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
984 *
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.
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
996 /**
997 * Toggle between default and wait cursors from an other thread than the one executing the main loop
998 *
999 * @param wait <code>true</code> for wait cursor else <code>false</code> for default cursor.
1000 */
1001 public void toggleWaitCursorAsync(final boolean wait) {
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 }
1012 if (wait) {
1013 if (fWaitCursor != null && !fWaitCursor.isDisposed()) {
1014 fWaitCursor.dispose();
1015 }
1016 fWaitCursor = new Cursor(getSDWidget().getDisplay(), SWT.CURSOR_WAIT);
1017 getSDWidget().setCursor(fWaitCursor);
1018 getSDWidget().getDisplay().update();
1019 } else {
1020 if (fWaitCursor != null && !fWaitCursor.isDisposed()) {
1021 fWaitCursor.dispose();
1022 }
1023 fWaitCursor = null;
1024 getSDWidget().setCursor(null);
1025 getSDWidget().getDisplay().update();
1026 }
1027 }
1028 });
1029 }
1030
1031 /**
1032 * Return the time compression bar widget
1033 *
1034 * @return the time compression bar
1035 */
1036 public TimeCompressionBar getTimeCompressionBar() {
1037 return fTimeCompressionBar;
1038 }
1039
1040 /**
1041 * Returns the current Frame (the sequence diagram container)
1042 *
1043 * @return the current frame
1044 */
1045 public Frame getFrame() {
1046 if (getSDWidget() != null) {
1047 return getSDWidget().getFrame();
1048 }
1049 return null;
1050 }
1051
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
1061 /**
1062 * Restores the loader for the view based on the view ID.
1063 *
1064 * @return boolean <code>true</code> if initialization is needed else <code>false</code>.
1065 */
1066 protected boolean restoreLoader() {
1067 String id = getViewSite().getId();
1068 if (id == null) {
1069 return true;
1070 }
1071 IUml2SDLoader loader = LoadersManager.getInstance().getCurrentLoader(id, this);
1072 if ((loader != null)) {
1073 loader.setViewer(this);
1074 return false;
1075 }
1076 loadBlank();
1077 return true;
1078 }
1079
1080 /**
1081 * Checks if current view is ready to be used.
1082 *
1083 * @return boolean <code>true</code> if view is ready else <code>false</code>.
1084 */
1085 protected boolean isViewReady() {
1086 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1087 if (page == null) {
1088 return false;
1089 }
1090
1091 IViewReference[] ref = page.getViewReferences();
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
1100 /**
1101 * Creates the menu group.
1102 */
1103 protected void createMenuGroup() {
1104 IActionBars bar = getViewSite().getActionBars();
1105 if (bar == null) {
1106 return;
1107 }
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));
1124 }
1125
1126 @Override
1127 public Object getAdapter(Class adapter) {
1128 Object obj = super.getAdapter(adapter);
1129 if (fSdPropertiesProvider != null && adapter.equals(IPropertySheetPage.class)) {
1130 return fSdPropertiesProvider.getPropertySheetEntry();
1131 }
1132
1133 return obj;
1134 }
1135
1136 /**
1137 * Loader for a blank sequence diagram.
1138 *
1139 * @version 1.0
1140 */
1141 public static class BlankUml2SdLoader implements IUml2SDLoader {
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
1150 @Override
1151 public String getTitleString() {
1152 return ""; //$NON-NLS-1$
1153 }
1154
1155 @Override
1156 public void dispose() {
1157 }
1158 }
1159 }
This page took 0.087022 seconds and 5 git commands to generate.