Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 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; | |
17 | import java.util.List; | |
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; | |
28 | import org.eclipse.core.runtime.IConfigurationElement; | |
29 | import org.eclipse.core.runtime.IProgressMonitor; | |
30 | import org.eclipse.core.runtime.InvalidRegistryObjectException; | |
93bfd50a | 31 | import org.eclipse.core.runtime.ListenerList; |
6151d86c | 32 | import org.eclipse.core.runtime.Platform; |
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; | |
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; | |
6151d86c PT |
46 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
47 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
faa38350 PT |
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; | |
6151d86c | 51 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; |
d7ee91bb | 52 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
6151d86c PT |
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; | |
6151d86c PT |
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; | |
faa38350 | 70 | import org.eclipse.ui.IPartListener; |
6151d86c PT |
71 | import org.eclipse.ui.IPropertyListener; |
72 | import org.eclipse.ui.IReusableEditor; | |
faa38350 | 73 | import org.eclipse.ui.IWorkbenchPart; |
6151d86c PT |
74 | import org.eclipse.ui.PartInitException; |
75 | import org.eclipse.ui.ide.IGotoMarker; | |
76 | import org.eclipse.ui.part.FileEditorInput; | |
93bfd50a | 77 | import org.eclipse.ui.views.properties.IPropertySheetPage; |
6151d86c PT |
78 | import org.osgi.framework.Bundle; |
79 | ||
80 | /** | |
81 | * Editor for TMF events | |
82 | * | |
83 | * @version 1.0 | |
84 | * @author Patrick Tasse | |
faa38350 | 85 | * @since 2.0 |
6151d86c | 86 | */ |
faa38350 | 87 | public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener, ISelectionProvider, ISelectionChangedListener, IPartListener { |
6151d86c PT |
88 | |
89 | /** ID for this class */ | |
90 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$ | |
91 | ||
92 | private TmfEventsTable fEventsTable; | |
93 | private IFile fFile; | |
94 | private ITmfTrace fTrace; | |
95 | private Composite fParent; | |
93bfd50a | 96 | private ListenerList fSelectionChangedListeners = new ListenerList(); |
81fe3479 | 97 | private boolean fTraceSelected; |
6151d86c PT |
98 | |
99 | @Override | |
100 | public void doSave(final IProgressMonitor monitor) { | |
101 | } | |
102 | ||
103 | @Override | |
104 | public void doSaveAs() { | |
105 | } | |
106 | ||
6151d86c PT |
107 | @Override |
108 | public void init(final IEditorSite site, IEditorInput input) throws PartInitException { | |
faa38350 | 109 | IFileEditorInput fileEditorInput; |
6151d86c PT |
110 | if (input instanceof TmfEditorInput) { |
111 | fFile = ((TmfEditorInput) input).getFile(); | |
112 | fTrace = ((TmfEditorInput) input).getTrace(); | |
faa38350 PT |
113 | /* change the input to a FileEditorInput to allow open handlers to find this editor */ |
114 | fileEditorInput = new FileEditorInput(fFile); | |
6151d86c | 115 | } else if (input instanceof IFileEditorInput) { |
faa38350 PT |
116 | fileEditorInput = (IFileEditorInput) input; |
117 | fFile = fileEditorInput.getFile(); | |
118 | if (fFile == null) { | |
119 | throw new PartInitException("Invalid IFileEditorInput: " + fileEditorInput); //$NON-NLS-1$ | |
6151d86c PT |
120 | } |
121 | try { | |
122 | final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE); | |
123 | if (traceTypeId == null) { | |
124 | throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); | |
125 | } | |
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); | |
133 | } | |
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++) { | |
a939ff99 | 144 | final TmfTraceElement traceElement = traceEntries.get(i).getElementUnderTraceFolder(); |
6151d86c PT |
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++) { | |
149 | traces[j].dispose(); | |
150 | } | |
151 | throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType); | |
152 | } | |
153 | try { | |
154 | trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); | |
155 | } catch (final TmfTraceException e) { | |
9c8e0546 | 156 | throw new PartInitException(Messages.OpenTraceHandler_InitError, e); |
6151d86c PT |
157 | } |
158 | cacheSize = Math.min(cacheSize, trace.getCacheSize()); | |
159 | traces[i] = trace; | |
160 | } | |
99504bb8 | 161 | final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource()); |
6151d86c PT |
162 | experiment.setBookmarksFile(fFile); |
163 | fTrace = experiment; | |
6151d86c PT |
164 | break; |
165 | } | |
166 | } | |
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); | |
181 | } | |
182 | try { | |
183 | trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); | |
184 | } catch (final TmfTraceException e) { | |
9c8e0546 | 185 | throw new PartInitException(Messages.OpenTraceHandler_InitError, e); |
6151d86c PT |
186 | } |
187 | fTrace = trace; | |
188 | break; | |
189 | } | |
190 | } | |
191 | } else { | |
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); | |
203 | } | |
204 | try { | |
205 | trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); | |
206 | } catch (final TmfTraceException e) { | |
9c8e0546 | 207 | throw new PartInitException(Messages.OpenTraceHandler_InitError, e); |
6151d86c PT |
208 | } |
209 | fTrace = trace; | |
210 | break; | |
211 | } | |
212 | } | |
213 | } | |
faa38350 PT |
214 | } catch (final PartInitException e) { |
215 | throw e; | |
6151d86c PT |
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$ | |
220 | } | |
faa38350 | 221 | } else { |
6151d86c PT |
222 | throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$ |
223 | } | |
faa38350 | 224 | if (fTrace == null) { |
6151d86c PT |
225 | throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$ |
226 | } | |
227 | super.setSite(site); | |
faa38350 | 228 | super.setInput(fileEditorInput); |
6151d86c PT |
229 | } |
230 | ||
231 | @Override | |
232 | public boolean isDirty() { | |
233 | return false; | |
234 | } | |
235 | ||
236 | @Override | |
237 | public boolean isSaveAsAllowed() { | |
238 | return false; | |
239 | } | |
240 | ||
241 | @Override | |
242 | public void setInput(final IEditorInput input) { | |
243 | super.setInput(input); | |
244 | firePropertyChange(IEditorPart.PROP_INPUT); | |
245 | } | |
246 | ||
247 | @Override | |
248 | public void propertyChanged(final Object source, final int propId) { | |
faa38350 | 249 | if (propId == IEditorPart.PROP_INPUT && getEditorInput() instanceof TmfEditorInput) { |
6151d86c PT |
250 | broadcast(new TmfTraceClosedSignal(this, fTrace)); |
251 | fFile = ((TmfEditorInput) getEditorInput()).getFile(); | |
252 | fTrace = ((TmfEditorInput) getEditorInput()).getTrace(); | |
faa38350 | 253 | /* change the input to a FileEditorInput to allow open handlers to find this editor */ |
6151d86c PT |
254 | super.setInput(new FileEditorInput(fFile)); |
255 | fEventsTable.dispose(); | |
256 | if (fTrace != null) { | |
257 | fEventsTable = createEventsTable(fParent, fTrace.getCacheSize()); | |
93bfd50a | 258 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
259 | fEventsTable.setTrace(fTrace, true); |
260 | fEventsTable.refreshBookmarks(fFile); | |
c4352ddc PT |
261 | |
262 | /* ensure start time is set */ | |
263 | final ITmfContext context = fTrace.seekEvent(0); | |
264 | fTrace.getNext(context); | |
265 | context.dispose(); | |
266 | ||
faa38350 | 267 | broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile)); |
6151d86c PT |
268 | } else { |
269 | fEventsTable = new TmfEventsTable(fParent, 0); | |
93bfd50a | 270 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
271 | } |
272 | fParent.layout(); | |
273 | } | |
274 | } | |
275 | ||
276 | @Override | |
277 | public void createPartControl(final Composite parent) { | |
278 | fParent = parent; | |
279 | if (fTrace != null) { | |
280 | setPartName(fTrace.getName()); | |
281 | fEventsTable = createEventsTable(parent, fTrace.getCacheSize()); | |
93bfd50a | 282 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
283 | fEventsTable.setTrace(fTrace, true); |
284 | fEventsTable.refreshBookmarks(fFile); | |
d7ee91bb PT |
285 | |
286 | /* ensure start time is set */ | |
287 | final ITmfContext context = fTrace.seekEvent(0); | |
288 | fTrace.getNext(context); | |
289 | context.dispose(); | |
290 | ||
faa38350 | 291 | broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile)); |
6151d86c PT |
292 | } else { |
293 | setPartName(getEditorInput().getName()); | |
294 | fEventsTable = new TmfEventsTable(parent, 0); | |
93bfd50a | 295 | fEventsTable.addSelectionChangedListener(this); |
6151d86c PT |
296 | } |
297 | addPropertyListener(this); | |
298 | ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); | |
93bfd50a PT |
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); | |
faa38350 | 303 | getSite().getPage().addPartListener(this); |
6151d86c PT |
304 | } |
305 | ||
306 | @Override | |
307 | public void dispose() { | |
faa38350 PT |
308 | if (getSite() != null) { |
309 | getSite().getPage().removePartListener(this); | |
310 | } | |
6151d86c PT |
311 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
312 | removePropertyListener(this); | |
313 | if (fTrace != null) { | |
314 | broadcast(new TmfTraceClosedSignal(this, fTrace)); | |
315 | } | |
316 | if (fEventsTable != null) { | |
317 | fEventsTable.dispose(); | |
318 | } | |
319 | super.dispose(); | |
320 | } | |
321 | ||
faa38350 PT |
322 | /** |
323 | * Create the events table | |
324 | * | |
325 | * @param parent the parent composite | |
326 | * @param cacheSize the cache size | |
327 | * @return an events table instance | |
328 | */ | |
6151d86c PT |
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); | |
333 | } | |
334 | return eventsTable; | |
335 | } | |
336 | ||
337 | private TmfEventsTable getEventsTable(final Composite parent, final int cacheSize) { | |
338 | if (fTrace instanceof TmfExperiment) { | |
339 | return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize); | |
340 | } | |
341 | TmfEventsTable eventsTable = null; | |
342 | try { | |
343 | if (fTrace.getResource() == null) { | |
344 | return null; | |
345 | } | |
346 | final String traceType = fTrace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); | |
347 | if (traceType == null) { | |
348 | return null; | |
349 | } | |
350 | if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
351 | return new CustomEventsTable(((CustomTxtTrace) fTrace).getDefinition(), parent, cacheSize); | |
352 | } | |
353 | if (traceType.startsWith(CustomXmlTrace.class.getCanonicalName())) { | |
354 | return new CustomEventsTable(((CustomXmlTrace) fTrace).getDefinition(), parent, cacheSize); | |
355 | } | |
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) { | |
360 | break; | |
361 | } | |
362 | final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR); | |
363 | if ((eventsTableType == null) || (eventsTableType.length() == 0)) { | |
364 | break; | |
365 | } | |
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); | |
372 | break; | |
373 | } | |
374 | } | |
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$ | |
393 | } | |
394 | return eventsTable; | |
395 | } | |
396 | ||
397 | /** | |
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 | |
400 | * | |
401 | * @param experiment | |
402 | * the experiment | |
403 | * @param parent | |
404 | * the parent Composite | |
405 | * @param cacheSize | |
406 | * the event table cache size | |
407 | * @return an events table of the appropriate type | |
408 | */ | |
409 | private static TmfEventsTable getExperimentEventsTable( | |
410 | final TmfExperiment experiment, final Composite parent, | |
411 | final int cacheSize) { | |
412 | TmfEventsTable eventsTable = null; | |
413 | String commonTraceType = null; | |
414 | try { | |
415 | for (final ITmfTrace trace : experiment.getTraces()) { | |
416 | final IResource resource = trace.getResource(); | |
417 | if (resource == null) { | |
418 | return null; | |
419 | } | |
420 | final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); | |
421 | if ((commonTraceType != null) && !commonTraceType.equals(traceType)) { | |
422 | return null; | |
423 | } | |
424 | commonTraceType = traceType; | |
425 | } | |
426 | if (commonTraceType == null) { | |
427 | return null; | |
428 | } | |
429 | if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
430 | return new CustomEventsTable(((CustomTxtTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize); | |
431 | } | |
432 | if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) { | |
433 | return new CustomEventsTable(((CustomXmlTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize); | |
434 | } | |
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) { | |
439 | break; | |
440 | } | |
441 | final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR); | |
442 | if ((eventsTableType == null) || (eventsTableType.length() == 0)) { | |
443 | break; | |
444 | } | |
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); | |
451 | break; | |
452 | } | |
453 | } | |
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$ | |
472 | } | |
473 | return eventsTable; | |
474 | } | |
475 | ||
476 | @Override | |
477 | public ITmfTrace getTrace() { | |
478 | return fTrace; | |
479 | } | |
480 | ||
481 | @Override | |
482 | public IFile getBookmarksFile() { | |
483 | return fFile; | |
484 | } | |
485 | ||
486 | @Override | |
487 | public void setFocus() { | |
488 | fEventsTable.setFocus(); | |
6151d86c PT |
489 | } |
490 | ||
491 | @Override | |
492 | public Object getAdapter(final Class adapter) { | |
493 | if (IGotoMarker.class.equals(adapter)) { | |
494 | return fEventsTable; | |
93bfd50a | 495 | } else if (IPropertySheetPage.class.equals(adapter)) { |
faa38350 | 496 | return new UnsortedPropertySheetPage(); |
6151d86c PT |
497 | } |
498 | return super.getAdapter(adapter); | |
499 | } | |
500 | ||
501 | @Override | |
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() { | |
508 | @Override | |
509 | public void run() { | |
510 | fEventsTable.removeBookmark(bookmark); | |
511 | } | |
512 | }); | |
513 | } else if (delta.getKind() == IResourceDelta.CHANGED) { | |
514 | Display.getDefault().asyncExec(new Runnable() { | |
515 | @Override | |
516 | public void run() { | |
517 | fEventsTable.getTable().refresh(); | |
518 | } | |
519 | }); | |
520 | } | |
521 | } | |
522 | } | |
523 | } | |
524 | ||
93bfd50a PT |
525 | // ------------------------------------------------------------------------ |
526 | // ISelectionProvider | |
527 | // ------------------------------------------------------------------------ | |
528 | ||
529 | /* (non-Javadoc) | |
530 | * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) | |
531 | */ | |
532 | /** | |
533 | * @since 2.0 | |
534 | */ | |
535 | @Override | |
536 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
537 | fSelectionChangedListeners.add(listener); | |
538 | } | |
539 | ||
540 | /* (non-Javadoc) | |
541 | * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() | |
542 | */ | |
543 | /** | |
544 | * @since 2.0 | |
545 | */ | |
546 | @Override | |
547 | public ISelection getSelection() { | |
548 | if (fEventsTable == null) { | |
549 | return StructuredSelection.EMPTY; | |
550 | } | |
551 | return fEventsTable.getSelection(); | |
552 | } | |
553 | ||
554 | /* (non-Javadoc) | |
555 | * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) | |
556 | */ | |
557 | /** | |
558 | * @since 2.0 | |
559 | */ | |
560 | @Override | |
561 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { | |
562 | fSelectionChangedListeners.remove(listener); | |
563 | } | |
564 | ||
565 | /* (non-Javadoc) | |
566 | * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection) | |
567 | */ | |
568 | /** | |
569 | * @since 2.0 | |
570 | */ | |
571 | @Override | |
572 | public void setSelection(ISelection selection) { | |
573 | // not implemented | |
574 | } | |
575 | ||
576 | /** | |
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. | |
579 | * | |
580 | * @param event a selection changed event | |
581 | * | |
582 | * @see ISelectionChangedListener#selectionChanged | |
583 | * @since 2.0 | |
584 | */ | |
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() { | |
590 | @Override | |
591 | public void run() { | |
592 | l.selectionChanged(event); | |
593 | } | |
594 | }); | |
595 | } | |
596 | } | |
597 | ||
598 | // ------------------------------------------------------------------------ | |
599 | // ISelectionChangedListener | |
600 | // ------------------------------------------------------------------------ | |
601 | ||
602 | /* | |
603 | * (non-Javadoc) | |
604 | * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) | |
605 | */ | |
606 | /** | |
607 | * @since 2.0 | |
608 | */ | |
609 | @Override | |
610 | public void selectionChanged(SelectionChangedEvent event) { | |
611 | fireSelectionChanged(event); | |
612 | } | |
613 | ||
faa38350 PT |
614 | // ------------------------------------------------------------------------ |
615 | // IPartListener | |
616 | // ------------------------------------------------------------------------ | |
617 | ||
618 | /* | |
619 | * (non-Javadoc) | |
620 | * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart) | |
621 | */ | |
622 | /** | |
623 | * @since 2.0 | |
624 | */ | |
625 | @Override | |
626 | public void partActivated(IWorkbenchPart part) { | |
627 | if (part == this && fTrace != null) { | |
81fe3479 PT |
628 | if (fTraceSelected) { |
629 | return; | |
630 | } | |
631 | fTraceSelected = true; | |
faa38350 PT |
632 | broadcast(new TmfTraceSelectedSignal(this, fTrace)); |
633 | } | |
634 | } | |
635 | ||
636 | /* | |
637 | * (non-Javadoc) | |
638 | * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart) | |
639 | */ | |
640 | /** | |
641 | * @since 2.0 | |
642 | */ | |
643 | @Override | |
644 | public void partBroughtToTop(IWorkbenchPart part) { | |
81fe3479 PT |
645 | if (part == this && fTrace != null) { |
646 | if (fTraceSelected) { | |
647 | return; | |
648 | } | |
649 | fTraceSelected = true; | |
650 | broadcast(new TmfTraceSelectedSignal(this, fTrace)); | |
651 | } | |
faa38350 PT |
652 | } |
653 | ||
654 | /* | |
655 | * (non-Javadoc) | |
656 | * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) | |
657 | */ | |
658 | /** | |
659 | * @since 2.0 | |
660 | */ | |
661 | @Override | |
662 | public void partClosed(IWorkbenchPart part) { | |
663 | } | |
664 | ||
665 | /* | |
666 | * (non-Javadoc) | |
667 | * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart) | |
668 | */ | |
669 | /** | |
670 | * @since 2.0 | |
671 | */ | |
672 | @Override | |
673 | public void partDeactivated(IWorkbenchPart part) { | |
674 | } | |
675 | ||
676 | /* | |
677 | * (non-Javadoc) | |
678 | * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart) | |
679 | */ | |
680 | /** | |
681 | * @since 2.0 | |
682 | */ | |
683 | @Override | |
684 | public void partOpened(IWorkbenchPart part) { | |
685 | } | |
686 | ||
6151d86c PT |
687 | // ------------------------------------------------------------------------ |
688 | // Global commands | |
689 | // ------------------------------------------------------------------------ | |
690 | ||
691 | /** | |
692 | * Add a bookmark | |
693 | */ | |
694 | public void addBookmark() { | |
695 | fEventsTable.addBookmark(fFile); | |
696 | } | |
697 | ||
698 | ||
699 | // ------------------------------------------------------------------------ | |
700 | // Signal handlers | |
701 | // ------------------------------------------------------------------------ | |
702 | ||
703 | /** | |
faa38350 | 704 | * Handler for the Trace Selected signal |
6151d86c PT |
705 | * |
706 | * @param signal The incoming signal | |
707 | */ | |
708 | @TmfSignalHandler | |
faa38350 | 709 | public void traceSelected(final TmfTraceSelectedSignal signal) { |
81fe3479 PT |
710 | if ((signal.getSource() != this)) { |
711 | if (signal.getTrace().equals(fTrace)) { | |
712 | getSite().getPage().bringToTop(this); | |
713 | } else { | |
714 | fTraceSelected = false; | |
715 | } | |
6151d86c PT |
716 | } |
717 | } | |
718 | ||
719 | /** | |
faa38350 | 720 | * Update the display to use the updated timestamp format |
6151d86c | 721 | * |
faa38350 PT |
722 | * @param signal the incoming signal |
723 | * @since 2.0 | |
6151d86c PT |
724 | */ |
725 | @TmfSignalHandler | |
faa38350 PT |
726 | public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) { |
727 | fEventsTable.refresh(); | |
6151d86c PT |
728 | } |
729 | ||
730 | } |