Fix NPEs in Sequence Diagram Framework during shutdown
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / SDView.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org.eclipse.linuxtools.tmf.ui.views.uml2sd;
15
16 import java.util.Iterator;
17
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.action.ActionContributionItem;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.action.IContributionItem;
22 import org.eclipse.jface.action.IMenuListener;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IToolBarManager;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.action.Separator;
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.linuxtools.internal.tmf.ui.Activator;
31 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
32 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage;
33 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame;
34 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
35 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage;
36 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessageReturn;
37 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax;
38 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.FirstPage;
39 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.KeyBindingsManager;
40 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.LastPage;
41 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveToMessage;
42 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.NextPage;
43 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.OpenSDFiltersDialog;
44 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.OpenSDFindDialog;
45 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.OpenSDPagesDialog;
46 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.PrevPage;
47 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.Print;
48 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd;
49 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart;
50 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.Zoom;
51 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.Zoom.ZoomType;
52 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.IExtendedFilterProvider;
53 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.IExtendedFindProvider;
54 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider;
55 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDCollapseProvider;
56 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDExtendedActionBarProvider;
57 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider;
58 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider;
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.SDMessages;
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 // Attributes
90 // ------------------------------------------------------------------------
91 /**
92 * The sequence diagram widget.
93 */
94 protected SDWidget fSdWidget = null;
95 /**
96 * The time compression bar.
97 */
98 protected TimeCompressionBar fTimeCompressionBar = null;
99 /**
100 * The sequence diagram find provider implementation.
101 */
102 protected ISDFindProvider fSdFindProvider = null;
103 /**
104 * The sequence diagram paging provider implementation.
105 */
106 protected ISDPagingProvider fSdPagingProvider = null;
107 /**
108 * The sequence diagram filter provider implementation.
109 */
110 protected ISDFilterProvider fSdFilterProvider = null;
111 /**
112 * The extended sequence diagram filter provider implementation.
113 */
114 protected IExtendedFilterProvider fSdExFilterProvider = null;
115 /**
116 * The extended sequence diagram find provider implementation.
117 */
118 protected IExtendedFindProvider fSdExFindProvider = null;
119 /**
120 * The extended sequence diagram action bar provider implementation.
121 */
122 protected ISDExtendedActionBarProvider fSdExtendedActionBarProvider = null;
123 /**
124 * The sequence diagram property provider implementation.
125 */
126 protected ISDPropertiesProvider fSdPropertiesProvider = null;
127 /**
128 * Button for executing the next page action.
129 */
130 protected NextPage fNextPageButton = null;
131 /**
132 * Button for executing the previous page action.
133 */
134 protected PrevPage fPrevPageButton = null;
135 /**
136 * Button for executing the first page page action.
137 */
138 protected FirstPage fFirstPageButton = null;
139 /**
140 * Button for executing the last page action.
141 */
142 protected LastPage fLastPageButton = null;
143 /**
144 * The menu manager reference.
145 */
146 protected MenuManager fMenuMgr = null;
147 /**
148 * Flag to indicate whether view needs initialization or not.
149 */
150 protected boolean fNeedInit = true;
151 /**
152 * WaitCursor is the cursor to be displayed when long tasks are running
153 */
154 protected Cursor fWaitCursor;
155
156 // ------------------------------------------------------------------------
157 // Methods
158 // ------------------------------------------------------------------------
159
160 /*
161 * (non-Javadoc)
162 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
163 */
164 @Override
165 public void createPartControl(Composite c) {
166 Composite parent = new Composite(c, SWT.NONE);
167 GridLayout parentLayout = new GridLayout();
168 parentLayout.numColumns = 2;
169 parentLayout.marginWidth = 0;
170 parentLayout.marginHeight = 0;
171 parent.setLayout(parentLayout);
172
173 GridData timeLayoutdata = new GridData(GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
174 timeLayoutdata.widthHint = 10;
175 GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
176 fTimeCompressionBar = new TimeCompressionBar(parent, SWT.NONE);
177 fTimeCompressionBar.setLayoutData(timeLayoutdata);
178 fSdWidget = new SDWidget(parent, SWT.NONE);// SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
179 fSdWidget.setLayoutData(seqDiagLayoutData);
180 fSdWidget.setSite(this);
181 fSdWidget.setTimeBar(fTimeCompressionBar);
182
183 // Add this view to the key bindings manager
184 KeyBindingsManager.getInstance().add(this.getSite().getId());
185
186 createCoolbarContent();
187
188 hookContextMenu();
189
190 fTimeCompressionBar.setVisible(false);
191 parent.layout(true);
192
193 Print print = new Print(this);
194 getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.PRINT.getId(), print);
195
196 fNeedInit = restoreLoader();
197 }
198
199 /**
200 * Load a blank page that is supposed to explain that a kind of interaction must be chosen.
201 */
202 protected void loadBlank() {
203 IUml2SDLoader loader = new BlankUml2SdLoader();
204 loader.setViewer(this);
205 setContentDescription(loader.getTitleString());
206 }
207
208 /*
209 * (non-Javadoc)
210 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
211 */
212 @Override
213 public void setFocus() {
214 if (fSdWidget != null) {
215 // update actions for key bindings
216 KeyBindingsManager.getInstance().setSdView(this);
217 fSdWidget.setFocus();
218 }
219 if (isViewReady() && fNeedInit) {
220 fNeedInit = restoreLoader();
221 }
222 }
223
224 /*
225 * (non-Javadoc)
226 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
227 */
228 @Override
229 public void dispose() {
230 KeyBindingsManager.getInstance().remove(this.getSite().getId());
231 super.dispose();
232 }
233
234 /**
235 * Returns the SD widget.
236 *
237 * @return The SD widget.
238 */
239 public SDWidget getSDWidget() {
240 return fSdWidget;
241 }
242
243 /**
244 * Set the find provider for the opened sequence diagram viewer<br>
245 * If the provider is not set, the find menu item will not be available in the viewer<br>
246 * A find provider is called back when the user perform a find action<br>
247 * The find provider is responsible to move the sequence diagram to the GraphNode which match the
248 * find criteria as well as to highlight the GraphNode
249 *
250 * @param provider the search provider
251 */
252 public void setSDFindProvider(ISDFindProvider provider) {
253 fSdFindProvider = provider;
254 fSdExFindProvider = null;
255 createCoolbarContent();
256 if (provider != null) {
257 KeyBindingsManager.getInstance().setFindEnabled(true);
258 }
259 else {
260 KeyBindingsManager.getInstance().setFindEnabled(false);
261 }
262 }
263
264 /**
265 * Set the find provider for the opened sequence diagram viewer<br>
266 * If the provider is not set, the find menu item will not be available in
267 * the viewer<br>
268 * A find provider is called back when the user perform a find action<br>
269 * If the extended find provider is set, it replaces the regular find
270 * provider (sdFindProvider).<br>
271 *
272 * @param provider
273 * The provider to set
274 */
275 public void setExtendedFindProvider(IExtendedFindProvider provider) {
276 fSdExFindProvider = provider;
277 fSdFindProvider = null;
278 createCoolbarContent();
279 if (provider != null) {
280 KeyBindingsManager.getInstance().setFindEnabled(true);
281 }
282 else {
283 KeyBindingsManager.getInstance().setFindEnabled(false);
284 }
285 }
286
287 /**
288 * Returns the extended find provider
289 *
290 * @return extended find provider.
291 */
292 public IExtendedFindProvider getExtendedFindProvider() {
293 return fSdExFindProvider;
294 }
295
296 /**
297 * Resets all providers.
298 */
299 public void resetProviders() {
300 KeyBindingsManager.getInstance().setFindEnabled(false);
301 fSdFindProvider = null;
302 fSdExFindProvider = null;
303 fSdFilterProvider = null;
304 fSdExFilterProvider = null;
305 fSdPagingProvider = null;
306 fSdExtendedActionBarProvider = null;
307 fSdPropertiesProvider = null;
308 if ((fSdWidget != null) && (!fSdWidget.isDisposed())) {
309 fSdWidget.setCollapseProvider(null);
310 }
311 }
312
313 /**
314 * Set the filter provider for the opened sequence diagram viewer<br>
315 * If the provider is not set, the filter menu item will not be available in the viewer<br>
316 * A filter provider is called back when the user perform a filter action<br>
317 *
318 * @param provider the filter provider
319 */
320 public void setSDFilterProvider(ISDFilterProvider provider) {
321 fSdFilterProvider = provider;
322 // Both systems can be used now, commenting out next statement
323 // sdExFilterProvider = null;
324 createCoolbarContent();
325 }
326
327 /**
328 * Sets the extended filter provider for the opened sequence diagram viewer.
329 *
330 * @param provider
331 * The provider to set
332 */
333 public void setExtendedFilterProvider(IExtendedFilterProvider provider) {
334 fSdExFilterProvider = provider;
335 // Both systems can be used now, commenting out next statement
336 // sdFilterProvider = null;
337 createCoolbarContent();
338 }
339
340 /**
341 * Returns the extended find provider.
342 *
343 * @return The extended find provider.
344 */
345 public IExtendedFilterProvider getExtendedFilterProvider() {
346 return fSdExFilterProvider;
347 }
348
349 /**
350 * Register the given provider to support Drag and Drop collapsing. This provider is
351 * responsible of updating the Frame.
352 *
353 * @param provider - the provider to register
354 */
355 public void setCollapsingProvider(ISDCollapseProvider provider) {
356 if ((fSdWidget != null) && (!fSdWidget.isDisposed())) {
357 fSdWidget.setCollapseProvider(provider);
358 }
359 }
360
361 /**
362 * Set the page provider for the opened sequence diagram viewer<br>
363 * If the sequence diagram provided (see setFrame) need to be split in many parts, a paging provider must be
364 * provided in order to handle page change requested by the user<br>
365 * Set a page provider will create the next and previous page buttons in the viewer coolBar
366 *
367 * @param provider the paging provider
368 */
369 public void setSDPagingProvider(ISDPagingProvider provider) {
370 fSdPagingProvider = provider;
371 createCoolbarContent();
372 }
373
374 /**
375 * Returns the current page provider for the view
376 *
377 * @return the paging provider
378 */
379 public ISDPagingProvider getSDPagingProvider() {
380 return fSdPagingProvider;
381 }
382
383 /**
384 * Returns the current find provider for the view
385 *
386 * @return the find provider
387 */
388 public ISDFindProvider getSDFindProvider() {
389 return fSdFindProvider;
390 }
391
392 /**
393 * Returns the current filter provider for the view
394 *
395 * @return the filter provider
396 */
397 public ISDFilterProvider getSDFilterProvider() {
398 return fSdFilterProvider;
399 }
400
401 /**
402 * Set the extended action bar provider for the opened sequence diagram viewer<br>
403 * This allow to add programmatically actions in the coolbar and/or in the drop-down menu
404 *
405 * @param provider the search provider
406 */
407 public void setSDExtendedActionBarProvider(ISDExtendedActionBarProvider provider) {
408 fSdExtendedActionBarProvider = provider;
409 createCoolbarContent();
410 }
411
412 /**
413 * Returns the current extended action bar provider for the view
414 *
415 * @return the extended action bar provider
416 */
417 public ISDExtendedActionBarProvider getSDExtendedActionBarProvider() {
418 return fSdExtendedActionBarProvider;
419 }
420
421 /**
422 * Set the properties view provider for the opened sequence diagram viewer
423 *
424 * @param provider the properties provider
425 */
426 public void setSDPropertiesProvider(ISDPropertiesProvider provider) {
427 fSdPropertiesProvider = provider;
428 }
429
430 /**
431 * Returns the current extended action bar provider for the view.
432 *
433 * @return the extended action bar provider
434 */
435 public ISDPropertiesProvider getSDPropertiesProvider() {
436 return fSdPropertiesProvider;
437 }
438
439 /**
440 * Creates the basic sequence diagram menu
441 */
442 protected void hookContextMenu() {
443 fMenuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
444 fMenuMgr.setRemoveAllWhenShown(true);
445 fMenuMgr.addMenuListener(new IMenuListener() {
446 @Override
447 public void menuAboutToShow(IMenuManager manager) {
448 fillContextMenu(manager);
449 }
450 });
451 Menu menu = fMenuMgr.createContextMenu(fSdWidget.getViewControl());
452 fSdWidget.getViewControl().setMenu(menu);
453 getSite().registerContextMenu(fMenuMgr, fSdWidget.getSelectionProvider());
454 }
455
456 /**
457 * Returns the context menu manager
458 *
459 * @return the menu manager
460 */
461 public MenuManager getMenuManager() {
462 return fMenuMgr;
463 }
464
465 /**
466 * Fills the basic sequence diagram menu and define the dynamic menu item insertion point
467 *
468 * @param manager the menu manager
469 */
470 protected void fillContextMenu(IMenuManager manager) {
471 manager.add(new Separator("Additions")); //$NON-NLS-1$
472 if (getSDWidget() != null && getSDWidget().fCurrentGraphNode != null) {
473 ISelectionProvider selProvider = fSdWidget.getSelectionProvider();
474 ISelection sel = selProvider.getSelection();
475 int nbMessage = 0;
476 Iterator<?> it = ((StructuredSelection) sel).iterator();
477 while (it.hasNext()) {
478 Object node = it.next();
479 if (node instanceof BaseMessage) {
480 nbMessage++;
481 }
482 }
483 if (nbMessage != 1) {
484 return;
485 }
486 GraphNode node = getSDWidget().fCurrentGraphNode;
487 if ((node instanceof SyncMessageReturn) && (((SyncMessageReturn) node).getMessage() != null)) {
488 Action goToMessage = new MoveToMessage(this);
489 goToMessage.setText(SDMessages._39);
490 manager.add(goToMessage);
491 }
492 if ((node instanceof SyncMessage) && (((SyncMessage) node).getMessageReturn() != null)) {
493 Action goToMessage = new MoveToMessage(this);
494 goToMessage.setText(SDMessages._40);
495 manager.add(goToMessage);
496 }
497 }
498 manager.add(new Separator("MultiSelectAdditions")); //$NON-NLS-1$
499 }
500
501 /**
502 * Enables/Disables an action with given name.
503 *
504 * @param actionName The action name
505 * @param state true or false
506 */
507 public void setEnableAction(String actionName, boolean state) {
508 IActionBars bar = getViewSite().getActionBars();
509 if (bar != null) {
510 IContributionItem item = bar.getMenuManager().find(actionName);
511 if ((item != null) && (item instanceof ActionContributionItem)) {
512 IAction action = ((ActionContributionItem) item).getAction();
513 if (action != null) {
514 action.setEnabled(state);
515 }
516 item.setVisible(state);
517 bar.updateActionBars();
518 }
519 }
520 }
521
522 /**
523 * Creates the coolBar icon depending on the actions supported by the Sequence Diagram provider<br>
524 * - Navigation buttons are displayed if ISDPovider.HasPaging return true<br>
525 * - Navigation buttons are enabled depending on the value return by ISDPovider.HasNext and HasPrev<br>
526 *
527 * @see ISDGraphNodeSupporter Action support definition
528 * @see SDView#setSDFilterProvider(ISDFilterProvider)
529 * @see SDView#setSDFindProvider(ISDFindProvider)
530 * @see SDView#setSDPagingProvider(ISDPagingProvider)
531 */
532 protected void createCoolbarContent() {
533 IActionBars bar = getViewSite().getActionBars();
534
535 bar.getMenuManager().removeAll();
536 bar.getToolBarManager().removeAll();
537
538 createMenuGroup();
539
540 Zoom resetZoom = new Zoom(this, ZoomType.ZOOM_RESET);
541 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", resetZoom);//$NON-NLS-1$
542 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", resetZoom); //$NON-NLS-1$
543
544 Zoom noZoom = new Zoom(this, ZoomType.ZOOM_NONE);
545 noZoom.setChecked(true);
546 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", noZoom);//$NON-NLS-1$
547 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", noZoom); //$NON-NLS-1$
548
549 Zoom zoomIn = new Zoom(this, ZoomType.ZOOM_IN);
550 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", zoomIn);//$NON-NLS-1$
551 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", zoomIn); //$NON-NLS-1$
552
553 Zoom zoomOut = new Zoom(this, ZoomType.ZOOM_OUT);
554 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", zoomOut);//$NON-NLS-1$
555 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", zoomOut); //$NON-NLS-1$
556
557 MenuManager navigation = new MenuManager(SDMessages._77);
558
559 ShowNodeStart showNodeStart = new ShowNodeStart(this);
560 showNodeStart.setText(SDMessages.uml_25);
561
562 showNodeStart.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
563 showNodeStart.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeStart");//$NON-NLS-1$
564 navigation.add(showNodeStart);
565
566 ShowNodeEnd showNodeEnd = new ShowNodeEnd(this);
567 showNodeEnd.setText(SDMessages.uml_23);
568
569 showNodeEnd.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
570 showNodeEnd.setActionDefinitionId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ShowNodeEnd");//$NON-NLS-1$
571 navigation.add(showNodeEnd);
572
573 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", navigation); //$NON-NLS-1$
574
575 ConfigureMinMax minMax = new ConfigureMinMax(this);
576 minMax.setText(SDMessages.uml_45);
577 minMax.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.ConfigureMinMax");//$NON-NLS-1$
578 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", minMax); //$NON-NLS-1$
579
580 if ((fSdWidget.getFrame() != null) && (fSdWidget.getFrame().hasTimeInfo())) {
581 minMax.setEnabled(true);
582 } else {
583 minMax.setEnabled(false);
584 }
585
586 // Do we need to display a paging item
587 if (fSdPagingProvider != null) {
588 fNextPageButton = new NextPage(this);
589 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", fNextPageButton); //$NON-NLS-1$
590 fNextPageButton.setEnabled(fSdPagingProvider.hasNextPage());
591 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", fNextPageButton); //$NON-NLS-1$
592
593 fPrevPageButton = new PrevPage(this);
594 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", fPrevPageButton); //$NON-NLS-1$
595 fPrevPageButton.setEnabled(fSdPagingProvider.hasPrevPage());
596 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", fPrevPageButton); //$NON-NLS-1$
597
598 fFirstPageButton = new FirstPage(this);
599 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", fFirstPageButton); //$NON-NLS-1$
600 fFirstPageButton.setEnabled(fSdPagingProvider.hasPrevPage());
601 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", fFirstPageButton); //$NON-NLS-1$
602
603 fLastPageButton = new LastPage(this);
604 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", fLastPageButton); //$NON-NLS-1$
605 fLastPageButton.setEnabled(fSdPagingProvider.hasNextPage());
606 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", fLastPageButton); //$NON-NLS-1$
607 }
608
609 if (fSdExFilterProvider != null) {
610 Action action = fSdExFilterProvider.getFilterAction();
611 if (action != null) {
612 if (action.getId() == null)
613 {
614 action.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFilter"); //$NON-NLS-1$
615 }
616 if (action.getImageDescriptor() == null) {
617 action.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FILTERS));
618 }
619 if (action.getText() == null || action.getText().length() == 0) {
620 action.setText(SDMessages._42);
621 }
622 bar.getMenuManager().prependToGroup("UML2SD_FILTERING", action); //$NON-NLS-1$
623 bar.getToolBarManager().prependToGroup("UML2SD_FILTERING", action); //$NON-NLS-1$
624 }
625 }
626 // Both systems can be used now: commenting out else keyword
627 /* else */if (fSdFilterProvider != null) {
628 bar.getMenuManager().appendToGroup("UML2SD_FILTERING", new OpenSDFiltersDialog(this, fSdFilterProvider)); //$NON-NLS-1$
629 // No longer in the coolbar: commenting out next statement
630 //bar.getToolBarManager().appendToGroup("UML2SD_FILTERING",new OpenSDFiltersDialog(this, sdFilterProvider)); //$NON-NLS-1$
631 }
632 if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) {
633 IContributionItem sdPaging = bar.getMenuManager().find(OpenSDPagesDialog.ID);
634 if (sdPaging != null) {
635 bar.getMenuManager().remove(sdPaging);
636 sdPaging = null;
637 }
638 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", new OpenSDPagesDialog(this, (ISDAdvancedPagingProvider) fSdPagingProvider)); //$NON-NLS-1$
639 updatePagesMenuItem(bar);
640 }
641
642 if (fSdExFindProvider != null) {
643 Action action = fSdExFindProvider.getFindAction();
644 if (action != null) {
645 if (action.getId() == null) {
646 action.setId("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.extendedFind"); //$NON-NLS-1$
647 }
648 if (action.getImageDescriptor() == null) {
649 action.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SEARCH_SEQ));
650 }
651 if (action.getText() == null) {
652 action.setText(SDMessages._41);
653 }
654 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", action); //$NON-NLS-1$
655 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", action); //$NON-NLS-1$
656 }
657 } else if (fSdFindProvider != null) {
658 bar.getMenuManager().appendToGroup("UML2SD_OTHER_COMMANDS", new OpenSDFindDialog(this)); //$NON-NLS-1$
659 bar.getToolBarManager().appendToGroup("UML2SD_OTHER_COMMANDS", new OpenSDFindDialog(this)); //$NON-NLS-1$
660 }
661
662 if (fSdExtendedActionBarProvider != null) {
663 fSdExtendedActionBarProvider.supplementCoolbarContent(bar);
664 }
665
666 bar.updateActionBars();
667 }
668
669 /**
670 * Updates the view coolbar buttons state according to the value return by: -
671 * ISDExtendedActionBarProvider.hasNextPage()<br>
672 * - ISDExtendedActionBarProvider.hasPrevPage()<br>
673 *
674 */
675 public void updateCoolBar() {
676 if (fSdPagingProvider != null) {
677 IActionBars bar = getViewSite().getActionBars();
678 if (bar == null) {
679 return;
680 }
681 IToolBarManager barManager = bar.getToolBarManager();
682 if (barManager == null) {
683 return;
684 }
685 IContributionItem nextPage = barManager.find(NextPage.ID);
686 if (nextPage instanceof ActionContributionItem) {
687 IAction nextPageAction = ((ActionContributionItem) nextPage).getAction();
688 if (nextPageAction instanceof NextPage) {
689 ((NextPage) nextPageAction).setEnabled(fSdPagingProvider.hasNextPage());
690 }
691 }
692
693 IContributionItem prevPage = barManager.find(PrevPage.ID);
694 if (prevPage instanceof ActionContributionItem) {
695 IAction prevPageAction = ((ActionContributionItem) prevPage).getAction();
696 if (prevPageAction instanceof PrevPage) {
697 ((PrevPage) prevPageAction).setEnabled(fSdPagingProvider.hasPrevPage());
698 }
699 }
700
701 IContributionItem firstPage = barManager.find(FirstPage.ID);
702 if (firstPage instanceof ActionContributionItem) {
703 IAction firstPageAction = ((ActionContributionItem) firstPage).getAction();
704 if (firstPageAction instanceof FirstPage) {
705 ((FirstPage) firstPageAction).setEnabled(fSdPagingProvider.hasPrevPage());
706 }
707 }
708
709 IContributionItem lastPage = barManager.find(LastPage.ID);
710 if (lastPage instanceof ActionContributionItem) {
711 IAction lastPageAction = ((ActionContributionItem) lastPage).getAction();
712 if (lastPageAction instanceof LastPage) {
713 ((LastPage) lastPageAction).setEnabled(fSdPagingProvider.hasNextPage());
714 }
715 }
716
717 updatePagesMenuItem(bar);
718 }
719 }
720
721 /**
722 * Enables or disables the Pages... menu item, depending on the number of pages
723 *
724 * @param bar the bar containing the action
725 */
726 protected void updatePagesMenuItem(IActionBars bar) {
727 if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) {
728 IMenuManager menuManager = bar.getMenuManager();
729 ActionContributionItem contributionItem = (ActionContributionItem) menuManager.find(OpenSDPagesDialog.ID);
730 IAction openSDPagesDialog = null;
731 if (contributionItem != null) {
732 openSDPagesDialog = contributionItem.getAction();
733 }
734
735 if (openSDPagesDialog instanceof OpenSDPagesDialog) {
736 openSDPagesDialog.setEnabled(((ISDAdvancedPagingProvider) fSdPagingProvider).pagesCount() > 1);
737 }
738 }
739 }
740
741 /**
742 * The frame to render (the sequence diagram)
743 *
744 * @param frame the frame to display
745 */
746 public void setFrame(Frame frame) {
747 setFrame(frame, true);
748 }
749
750 /**
751 * The frame to render (the sequence diagram)
752 *
753 * @param frame the frame to display
754 * @param resetPosition boolean Flag whether to reset the position or not.
755 */
756 protected void setFrame(Frame frame, boolean resetPosition) {
757 if (fSdWidget == null) {
758 return;
759 }
760
761 if (frame == null) {
762 loadBlank();
763 return;
764 }
765
766 IUml2SDLoader loader = LoadersManager.getInstance().getCurrentLoader(getViewSite().getId(), this);
767 if (loader == null) {
768 return;
769 }
770
771 if (loader.getTitleString() != null) {
772 setContentDescription(loader.getTitleString());
773 }
774
775 if (getSDWidget() != null) {
776 getSDWidget().setFrame(frame, resetPosition);
777 }
778
779 if (fTimeCompressionBar != null) {
780 fTimeCompressionBar.setFrame(frame);
781 }
782 updateCoolBar();
783 if (!frame.hasTimeInfo()) {
784 Composite parent = fTimeCompressionBar.getParent();
785 fTimeCompressionBar.setVisible(false);
786 parent.layout(true);
787 } else {
788 Composite parent = fTimeCompressionBar.getParent();
789 fTimeCompressionBar.setVisible(true);
790 parent.layout(true);
791 }
792 IContributionItem shortKeysMenu = getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
793 MenuManager shortKeys = (MenuManager) shortKeysMenu;
794 if (shortKeys != null) {
795 IContributionItem[] items = shortKeys.getItems();
796 for (int i = 0; i < items.length; i++) {
797 if (items[i] instanceof ActionContributionItem) {
798 IAction action = ((ActionContributionItem) items[i]).getAction();
799 if (action != null) {
800 action.setEnabled(true);
801 }
802 }
803 }
804 }
805 createCoolbarContent();
806 }
807
808 /**
809 * Activate or deactivate the short key command given in parameter (see plugin.xml)
810 *
811 * @param id the command id defined in the plugin.xml
812 * @param value the state value
813 */
814 public void setEnableCommand(String id, boolean value) {
815 IContributionItem shortKeysMenu = getViewSite().getActionBars().getMenuManager().find("org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers");//$NON-NLS-1$
816 MenuManager shortKeys = (MenuManager) shortKeysMenu;
817 if (shortKeys == null) {
818 return;
819 }
820 IContributionItem item = shortKeys.find(id);
821 if ((item != null) && (item instanceof ActionContributionItem)) {
822 IAction action = ((ActionContributionItem) item).getAction();
823 if (action != null) {
824 action.setEnabled(value);
825 }
826 }
827 }
828
829 /**
830 * Set the frame from an other thread than the one executing the main loop
831 *
832 * @param frame The frame to set (and display)
833 */
834 public void setFrameSync(final Frame frame) {
835 if (getSDWidget() == null || getSDWidget().isDisposed()) {
836 return;
837 }
838 getSDWidget().getDisplay().syncExec(new Runnable() {
839 @Override
840 public void run() {
841 if (getSDWidget() == null || getSDWidget().isDisposed()) {
842 return;
843 }
844 setFrame(frame);
845 }
846 });
847
848 }
849
850 /**
851 * Ensure an object is visible from an other thread than the one executing the main loop
852 *
853 * @param sm The node to make visible in view
854 */
855 public void ensureVisibleSync(final GraphNode sm) {
856 getSDWidget().getDisplay().syncExec(new Runnable() {
857 @Override
858 public void run() {
859 if (getSDWidget() == null || getSDWidget().isDisposed()) {
860 return;
861 }
862 getSDWidget().ensureVisible(sm);
863 }
864 });
865 }
866
867 /**
868 * Set the frame and ensure an object is visible from an other thread than the one executing the main loop
869 *
870 * @param sm The node to make visible in view
871 * @param frame Frame The frame to set
872 */
873 public void setFrameAndEnsureVisibleSync(final Frame frame, final GraphNode sm) {
874 if (getSDWidget() == null || getSDWidget().isDisposed()) {
875 return;
876 }
877 getSDWidget().getDisplay().syncExec(new Runnable() {
878 @Override
879 public void run() {
880 if (getSDWidget() == null || getSDWidget().isDisposed()) {
881 return;
882 }
883 setFrameAndEnsureVisible(frame, sm);
884 }
885 });
886 }
887
888 /**
889 * Set the frame and ensure an object is visible
890 *
891 * @param sm The node to make visible in view
892 * @param frame Frame The frame to set
893 */
894 public void setFrameAndEnsureVisible(Frame frame, GraphNode sm) {
895 getSDWidget().clearSelection();
896 setFrame(frame, false);
897 getSDWidget().ensureVisible(sm);
898 }
899
900 /**
901 * Set the frame and ensure an object is visible from an other thread than the one executing the main loop
902 *
903 * @param frame The frame to set.
904 * @param x The x coordinate to make visible.
905 * @param y The y coordinate to make visible.
906 */
907 public void setFrameAndEnsureVisibleSync(final Frame frame, final int x, final int y) {
908 if (getSDWidget() == null || getSDWidget().isDisposed()) {
909 return;
910 }
911
912 getSDWidget().getDisplay().syncExec(new Runnable() {
913 @Override
914 public void run() {
915 setFrameAndEnsureVisible(frame, x, y);
916 }
917 });
918 }
919
920 /**
921 * Set the frame and ensure an object is visible
922 *
923 * @param frame The frame to set.
924 * @param x The x coordinate to make visible.
925 * @param y The y coordinate to make visible.
926 */
927 public void setFrameAndEnsureVisible(Frame frame, int x, int y) {
928 getSDWidget().clearSelection();
929 setFrame(frame, false);
930 getSDWidget().ensureVisible(x, y);
931 getSDWidget().redraw();
932 }
933
934 /**
935 * Toggle between default and wait cursors from an other thread than the one executing the main loop
936 *
937 * @param wait <code>true</code> for wait cursor else <code>false</code> for default cursor.
938 */
939 public void toggleWaitCursorAsync(final boolean wait) {
940 if (getSDWidget() == null || getSDWidget().isDisposed()) {
941 return;
942 }
943
944 getSDWidget().getDisplay().asyncExec(new Runnable() {
945 @Override
946 public void run() {
947 if (getSDWidget() == null || getSDWidget().isDisposed()) {
948 return;
949 }
950 if (wait) {
951 if (fWaitCursor != null && !fWaitCursor.isDisposed()) {
952 fWaitCursor.dispose();
953 }
954 fWaitCursor = new Cursor(getSDWidget().getDisplay(), SWT.CURSOR_WAIT);
955 getSDWidget().setCursor(fWaitCursor);
956 getSDWidget().getDisplay().update();
957 } else {
958 if (fWaitCursor != null && !fWaitCursor.isDisposed()) {
959 fWaitCursor.dispose();
960 }
961 fWaitCursor = null;
962 getSDWidget().setCursor(null);
963 getSDWidget().getDisplay().update();
964 }
965 }
966 });
967 }
968
969 /**
970 * Return the time compression bar widget
971 *
972 * @return the time compression bar
973 */
974 public TimeCompressionBar getTimeCompressionBar() {
975 return fTimeCompressionBar;
976 }
977
978 /**
979 * Returns the current Frame (the sequence diagram container)
980 *
981 * @return the current frame
982 */
983 public Frame getFrame() {
984 if (getSDWidget() != null) {
985 return getSDWidget().getFrame();
986 }
987 return null;
988 }
989
990 /**
991 * Restores the loader for the view based on the view ID.
992 *
993 * @return boolean <code>true</code> if initialization is needed else <code>false</code>.
994 */
995 protected boolean restoreLoader() {
996 String id = getViewSite().getId();
997 // System.err.println("restoreLoader() id="+id);
998 if (id == null) {
999 return true;
1000 }
1001 IUml2SDLoader loader = LoadersManager.getInstance().getCurrentLoader(id, this);
1002 // System.err.println("restoreLoader() l="+l);
1003 if ((loader != null)) {// &&( LoadersManager.getLoadersManager().getViewer(l)==this)){
1004 loader.setViewer(this);
1005 return false;
1006 }
1007 loadBlank();
1008 return true;
1009 }
1010
1011 /**
1012 * Checks if current view is ready to be used.
1013 *
1014 * @return boolean <code>true</code> if view is ready else <code>false</code>.
1015 */
1016 protected boolean isViewReady() {
1017 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1018 if (page == null) {
1019 return false;
1020 }
1021
1022 IViewReference[] ref = page.getViewReferences();
1023 for (int i = 0; i < ref.length; i++) {
1024 if (ref[i].getView(false) == this) {
1025 return true;
1026 }
1027 }
1028 return false;
1029 }
1030
1031 /**
1032 * Creates the menu group.
1033 */
1034 protected void createMenuGroup() {
1035 IActionBars bar = getViewSite().getActionBars();
1036 if (bar == null) {
1037 return;
1038 }
1039 bar.getToolBarManager().add(new Separator("UML2SD_VIEW_MODES")); //$NON-NLS-1$
1040 bar.getToolBarManager().add(new Separator("UML2SD_WORKING_SET")); //$NON-NLS-1$
1041 bar.getToolBarManager().add(new Separator("UML2SD_SORTING")); //$NON-NLS-1$
1042 bar.getToolBarManager().add(new Separator("UML2SD_FILTERING")); //$NON-NLS-1$
1043 bar.getToolBarManager().add(new Separator("UML2SD_VIEW_LAYOUT")); //$NON-NLS-1$
1044 bar.getToolBarManager().add(new Separator("UML2SD_LINK_EDITOR")); //$NON-NLS-1$
1045 bar.getToolBarManager().add(new Separator("UML2SD_OTHER_COMMANDS")); //$NON-NLS-1$
1046 bar.getToolBarManager().add(new Separator("UML2SD_OTHER_PLUGINS_COMMANDS")); //$NON-NLS-1$
1047 bar.getMenuManager().add(new Separator("UML2SD_VIEW_MODES")); //$NON-NLS-1$
1048 bar.getMenuManager().add(new Separator("UML2SD_WORKING_SET")); //$NON-NLS-1$
1049 bar.getMenuManager().add(new Separator("UML2SD_SORTING")); //$NON-NLS-1$
1050 bar.getMenuManager().add(new Separator("UML2SD_FILTERING")); //$NON-NLS-1$
1051 bar.getMenuManager().add(new Separator("UML2SD_VIEW_LAYOUT")); //$NON-NLS-1$
1052 bar.getMenuManager().add(new Separator("UML2SD_LINK_EDITOR")); //$NON-NLS-1$
1053 bar.getMenuManager().add(new Separator("UML2SD_OTHER_COMMANDS")); //$NON-NLS-1$
1054 bar.getMenuManager().add(new Separator("UML2SD_OTHER_PLUGINS_COMMANDS")); //$NON-NLS-1$
1055 }
1056
1057 /*
1058 * Gets adapter for this view for properties.
1059 * (non-Javadoc)
1060 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
1061 */
1062 @Override
1063 public Object getAdapter(Class adapter) {
1064 Object obj = super.getAdapter(adapter);
1065 if (fSdPropertiesProvider != null && adapter.equals(IPropertySheetPage.class)) {
1066 return fSdPropertiesProvider.getPropertySheetEntry();
1067 }
1068
1069 return obj;
1070 }
1071
1072 /**
1073 * Loader for a blank sequence diagram.
1074 *
1075 * @version 1.0
1076 */
1077 public static class BlankUml2SdLoader implements IUml2SDLoader {
1078 /*
1079 * (non-Javadoc)
1080 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
1081 */
1082 @Override
1083 public void setViewer(SDView viewer) {
1084 // Nothing to do
1085 Frame f = new Frame();
1086 f.setName(""); //$NON-NLS-1$
1087 viewer.setFrame(f);
1088 }
1089
1090 /*
1091 * (non-Javadoc)
1092 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
1093 */
1094 @Override
1095 public String getTitleString() {
1096 return ""; //$NON-NLS-1$
1097 }
1098
1099 /*
1100 * (non-Javadoc)
1101 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#dispose()
1102 */
1103 @Override
1104 public void dispose() {
1105 }
1106 }
1107 }
This page took 0.056977 seconds and 6 git commands to generate.