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