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