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