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