Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
1cf25311 | 2 | * Copyright (c) 2010, 2014 Ericsson |
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 | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.editors; | |
14 | ||
15 | import java.lang.reflect.Constructor; | |
16 | import java.lang.reflect.InvocationTargetException; | |
6151d86c PT |
17 | |
18 | import org.eclipse.core.resources.IFile; | |
19 | import org.eclipse.core.resources.IMarker; | |
20 | import org.eclipse.core.resources.IMarkerDelta; | |
21 | import org.eclipse.core.resources.IResource; | |
22 | import org.eclipse.core.resources.IResourceChangeEvent; | |
23 | import org.eclipse.core.resources.IResourceChangeListener; | |
24 | import org.eclipse.core.resources.IResourceDelta; | |
25 | import org.eclipse.core.resources.ResourcesPlugin; | |
26 | import org.eclipse.core.runtime.CoreException; | |
27 | import org.eclipse.core.runtime.IConfigurationElement; | |
28 | import org.eclipse.core.runtime.IProgressMonitor; | |
29 | import org.eclipse.core.runtime.InvalidRegistryObjectException; | |
93bfd50a | 30 | import org.eclipse.core.runtime.ListenerList; |
6151d86c | 31 | import org.eclipse.core.runtime.Platform; |
3f43dc48 | 32 | import org.eclipse.jface.action.IStatusLineManager; |
93bfd50a PT |
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; | |
6151d86c PT |
39 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
40 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable; | |
6151d86c | 41 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
47aafe74 AM |
42 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace; |
43 | import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace; | |
6151d86c | 44 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
faa38350 PT |
45 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal; |
46 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; | |
47 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
6151d86c | 48 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; |
d7ee91bb | 49 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
6151d86c PT |
50 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
51 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; | |
52 | import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; | |
53 | import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; | |
67c53011 | 54 | import org.eclipse.linuxtools.tmf.ui.project.model.Messages; |
6151d86c | 55 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; |
eb271b88 | 56 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; |
6151d86c PT |
57 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; |
58 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; | |
59 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; | |
a926c25c | 60 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceTypeUIUtils; |
6151d86c PT |
61 | import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; |
62 | import org.eclipse.swt.widgets.Composite; | |
63 | import org.eclipse.swt.widgets.Display; | |
64 | import org.eclipse.ui.IEditorInput; | |
65 | import org.eclipse.ui.IEditorPart; | |
66 | import org.eclipse.ui.IEditorSite; | |
67 | import org.eclipse.ui.IFileEditorInput; | |
faa38350 | 68 | import org.eclipse.ui.IPartListener; |
6151d86c PT |
69 | import org.eclipse.ui.IPropertyListener; |
70 | import org.eclipse.ui.IReusableEditor; | |
faa38350 | 71 | import org.eclipse.ui.IWorkbenchPart; |
6151d86c PT |
72 | import org.eclipse.ui.PartInitException; |
73 | import org.eclipse.ui.ide.IGotoMarker; | |
74 | import org.eclipse.ui.part.FileEditorInput; | |
93bfd50a | 75 | import org.eclipse.ui.views.properties.IPropertySheetPage; |
6151d86c PT |
76 | import org.osgi.framework.Bundle; |
77 | ||
78 | /** | |
79 | * Editor for TMF events | |
80 | * | |
81 | * @version 1.0 | |
82 | * @author Patrick Tasse | |
faa38350 | 83 | * @since 2.0 |
6151d86c | 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 PT |
124 | } |
125 | if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) { | |
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 PT |
130 | } |
131 | for (final ITmfProjectModelElement projectElement : project.getExperimentsFolder().getChildren()) { | |
132 | final String traceName = fFile.getParent().getName(); | |
133 | if (projectElement.getName().equals(traceName)) { | |
134 | final TmfExperimentElement experimentElement = (TmfExperimentElement) projectElement; | |
eb271b88 PT |
135 | setPartName(experimentElement.getName()); |
136 | super.setSite(site); | |
137 | super.setInput(fileEditorInput); | |
138 | TmfOpenTraceHelper.reopenExperimentFromElement(experimentElement, this); | |
139 | return; | |
6151d86c PT |
140 | } |
141 | } | |
142 | } else if (traceTypeId.equals(TmfTrace.class.getCanonicalName())) { | |
143 | // Special case: trace bookmark resource | |
f537c959 | 144 | final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject(), true); |
6151d86c PT |
145 | for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) { |
146 | final String traceName = fFile.getParent().getName(); | |
147 | if (projectElement.getName().equals(traceName)) { | |
148 | final TmfTraceElement traceElement = (TmfTraceElement) projectElement; | |
eb271b88 PT |
149 | setPartName(traceElement.getName()); |
150 | super.setSite(site); | |
151 | super.setInput(fileEditorInput); | |
152 | TmfOpenTraceHelper.reopenTraceFromElement(traceElement, this); | |
153 | return; | |
6151d86c PT |
154 | } |
155 | } | |
156 | } else { | |
f537c959 | 157 | final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject(), true); |
6151d86c PT |
158 | for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) { |
159 | if (projectElement.getResource().equals(fFile)) { | |
160 | final TmfTraceElement traceElement = (TmfTraceElement) projectElement; | |
eb271b88 PT |
161 | setPartName(traceElement.getName()); |
162 | super.setSite(site); | |
163 | super.setInput(fileEditorInput); | |
164 | TmfOpenTraceHelper.reopenTraceFromElement(traceElement, this); | |
165 | return; | |
6151d86c PT |
166 | } |
167 | } | |
168 | } | |
faa38350 PT |
169 | } catch (final PartInitException e) { |
170 | throw e; | |
6151d86c PT |
171 | } catch (final InvalidRegistryObjectException e) { |
172 | Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$ | |
173 | } catch (final CoreException e) { | |
174 | Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$ | |
175 | } | |
faa38350 | 176 | } else { |
6151d86c PT |
177 | throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$ |
178 | } | |
faa38350 | 179 | if (fTrace == null) { |
6151d86c PT |
180 | throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$ |
181 | } | |
182 | super.setSite(site); | |
faa38350 | 183 | super.setInput(fileEditorInput); |
6151d86c PT |
184 | } |
185 | ||
186 | @Override | |
187 | public boolean isDirty() { | |
188 | return false; | |
189 | } | |
190 | ||
191 | @Override | |
192 | public boolean isSaveAsAllowed() { | |
193 | return false; | |
194 | } | |
195 | ||
196 | @Override | |
197 | public void setInput(final IEditorInput input) { | |
198 | super.setInput(input); | |
199 | firePropertyChange(IEditorPart.PROP_INPUT); | |
200 | } | |
201 | ||
202 | @Override | |
203 | public void propertyChanged(final Object source, final int propId) { | |
faa38350 | 204 | if (propId == IEditorPart.PROP_INPUT && getEditorInput() instanceof TmfEditorInput) { |
1cf25311 PT |
205 | if (fTrace != null) { |
206 | broadcast(new TmfTraceClosedSignal(this, fTrace)); | |
207 | } | |
7e81f48c | 208 | fTraceSelected = false; |
6151d86c PT |
209 | fFile = ((TmfEditorInput) getEditorInput()).getFile(); |
210 | fTrace = ((TmfEditorInput) getEditorInput()).getTrace(); | |
faa38350 | 211 | /* change the input to a FileEditorInput to allow open handlers to find this editor */ |
6151d86c PT |
212 | super.setInput(new FileEditorInput(fFile)); |
213 | fEventsTable.dispose(); | |
214 | if (fTrace != null) { | |
eb271b88 | 215 | setPartName(fTrace.getName()); |
6151d86c | 216 | fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); |
93bfd50a | 217 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
218 | fEventsTable.setTrace(fTrace, true); |
219 | fEventsTable.refreshBookmarks(fFile); | |
eb271b88 PT |
220 | if (fPendingGotoMarker != null) { |
221 | fEventsTable.gotoMarker(fPendingGotoMarker); | |
222 | fPendingGotoMarker = null; | |
223 | } | |
c4352ddc PT |
224 | |
225 | /* ensure start time is set */ | |
226 | final ITmfContext context = fTrace.seekEvent(0); | |
227 | fTrace.getNext(context); | |
228 | context.dispose(); | |
229 | ||
faa38350 | 230 | broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile)); |
6151d86c | 231 | } else { |
eb271b88 | 232 | setPartName(getEditorInput().getName()); |
6151d86c | 233 | fEventsTable = new TmfEventsTable(fParent, 0); |
93bfd50a | 234 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
235 | } |
236 | fParent.layout(); | |
237 | } | |
238 | } | |
239 | ||
240 | @Override | |
241 | public void createPartControl(final Composite parent) { | |
242 | fParent = parent; | |
243 | if (fTrace != null) { | |
244 | setPartName(fTrace.getName()); | |
245 | fEventsTable = createEventsTable(parent, fTrace.getCacheSize()); | |
93bfd50a | 246 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
247 | fEventsTable.setTrace(fTrace, true); |
248 | fEventsTable.refreshBookmarks(fFile); | |
d7ee91bb PT |
249 | |
250 | /* ensure start time is set */ | |
251 | final ITmfContext context = fTrace.seekEvent(0); | |
252 | fTrace.getNext(context); | |
253 | context.dispose(); | |
254 | ||
faa38350 | 255 | broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile)); |
6151d86c | 256 | } else { |
6151d86c | 257 | fEventsTable = new TmfEventsTable(parent, 0); |
93bfd50a | 258 | fEventsTable.addSelectionChangedListener(this); |
6151d86c | 259 | } |
3f43dc48 PT |
260 | IStatusLineManager statusLineManager = getEditorSite().getActionBars().getStatusLineManager(); |
261 | fEventsTable.setStatusLineManager(statusLineManager); | |
6151d86c PT |
262 | addPropertyListener(this); |
263 | ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); | |
93bfd50a PT |
264 | // we need to wrap the ISelectionProvider interface in the editor because |
265 | // the events table can be replaced later while the selection changed listener | |
266 | // is only added once by the platform to the selection provider set here | |
267 | getSite().setSelectionProvider(this); | |
faa38350 | 268 | getSite().getPage().addPartListener(this); |
6151d86c PT |
269 | } |
270 | ||
271 | @Override | |
272 | public void dispose() { | |
faa38350 PT |
273 | if (getSite() != null) { |
274 | getSite().getPage().removePartListener(this); | |
275 | } | |
6151d86c PT |
276 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
277 | removePropertyListener(this); | |
278 | if (fTrace != null) { | |
279 | broadcast(new TmfTraceClosedSignal(this, fTrace)); | |
280 | } | |
281 | if (fEventsTable != null) { | |
282 | fEventsTable.dispose(); | |
283 | } | |
284 | super.dispose(); | |
285 | } | |
286 | ||
faa38350 PT |
287 | /** |
288 | * Create the events table | |
289 | * | |
290 | * @param parent the parent composite | |
291 | * @param cacheSize the cache size | |
292 | * @return an events table instance | |
293 | */ | |
6151d86c PT |
294 | protected TmfEventsTable createEventsTable(final Composite parent, final int cacheSize) { |
295 | TmfEventsTable eventsTable = getEventsTable(parent, cacheSize); | |
296 | if (eventsTable == null) { | |
297 | eventsTable = new TmfEventsTable(parent, cacheSize); | |
298 | } | |
299 | return eventsTable; | |
300 | } | |
301 | ||
302 | private TmfEventsTable getEventsTable(final Composite parent, final int cacheSize) { | |
303 | if (fTrace instanceof TmfExperiment) { | |
304 | return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize); | |
305 | } | |
306 | TmfEventsTable eventsTable = null; | |
307 | try { | |
308 | if (fTrace.getResource() == null) { | |
309 | return null; | |
310 | } | |
311 | final String traceType = fTrace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); | |
312 | if (traceType == null) { | |
313 | return null; | |
314 | } | |
315 | if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
316 | return new CustomEventsTable(((CustomTxtTrace) fTrace).getDefinition(), parent, cacheSize); | |
317 | } | |
318 | if (traceType.startsWith(CustomXmlTrace.class.getCanonicalName())) { | |
319 | return new CustomEventsTable(((CustomXmlTrace) fTrace).getDefinition(), parent, cacheSize); | |
320 | } | |
a926c25c AM |
321 | for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements()) { |
322 | if (ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR).equals(traceType)) { | |
323 | final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceTypeUIUtils.EVENTS_TABLE_TYPE_ELEM); | |
6151d86c PT |
324 | if (eventsTableTypeCE.length != 1) { |
325 | break; | |
326 | } | |
a926c25c | 327 | final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.CLASS_ATTR); |
6151d86c PT |
328 | if ((eventsTableType == null) || (eventsTableType.length() == 0)) { |
329 | break; | |
330 | } | |
331 | final Bundle bundle = Platform.getBundle(ce.getContributor().getName()); | |
332 | final Class<?> c = bundle.loadClass(eventsTableType); | |
333 | final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class }; | |
334 | final Constructor<?> constructor = c.getConstructor(constructorArgs); | |
335 | final Object[] args = new Object[] { parent, cacheSize }; | |
336 | eventsTable = (TmfEventsTable) constructor.newInstance(args); | |
337 | break; | |
338 | } | |
339 | } | |
340 | } catch (final InvalidRegistryObjectException e) { | |
341 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
342 | } catch (final CoreException e) { | |
343 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
344 | } catch (final ClassNotFoundException e) { | |
345 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
346 | } catch (final SecurityException e) { | |
347 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
348 | } catch (final NoSuchMethodException e) { | |
349 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
350 | } catch (final IllegalArgumentException e) { | |
351 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
352 | } catch (final InstantiationException e) { | |
353 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
354 | } catch (final IllegalAccessException e) { | |
355 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
356 | } catch (final InvocationTargetException e) { | |
357 | Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$ | |
358 | } | |
359 | return eventsTable; | |
360 | } | |
361 | ||
362 | /** | |
363 | * Get the events table for an experiment. If all traces in the experiment | |
364 | * are of the same type, use the extension point specified event table | |
365 | * | |
366 | * @param experiment | |
367 | * the experiment | |
368 | * @param parent | |
369 | * the parent Composite | |
370 | * @param cacheSize | |
371 | * the event table cache size | |
372 | * @return an events table of the appropriate type | |
373 | */ | |
374 | private static TmfEventsTable getExperimentEventsTable( | |
375 | final TmfExperiment experiment, final Composite parent, | |
376 | final int cacheSize) { | |
377 | TmfEventsTable eventsTable = null; | |
378 | String commonTraceType = null; | |
379 | try { | |
380 | for (final ITmfTrace trace : experiment.getTraces()) { | |
381 | final IResource resource = trace.getResource(); | |
382 | if (resource == null) { | |
383 | return null; | |
384 | } | |
385 | final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); | |
386 | if ((commonTraceType != null) && !commonTraceType.equals(traceType)) { | |
387 | return null; | |
388 | } | |
389 | commonTraceType = traceType; | |
390 | } | |
391 | if (commonTraceType == null) { | |
392 | return null; | |
393 | } | |
394 | if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
395 | return new CustomEventsTable(((CustomTxtTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize); | |
396 | } | |
397 | if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) { | |
398 | return new CustomEventsTable(((CustomXmlTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize); | |
399 | } | |
a926c25c AM |
400 | for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements()) { |
401 | if (ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR).equals(commonTraceType)) { | |
402 | final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceTypeUIUtils.EVENTS_TABLE_TYPE_ELEM); | |
6151d86c PT |
403 | if (eventsTableTypeCE.length != 1) { |
404 | break; | |
405 | } | |
a926c25c | 406 | final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.CLASS_ATTR); |
6151d86c PT |
407 | if ((eventsTableType == null) || (eventsTableType.length() == 0)) { |
408 | break; | |
409 | } | |
410 | final Bundle bundle = Platform.getBundle(ce.getContributor().getName()); | |
411 | final Class<?> c = bundle.loadClass(eventsTableType); | |
412 | final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class }; | |
413 | final Constructor<?> constructor = c.getConstructor(constructorArgs); | |
414 | final Object[] args = new Object[] { parent, cacheSize }; | |
415 | eventsTable = (TmfEventsTable) constructor.newInstance(args); | |
416 | break; | |
417 | } | |
418 | } | |
419 | } catch (final CoreException e) { | |
420 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
421 | } catch (final InvalidRegistryObjectException e) { | |
422 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
423 | } catch (final SecurityException e) { | |
424 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
425 | } catch (final IllegalArgumentException e) { | |
426 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
427 | } catch (final ClassNotFoundException e) { | |
428 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
429 | } catch (final NoSuchMethodException e) { | |
430 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
431 | } catch (final InstantiationException e) { | |
432 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
433 | } catch (final IllegalAccessException e) { | |
434 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
435 | } catch (final InvocationTargetException e) { | |
436 | Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$ | |
437 | } | |
438 | return eventsTable; | |
439 | } | |
440 | ||
441 | @Override | |
442 | public ITmfTrace getTrace() { | |
443 | return fTrace; | |
444 | } | |
445 | ||
446 | @Override | |
447 | public IFile getBookmarksFile() { | |
448 | return fFile; | |
449 | } | |
450 | ||
451 | @Override | |
452 | public void setFocus() { | |
453 | fEventsTable.setFocus(); | |
6151d86c PT |
454 | } |
455 | ||
456 | @Override | |
457 | public Object getAdapter(final Class adapter) { | |
458 | if (IGotoMarker.class.equals(adapter)) { | |
eb271b88 PT |
459 | if (fTrace == null || fEventsTable == null) { |
460 | return this; | |
461 | } | |
6151d86c | 462 | return fEventsTable; |
93bfd50a | 463 | } else if (IPropertySheetPage.class.equals(adapter)) { |
faa38350 | 464 | return new UnsortedPropertySheetPage(); |
6151d86c PT |
465 | } |
466 | return super.getAdapter(adapter); | |
467 | } | |
468 | ||
eb271b88 PT |
469 | /** |
470 | * @since 2.1 | |
471 | */ | |
472 | @Override | |
473 | public void gotoMarker(IMarker marker) { | |
474 | if (fTrace == null || fEventsTable == null) { | |
475 | fPendingGotoMarker = marker; | |
476 | } else { | |
477 | fEventsTable.gotoMarker(marker); | |
478 | } | |
479 | } | |
480 | ||
6151d86c PT |
481 | @Override |
482 | public void resourceChanged(final IResourceChangeEvent event) { | |
483 | for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) { | |
484 | if (delta.getResource().equals(fFile)) { | |
485 | if (delta.getKind() == IResourceDelta.REMOVED) { | |
486 | final IMarker bookmark = delta.getMarker(); | |
487 | Display.getDefault().asyncExec(new Runnable() { | |
488 | @Override | |
489 | public void run() { | |
490 | fEventsTable.removeBookmark(bookmark); | |
491 | } | |
492 | }); | |
493 | } else if (delta.getKind() == IResourceDelta.CHANGED) { | |
494 | Display.getDefault().asyncExec(new Runnable() { | |
495 | @Override | |
496 | public void run() { | |
497 | fEventsTable.getTable().refresh(); | |
498 | } | |
499 | }); | |
500 | } | |
501 | } | |
502 | } | |
503 | } | |
504 | ||
93bfd50a PT |
505 | // ------------------------------------------------------------------------ |
506 | // ISelectionProvider | |
507 | // ------------------------------------------------------------------------ | |
508 | ||
93bfd50a PT |
509 | /** |
510 | * @since 2.0 | |
511 | */ | |
512 | @Override | |
513 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
514 | fSelectionChangedListeners.add(listener); | |
515 | } | |
516 | ||
93bfd50a PT |
517 | /** |
518 | * @since 2.0 | |
519 | */ | |
520 | @Override | |
521 | public ISelection getSelection() { | |
522 | if (fEventsTable == null) { | |
523 | return StructuredSelection.EMPTY; | |
524 | } | |
525 | return fEventsTable.getSelection(); | |
526 | } | |
527 | ||
93bfd50a PT |
528 | /** |
529 | * @since 2.0 | |
530 | */ | |
531 | @Override | |
532 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { | |
533 | fSelectionChangedListeners.remove(listener); | |
534 | } | |
535 | ||
93bfd50a PT |
536 | /** |
537 | * @since 2.0 | |
538 | */ | |
539 | @Override | |
540 | public void setSelection(ISelection selection) { | |
541 | // not implemented | |
542 | } | |
543 | ||
544 | /** | |
545 | * Notifies any selection changed listeners that the viewer's selection has changed. | |
546 | * Only listeners registered at the time this method is called are notified. | |
547 | * | |
548 | * @param event a selection changed event | |
549 | * | |
550 | * @see ISelectionChangedListener#selectionChanged | |
551 | * @since 2.0 | |
552 | */ | |
553 | protected void fireSelectionChanged(final SelectionChangedEvent event) { | |
554 | Object[] listeners = fSelectionChangedListeners.getListeners(); | |
555 | for (int i = 0; i < listeners.length; ++i) { | |
556 | final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; | |
557 | SafeRunnable.run(new SafeRunnable() { | |
558 | @Override | |
559 | public void run() { | |
560 | l.selectionChanged(event); | |
561 | } | |
562 | }); | |
563 | } | |
564 | } | |
565 | ||
566 | // ------------------------------------------------------------------------ | |
567 | // ISelectionChangedListener | |
568 | // ------------------------------------------------------------------------ | |
569 | ||
93bfd50a PT |
570 | /** |
571 | * @since 2.0 | |
572 | */ | |
573 | @Override | |
574 | public void selectionChanged(SelectionChangedEvent event) { | |
575 | fireSelectionChanged(event); | |
576 | } | |
577 | ||
faa38350 PT |
578 | // ------------------------------------------------------------------------ |
579 | // IPartListener | |
580 | // ------------------------------------------------------------------------ | |
581 | ||
faa38350 PT |
582 | /** |
583 | * @since 2.0 | |
584 | */ | |
585 | @Override | |
586 | public void partActivated(IWorkbenchPart part) { | |
587 | if (part == this && fTrace != null) { | |
81fe3479 PT |
588 | if (fTraceSelected) { |
589 | return; | |
590 | } | |
591 | fTraceSelected = true; | |
faa38350 PT |
592 | broadcast(new TmfTraceSelectedSignal(this, fTrace)); |
593 | } | |
594 | } | |
595 | ||
faa38350 PT |
596 | /** |
597 | * @since 2.0 | |
598 | */ | |
599 | @Override | |
600 | public void partBroughtToTop(IWorkbenchPart part) { | |
81fe3479 PT |
601 | if (part == this && fTrace != null) { |
602 | if (fTraceSelected) { | |
603 | return; | |
604 | } | |
605 | fTraceSelected = true; | |
606 | broadcast(new TmfTraceSelectedSignal(this, fTrace)); | |
607 | } | |
faa38350 PT |
608 | } |
609 | ||
faa38350 PT |
610 | /** |
611 | * @since 2.0 | |
612 | */ | |
613 | @Override | |
614 | public void partClosed(IWorkbenchPart part) { | |
615 | } | |
616 | ||
faa38350 PT |
617 | /** |
618 | * @since 2.0 | |
619 | */ | |
620 | @Override | |
621 | public void partDeactivated(IWorkbenchPart part) { | |
622 | } | |
623 | ||
faa38350 PT |
624 | /** |
625 | * @since 2.0 | |
626 | */ | |
627 | @Override | |
628 | public void partOpened(IWorkbenchPart part) { | |
629 | } | |
630 | ||
6151d86c PT |
631 | // ------------------------------------------------------------------------ |
632 | // Global commands | |
633 | // ------------------------------------------------------------------------ | |
634 | ||
635 | /** | |
636 | * Add a bookmark | |
637 | */ | |
638 | public void addBookmark() { | |
639 | fEventsTable.addBookmark(fFile); | |
640 | } | |
641 | ||
642 | ||
643 | // ------------------------------------------------------------------------ | |
644 | // Signal handlers | |
645 | // ------------------------------------------------------------------------ | |
646 | ||
647 | /** | |
faa38350 | 648 | * Handler for the Trace Selected signal |
6151d86c PT |
649 | * |
650 | * @param signal The incoming signal | |
651 | */ | |
652 | @TmfSignalHandler | |
faa38350 | 653 | public void traceSelected(final TmfTraceSelectedSignal signal) { |
81fe3479 PT |
654 | if ((signal.getSource() != this)) { |
655 | if (signal.getTrace().equals(fTrace)) { | |
656 | getSite().getPage().bringToTop(this); | |
657 | } else { | |
658 | fTraceSelected = false; | |
659 | } | |
6151d86c PT |
660 | } |
661 | } | |
662 | ||
663 | /** | |
faa38350 | 664 | * Update the display to use the updated timestamp format |
6151d86c | 665 | * |
faa38350 PT |
666 | * @param signal the incoming signal |
667 | * @since 2.0 | |
6151d86c PT |
668 | */ |
669 | @TmfSignalHandler | |
faa38350 | 670 | public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { |
c1cd9635 MAL |
671 | if (fEventsTable != null) { |
672 | fEventsTable.refresh(); | |
673 | } | |
6151d86c PT |
674 | } |
675 | ||
676 | } |