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