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