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