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());
271 disposeZoomActions();
272 fPrintActionHandler
.dispose();
276 private void disposeZoomActions() {
277 if (fResetZoomAction
!= null) {
278 fResetZoomAction
.dispose();
280 if (fNoZoomAction
!= null) {
281 fNoZoomAction
.dispose();
283 if (fZoomInAction
!= null) {
284 fZoomInAction
.dispose();
286 if (fZoomOutAction
!= null) {
287 fZoomOutAction
.dispose();
292 * Returns the SD widget.
294 * @return The SD widget.
296 public SDWidget
getSDWidget() {
301 * Set the find provider for the opened sequence diagram viewer<br>
302 * If the provider is not set, the find menu item will not be available in the viewer<br>
303 * A find provider is called back when the user perform a find action<br>
304 * The find provider is responsible to move the sequence diagram to the GraphNode which match the
305 * find criteria as well as to highlight the GraphNode
307 * @param provider the search provider
309 public void setSDFindProvider(ISDFindProvider provider
) {
310 fSdFindProvider
= provider
;
311 fSdExFindProvider
= null;
312 createCoolbarContent();
313 if (provider
!= null) {
314 KeyBindingsManager
.getInstance().setFindEnabled(true);
317 KeyBindingsManager
.getInstance().setFindEnabled(false);
322 * Set the find provider for the opened sequence diagram viewer<br>
323 * If the provider is not set, the find menu item will not be available in
325 * A find provider is called back when the user perform a find action<br>
326 * If the extended find provider is set, it replaces the regular find
327 * provider (sdFindProvider).<br>
330 * The provider to set
332 public void setExtendedFindProvider(IExtendedFindProvider provider
) {
333 fSdExFindProvider
= provider
;
334 fSdFindProvider
= null;
335 createCoolbarContent();
336 if (provider
!= null) {
337 KeyBindingsManager
.getInstance().setFindEnabled(true);
340 KeyBindingsManager
.getInstance().setFindEnabled(false);
345 * Returns the extended find provider
347 * @return extended find provider.
349 public IExtendedFindProvider
getExtendedFindProvider() {
350 return fSdExFindProvider
;
354 * Resets all providers.
356 public void resetProviders() {
357 KeyBindingsManager
.getInstance().setFindEnabled(false);
358 fSdFindProvider
= null;
359 fSdExFindProvider
= null;
360 fSdFilterProvider
= null;
361 fSdExFilterProvider
= null;
362 fSdPagingProvider
= null;
363 fSdExtendedActionBarProvider
= null;
364 fSdPropertiesProvider
= null;
365 if ((fSdWidget
!= null) && (!fSdWidget
.isDisposed())) {
366 fSdWidget
.setCollapseProvider(null);
371 * Set the filter provider for the opened sequence diagram viewer<br>
372 * If the provider is not set, the filter menu item will not be available in the viewer<br>
373 * A filter provider is called back when the user perform a filter action<br>
375 * @param provider the filter provider
377 public void setSDFilterProvider(ISDFilterProvider provider
) {
378 fSdFilterProvider
= provider
;
379 // Both systems can be used now, commenting out next statement
380 createCoolbarContent();
384 * Sets the extended filter provider for the opened sequence diagram viewer.
387 * The provider to set
389 public void setExtendedFilterProvider(IExtendedFilterProvider provider
) {
390 fSdExFilterProvider
= provider
;
391 // Both systems can be used now, commenting out next statement
392 createCoolbarContent();
396 * Returns the extended find provider.
398 * @return The extended find provider.
400 public IExtendedFilterProvider
getExtendedFilterProvider() {
401 return fSdExFilterProvider
;
405 * Register the given provider to support Drag and Drop collapsing. This provider is
406 * responsible of updating the Frame.
408 * @param provider - the provider to register
410 public void setCollapsingProvider(ISDCollapseProvider provider
) {
411 if ((fSdWidget
!= null) && (!fSdWidget
.isDisposed())) {
412 fSdWidget
.setCollapseProvider(provider
);
417 * Set the page provider for the opened sequence diagram viewer<br>
418 * If the sequence diagram provided (see setFrame) need to be split in many parts, a paging provider must be
419 * provided in order to handle page change requested by the user<br>
420 * Set a page provider will create the next and previous page buttons in the viewer coolBar
422 * @param provider the paging provider
424 public void setSDPagingProvider(ISDPagingProvider provider
) {
425 fSdPagingProvider
= provider
;
426 createCoolbarContent();
430 * Returns the current page provider for the view
432 * @return the paging provider
434 public ISDPagingProvider
getSDPagingProvider() {
435 return fSdPagingProvider
;
439 * Returns the current find provider for the view
441 * @return the find provider
443 public ISDFindProvider
getSDFindProvider() {
444 return fSdFindProvider
;
448 * Returns the current filter provider for the view
450 * @return the filter provider
452 public ISDFilterProvider
getSDFilterProvider() {
453 return fSdFilterProvider
;
457 * Set the extended action bar provider for the opened sequence diagram viewer<br>
458 * This allow to add programmatically actions in the coolbar and/or in the drop-down menu
460 * @param provider the search provider
462 public void setSDExtendedActionBarProvider(ISDExtendedActionBarProvider provider
) {
463 fSdExtendedActionBarProvider
= provider
;
464 createCoolbarContent();
468 * Returns the current extended action bar provider for the view
470 * @return the extended action bar provider
472 public ISDExtendedActionBarProvider
getSDExtendedActionBarProvider() {
473 return fSdExtendedActionBarProvider
;
477 * Set the properties view provider for the opened sequence diagram viewer
479 * @param provider the properties provider
481 public void setSDPropertiesProvider(ISDPropertiesProvider provider
) {
482 fSdPropertiesProvider
= provider
;
486 * Returns the current extended action bar provider for the view.
488 * @return the extended action bar provider
490 public ISDPropertiesProvider
getSDPropertiesProvider() {
491 return fSdPropertiesProvider
;
500 protected void setSDWidget(SDWidget sdWidget
) {
501 fSdWidget
= sdWidget
;
505 * Sets the time compression bar.
507 * @param timeCompressionbar
510 protected void setTimeBar(TimeCompressionBar timeCompressionbar
) {
511 fTimeCompressionBar
= timeCompressionbar
;
515 * Sets the initialization flag.
520 protected void setNeedInit(boolean needInit
) {
521 fNeedInit
= needInit
;
525 * Creates the basic sequence diagram menu
527 protected void hookContextMenu() {
528 fMenuMgr
= new MenuManager("#PopupMenu"); //$NON-NLS-1$
529 fMenuMgr
.setRemoveAllWhenShown(true);
530 fMenuMgr
.addMenuListener(new IMenuListener() {
532 public void menuAboutToShow(IMenuManager manager
) {
533 fillContextMenu(manager
);
536 Menu menu
= fMenuMgr
.createContextMenu(fSdWidget
.getViewControl());
537 fSdWidget
.getViewControl().setMenu(menu
);
538 getSite().registerContextMenu(fMenuMgr
, fSdWidget
.getSelectionProvider());
542 * Returns the context menu manager
544 * @return the menu manager
546 public MenuManager
getMenuManager() {
551 * Fills the basic sequence diagram menu and define the dynamic menu item insertion point
553 * @param manager the menu manager
555 protected void fillContextMenu(IMenuManager manager
) {
556 manager
.add(new Separator("Additions")); //$NON-NLS-1$
557 if (getSDWidget() != null && getSDWidget().getCurrentGraphNode() != null) {
558 ISelectionProvider selProvider
= fSdWidget
.getSelectionProvider();
559 ISelection sel
= selProvider
.getSelection();
561 Iterator
<?
> it
= ((StructuredSelection
) sel
).iterator();
562 while (it
.hasNext()) {
563 Object node
= it
.next();
564 if (node
instanceof BaseMessage
) {
568 if (nbMessage
!= 1) {
571 GraphNode node
= getSDWidget().getCurrentGraphNode();
572 if ((node
instanceof SyncMessageReturn
) && (((SyncMessageReturn
) node
).getMessage() != null)) {
573 Action goToMessage
= new MoveToMessage(this);
574 goToMessage
.setText(Messages
.SequenceDiagram_GoToMessage
);
575 manager
.add(goToMessage
);
577 if ((node
instanceof SyncMessage
) && (((SyncMessage
) node
).getMessageReturn() != null)) {
578 Action goToMessage
= new MoveToMessage(this);
579 goToMessage
.setText(Messages
.SequenceDiagram_GoToMessageReturn
);
580 manager
.add(goToMessage
);
583 manager
.add(new Separator("MultiSelectAdditions")); //$NON-NLS-1$
587 * Enables/Disables an action with given name.
589 * @param actionName The action name
590 * @param state true or false
592 public void setEnableAction(String actionName
, boolean state
) {
593 IActionBars bar
= getViewSite().getActionBars();
595 IContributionItem item
= bar
.getMenuManager().find(actionName
);
596 if ((item
!= null) && (item
instanceof ActionContributionItem
)) {
597 IAction action
= ((ActionContributionItem
) item
).getAction();
598 if (action
!= null) {
599 action
.setEnabled(state
);
601 item
.setVisible(state
);
602 bar
.updateActionBars();
608 * Creates the coolBar icon depending on the actions supported by the Sequence Diagram provider<br>
609 * - Navigation buttons are displayed if ISDPovider.HasPaging return true<br>
610 * - Navigation buttons are enabled depending on the value return by ISDPovider.HasNext and HasPrev<br>
612 * @see ISDGraphNodeSupporter Action support definition
613 * @see SDView#setSDFilterProvider(ISDFilterProvider)
614 * @see SDView#setSDFindProvider(ISDFindProvider)
615 * @see SDView#setSDPagingProvider(ISDPagingProvider)
617 protected void createCoolbarContent() {
618 IActionBars bar
= getViewSite().getActionBars();
620 bar
.getMenuManager().removeAll();
621 bar
.getToolBarManager().removeAll();
622 disposeZoomActions();
626 fResetZoomAction
= new Zoom(this, ZoomType
.ZOOM_RESET
);
627 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fResetZoomAction
);
628 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fResetZoomAction
);
630 fNoZoomAction
= new Zoom(this, ZoomType
.ZOOM_NONE
);
631 fNoZoomAction
.setChecked(true);
632 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNoZoomAction
);
633 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNoZoomAction
);
635 fZoomInAction
= new Zoom(this, ZoomType
.ZOOM_IN
);
636 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomInAction
);
637 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomInAction
);
639 fZoomOutAction
= new Zoom(this, ZoomType
.ZOOM_OUT
);
640 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomOutAction
);
641 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fZoomOutAction
);
643 MenuManager navigation
= new MenuManager(Messages
.SequenceDiagram_Navigation
);
645 ShowNodeStart showNodeStart
= new ShowNodeStart(this);
646 showNodeStart
.setText(Messages
.SequenceDiagram_ShowNodeStart
);
648 showNodeStart
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
649 showNodeStart
.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
650 navigation
.add(showNodeStart
);
652 ShowNodeEnd showNodeEnd
= new ShowNodeEnd(this);
653 showNodeEnd
.setText(Messages
.SequenceDiagram_ShowNodeEnd
);
655 showNodeEnd
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
656 showNodeEnd
.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
657 navigation
.add(showNodeEnd
);
659 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, navigation
);
661 ConfigureMinMax minMax
= new ConfigureMinMax(this);
662 minMax
.setText(Messages
.SequenceDiagram_ConfigureMinMax
);
663 minMax
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax");//$NON-NLS-1$
664 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, minMax
);
666 if ((fSdWidget
.getFrame() != null) && (fSdWidget
.getFrame().hasTimeInfo())) {
667 minMax
.setEnabled(true);
669 minMax
.setEnabled(false);
672 // Do we need to display a paging item
673 if (fSdPagingProvider
!= null) {
674 fNextPageButton
= new NextPage(this);
675 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNextPageButton
);
676 fNextPageButton
.setEnabled(fSdPagingProvider
.hasNextPage());
677 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fNextPageButton
);
679 fPrevPageButton
= new PrevPage(this);
680 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fPrevPageButton
);
681 fPrevPageButton
.setEnabled(fSdPagingProvider
.hasPrevPage());
682 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fPrevPageButton
);
684 fFirstPageButton
= new FirstPage(this);
685 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fFirstPageButton
);
686 fFirstPageButton
.setEnabled(fSdPagingProvider
.hasPrevPage());
687 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fFirstPageButton
);
689 fLastPageButton
= new LastPage(this);
690 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fLastPageButton
);
691 fLastPageButton
.setEnabled(fSdPagingProvider
.hasNextPage());
692 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, fLastPageButton
);
695 if (fSdExFilterProvider
!= null) {
696 Action action
= fSdExFilterProvider
.getFilterAction();
697 if (action
!= null) {
698 if (action
.getId() == null)
700 action
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFilter"); //$NON-NLS-1$
702 if (action
.getImageDescriptor() == null) {
703 action
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_FILTERS
));
705 if (action
.getText() == null || action
.getText().length() == 0) {
706 action
.setText(Messages
.SequenceDiagram_EditFilters
);
708 bar
.getMenuManager().prependToGroup(UML2SD_FILTERING_SEPARATOR
, action
);
709 bar
.getToolBarManager().prependToGroup(UML2SD_FILTERING_SEPARATOR
, action
);
712 // Both systems can be used now: commenting out else keyword
713 if (fSdFilterProvider
!= null) {
714 bar
.getMenuManager().appendToGroup(UML2SD_FILTERING_SEPARATOR
, new OpenSDFiltersDialog(this, fSdFilterProvider
));
716 if (fSdPagingProvider
instanceof ISDAdvancedPagingProvider
) {
717 IContributionItem sdPaging
= bar
.getMenuManager().find(OpenSDPagesDialog
.ID
);
718 if (sdPaging
!= null) {
719 bar
.getMenuManager().remove(sdPaging
);
722 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, new OpenSDPagesDialog(this, (ISDAdvancedPagingProvider
) fSdPagingProvider
));
723 updatePagesMenuItem(bar
);
726 if (fSdExFindProvider
!= null) {
727 Action action
= fSdExFindProvider
.getFindAction();
728 if (action
!= null) {
729 if (action
.getId() == null) {
730 action
.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFind"); //$NON-NLS-1$
732 if (action
.getImageDescriptor() == null) {
733 action
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_SEARCH_SEQ
));
735 if (action
.getText() == null) {
736 action
.setText(Messages
.SequenceDiagram_Find
+ "..."); //$NON-NLS-1$
738 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, action
);
739 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, action
);
741 } else if (fSdFindProvider
!= null) {
742 bar
.getMenuManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, new OpenSDFindDialog(this));
743 bar
.getToolBarManager().appendToGroup(UML2SD_OTHER_COMMANDS_SEPARATOR
, new OpenSDFindDialog(this));
746 if (fSdExtendedActionBarProvider
!= null) {
747 fSdExtendedActionBarProvider
.supplementCoolbarContent(bar
);
750 bar
.updateActionBars();
754 * Updates the view coolbar buttons state according to the value return by: -
755 * ISDExtendedActionBarProvider.hasNextPage()<br>
756 * - ISDExtendedActionBarProvider.hasPrevPage()<br>
759 public void updateCoolBar() {
760 if (fSdPagingProvider
!= null) {
761 IActionBars bar
= getViewSite().getActionBars();
765 IToolBarManager barManager
= bar
.getToolBarManager();
766 if (barManager
== null) {
769 IContributionItem nextPage
= barManager
.find(NextPage
.ID
);
770 if (nextPage
instanceof ActionContributionItem
) {
771 IAction nextPageAction
= ((ActionContributionItem
) nextPage
).getAction();
772 if (nextPageAction
instanceof NextPage
) {
773 ((NextPage
) nextPageAction
).setEnabled(fSdPagingProvider
.hasNextPage());
777 IContributionItem prevPage
= barManager
.find(PrevPage
.ID
);
778 if (prevPage
instanceof ActionContributionItem
) {
779 IAction prevPageAction
= ((ActionContributionItem
) prevPage
).getAction();
780 if (prevPageAction
instanceof PrevPage
) {
781 ((PrevPage
) prevPageAction
).setEnabled(fSdPagingProvider
.hasPrevPage());
785 IContributionItem firstPage
= barManager
.find(FirstPage
.ID
);
786 if (firstPage
instanceof ActionContributionItem
) {
787 IAction firstPageAction
= ((ActionContributionItem
) firstPage
).getAction();
788 if (firstPageAction
instanceof FirstPage
) {
789 ((FirstPage
) firstPageAction
).setEnabled(fSdPagingProvider
.hasPrevPage());
793 IContributionItem lastPage
= barManager
.find(LastPage
.ID
);
794 if (lastPage
instanceof ActionContributionItem
) {
795 IAction lastPageAction
= ((ActionContributionItem
) lastPage
).getAction();
796 if (lastPageAction
instanceof LastPage
) {
797 ((LastPage
) lastPageAction
).setEnabled(fSdPagingProvider
.hasNextPage());
801 updatePagesMenuItem(bar
);
806 * Enables or disables the Pages... menu item, depending on the number of pages
808 * @param bar the bar containing the action
810 protected void updatePagesMenuItem(IActionBars bar
) {
811 if (fSdPagingProvider
instanceof ISDAdvancedPagingProvider
) {
812 IMenuManager menuManager
= bar
.getMenuManager();
813 ActionContributionItem contributionItem
= (ActionContributionItem
) menuManager
.find(OpenSDPagesDialog
.ID
);
814 IAction openSDPagesDialog
= null;
815 if (contributionItem
!= null) {
816 openSDPagesDialog
= contributionItem
.getAction();
819 if (openSDPagesDialog
instanceof OpenSDPagesDialog
) {
820 openSDPagesDialog
.setEnabled(((ISDAdvancedPagingProvider
) fSdPagingProvider
).pagesCount() > 1);
826 * The frame to render (the sequence diagram)
828 * @param frame the frame to display
830 public void setFrame(Frame frame
) {
831 setFrame(frame
, true);
835 * The frame to render (the sequence diagram)
837 * @param frame the frame to display
838 * @param resetPosition boolean Flag whether to reset the position or not.
840 protected void setFrame(Frame frame
, boolean resetPosition
) {
841 if (getSDWidget() == null) {
850 IUml2SDLoader loader
= LoadersManager
.getInstance().getCurrentLoader(getViewSite().getId(), this);
851 if (loader
== null) {
855 if (loader
.getTitleString() != null) {
856 setContentDescription(loader
.getTitleString());
859 getSDWidget().setFrame(frame
, resetPosition
);
861 if (fTimeCompressionBar
!= null) {
862 fTimeCompressionBar
.setFrame(frame
);
865 if (fTimeCompressionBar
!= null) {
866 if (!frame
.hasTimeInfo()) {
867 Composite parent
= fTimeCompressionBar
.getParent();
868 fTimeCompressionBar
.setVisible(false);
871 Composite parent
= fTimeCompressionBar
.getParent();
872 fTimeCompressionBar
.setVisible(true);
876 IContributionItem shortKeysMenu
= getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
877 MenuManager shortKeys
= (MenuManager
) shortKeysMenu
;
878 if (shortKeys
!= null) {
879 IContributionItem
[] items
= shortKeys
.getItems();
880 for (int i
= 0; i
< items
.length
; i
++) {
881 if (items
[i
] instanceof ActionContributionItem
) {
882 IAction action
= ((ActionContributionItem
) items
[i
]).getAction();
883 if (action
!= null) {
884 action
.setEnabled(true);
889 createCoolbarContent();
893 * Activate or deactivate the short key command given in parameter (see plugin.xml)
895 * @param id the command id defined in the plugin.xml
896 * @param value the state value
898 public void setEnableCommand(String id
, boolean value
) {
899 IContributionItem shortKeysMenu
= getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
900 MenuManager shortKeys
= (MenuManager
) shortKeysMenu
;
901 if (shortKeys
== null) {
904 IContributionItem item
= shortKeys
.find(id
);
905 if ((item
!= null) && (item
instanceof ActionContributionItem
)) {
906 IAction action
= ((ActionContributionItem
) item
).getAction();
907 if (action
!= null) {
908 action
.setEnabled(value
);
914 * Set the frame from an other thread than the one executing the main loop
916 * @param frame The frame to set (and display)
918 public void setFrameSync(final Frame frame
) {
919 if (getSDWidget() == null || getSDWidget().isDisposed()) {
922 getSDWidget().getDisplay().syncExec(new Runnable() {
925 if (getSDWidget() == null || getSDWidget().isDisposed() ||
926 ((fTimeCompressionBar
!= null) && fTimeCompressionBar
.isDisposed())) {
936 * Ensure an object is visible from an other thread than the one executing the main loop
938 * @param sm The node to make visible in view
940 public void ensureVisibleSync(final GraphNode sm
) {
941 getSDWidget().getDisplay().syncExec(new Runnable() {
944 if (getSDWidget() == null || getSDWidget().isDisposed()) {
947 getSDWidget().ensureVisible(sm
);
953 * Set the frame and ensure an object is visible from an other thread than the one executing the main loop
955 * @param sm The node to make visible in view
956 * @param frame Frame The frame to set
958 public void setFrameAndEnsureVisibleSync(final Frame frame
, final GraphNode sm
) {
959 if (getSDWidget() == null || getSDWidget().isDisposed()) {
962 getSDWidget().getDisplay().syncExec(new Runnable() {
965 if (getSDWidget() == null || getSDWidget().isDisposed()) {
968 setFrameAndEnsureVisible(frame
, sm
);
974 * Set the frame and ensure an object is visible
976 * @param sm The node to make visible in view
977 * @param frame Frame The frame to set
979 public void setFrameAndEnsureVisible(Frame frame
, GraphNode sm
) {
980 getSDWidget().clearSelection();
981 setFrame(frame
, false);
982 getSDWidget().ensureVisible(sm
);
986 * Set the frame and ensure an object is visible from an other thread than the one executing the main loop
988 * @param frame The frame to set.
989 * @param x The x coordinate to make visible.
990 * @param y The y coordinate to make visible.
992 public void setFrameAndEnsureVisibleSync(final Frame frame
, final int x
, final int y
) {
993 if (getSDWidget() == null || getSDWidget().isDisposed()) {
997 getSDWidget().getDisplay().syncExec(new Runnable() {
1000 setFrameAndEnsureVisible(frame
, x
, y
);
1006 * Set the frame and ensure an object is visible
1008 * @param frame The frame to set.
1009 * @param x The x coordinate to make visible.
1010 * @param y The y coordinate to make visible.
1012 public void setFrameAndEnsureVisible(Frame frame
, int x
, int y
) {
1013 getSDWidget().clearSelection();
1014 setFrame(frame
, false);
1015 getSDWidget().ensureVisible(x
, y
);
1016 getSDWidget().redraw();
1020 * Toggle between default and wait cursors from an other thread than the one executing the main loop
1022 * @param wait <code>true</code> for wait cursor else <code>false</code> for default cursor.
1024 public void toggleWaitCursorAsync(final boolean wait
) {
1025 if (getSDWidget() == null || getSDWidget().isDisposed()) {
1029 getSDWidget().getDisplay().asyncExec(new Runnable() {
1032 if (getSDWidget() == null || getSDWidget().isDisposed()) {
1036 if (fWaitCursor
!= null && !fWaitCursor
.isDisposed()) {
1037 fWaitCursor
.dispose();
1039 fWaitCursor
= new Cursor(getSDWidget().getDisplay(), SWT
.CURSOR_WAIT
);
1040 getSDWidget().setCursor(fWaitCursor
);
1041 getSDWidget().getDisplay().update();
1043 if (fWaitCursor
!= null && !fWaitCursor
.isDisposed()) {
1044 fWaitCursor
.dispose();
1047 getSDWidget().setCursor(null);
1048 getSDWidget().getDisplay().update();
1055 * Return the time compression bar widget
1057 * @return the time compression bar
1059 public TimeCompressionBar
getTimeCompressionBar() {
1060 return fTimeCompressionBar
;
1064 * Returns the current Frame (the sequence diagram container)
1066 * @return the current frame
1068 public Frame
getFrame() {
1069 if (getSDWidget() != null) {
1070 return getSDWidget().getFrame();
1076 * Gets the initialization flag.
1077 * @return the value of the initialization flag.
1079 protected boolean isNeedInit() {
1084 * Restores the loader for the view based on the view ID.
1086 * @return boolean <code>true</code> if initialization is needed else <code>false</code>.
1088 protected boolean restoreLoader() {
1089 String id
= getViewSite().getId();
1093 IUml2SDLoader loader
= LoadersManager
.getInstance().getCurrentLoader(id
, this);
1094 if ((loader
!= null)) {
1095 loader
.setViewer(this);
1103 * Checks if current view is ready to be used.
1105 * @return boolean <code>true</code> if view is ready else <code>false</code>.
1107 protected boolean isViewReady() {
1108 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1113 IViewReference
[] ref
= page
.getViewReferences();
1114 for (int i
= 0; i
< ref
.length
; i
++) {
1115 if (ref
[i
].getView(false) == this) {
1123 * Creates the menu group.
1125 protected void createMenuGroup() {
1126 IActionBars bar
= getViewSite().getActionBars();
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
));
1149 public <T
> T
getAdapter(Class
<T
> adapter
) {
1150 T obj
= super.getAdapter(adapter
);
1151 if (fSdPropertiesProvider
!= null && adapter
.equals(IPropertySheetPage
.class)) {
1152 return adapter
.cast(fSdPropertiesProvider
.getPropertySheetEntry());
1159 * Loader for a blank sequence diagram.
1163 public static class BlankUml2SdLoader
implements IUml2SDLoader
{
1165 public void setViewer(SDView viewer
) {
1167 Frame f
= new Frame();
1168 f
.setName(""); //$NON-NLS-1$
1173 public String
getTitleString() {
1174 return ""; //$NON-NLS-1$
1178 public void dispose() {
1183 public void partActivated(IWorkbenchPart part
) {
1185 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
1186 fPrintHandlerActivation
= ((IHandlerService
) service
).activateHandler(ActionFactory
.PRINT
.getCommandId(), fPrintActionHandler
);
1191 public void partBroughtToTop(IWorkbenchPart part
) {
1195 public void partClosed(IWorkbenchPart part
) {
1199 public void partDeactivated(IWorkbenchPart part
) {
1200 if (part
== this && fPrintHandlerActivation
!= null) {
1201 final Object service
= PlatformUI
.getWorkbench().getService(IHandlerService
.class);
1202 ((IHandlerService
) service
).deactivateHandler(fPrintHandlerActivation
);
1207 public void partOpened(IWorkbenchPart part
) {