Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
50a41a0d | 2 | * Copyright (c) 2010, 2014 Ericsson, École Polytechnique de Montréal |
6151d86c PT |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
50a41a0d | 11 | * Geneviève Bastien - Experiment instantiated with experiment type |
6151d86c PT |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.editors; |
6151d86c | 15 | |
99d7adc6 AM |
16 | import java.util.LinkedHashSet; |
17 | import java.util.Set; | |
6151d86c PT |
18 | |
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; | |
6151d86c PT |
28 | import org.eclipse.core.runtime.IProgressMonitor; |
29 | import org.eclipse.core.runtime.InvalidRegistryObjectException; | |
93bfd50a | 30 | import org.eclipse.core.runtime.ListenerList; |
99d7adc6 AM |
31 | import org.eclipse.jdt.annotation.NonNull; |
32 | import org.eclipse.jdt.annotation.Nullable; | |
3f43dc48 | 33 | import org.eclipse.jface.action.IStatusLineManager; |
93bfd50a PT |
34 | import org.eclipse.jface.util.SafeRunnable; |
35 | import org.eclipse.jface.viewers.ISelection; | |
36 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
37 | import org.eclipse.jface.viewers.ISelectionProvider; | |
38 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
39 | import org.eclipse.jface.viewers.StructuredSelection; | |
6151d86c PT |
40 | import org.eclipse.swt.widgets.Composite; |
41 | import org.eclipse.swt.widgets.Display; | |
2bdf0193 AM |
42 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
43 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; | |
b04903a2 | 44 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
2bdf0193 AM |
45 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
46 | import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal; | |
47 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; | |
48 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; | |
49 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; | |
50 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
51 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2bdf0193 | 52 | import org.eclipse.tracecompass.tmf.core.trace.TmfTrace; |
5c5fa260 | 53 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
2bdf0193 AM |
54 | import org.eclipse.tracecompass.tmf.ui.project.model.Messages; |
55 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; | |
56 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper; | |
57 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
58 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; | |
59 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
60 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceTypeUIUtils; | |
61 | import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable; | |
6151d86c PT |
62 | import org.eclipse.ui.IEditorInput; |
63 | import org.eclipse.ui.IEditorPart; | |
64 | import org.eclipse.ui.IEditorSite; | |
65 | import org.eclipse.ui.IFileEditorInput; | |
faa38350 | 66 | import org.eclipse.ui.IPartListener; |
6151d86c PT |
67 | import org.eclipse.ui.IPropertyListener; |
68 | import org.eclipse.ui.IReusableEditor; | |
faa38350 | 69 | import org.eclipse.ui.IWorkbenchPart; |
6151d86c PT |
70 | import org.eclipse.ui.PartInitException; |
71 | import org.eclipse.ui.ide.IGotoMarker; | |
72 | import org.eclipse.ui.part.FileEditorInput; | |
93bfd50a | 73 | import org.eclipse.ui.views.properties.IPropertySheetPage; |
6151d86c PT |
74 | |
75 | /** | |
76 | * Editor for TMF events | |
77 | * | |
78 | * @version 1.0 | |
79 | * @author Patrick Tasse | |
faa38350 | 80 | * @since 2.0 |
6151d86c | 81 | */ |
eb271b88 | 82 | public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener, ISelectionProvider, ISelectionChangedListener, IPartListener, IGotoMarker { |
6151d86c PT |
83 | |
84 | /** ID for this class */ | |
85 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$ | |
86 | ||
87 | private TmfEventsTable fEventsTable; | |
88 | private IFile fFile; | |
89 | private ITmfTrace fTrace; | |
90 | private Composite fParent; | |
93bfd50a | 91 | private ListenerList fSelectionChangedListeners = new ListenerList(); |
81fe3479 | 92 | private boolean fTraceSelected; |
eb271b88 | 93 | private IMarker fPendingGotoMarker; |
6151d86c PT |
94 | |
95 | @Override | |
96 | public void doSave(final IProgressMonitor monitor) { | |
97 | } | |
98 | ||
99 | @Override | |
100 | public void doSaveAs() { | |
101 | } | |
102 | ||
6151d86c PT |
103 | @Override |
104 | public void init(final IEditorSite site, IEditorInput input) throws PartInitException { | |
faa38350 | 105 | IFileEditorInput fileEditorInput; |
6151d86c PT |
106 | if (input instanceof TmfEditorInput) { |
107 | fFile = ((TmfEditorInput) input).getFile(); | |
108 | fTrace = ((TmfEditorInput) input).getTrace(); | |
faa38350 PT |
109 | /* change the input to a FileEditorInput to allow open handlers to find this editor */ |
110 | fileEditorInput = new FileEditorInput(fFile); | |
6151d86c | 111 | } else if (input instanceof IFileEditorInput) { |
faa38350 PT |
112 | fileEditorInput = (IFileEditorInput) input; |
113 | fFile = fileEditorInput.getFile(); | |
114 | if (fFile == null) { | |
115 | throw new PartInitException("Invalid IFileEditorInput: " + fileEditorInput); //$NON-NLS-1$ | |
6151d86c PT |
116 | } |
117 | try { | |
118 | final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE); | |
119 | if (traceTypeId == null) { | |
67c53011 | 120 | throw new PartInitException(Messages.TmfOpenTraceHelper_NoTraceType); |
6151d86c PT |
121 | } |
122 | if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) { | |
123 | // Special case: experiment bookmark resource | |
f537c959 | 124 | final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject(), true); |
6151d86c | 125 | if (project == null) { |
67c53011 | 126 | throw new PartInitException(Messages.TmfOpenTraceHelper_NoTraceType); |
6151d86c | 127 | } |
339d539c PT |
128 | for (final TmfExperimentElement experimentElement : project.getExperimentsFolder().getExperiments()) { |
129 | if (experimentElement.getResource().equals(fFile.getParent())) { | |
eb271b88 PT |
130 | setPartName(experimentElement.getName()); |
131 | super.setSite(site); | |
132 | super.setInput(fileEditorInput); | |
9d2e08b9 | 133 | TmfOpenTraceHelper.reopenTraceFromElement(experimentElement, this); |
eb271b88 | 134 | return; |
6151d86c PT |
135 | } |
136 | } | |
137 | } else if (traceTypeId.equals(TmfTrace.class.getCanonicalName())) { | |
138 | // Special case: trace bookmark resource | |
f537c959 | 139 | final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject(), true); |
339d539c PT |
140 | for (final TmfTraceElement traceElement : project.getTracesFolder().getTraces()) { |
141 | if (traceElement.getResource().equals(fFile.getParent())) { | |
eb271b88 PT |
142 | setPartName(traceElement.getName()); |
143 | super.setSite(site); | |
144 | super.setInput(fileEditorInput); | |
145 | TmfOpenTraceHelper.reopenTraceFromElement(traceElement, this); | |
146 | return; | |
6151d86c PT |
147 | } |
148 | } | |
149 | } else { | |
f537c959 | 150 | final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject(), true); |
339d539c PT |
151 | for (final TmfTraceElement traceElement : project.getTracesFolder().getTraces()) { |
152 | if (traceElement.getResource().equals(fFile)) { | |
eb271b88 PT |
153 | setPartName(traceElement.getName()); |
154 | super.setSite(site); | |
155 | super.setInput(fileEditorInput); | |
156 | TmfOpenTraceHelper.reopenTraceFromElement(traceElement, this); | |
157 | return; | |
6151d86c PT |
158 | } |
159 | } | |
160 | } | |
faa38350 PT |
161 | } catch (final PartInitException e) { |
162 | throw e; | |
6151d86c PT |
163 | } catch (final InvalidRegistryObjectException e) { |
164 | Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$ | |
165 | } catch (final CoreException e) { | |
166 | Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$ | |
167 | } | |
faa38350 | 168 | } else { |
6151d86c PT |
169 | throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$ |
170 | } | |
faa38350 | 171 | if (fTrace == null) { |
6151d86c PT |
172 | throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$ |
173 | } | |
174 | super.setSite(site); | |
faa38350 | 175 | super.setInput(fileEditorInput); |
6151d86c PT |
176 | } |
177 | ||
178 | @Override | |
179 | public boolean isDirty() { | |
180 | return false; | |
181 | } | |
182 | ||
183 | @Override | |
184 | public boolean isSaveAsAllowed() { | |
185 | return false; | |
186 | } | |
187 | ||
188 | @Override | |
189 | public void setInput(final IEditorInput input) { | |
190 | super.setInput(input); | |
191 | firePropertyChange(IEditorPart.PROP_INPUT); | |
192 | } | |
193 | ||
194 | @Override | |
195 | public void propertyChanged(final Object source, final int propId) { | |
faa38350 | 196 | if (propId == IEditorPart.PROP_INPUT && getEditorInput() instanceof TmfEditorInput) { |
1cf25311 PT |
197 | if (fTrace != null) { |
198 | broadcast(new TmfTraceClosedSignal(this, fTrace)); | |
199 | } | |
7e81f48c | 200 | fTraceSelected = false; |
6151d86c PT |
201 | fFile = ((TmfEditorInput) getEditorInput()).getFile(); |
202 | fTrace = ((TmfEditorInput) getEditorInput()).getTrace(); | |
faa38350 | 203 | /* change the input to a FileEditorInput to allow open handlers to find this editor */ |
6151d86c PT |
204 | super.setInput(new FileEditorInput(fFile)); |
205 | fEventsTable.dispose(); | |
206 | if (fTrace != null) { | |
eb271b88 | 207 | setPartName(fTrace.getName()); |
6151d86c | 208 | fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); |
93bfd50a | 209 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
210 | fEventsTable.setTrace(fTrace, true); |
211 | fEventsTable.refreshBookmarks(fFile); | |
eb271b88 PT |
212 | if (fPendingGotoMarker != null) { |
213 | fEventsTable.gotoMarker(fPendingGotoMarker); | |
214 | fPendingGotoMarker = null; | |
215 | } | |
c4352ddc PT |
216 | |
217 | /* ensure start time is set */ | |
218 | final ITmfContext context = fTrace.seekEvent(0); | |
219 | fTrace.getNext(context); | |
220 | context.dispose(); | |
221 | ||
faa38350 | 222 | broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile)); |
6151d86c | 223 | } else { |
eb271b88 | 224 | setPartName(getEditorInput().getName()); |
6151d86c | 225 | fEventsTable = new TmfEventsTable(fParent, 0); |
93bfd50a | 226 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
227 | } |
228 | fParent.layout(); | |
229 | } | |
230 | } | |
231 | ||
232 | @Override | |
233 | public void createPartControl(final Composite parent) { | |
234 | fParent = parent; | |
235 | if (fTrace != null) { | |
236 | setPartName(fTrace.getName()); | |
237 | fEventsTable = createEventsTable(parent, fTrace.getCacheSize()); | |
93bfd50a | 238 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
239 | fEventsTable.setTrace(fTrace, true); |
240 | fEventsTable.refreshBookmarks(fFile); | |
d7ee91bb PT |
241 | |
242 | /* ensure start time is set */ | |
243 | final ITmfContext context = fTrace.seekEvent(0); | |
244 | fTrace.getNext(context); | |
245 | context.dispose(); | |
246 | ||
faa38350 | 247 | broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile)); |
6151d86c | 248 | } else { |
6151d86c | 249 | fEventsTable = new TmfEventsTable(parent, 0); |
93bfd50a | 250 | fEventsTable.addSelectionChangedListener(this); |
6151d86c | 251 | } |
3f43dc48 PT |
252 | IStatusLineManager statusLineManager = getEditorSite().getActionBars().getStatusLineManager(); |
253 | fEventsTable.setStatusLineManager(statusLineManager); | |
6151d86c PT |
254 | addPropertyListener(this); |
255 | ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); | |
93bfd50a PT |
256 | // we need to wrap the ISelectionProvider interface in the editor because |
257 | // the events table can be replaced later while the selection changed listener | |
258 | // is only added once by the platform to the selection provider set here | |
259 | getSite().setSelectionProvider(this); | |
faa38350 | 260 | getSite().getPage().addPartListener(this); |
6151d86c PT |
261 | } |
262 | ||
263 | @Override | |
264 | public void dispose() { | |
faa38350 PT |
265 | if (getSite() != null) { |
266 | getSite().getPage().removePartListener(this); | |
267 | } | |
6151d86c PT |
268 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
269 | removePropertyListener(this); | |
270 | if (fTrace != null) { | |
271 | broadcast(new TmfTraceClosedSignal(this, fTrace)); | |
272 | } | |
273 | if (fEventsTable != null) { | |
274 | fEventsTable.dispose(); | |
275 | } | |
276 | super.dispose(); | |
277 | } | |
278 | ||
faa38350 | 279 | /** |
99d7adc6 | 280 | * Create the event table |
faa38350 | 281 | * |
99d7adc6 AM |
282 | * @param parent |
283 | * The parent composite | |
284 | * @param cacheSize | |
285 | * The cache size | |
286 | * @return The event table instance | |
faa38350 | 287 | */ |
99d7adc6 AM |
288 | protected @NonNull TmfEventsTable createEventsTable(final Composite parent, final int cacheSize) { |
289 | return getEventTable(fTrace, parent, cacheSize); | |
6151d86c PT |
290 | } |
291 | ||
99d7adc6 AM |
292 | /** |
293 | * Get the event table for the given trace. It will be of the type defined | |
294 | * by the extension point if applicable, else it will be a default table | |
295 | * with the extension-point-defined columns (if any). | |
296 | * | |
297 | * @param trace | |
298 | * The event table is for this trace | |
299 | * @param parent | |
300 | * The parent composite of the table | |
301 | * @param cacheSize | |
302 | * The cache size to use | |
303 | * @return The event table for the trace | |
304 | */ | |
305 | private static @NonNull TmfEventsTable getEventTable(ITmfTrace trace, | |
306 | final Composite parent, final int cacheSize) { | |
307 | if (trace instanceof TmfExperiment) { | |
308 | return getExperimentEventTable((TmfExperiment) trace, parent, cacheSize); | |
309 | } | |
50a41a0d | 310 | |
99d7adc6 AM |
311 | TmfEventsTable table = TmfTraceTypeUIUtils.getEventTable(trace, parent, cacheSize); |
312 | if (table != null) { | |
313 | /* | |
314 | * The trace type specified an event table type, we will give it to | |
315 | * them. | |
316 | */ | |
317 | return table; | |
6151d86c | 318 | } |
99d7adc6 AM |
319 | |
320 | /* | |
b04903a2 AM |
321 | * The trace type did not specify an event table, we will use a standard |
322 | * table with the trace's advertised aspects (if any). | |
99d7adc6 | 323 | */ |
8192209b | 324 | return new TmfEventsTable(parent, cacheSize, trace.getEventAspects()); |
6151d86c PT |
325 | } |
326 | ||
327 | /** | |
328 | * Get the events table for an experiment. If all traces in the experiment | |
99d7adc6 AM |
329 | * are of the same type, use the same behavior as if it was one trace of |
330 | * that type. | |
6151d86c PT |
331 | * |
332 | * @param experiment | |
333 | * the experiment | |
334 | * @param parent | |
335 | * the parent Composite | |
336 | * @param cacheSize | |
337 | * the event table cache size | |
99d7adc6 | 338 | * @return An event table of the appropriate type |
6151d86c | 339 | */ |
99d7adc6 | 340 | private static @NonNull TmfEventsTable getExperimentEventTable( |
6151d86c PT |
341 | final TmfExperiment experiment, final Composite parent, |
342 | final int cacheSize) { | |
99d7adc6 AM |
343 | |
344 | String commonTraceType = getCommonTraceType(experiment); | |
345 | if (commonTraceType != null) { | |
346 | /* | |
347 | * All the traces in this experiment are of the same type, let's | |
348 | * just use the normal table for that type. | |
349 | */ | |
350 | return getEventTable(experiment.getTraces()[0], parent, cacheSize); | |
351 | } | |
352 | ||
353 | /* | |
354 | * There are different trace types in the experiment, so we are | |
355 | * definitely using a TmfEventsTable. Aggregate the columns from all | |
356 | * trace types. | |
357 | */ | |
358 | ITmfTrace[] traces = experiment.getTraces(); | |
b04903a2 | 359 | Set<ITmfEventAspect> aspects = new LinkedHashSet<>(); |
99d7adc6 AM |
360 | |
361 | for (ITmfTrace trace : traces) { | |
b04903a2 | 362 | Iterable<ITmfEventAspect> traceAspects = trace.getEventAspects(); |
8192209b AM |
363 | for (ITmfEventAspect aspect : traceAspects) { |
364 | aspects.add(aspect); | |
99d7adc6 AM |
365 | } |
366 | } | |
367 | ||
b04903a2 | 368 | return new TmfEventsTable(parent, cacheSize, aspects); |
99d7adc6 AM |
369 | } |
370 | ||
371 | /** | |
372 | * Check if an experiment contains traces of all the same type. If so, | |
373 | * returns this type as a String. If not, returns null. | |
374 | * | |
375 | * @param experiment | |
376 | * The experiment | |
377 | * @return The common trace type if there is one, or 'null' if there are | |
378 | * different types. | |
379 | */ | |
380 | private static @Nullable String getCommonTraceType(TmfExperiment experiment) { | |
6151d86c PT |
381 | String commonTraceType = null; |
382 | try { | |
383 | for (final ITmfTrace trace : experiment.getTraces()) { | |
384 | final IResource resource = trace.getResource(); | |
385 | if (resource == null) { | |
386 | return null; | |
387 | } | |
99d7adc6 | 388 | |
6151d86c PT |
389 | final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); |
390 | if ((commonTraceType != null) && !commonTraceType.equals(traceType)) { | |
391 | return null; | |
392 | } | |
393 | commonTraceType = traceType; | |
394 | } | |
99d7adc6 AM |
395 | } catch (CoreException e) { |
396 | /* | |
397 | * One of the traces didn't advertise its type, we can't infer | |
398 | * anything. | |
399 | */ | |
400 | return null; | |
6151d86c | 401 | } |
99d7adc6 | 402 | return commonTraceType; |
6151d86c PT |
403 | } |
404 | ||
405 | @Override | |
406 | public ITmfTrace getTrace() { | |
407 | return fTrace; | |
408 | } | |
409 | ||
6151d86c PT |
410 | @Override |
411 | public void setFocus() { | |
412 | fEventsTable.setFocus(); | |
6151d86c PT |
413 | } |
414 | ||
415 | @Override | |
416 | public Object getAdapter(final Class adapter) { | |
417 | if (IGotoMarker.class.equals(adapter)) { | |
eb271b88 PT |
418 | if (fTrace == null || fEventsTable == null) { |
419 | return this; | |
420 | } | |
6151d86c | 421 | return fEventsTable; |
93bfd50a | 422 | } else if (IPropertySheetPage.class.equals(adapter)) { |
faa38350 | 423 | return new UnsortedPropertySheetPage(); |
6151d86c PT |
424 | } |
425 | return super.getAdapter(adapter); | |
426 | } | |
427 | ||
eb271b88 PT |
428 | /** |
429 | * @since 2.1 | |
430 | */ | |
431 | @Override | |
432 | public void gotoMarker(IMarker marker) { | |
433 | if (fTrace == null || fEventsTable == null) { | |
434 | fPendingGotoMarker = marker; | |
435 | } else { | |
436 | fEventsTable.gotoMarker(marker); | |
437 | } | |
438 | } | |
439 | ||
6151d86c PT |
440 | @Override |
441 | public void resourceChanged(final IResourceChangeEvent event) { | |
442 | for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) { | |
443 | if (delta.getResource().equals(fFile)) { | |
444 | if (delta.getKind() == IResourceDelta.REMOVED) { | |
445 | final IMarker bookmark = delta.getMarker(); | |
446 | Display.getDefault().asyncExec(new Runnable() { | |
447 | @Override | |
448 | public void run() { | |
449 | fEventsTable.removeBookmark(bookmark); | |
450 | } | |
451 | }); | |
452 | } else if (delta.getKind() == IResourceDelta.CHANGED) { | |
453 | Display.getDefault().asyncExec(new Runnable() { | |
454 | @Override | |
455 | public void run() { | |
456 | fEventsTable.getTable().refresh(); | |
457 | } | |
458 | }); | |
459 | } | |
460 | } | |
461 | } | |
462 | } | |
463 | ||
93bfd50a PT |
464 | // ------------------------------------------------------------------------ |
465 | // ISelectionProvider | |
466 | // ------------------------------------------------------------------------ | |
467 | ||
93bfd50a PT |
468 | /** |
469 | * @since 2.0 | |
470 | */ | |
471 | @Override | |
472 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
473 | fSelectionChangedListeners.add(listener); | |
474 | } | |
475 | ||
93bfd50a PT |
476 | /** |
477 | * @since 2.0 | |
478 | */ | |
479 | @Override | |
480 | public ISelection getSelection() { | |
481 | if (fEventsTable == null) { | |
482 | return StructuredSelection.EMPTY; | |
483 | } | |
484 | return fEventsTable.getSelection(); | |
485 | } | |
486 | ||
93bfd50a PT |
487 | /** |
488 | * @since 2.0 | |
489 | */ | |
490 | @Override | |
491 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { | |
492 | fSelectionChangedListeners.remove(listener); | |
493 | } | |
494 | ||
93bfd50a PT |
495 | /** |
496 | * @since 2.0 | |
497 | */ | |
498 | @Override | |
499 | public void setSelection(ISelection selection) { | |
500 | // not implemented | |
501 | } | |
502 | ||
503 | /** | |
504 | * Notifies any selection changed listeners that the viewer's selection has changed. | |
505 | * Only listeners registered at the time this method is called are notified. | |
506 | * | |
507 | * @param event a selection changed event | |
508 | * | |
509 | * @see ISelectionChangedListener#selectionChanged | |
510 | * @since 2.0 | |
511 | */ | |
512 | protected void fireSelectionChanged(final SelectionChangedEvent event) { | |
513 | Object[] listeners = fSelectionChangedListeners.getListeners(); | |
514 | for (int i = 0; i < listeners.length; ++i) { | |
515 | final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; | |
516 | SafeRunnable.run(new SafeRunnable() { | |
517 | @Override | |
518 | public void run() { | |
519 | l.selectionChanged(event); | |
520 | } | |
521 | }); | |
522 | } | |
523 | } | |
524 | ||
525 | // ------------------------------------------------------------------------ | |
526 | // ISelectionChangedListener | |
527 | // ------------------------------------------------------------------------ | |
528 | ||
93bfd50a PT |
529 | /** |
530 | * @since 2.0 | |
531 | */ | |
532 | @Override | |
533 | public void selectionChanged(SelectionChangedEvent event) { | |
534 | fireSelectionChanged(event); | |
535 | } | |
536 | ||
faa38350 PT |
537 | // ------------------------------------------------------------------------ |
538 | // IPartListener | |
539 | // ------------------------------------------------------------------------ | |
540 | ||
faa38350 PT |
541 | /** |
542 | * @since 2.0 | |
543 | */ | |
544 | @Override | |
545 | public void partActivated(IWorkbenchPart part) { | |
546 | if (part == this && fTrace != null) { | |
81fe3479 PT |
547 | if (fTraceSelected) { |
548 | return; | |
549 | } | |
550 | fTraceSelected = true; | |
faa38350 PT |
551 | broadcast(new TmfTraceSelectedSignal(this, fTrace)); |
552 | } | |
553 | } | |
554 | ||
faa38350 PT |
555 | /** |
556 | * @since 2.0 | |
557 | */ | |
558 | @Override | |
559 | public void partBroughtToTop(IWorkbenchPart part) { | |
81fe3479 PT |
560 | if (part == this && fTrace != null) { |
561 | if (fTraceSelected) { | |
562 | return; | |
563 | } | |
564 | fTraceSelected = true; | |
565 | broadcast(new TmfTraceSelectedSignal(this, fTrace)); | |
566 | } | |
faa38350 PT |
567 | } |
568 | ||
faa38350 PT |
569 | /** |
570 | * @since 2.0 | |
571 | */ | |
572 | @Override | |
573 | public void partClosed(IWorkbenchPart part) { | |
574 | } | |
575 | ||
faa38350 PT |
576 | /** |
577 | * @since 2.0 | |
578 | */ | |
579 | @Override | |
580 | public void partDeactivated(IWorkbenchPart part) { | |
581 | } | |
582 | ||
faa38350 PT |
583 | /** |
584 | * @since 2.0 | |
585 | */ | |
586 | @Override | |
587 | public void partOpened(IWorkbenchPart part) { | |
588 | } | |
589 | ||
6151d86c PT |
590 | // ------------------------------------------------------------------------ |
591 | // Global commands | |
592 | // ------------------------------------------------------------------------ | |
593 | ||
594 | /** | |
595 | * Add a bookmark | |
596 | */ | |
597 | public void addBookmark() { | |
598 | fEventsTable.addBookmark(fFile); | |
599 | } | |
600 | ||
601 | ||
602 | // ------------------------------------------------------------------------ | |
603 | // Signal handlers | |
604 | // ------------------------------------------------------------------------ | |
605 | ||
606 | /** | |
faa38350 | 607 | * Handler for the Trace Selected signal |
6151d86c PT |
608 | * |
609 | * @param signal The incoming signal | |
610 | */ | |
611 | @TmfSignalHandler | |
faa38350 | 612 | public void traceSelected(final TmfTraceSelectedSignal signal) { |
81fe3479 PT |
613 | if ((signal.getSource() != this)) { |
614 | if (signal.getTrace().equals(fTrace)) { | |
615 | getSite().getPage().bringToTop(this); | |
616 | } else { | |
617 | fTraceSelected = false; | |
618 | } | |
6151d86c PT |
619 | } |
620 | } | |
621 | ||
622 | /** | |
faa38350 | 623 | * Update the display to use the updated timestamp format |
6151d86c | 624 | * |
faa38350 PT |
625 | * @param signal the incoming signal |
626 | * @since 2.0 | |
6151d86c PT |
627 | */ |
628 | @TmfSignalHandler | |
faa38350 | 629 | public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { |
c1cd9635 MAL |
630 | if (fEventsTable != null) { |
631 | fEventsTable.refresh(); | |
632 | } | |
6151d86c PT |
633 | } |
634 | ||
635 | } |