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