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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
;
15 import java
.util
.Iterator
;
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
;
85 * This class is a generic sequence diagram view implementation.
91 public class SDView
extends ViewPart
implements IPartListener
{
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
97 * Name of menu separator for view modes
99 public static final String UML2SD_VIEW_MODES_SEPARATOR
= "UML2SD_VIEW_MODES"; //$NON-NLS-1$
101 * Name of menu separator for working set
103 public static final String UML2SD_WORKING_SET_SEPARATOR
= "UML2SD_WORKING_SET"; //$NON-NLS-1$
105 * Name of menu separator for sorting
107 public static final String UML2SD_SORTING_SEPARATOR
= "UML2SD_SORTING"; //$NON-NLS-1$
109 * Name of menu separator for filtering
111 public static final String UML2SD_FILTERING_SEPARATOR
= "UML2SD_FILTERING"; //$NON-NLS-1$
113 * Name of menu separator for view layout
115 public static final String UML2SD_VIEW_LAYOUT_SEPARATOR
= "UML2SD_VIEW_LAYOUT"; //$NON-NLS-1$
117 * Name of menu separator for link editor
119 public static final String UML2SD_LINK_EDITOR_SEPARATOR
= "UML2SD_LINK_EDITOR"; //$NON-NLS-1$
121 * Name of menu separator for other commands
123 public static final String UML2SD_OTHER_COMMANDS_SEPARATOR
= "UML2SD_OTHER_COMMANDS"; //$NON-NLS-1$
125 * Name of menu separator for other plug-in commands
127 public static final String UML2SD_OTHER_PLUGINS_COMMANDS_SEPARATOR
= "UML2SD_OTHER_PLUGINS_COMMANDS"; //$NON-NLS-1$
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
133 * The sequence diagram widget.
135 private SDWidget fSdWidget
= null;
137 * The time compression bar.
139 private TimeCompressionBar fTimeCompressionBar
= null;
141 * The sequence diagram find provider implementation.
143 private ISDFindProvider fSdFindProvider
= null;
145 * The sequence diagram paging provider implementation.
147 private ISDPagingProvider fSdPagingProvider
= null;
149 * The sequence diagram filter provider implementation.
151 private ISDFilterProvider fSdFilterProvider
= null;
153 * The extended sequence diagram filter provider implementation.
155 private IExtendedFilterProvider fSdExFilterProvider
= null;
157 * The extended sequence diagram find provider implementation.
159 private IExtendedFindProvider fSdExFindProvider
= null;
161 * The extended sequence diagram action bar provider implementation.
163 private ISDExtendedActionBarProvider fSdExtendedActionBarProvider
= null;
165 * The sequence diagram property provider implementation.
167 private ISDPropertiesProvider fSdPropertiesProvider
= null;
169 * Button for executing the next page action.
171 private NextPage fNextPageButton
= null;
173 * Button for executing the previous page action.
175 private PrevPage fPrevPageButton
= null;
177 * Button for executing the first page page action.
179 private FirstPage fFirstPageButton
= null;
181 * Button for executing the last page action.
183 private LastPage fLastPageButton
= null;
185 * The menu manager reference.
187 private MenuManager fMenuMgr
= null;
189 * Flag to indicate whether view needs initialization or not.
191 private boolean fNeedInit
= true;
193 * WaitCursor is the cursor to be displayed when long tasks are running
195 private Cursor fWaitCursor
;
197 private Zoom fResetZoomAction
;
198 private Zoom fNoZoomAction
;
199 private Zoom fZoomInAction
;
200 private Zoom fZoomOutAction
;
201 private ActionHandler fPrintActionHandler
;
203 * Keeping this allows to deactivate the action when the view is
206 private IHandlerActivation fPrintHandlerActivation
;
208 // ------------------------------------------------------------------------
210 // ------------------------------------------------------------------------
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
);
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
);
231 // Add this view to the key bindings manager
232 KeyBindingsManager
.getInstance().add(this.getSite().getId());
234 createCoolbarContent();
238 fTimeCompressionBar
.setVisible(false);
241 fPrintActionHandler
= new ActionHandler(new Print(this));
242 getSite().getPage().addPartListener(this);
244 fNeedInit
= restoreLoader();
248 * Load a blank page that is supposed to explain that a kind of interaction must be chosen.
250 protected void loadBlank() {
251 IUml2SDLoader loader
= new BlankUml2SdLoader();
252 loader
.setViewer(this);
253 setContentDescription(loader
.getTitleString());
257 public void setFocus() {
258 if (fSdWidget
!= null) {
259 // update actions for key bindings
260 KeyBindingsManager
.getInstance().setSdView(this);
261 fSdWidget
.setFocus();
263 if (isViewReady() && fNeedInit
) {
264 fNeedInit
= restoreLoader();
269 public void dispose() {
270 KeyBindingsManager
.getInstance().remove(this.getSite().getId());
272 /* Workaround for Bug 490400: Clear the action bars */
273 IActionBars bars
= getViewSite().getActionBars();
274 bars
.getToolBarManager().removeAll();
275 bars
.getMenuManager().removeAll();
277 disposeZoomActions();
278 fPrintActionHandler
.dispose();
282 private void disposeZoomActions() {
283 if (fResetZoomAction
!= null) {
284 fResetZoomAction
.dispose();
286 if (fNoZoomAction
!= null) {
287 fNoZoomAction
.dispose();
289 if (fZoomInAction
!= null) {
290 fZoomInAction
.dispose();
292 if (fZoomOutAction
!= null) {
293 fZoomOutAction
.dispose();
298 * Returns the SD widget.
300 * @return The SD widget.
302 public SDWidget
getSDWidget() {
307 * Set the find provider for the opened sequence diagram viewer<br>
308 * If the provider is not set, the find menu item will not be available in the viewer<br>
309 * A find provider is called back when the user perform a find action<br>
310 * The find provider is responsible to move the sequence diagram to the GraphNode which match the
311 * find criteria as well as to highlight the GraphNode
313 * @param provider the search provider
315 public void setSDFindProvider(ISDFindProvider provider
) {
316 fSdFindProvider
= provider
;
317 fSdExFindProvider
= null;
318 createCoolbarContent();
319 if (provider
!= null) {
320 KeyBindingsManager
.getInstance().setFindEnabled(true);
323 KeyBindingsManager
.getInstance().setFindEnabled(false);
328 * Set the find provider for the opened sequence diagram viewer<br>
329 * If the provider is not set, the find menu item will not be available in
331 * A find provider is called back when the user perform a find action<br>
332 * If the extended find provider is set, it replaces the regular find
333 * provider (sdFindProvider).<br>
336 * The provider to set
338 public void setExtendedFindProvider(IExtendedFindProvider provider
) {
339 fSdExFindProvider
= provider
;
340 fSdFindProvider
= null;
341 createCoolbarContent();
342 if (provider
!= null) {
343 KeyBindingsManager
.getInstance().setFindEnabled(true);
346 KeyBindingsManager
.getInstance().setFindEnabled(false);
351 * Returns the extended find provider
353 * @return extended find provider.
355 public IExtendedFindProvider
getExtendedFindProvider() {
356 return fSdExFindProvider
;
360 * Resets all providers.
362 public void resetProviders() {
363 KeyBindingsManager
.getInstance().setFindEnabled(false);
364 fSdFindProvider
= null;
365 fSdExFindProvider
= null;
366 fSdFilterProvider
= null;
367 fSdExFilterProvider
= null;
368 fSdPagingProvider
= null;
369 fSdExtendedActionBarProvider
= null;
370 fSdPropertiesProvider
= null;
371 if ((fSdWidget
!= null) && (!fSdWidget
.isDisposed())) {
372 fSdWidget
.setCollapseProvider(null);
377 * Set the filter provider for the opened sequence diagram viewer<br>
378 * If the provider is not set, the filter menu item will not be available in the viewer<br>
379 * A filter provider is called back when the user perform a filter action<br>
381 * @param provider the filter provider
383 public void setSDFilterProvider(ISDFilterProvider provider
) {
384 fSdFilterProvider
= provider
;
385 // Both systems can be used now, commenting out next statement
386 createCoolbarContent();
390 * Sets the extended filter provider for the opened sequence diagram viewer.
393 * The provider to set
395 public void setExtendedFilterProvider(IExtendedFilterProvider provider
) {
396 fSdExFilterProvider
= provider
;
397 // Both systems can be used now, commenting out next statement
398 createCoolbarContent();
402 * Returns the extended find provider.
404 * @return The extended find provider.
406 public IExtendedFilterProvider
getExtendedFilterProvider() {
407 return fSdExFilterProvider
;
411 * Register the given provider to support Drag and Drop collapsing. This provider is
412 * responsible of updating the Frame.
414 * @param provider - the provider to register
416 public void setCollapsingProvider(ISDCollapseProvider provider
) {
417 if ((fSdWidget
!= null) && (!fSdWidget
.isDisposed())) {
418 fSdWidget
.setCollapseProvider(provider
);
423 * Set the page provider for the opened sequence diagram viewer<br>
424 * If the sequence diagram provided (see setFrame) need to be split in many parts, a paging provider must be
425 * provided in order to handle page change requested by the user<br>
426 * Set a page provider will create the next and previous page buttons in the viewer coolBar
428 * @param provider the paging provider
430 public void setSDPagingProvider(ISDPagingProvider provider
) {
431 fSdPagingProvider
= provider
;
432 createCoolbarContent();
436 * Returns the current page provider for the view
438 * @return the paging provider
440 public ISDPagingProvider
getSDPagingProvider() {
441 return fSdPagingProvider
;
445 * Returns the current find provider for the view
447 * @return the find provider
449 public ISDFindProvider
getSDFindProvider() {
450 return fSdFindProvider
;
454 * Returns the current filter provider for the view
456 * @return the filter provider
458 public ISDFilterProvider
getSDFilterProvider() {
459 return fSdFilterProvider
;
463 * Set the extended action bar provider for the opened sequence diagram viewer<br>
464 * This allow to add programmatically actions in the coolbar and/or in the drop-down menu
466 * @param provider the search provider
468 public void setSDExtendedActionBarProvider(ISDExtendedActionBarProvider provider
) {
469 fSdExtendedActionBarProvider
= provider
;
470 createCoolbarContent();
474 * Returns the current extended action bar provider for the view
476 * @return the extended action bar provider
478 public ISDExtendedActionBarProvider
getSDExtendedActionBarProvider() {
479 return fSdExtendedActionBarProvider
;
483 * Set the properties view provider for the opened sequence diagram viewer
485 * @param provider the properties provider
487 public void setSDPropertiesProvider(ISDPropertiesProvider provider
) {
488 fSdPropertiesProvider
= provider
;
492 * Returns the current extended action bar provider for the view.
494 * @return the extended action bar provider
496 public ISDPropertiesProvider
getSDPropertiesProvider() {
497 return fSdPropertiesProvider
;
506 protected void setSDWidget(SDWidget sdWidget
) {
507 fSdWidget
= sdWidget
;
511 * Sets the time compression bar.
513 * @param timeCompressionbar
516 protected void setTimeBar(TimeCompressionBar timeCompressionbar
) {
517 fTimeCompressionBar
= timeCompressionbar
;
521 * Sets the initialization flag.
526 protected void setNeedInit(boolean needInit
) {
527 fNeedInit
= needInit
;
531 * Creates the basic sequence diagram menu
533 protected void hookContextMenu() {
534 fMenuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
535 fMenuMgr
.setRemoveAllWhenShown(true);
536 fMenuMgr
.addMenuListener(new IMenuListener() {
538 public void menuAboutToShow(IMenuManager manager
) {
539 fillContextMenu(manager
);
542 Menu menu
= fMenuMgr
.createContextMenu(fSdWidget
.getViewControl());
543 fSdWidget
.getViewControl().setMenu(menu
);
544 getSite().registerContextMenu(fMenuMgr
, fSdWidget
.getSelectionProvider());
548 * Returns the context menu manager
550 * @return the menu manager
552 public MenuManager
getMenuManager() {
557 * Fills the basic sequence diagram menu and define the dynamic menu item insertion point
559 * @param manager the menu manager
561 protected void fillContextMenu(IMenuManager manager
) {
562 manager
.add(new Separator("Additions")); //$NON-NLS-1$
563 if (getSDWidget() != null && getSDWidget().getCurrentGraphNode() != null) {
564 ISelectionProvider selProvider
= fSdWidget
.getSelectionProvider();
565 ISelection sel
= selProvider
.getSelection();
567 Iterator
<?
> it
= ((StructuredSelection
) sel
).iterator();
568 while (it
.hasNext()) {
569 Object node
= it
.next();
570 if (node
instanceof BaseMessage
) {
574 if (nbMessage
!= 1) {
577 GraphNode node
= getSDWidget().getCurrentGraphNode();
578 if ((node
instanceof SyncMessageReturn
) && (((SyncMessageReturn
) node
).getMessage() != null)) {
579 Action goToMessage
= new MoveToMessage(this);
580 goToMessage
.setText(Messages
.SequenceDiagram_GoToMessage
);
581 manager
.add(goToMessage
);
583 if ((node
instanceof SyncMessage
) && (((SyncMessage
) node
).getMessageReturn() != null)) {
584 Action goToMessage
= new MoveToMessage(this);
585 goToMessage
.setText(Messages
.SequenceDiagram_GoToMessageReturn
);
586 manager
.add(goToMessage
);
589 manager
.add(new Separator("MultiSelectAdditions")); //$NON-NLS-1$
593 * Enables/Disables an action with given name.
595 * @param actionName The action name
596 * @param state true or false
598 public void setEnableAction(String actionName
, boolean state
) {
599 IActionBars bar
= getViewSite().getActionBars();
601 IContributionItem item
= bar
.getMenuManager().find(actionName
);
602 if ((item
!= null) && (item
instanceof ActionContributionItem
)) {
603 IAction action
= ((ActionContributionItem
) item
).getAction();
604 if (action
!= null) {
605 action
.setEnabled(state
);
607 item
.setVisible(state
);
608 bar
.updateActionBars();
614 * Creates the coolBar icon depending on the actions supported by the Sequence Diagram provider<br>
615 * - Navigation buttons are displayed if ISDPovider.HasPaging return true<br>
616 * - Navigation buttons are enabled depending on the value return by ISDPovider.HasNext and HasPrev<br>
618 * @see ISDGraphNodeSupporter Action support definition
619 * @see SDView#setSDFilterProvider(ISDFilterProvider)
620 * @see SDView#setSDFindProvider(ISDFindProvider)
621 * @see SDView#setSDPagingProvider(ISDPagingProvider)
623 protected void createCoolbarContent() {
624 IActionBars bar
= getViewSite().getActionBars();
626 bar
.getMenuManager().removeAll();
627 bar
.getToolBarManager().removeAll();
628 disposeZoomActions();
632 fResetZoomAction
= new Zoom(this, ZoomType
.ZOOM_RESET
);
633 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fResetZoomAction
);
634 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fResetZoomAction
);
636 fNoZoomAction
= new Zoom(this, ZoomType
.ZOOM_NONE
);
637 fNoZoomAction
.setChecked(true);
638 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNoZoomAction
);
639 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNoZoomAction
);
641 fZoomInAction
= new Zoom(this, ZoomType
.ZOOM_IN
);
642 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomInAction
);
643 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomInAction
);
645 fZoomOutAction
= new Zoom(this, ZoomType
.ZOOM_OUT
);
646 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomOutAction
);
647 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomOutAction
);
649 MenuManager navigation
= new MenuManager(Messages
.SequenceDiagram_Navigation
);
651 ShowNodeStart showNodeStart
= new ShowNodeStart(this);
652 showNodeStart
.setText(Messages
.SequenceDiagram_ShowNodeStart
);
654 showNodeStart
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
655 showNodeStart
.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
656 navigation
.add(showNodeStart
);
658 ShowNodeEnd showNodeEnd
= new ShowNodeEnd(this);
659 showNodeEnd
.setText(Messages
.SequenceDiagram_ShowNodeEnd
);
661 showNodeEnd
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
662 showNodeEnd
.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
663 navigation
.add(showNodeEnd
);
665 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, navigation
);
667 ConfigureMinMax minMax
= new ConfigureMinMax(this);
668 minMax
.setText(Messages
.SequenceDiagram_ConfigureMinMax
);
669 minMax
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax");//$NON-NLS-1$
670 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, minMax
);
672 if ((fSdWidget
.getFrame() != null) && (fSdWidget
.getFrame().hasTimeInfo())) {
673 minMax
.setEnabled(true);
675 minMax
.setEnabled(false);
678 // Do we need to display a paging item
679 if (fSdPagingProvider
!= null) {
680 fNextPageButton
= new NextPage(this);
681 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNextPageButton
);
682 fNextPageButton
.setEnabled(fSdPagingProvider
.hasNextPage());
683 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNextPageButton
);
685 fPrevPageButton
= new PrevPage(this);
686 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fPrevPageButton
);
687 fPrevPageButton
.setEnabled(fSdPagingProvider
.hasPrevPage());
688 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fPrevPageButton
);
690 fFirstPageButton
= new FirstPage(this);
691 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fFirstPageButton
);
692 fFirstPageButton
.setEnabled(fSdPagingProvider
.hasPrevPage());
693 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fFirstPageButton
);
695 fLastPageButton
= new LastPage(this);
696 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fLastPageButton
);
697 fLastPageButton
.setEnabled(fSdPagingProvider
.hasNextPage());
698 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fLastPageButton
);
701 if (fSdExFilterProvider
!= null) {
702 Action action
= fSdExFilterProvider
.getFilterAction();
703 if (action
!= null) {
704 if (action
.getId() == null)
706 action
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFilter"); //$NON-NLS-1$
708 if (action
.getImageDescriptor() == null) {
709 action
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FILTERS
));
711 if (action
.getText() == null || action
.getText().length() == 0) {
712 action
.setText(Messages
.SequenceDiagram_EditFilters
);
714 bar
.getMenuManager().prependToGroup(UML2SD_FILTERING_SEPARATOR
, action
);
715 bar
.getToolBarManager().prependToGroup(UML2SD_FILTERING_SEPARATOR
, action
);
718 // Both systems can be used now: commenting out else keyword
719 if (fSdFilterProvider
!= null) {
720 bar
.getMenuManager().appendToGroup(UML2SD_FILTERING_SEPARATOR
, new OpenSDFiltersDialog(this, fSdFilterProvider
));
722 if (fSdPagingProvider
instanceof ISDAdvancedPagingProvider
) {
723 IContributionItem sdPaging
= bar
.getMenuManager().find(OpenSDPagesDialog
.ID
);
724 if (sdPaging
!= null) {
725 bar
.getMenuManager().remove(sdPaging
);
728 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, new OpenSDPagesDialog(this, (ISDAdvancedPagingProvider
) fSdPagingProvider
));
729 updatePagesMenuItem(bar
);
732 if (fSdExFindProvider
!= null) {
733 Action action
= fSdExFindProvider
.getFindAction();
734 if (action
!= null) {
735 if (action
.getId() == null) {
736 action
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFind"); //$NON-NLS-1$
738 if (action
.getImageDescriptor() == null) {
739 action
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SEARCH_SEQ
));
741 if (action
.getText() == null) {
742 action
.setText(Messages
.SequenceDiagram_Find
+ "..."); //$NON-NLS-1$
744 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, action
);
745 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, action
);
747 } else if (fSdFindProvider
!= null) {
748 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, new OpenSDFindDialog(this));
749 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, new OpenSDFindDialog(this));
752 if (fSdExtendedActionBarProvider
!= null) {
753 fSdExtendedActionBarProvider
.supplementCoolbarContent(bar
);
756 bar
.updateActionBars();
760 * Updates the view coolbar buttons state according to the value return by: -
761 * ISDExtendedActionBarProvider.hasNextPage()<br>
762 * - ISDExtendedActionBarProvider.hasPrevPage()<br>
765 public void updateCoolBar() {
766 if (fSdPagingProvider
!= null) {
767 IActionBars bar
= getViewSite().getActionBars();
771 IToolBarManager barManager
= bar
.getToolBarManager();
772 if (barManager
== null) {
775 IContributionItem nextPage
= barManager
.find(NextPage
.ID
);
776 if (nextPage
instanceof ActionContributionItem
) {
777 IAction nextPageAction
= ((ActionContributionItem
) nextPage
).getAction();
778 if (nextPageAction
instanceof NextPage
) {
779 ((NextPage
) nextPageAction
).setEnabled(fSdPagingProvider
.hasNextPage());
783 IContributionItem prevPage
= barManager
.find(PrevPage
.ID
);
784 if (prevPage
instanceof ActionContributionItem
) {
785 IAction prevPageAction
= ((ActionContributionItem
) prevPage
).getAction();
786 if (prevPageAction
instanceof PrevPage
) {
787 ((PrevPage
) prevPageAction
).setEnabled(fSdPagingProvider
.hasPrevPage());
791 IContributionItem firstPage
= barManager
.find(FirstPage
.ID
);
792 if (firstPage
instanceof ActionContributionItem
) {
793 IAction firstPageAction
= ((ActionContributionItem
) firstPage
).getAction();
794 if (firstPageAction
instanceof FirstPage
) {
795 ((FirstPage
) firstPageAction
).setEnabled(fSdPagingProvider
.hasPrevPage());
799 IContributionItem lastPage
= barManager
.find(LastPage
.ID
);
800 if (lastPage
instanceof ActionContributionItem
) {
801 IAction lastPageAction
= ((ActionContributionItem
) lastPage
).getAction();
802 if (lastPageAction
instanceof LastPage
) {
803 ((LastPage
) lastPageAction
).setEnabled(fSdPagingProvider
.hasNextPage());
807 updatePagesMenuItem(bar
);
812 * Enables or disables the Pages... menu item, depending on the number of pages
814 * @param bar the bar containing the action
816 protected void updatePagesMenuItem(IActionBars bar
) {
817 if (fSdPagingProvider
instanceof ISDAdvancedPagingProvider
) {
818 IMenuManager menuManager
= bar
.getMenuManager();
819 ActionContributionItem contributionItem
= (ActionContributionItem
) menuManager
.find(OpenSDPagesDialog
.ID
);
820 IAction openSDPagesDialog
= null;
821 if (contributionItem
!= null) {
822 openSDPagesDialog
= contributionItem
.getAction();
825 if (openSDPagesDialog
instanceof OpenSDPagesDialog
) {
826 openSDPagesDialog
.setEnabled(((ISDAdvancedPagingProvider
) fSdPagingProvider
).pagesCount() > 1);
832 * The frame to render (the sequence diagram)
834 * @param frame the frame to display
836 public void setFrame(Frame frame
) {
837 setFrame(frame
, true);
841 * The frame to render (the sequence diagram)
843 * @param frame the frame to display
844 * @param resetPosition boolean Flag whether to reset the position or not.
846 protected void setFrame(Frame frame
, boolean resetPosition
) {
847 if (getSDWidget() == null) {
856 IUml2SDLoader loader
= LoadersManager
.getInstance().getCurrentLoader(getViewSite().getId(), this);
857 if (loader
== null) {
861 if (loader
.getTitleString() != null) {
862 setContentDescription(loader
.getTitleString());
865 getSDWidget().setFrame(frame
, resetPosition
);
867 if (fTimeCompressionBar
!= null) {
868 fTimeCompressionBar
.setFrame(frame
);
871 if (fTimeCompressionBar
!= null) {
872 if (!frame
.hasTimeInfo()) {
873 Composite parent
= fTimeCompressionBar
.getParent();
874 fTimeCompressionBar
.setVisible(false);
877 Composite parent
= fTimeCompressionBar
.getParent();
878 fTimeCompressionBar
.setVisible(true);
882 IContributionItem shortKeysMenu
= getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
883 MenuManager shortKeys
= (MenuManager
) shortKeysMenu
;
884 if (shortKeys
!= null) {
885 IContributionItem
[] items
= shortKeys
.getItems();
886 for (int i
= 0; i
< items
.length
; i
++) {
887 if (items
[i
] instanceof ActionContributionItem
) {
888 IAction action
= ((ActionContributionItem
) items
[i
]).getAction();
889 if (action
!= null) {
890 action
.setEnabled(true);
895 createCoolbarContent();
899 * Activate or deactivate the short key command given in parameter (see plugin.xml)
901 * @param id the command id defined in the plugin.xml
902 * @param value the state value
904 public void setEnableCommand(String id
, boolean value
) {
905 IContributionItem shortKeysMenu
= getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
906 MenuManager shortKeys
= (MenuManager
) shortKeysMenu
;
907 if (shortKeys
== null) {
910 IContributionItem item
= shortKeys
.find(id
);
911 if ((item
!= null) && (item
instanceof ActionContributionItem
)) {
912 IAction action
= ((ActionContributionItem
) item
).getAction();
913 if (action
!= null) {
914 action
.setEnabled(value
);
920 * Set the frame from an other thread than the one executing the main loop
922 * @param frame The frame to set (and display)
924 public void setFrameSync(final Frame frame
) {
925 if (getSDWidget() == null || getSDWidget().isDisposed()) {
928 getSDWidget().getDisplay().syncExec(new Runnable() {
931 if (getSDWidget() == null || getSDWidget().isDisposed() ||
932 ((fTimeCompressionBar
!= null) && fTimeCompressionBar
.isDisposed())) {
942 * Ensure an object is visible from an other thread than the one executing the main loop
944 * @param sm The node to make visible in view
946 public void ensureVisibleSync(final GraphNode sm
) {
947 getSDWidget().getDisplay().syncExec(new Runnable() {
950 if (getSDWidget() == null || getSDWidget().isDisposed()) {
953 getSDWidget().ensureVisible(sm
);
959 * Set the frame and ensure an object is visible from an other thread than the one executing the main loop
961 * @param sm The node to make visible in view
962 * @param frame Frame The frame to set
964 public void setFrameAndEnsureVisibleSync(final Frame frame
, final GraphNode sm
) {
965 if (getSDWidget() == null || getSDWidget().isDisposed()) {
968 getSDWidget().getDisplay().syncExec(new Runnable() {
971 if (getSDWidget() == null || getSDWidget().isDisposed()) {
974 setFrameAndEnsureVisible(frame
, sm
);
980 * Set the frame and ensure an object is visible
982 * @param sm The node to make visible in view
983 * @param frame Frame The frame to set
985 public void setFrameAndEnsureVisible(Frame frame
, GraphNode sm
) {
986 getSDWidget().clearSelection();
987 setFrame(frame
, false);
988 getSDWidget().ensureVisible(sm
);
992 * Set the frame and ensure an object is visible from an other thread than the one executing the main loop
994 * @param frame The frame to set.
995 * @param x The x coordinate to make visible.
996 * @param y The y coordinate to make visible.
998 public void setFrameAndEnsureVisibleSync(final Frame frame
, final int x
, final int y
) {
999 if (getSDWidget() == null || getSDWidget().isDisposed()) {
1003 getSDWidget().getDisplay().syncExec(new Runnable() {
1006 setFrameAndEnsureVisible(frame
, x
, y
);
1012 * Set the frame and ensure an object is visible
1014 * @param frame The frame to set.
1015 * @param x The x coordinate to make visible.
1016 * @param y The y coordinate to make visible.
1018 public void setFrameAndEnsureVisible(Frame frame
, int x
, int y
) {
1019 getSDWidget().clearSelection();
1020 setFrame(frame
, false);
1021 getSDWidget().ensureVisible(x
, y
);
1022 getSDWidget().redraw();
1026 * Toggle between default and wait cursors from an other thread than the one executing the main loop
1028 * @param wait <code>true</code> for wait cursor else <code>false</code> for default cursor.
1030 public void toggleWaitCursorAsync(final boolean wait
) {
1031 if (getSDWidget() == null || getSDWidget().isDisposed()) {
1035 getSDWidget().getDisplay().asyncExec(new Runnable() {
1038 if (getSDWidget() == null || getSDWidget().isDisposed()) {
1042 if (fWaitCursor
!= null && !fWaitCursor
.isDisposed()) {
1043 fWaitCursor
.dispose();
1045 fWaitCursor
= new Cursor(getSDWidget().getDisplay(), SWT
.CURSOR_WAIT
);
1046 getSDWidget().setCursor(fWaitCursor
);
1047 getSDWidget().getDisplay().update();
1049 if (fWaitCursor
!= null && !fWaitCursor
.isDisposed()) {
1050 fWaitCursor
.dispose();
1053 getSDWidget().setCursor(null);
1054 getSDWidget().getDisplay().update();
1061 * Return the time compression bar widget
1063 * @return the time compression bar
1065 public TimeCompressionBar
getTimeCompressionBar() {
1066 return fTimeCompressionBar
;
1070 * Returns the current Frame (the sequence diagram container)
1072 * @return the current frame
1074 public Frame
getFrame() {
1075 if (getSDWidget() != null) {
1076 return getSDWidget().getFrame();
1082 * Gets the initialization flag.
1083 * @return the value of the initialization flag.
1085 protected boolean isNeedInit() {
1090 * Restores the loader for the view based on the view ID.
1092 * @return boolean <code>true</code> if initialization is needed else <code>false</code>.
1094 protected boolean restoreLoader() {
1095 String id
= getViewSite().getId();
1099 IUml2SDLoader loader
= LoadersManager
.getInstance().getCurrentLoader(id
, this);
1100 if ((loader
!= null)) {
1101 loader
.setViewer(this);
1109 * Checks if current view is ready to be used.
1111 * @return boolean <code>true</code> if view is ready else <code>false</code>.
1113 protected boolean isViewReady() {
1114 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1119 IViewReference
[] ref
= page
.getViewReferences();
1120 for (int i
= 0; i
< ref
.length
; i
++) {
1121 if (ref
[i
].getView(false) == this) {
1129 * Creates the menu group.
1131 protected void createMenuGroup() {
1132 IActionBars bar
= getViewSite().getActionBars();
1136 bar
.getToolBarManager().add(new Separator(UML2SD_VIEW_MODES_SEPARATOR
));
1137 bar
.getToolBarManager().add(new Separator(UML2SD_WORKING_SET_SEPARATOR
));
1138 bar
.getToolBarManager().add(new Separator(UML2SD_SORTING_SEPARATOR
));
1139 bar
.getToolBarManager().add(new Separator(UML2SD_FILTERING_SEPARATOR
));
1140 bar
.getToolBarManager().add(new Separator(UML2SD_VIEW_LAYOUT_SEPARATOR
));
1141 bar
.getToolBarManager().add(new Separator(UML2SD_LINK_EDITOR_SEPARATOR
));
1142 bar
.getToolBarManager().add(new Separator(UML2SD_OTHER_COMMANDS_SEPARATOR
));
1143 bar
.getToolBarManager().add(new Separator(UML2SD_OTHER_PLUGINS_COMMANDS_SEPARATOR
));
1144 bar
.getMenuManager().add(new Separator(UML2SD_VIEW_MODES_SEPARATOR
));
1145 bar
.getMenuManager().add(new Separator(UML2SD_WORKING_SET_SEPARATOR
));
1146 bar
.getMenuManager().add(new Separator(UML2SD_SORTING_SEPARATOR
));
1147 bar
.getMenuManager().add(new Separator(UML2SD_FILTERING_SEPARATOR
));
1148 bar
.getMenuManager().add(new Separator(UML2SD_VIEW_LAYOUT_SEPARATOR
));
1149 bar
.getMenuManager().add(new Separator(UML2SD_LINK_EDITOR_SEPARATOR
));
1150 bar
.getMenuManager().add(new Separator(UML2SD_OTHER_COMMANDS_SEPARATOR
));
1151 bar
.getMenuManager().add(new Separator(UML2SD_OTHER_PLUGINS_COMMANDS_SEPARATOR
));
1155 public <T
> T
getAdapter(Class
<T
> adapter
) {
1156 if (fSdPropertiesProvider
!= null && adapter
.equals(IPropertySheetPage
.class)) {
1157 return adapter
.cast(fSdPropertiesProvider
.getPropertySheetEntry());
1159 return super.getAdapter(adapter
);
1163 * Loader for a blank sequence diagram.
1167 public static class BlankUml2SdLoader
implements IUml2SDLoader
{
1169 public void setViewer(SDView viewer
) {
1171 Frame f
= new Frame();
1172 f
.setName(""); //$NON-NLS-1$
1177 public String
getTitleString() {
1178 return ""; //$NON-NLS-1$
1182 public void dispose() {
1187 public void partActivated(IWorkbenchPart part
) {
1189 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
1190 fPrintHandlerActivation
= ((IHandlerService
) service
).activateHandler(ActionFactory
.PRINT
.getCommandId(), fPrintActionHandler
);
1195 public void partBroughtToTop(IWorkbenchPart part
) {
1199 public void partClosed(IWorkbenchPart part
) {
1203 public void partDeactivated(IWorkbenchPart part
) {
1204 if (part
== this && fPrintHandlerActivation
!= null) {
1205 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
1206 ((IHandlerService
) service
).deactivateHandler(fPrintHandlerActivation
);
1211 public void partOpened(IWorkbenchPart part
) {