1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.editors
;
15 import java
.lang
.reflect
.Constructor
;
16 import java
.lang
.reflect
.InvocationTargetException
;
17 import java
.util
.List
;
19 import org
.eclipse
.core
.resources
.IFile
;
20 import org
.eclipse
.core
.resources
.IMarker
;
21 import org
.eclipse
.core
.resources
.IMarkerDelta
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.core
.resources
.IResourceChangeEvent
;
24 import org
.eclipse
.core
.resources
.IResourceChangeListener
;
25 import org
.eclipse
.core
.resources
.IResourceDelta
;
26 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
27 import org
.eclipse
.core
.runtime
.CoreException
;
28 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
29 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
30 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
31 import org
.eclipse
.core
.runtime
.ListenerList
;
32 import org
.eclipse
.core
.runtime
.Platform
;
33 import org
.eclipse
.jface
.util
.SafeRunnable
;
34 import org
.eclipse
.jface
.viewers
.ISelection
;
35 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
36 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
37 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
38 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
39 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
40 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
41 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
42 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
43 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
.Messages
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.TmfCommonConstants
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
52 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
53 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
54 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
55 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfNavigatorContentProvider
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectElement
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
61 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
62 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceType
;
63 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
64 import org
.eclipse
.swt
.widgets
.Composite
;
65 import org
.eclipse
.swt
.widgets
.Display
;
66 import org
.eclipse
.ui
.IEditorInput
;
67 import org
.eclipse
.ui
.IEditorPart
;
68 import org
.eclipse
.ui
.IEditorSite
;
69 import org
.eclipse
.ui
.IFileEditorInput
;
70 import org
.eclipse
.ui
.IPartListener
;
71 import org
.eclipse
.ui
.IPropertyListener
;
72 import org
.eclipse
.ui
.IReusableEditor
;
73 import org
.eclipse
.ui
.IWorkbenchPart
;
74 import org
.eclipse
.ui
.PartInitException
;
75 import org
.eclipse
.ui
.ide
.IGotoMarker
;
76 import org
.eclipse
.ui
.part
.FileEditorInput
;
77 import org
.eclipse
.ui
.views
.properties
.IPropertySheetPage
;
78 import org
.osgi
.framework
.Bundle
;
81 * Editor for TMF events
84 * @author Patrick Tasse
87 public class TmfEventsEditor
extends TmfEditor
implements ITmfTraceEditor
, IReusableEditor
, IPropertyListener
, IResourceChangeListener
, ISelectionProvider
, ISelectionChangedListener
, IPartListener
{
89 /** ID for this class */
90 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$
92 private TmfEventsTable fEventsTable
;
94 private ITmfTrace fTrace
;
95 private Composite fParent
;
96 private ListenerList fSelectionChangedListeners
= new ListenerList();
97 private boolean fTraceSelected
;
100 public void doSave(final IProgressMonitor monitor
) {
104 public void doSaveAs() {
108 public void init(final IEditorSite site
, IEditorInput input
) throws PartInitException
{
109 IFileEditorInput fileEditorInput
;
110 if (input
instanceof TmfEditorInput
) {
111 fFile
= ((TmfEditorInput
) input
).getFile();
112 fTrace
= ((TmfEditorInput
) input
).getTrace();
113 /* change the input to a FileEditorInput to allow open handlers to find this editor */
114 fileEditorInput
= new FileEditorInput(fFile
);
115 } else if (input
instanceof IFileEditorInput
) {
116 fileEditorInput
= (IFileEditorInput
) input
;
117 fFile
= fileEditorInput
.getFile();
119 throw new PartInitException("Invalid IFileEditorInput: " + fileEditorInput
); //$NON-NLS-1$
122 final String traceTypeId
= fFile
.getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
123 if (traceTypeId
== null) {
124 throw new PartInitException(Messages
.OpenTraceHandler_NoTraceType
);
126 if (traceTypeId
.equals(TmfExperiment
.class.getCanonicalName())) {
127 // Special case: experiment bookmark resource
128 final TmfNavigatorContentProvider ncp
= new TmfNavigatorContentProvider();
129 ncp
.getChildren(fFile
.getProject()); // force the model to be populated
130 final TmfProjectElement project
= TmfProjectRegistry
.getProject(fFile
.getProject());
131 if (project
== null) {
132 throw new PartInitException(Messages
.OpenExperimentHandler_NoTraceType
);
134 for (final ITmfProjectModelElement projectElement
: project
.getExperimentsFolder().getChildren()) {
135 final String traceName
= fFile
.getParent().getName();
136 if (projectElement
.getName().equals(traceName
)) {
137 final TmfExperimentElement experimentElement
= (TmfExperimentElement
) projectElement
;
138 // Instantiate the experiment's traces
139 final List
<TmfTraceElement
> traceEntries
= experimentElement
.getTraces();
140 final int nbTraces
= traceEntries
.size();
141 int cacheSize
= Integer
.MAX_VALUE
;
142 final ITmfTrace
[] traces
= new ITmfTrace
[nbTraces
];
143 for (int i
= 0; i
< nbTraces
; i
++) {
144 final TmfTraceElement traceElement
= traceEntries
.get(i
);
145 final ITmfTrace trace
= traceElement
.instantiateTrace();
146 final ITmfEvent traceEvent
= traceElement
.instantiateEvent();
147 if ((trace
== null) || (traceEvent
== null)) {
148 for (int j
= 0; j
< i
; j
++) {
151 throw new PartInitException(Messages
.OpenExperimentHandler_NoTraceType
);
154 trace
.initTrace(traceElement
.getResource(), traceElement
.getLocation().getPath(), traceEvent
.getClass());
155 } catch (final TmfTraceException e
) {
156 throw new PartInitException(Messages
.OpenTraceHandler_InitError
, e
);
158 cacheSize
= Math
.min(cacheSize
, trace
.getCacheSize());
161 final TmfExperiment experiment
= new TmfExperiment(ITmfEvent
.class, experimentElement
.getName(), traces
, cacheSize
);
162 experiment
.setBookmarksFile(fFile
);
167 } else if (traceTypeId
.equals(TmfTrace
.class.getCanonicalName())) {
168 // Special case: trace bookmark resource
169 final TmfNavigatorContentProvider ncp
= new TmfNavigatorContentProvider();
170 ncp
.getChildren(fFile
.getProject()); // force the model to be populated
171 final TmfProjectElement project
= TmfProjectRegistry
.getProject(fFile
.getProject());
172 for (final ITmfProjectModelElement projectElement
: project
.getTracesFolder().getChildren()) {
173 final String traceName
= fFile
.getParent().getName();
174 if (projectElement
.getName().equals(traceName
)) {
175 final TmfTraceElement traceElement
= (TmfTraceElement
) projectElement
;
176 // Instantiate the trace
177 final ITmfTrace trace
= traceElement
.instantiateTrace();
178 final ITmfEvent traceEvent
= traceElement
.instantiateEvent();
179 if ((trace
== null) || (traceEvent
== null)) {
180 throw new PartInitException(Messages
.OpenTraceHandler_NoTraceType
);
183 trace
.initTrace(traceElement
.getResource(), traceElement
.getLocation().getPath(), traceEvent
.getClass());
184 } catch (final TmfTraceException e
) {
185 throw new PartInitException(Messages
.OpenTraceHandler_InitError
, e
);
192 final TmfNavigatorContentProvider ncp
= new TmfNavigatorContentProvider();
193 ncp
.getChildren(fFile
.getProject()); // force the model to be populated
194 final TmfProjectElement project
= TmfProjectRegistry
.getProject(fFile
.getProject());
195 for (final ITmfProjectModelElement projectElement
: project
.getTracesFolder().getChildren()) {
196 if (projectElement
.getResource().equals(fFile
)) {
197 final TmfTraceElement traceElement
= (TmfTraceElement
) projectElement
;
198 // Instantiate the trace
199 final ITmfTrace trace
= traceElement
.instantiateTrace();
200 final ITmfEvent traceEvent
= traceElement
.instantiateEvent();
201 if ((trace
== null) || (traceEvent
== null)) {
202 throw new PartInitException(Messages
.OpenTraceHandler_NoTraceType
);
205 trace
.initTrace(traceElement
.getResource(), traceElement
.getLocation().getPath(), traceEvent
.getClass());
206 } catch (final TmfTraceException e
) {
207 throw new PartInitException(Messages
.OpenTraceHandler_InitError
, e
);
214 } catch (final PartInitException e
) {
216 } catch (final InvalidRegistryObjectException e
) {
217 Activator
.getDefault().logError("Error initializing TmfEventsEditor", e
); //$NON-NLS-1$
218 } catch (final CoreException e
) {
219 Activator
.getDefault().logError("Error initializing TmfEventsEditor", e
); //$NON-NLS-1$
222 throw new PartInitException("Invalid IEditorInput: " + input
.getClass()); //$NON-NLS-1$
224 if (fTrace
== null) {
225 throw new PartInitException("Invalid IEditorInput: " + fFile
.getName()); //$NON-NLS-1$
228 super.setInput(fileEditorInput
);
232 public boolean isDirty() {
237 public boolean isSaveAsAllowed() {
242 public void setInput(final IEditorInput input
) {
243 super.setInput(input
);
244 firePropertyChange(IEditorPart
.PROP_INPUT
);
248 public void propertyChanged(final Object source
, final int propId
) {
249 if (propId
== IEditorPart
.PROP_INPUT
&& getEditorInput() instanceof TmfEditorInput
) {
250 broadcast(new TmfTraceClosedSignal(this, fTrace
));
251 fFile
= ((TmfEditorInput
) getEditorInput()).getFile();
252 fTrace
= ((TmfEditorInput
) getEditorInput()).getTrace();
253 /* change the input to a FileEditorInput to allow open handlers to find this editor */
254 super.setInput(new FileEditorInput(fFile
));
255 fEventsTable
.dispose();
256 if (fTrace
!= null) {
257 fEventsTable
= createEventsTable(fParent
, fTrace
.getCacheSize());
258 fEventsTable
.addSelectionChangedListener(this);
259 fEventsTable
.setTrace(fTrace
, true);
260 fEventsTable
.refreshBookmarks(fFile
);
262 /* ensure start time is set */
263 final ITmfContext context
= fTrace
.seekEvent(0);
264 fTrace
.getNext(context
);
267 broadcast(new TmfTraceOpenedSignal(this, fTrace
, fFile
));
269 fEventsTable
= new TmfEventsTable(fParent
, 0);
270 fEventsTable
.addSelectionChangedListener(this);
277 public void createPartControl(final Composite parent
) {
279 if (fTrace
!= null) {
280 setPartName(fTrace
.getName());
281 fEventsTable
= createEventsTable(parent
, fTrace
.getCacheSize());
282 fEventsTable
.addSelectionChangedListener(this);
283 fEventsTable
.setTrace(fTrace
, true);
284 fEventsTable
.refreshBookmarks(fFile
);
286 /* ensure start time is set */
287 final ITmfContext context
= fTrace
.seekEvent(0);
288 fTrace
.getNext(context
);
291 broadcast(new TmfTraceOpenedSignal(this, fTrace
, fFile
));
293 setPartName(getEditorInput().getName());
294 fEventsTable
= new TmfEventsTable(parent
, 0);
295 fEventsTable
.addSelectionChangedListener(this);
297 addPropertyListener(this);
298 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
299 // we need to wrap the ISelectionProvider interface in the editor because
300 // the events table can be replaced later while the selection changed listener
301 // is only added once by the platform to the selection provider set here
302 getSite().setSelectionProvider(this);
303 getSite().getPage().addPartListener(this);
307 public void dispose() {
308 if (getSite() != null) {
309 getSite().getPage().removePartListener(this);
311 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
312 removePropertyListener(this);
313 if (fTrace
!= null) {
314 broadcast(new TmfTraceClosedSignal(this, fTrace
));
316 if (fEventsTable
!= null) {
317 fEventsTable
.dispose();
323 * Create the events table
325 * @param parent the parent composite
326 * @param cacheSize the cache size
327 * @return an events table instance
329 protected TmfEventsTable
createEventsTable(final Composite parent
, final int cacheSize
) {
330 TmfEventsTable eventsTable
= getEventsTable(parent
, cacheSize
);
331 if (eventsTable
== null) {
332 eventsTable
= new TmfEventsTable(parent
, cacheSize
);
337 private TmfEventsTable
getEventsTable(final Composite parent
, final int cacheSize
) {
338 if (fTrace
instanceof TmfExperiment
) {
339 return getExperimentEventsTable((TmfExperiment
) fTrace
, parent
, cacheSize
);
341 TmfEventsTable eventsTable
= null;
343 if (fTrace
.getResource() == null) {
346 final String traceType
= fTrace
.getResource().getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
347 if (traceType
== null) {
350 if (traceType
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
351 return new CustomEventsTable(((CustomTxtTrace
) fTrace
).getDefinition(), parent
, cacheSize
);
353 if (traceType
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
354 return new CustomEventsTable(((CustomXmlTrace
) fTrace
).getDefinition(), parent
, cacheSize
);
356 for (final IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
357 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(traceType
)) {
358 final IConfigurationElement
[] eventsTableTypeCE
= ce
.getChildren(TmfTraceType
.EVENTS_TABLE_TYPE_ELEM
);
359 if (eventsTableTypeCE
.length
!= 1) {
362 final String eventsTableType
= eventsTableTypeCE
[0].getAttribute(TmfTraceType
.CLASS_ATTR
);
363 if ((eventsTableType
== null) || (eventsTableType
.length() == 0)) {
366 final Bundle bundle
= Platform
.getBundle(ce
.getContributor().getName());
367 final Class
<?
> c
= bundle
.loadClass(eventsTableType
);
368 final Class
<?
>[] constructorArgs
= new Class
[] { Composite
.class, int.class };
369 final Constructor
<?
> constructor
= c
.getConstructor(constructorArgs
);
370 final Object
[] args
= new Object
[] { parent
, cacheSize
};
371 eventsTable
= (TmfEventsTable
) constructor
.newInstance(args
);
375 } catch (final InvalidRegistryObjectException e
) {
376 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
377 } catch (final CoreException e
) {
378 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
379 } catch (final ClassNotFoundException e
) {
380 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
381 } catch (final SecurityException e
) {
382 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
383 } catch (final NoSuchMethodException e
) {
384 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
385 } catch (final IllegalArgumentException e
) {
386 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
387 } catch (final InstantiationException e
) {
388 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
389 } catch (final IllegalAccessException e
) {
390 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
391 } catch (final InvocationTargetException e
) {
392 Activator
.getDefault().logError("Error getting TmfEventsTable", e
); //$NON-NLS-1$
398 * Get the events table for an experiment. If all traces in the experiment
399 * are of the same type, use the extension point specified event table
404 * the parent Composite
406 * the event table cache size
407 * @return an events table of the appropriate type
409 private static TmfEventsTable
getExperimentEventsTable(
410 final TmfExperiment experiment
, final Composite parent
,
411 final int cacheSize
) {
412 TmfEventsTable eventsTable
= null;
413 String commonTraceType
= null;
415 for (final ITmfTrace trace
: experiment
.getTraces()) {
416 final IResource resource
= trace
.getResource();
417 if (resource
== null) {
420 final String traceType
= resource
.getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
421 if ((commonTraceType
!= null) && !commonTraceType
.equals(traceType
)) {
424 commonTraceType
= traceType
;
426 if (commonTraceType
== null) {
429 if (commonTraceType
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
430 return new CustomEventsTable(((CustomTxtTrace
) experiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
432 if (commonTraceType
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
433 return new CustomEventsTable(((CustomXmlTrace
) experiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
435 for (final IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
436 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(commonTraceType
)) {
437 final IConfigurationElement
[] eventsTableTypeCE
= ce
.getChildren(TmfTraceType
.EVENTS_TABLE_TYPE_ELEM
);
438 if (eventsTableTypeCE
.length
!= 1) {
441 final String eventsTableType
= eventsTableTypeCE
[0].getAttribute(TmfTraceType
.CLASS_ATTR
);
442 if ((eventsTableType
== null) || (eventsTableType
.length() == 0)) {
445 final Bundle bundle
= Platform
.getBundle(ce
.getContributor().getName());
446 final Class
<?
> c
= bundle
.loadClass(eventsTableType
);
447 final Class
<?
>[] constructorArgs
= new Class
[] { Composite
.class, int.class };
448 final Constructor
<?
> constructor
= c
.getConstructor(constructorArgs
);
449 final Object
[] args
= new Object
[] { parent
, cacheSize
};
450 eventsTable
= (TmfEventsTable
) constructor
.newInstance(args
);
454 } catch (final CoreException e
) {
455 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
456 } catch (final InvalidRegistryObjectException e
) {
457 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
458 } catch (final SecurityException e
) {
459 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
460 } catch (final IllegalArgumentException e
) {
461 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
462 } catch (final ClassNotFoundException e
) {
463 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
464 } catch (final NoSuchMethodException e
) {
465 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
466 } catch (final InstantiationException e
) {
467 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
468 } catch (final IllegalAccessException e
) {
469 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
470 } catch (final InvocationTargetException e
) {
471 Activator
.getDefault().logError("Error getting TmfEventsTable for experiment", e
); //$NON-NLS-1$
477 public ITmfTrace
getTrace() {
482 public IFile
getBookmarksFile() {
487 public void setFocus() {
488 fEventsTable
.setFocus();
492 public Object
getAdapter(final Class adapter
) {
493 if (IGotoMarker
.class.equals(adapter
)) {
495 } else if (IPropertySheetPage
.class.equals(adapter
)) {
496 return new UnsortedPropertySheetPage();
498 return super.getAdapter(adapter
);
502 public void resourceChanged(final IResourceChangeEvent event
) {
503 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
504 if (delta
.getResource().equals(fFile
)) {
505 if (delta
.getKind() == IResourceDelta
.REMOVED
) {
506 final IMarker bookmark
= delta
.getMarker();
507 Display
.getDefault().asyncExec(new Runnable() {
510 fEventsTable
.removeBookmark(bookmark
);
513 } else if (delta
.getKind() == IResourceDelta
.CHANGED
) {
514 Display
.getDefault().asyncExec(new Runnable() {
517 fEventsTable
.getTable().refresh();
525 // ------------------------------------------------------------------------
526 // ISelectionProvider
527 // ------------------------------------------------------------------------
530 * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
536 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
537 fSelectionChangedListeners
.add(listener
);
541 * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
547 public ISelection
getSelection() {
548 if (fEventsTable
== null) {
549 return StructuredSelection
.EMPTY
;
551 return fEventsTable
.getSelection();
555 * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
561 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
562 fSelectionChangedListeners
.remove(listener
);
566 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
572 public void setSelection(ISelection selection
) {
577 * Notifies any selection changed listeners that the viewer's selection has changed.
578 * Only listeners registered at the time this method is called are notified.
580 * @param event a selection changed event
582 * @see ISelectionChangedListener#selectionChanged
585 protected void fireSelectionChanged(final SelectionChangedEvent event
) {
586 Object
[] listeners
= fSelectionChangedListeners
.getListeners();
587 for (int i
= 0; i
< listeners
.length
; ++i
) {
588 final ISelectionChangedListener l
= (ISelectionChangedListener
) listeners
[i
];
589 SafeRunnable
.run(new SafeRunnable() {
592 l
.selectionChanged(event
);
598 // ------------------------------------------------------------------------
599 // ISelectionChangedListener
600 // ------------------------------------------------------------------------
604 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
610 public void selectionChanged(SelectionChangedEvent event
) {
611 fireSelectionChanged(event
);
614 // ------------------------------------------------------------------------
616 // ------------------------------------------------------------------------
620 * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
626 public void partActivated(IWorkbenchPart part
) {
627 if (part
== this && fTrace
!= null) {
628 if (fTraceSelected
) {
631 fTraceSelected
= true;
632 broadcast(new TmfTraceSelectedSignal(this, fTrace
));
638 * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
644 public void partBroughtToTop(IWorkbenchPart part
) {
645 if (part
== this && fTrace
!= null) {
646 if (fTraceSelected
) {
649 fTraceSelected
= true;
650 broadcast(new TmfTraceSelectedSignal(this, fTrace
));
656 * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
662 public void partClosed(IWorkbenchPart part
) {
667 * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
673 public void partDeactivated(IWorkbenchPart part
) {
678 * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
684 public void partOpened(IWorkbenchPart part
) {
687 // ------------------------------------------------------------------------
689 // ------------------------------------------------------------------------
694 public void addBookmark() {
695 fEventsTable
.addBookmark(fFile
);
699 // ------------------------------------------------------------------------
701 // ------------------------------------------------------------------------
704 * Handler for the Trace Selected signal
706 * @param signal The incoming signal
709 public void traceSelected(final TmfTraceSelectedSignal signal
) {
710 if ((signal
.getSource() != this)) {
711 if (signal
.getTrace().equals(fTrace
)) {
712 getSite().getPage().bringToTop(this);
714 fTraceSelected
= false;
720 * Update the display to use the updated timestamp format
722 * @param signal the incoming signal
726 public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal
) {
727 fEventsTable
.refresh();