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