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