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