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