1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Factored out events table
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.events
;
16 import java
.lang
.reflect
.Constructor
;
17 import java
.lang
.reflect
.InvocationTargetException
;
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
.InvalidRegistryObjectException
;
29 import org
.eclipse
.core
.runtime
.Platform
;
30 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
31 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
32 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
33 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.TmfCommonConstants
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentDisposedSignal
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceType
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
44 import org
.eclipse
.swt
.widgets
.Composite
;
45 import org
.eclipse
.swt
.widgets
.Display
;
46 import org
.eclipse
.ui
.ide
.IGotoMarker
;
47 import org
.osgi
.framework
.Bundle
;
50 * The generic TMF Events View.
54 * <li>Traces larger than available memory
55 * <li>Searching and Filtering
56 * <li>Customized table viewers (per trace type)
59 * TODO: Handle column selection, sort, ... generically (nothing less...)
60 * TODO: Implement hide/display columns
63 * @author Francois Chouinard
64 * @author Patrick Tasse
66 public class TmfEventsView
extends TmfView
implements IResourceChangeListener
{
68 /** Event View's ID */
69 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$
71 private TmfExperiment
<?
> fExperiment
;
72 private TmfEventsTable fEventsTable
;
73 private static final int DEFAULT_CACHE_SIZE
= 100;
74 private String fTitlePrefix
;
75 private Composite fParent
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * Create an events view with a cache size
83 * @param cacheSize not used
85 public TmfEventsView(int cacheSize
) {
86 super("TmfEventsView"); //$NON-NLS-1$
90 * Default constructor, with a default cache size
92 public TmfEventsView() {
93 this(DEFAULT_CACHE_SIZE
);
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 @SuppressWarnings("unchecked")
102 public void createPartControl(Composite parent
) {
105 fTitlePrefix
= getTitle();
107 // If an experiment is already selected, update the table
108 TmfExperiment
<ITmfEvent
> experiment
= (TmfExperiment
<ITmfEvent
>) TmfExperiment
.getCurrentExperiment();
109 if (experiment
!= null) {
110 experimentSelected(new TmfExperimentSelectedSignal
<ITmfEvent
>(this, experiment
));
112 fEventsTable
= createEventsTable(parent
);
117 public void dispose() {
118 if (fEventsTable
!= null) {
119 fEventsTable
.dispose();
125 * Get the events table for an experiment.
126 * If all traces in the experiment are of the same type,
127 * use the extension point specified event table
128 * @param parent the parent Composite
129 * @return an events table of the appropriate type
131 protected TmfEventsTable
createEventsTable(Composite parent
) {
132 if (fExperiment
== null) {
133 return new TmfEventsTable(parent
, DEFAULT_CACHE_SIZE
);
135 int cacheSize
= fExperiment
.getCacheSize();
136 String commonTraceType
= null;
138 for (ITmfTrace
<?
> trace
: fExperiment
.getTraces()) {
139 IResource resource
= trace
.getResource();
140 if (resource
== null) {
141 return new TmfEventsTable(parent
, cacheSize
);
143 String traceType
= resource
.getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
144 if ((commonTraceType
!= null) && !commonTraceType
.equals(traceType
)) {
145 return new TmfEventsTable(parent
, cacheSize
);
147 commonTraceType
= traceType
;
149 if (commonTraceType
== null) {
150 return new TmfEventsTable(parent
, cacheSize
);
152 if (commonTraceType
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
153 return new CustomEventsTable(((CustomTxtTrace
) fExperiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
155 if (commonTraceType
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
156 return new CustomEventsTable(((CustomXmlTrace
) fExperiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
158 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
159 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(commonTraceType
)) {
160 IConfigurationElement
[] eventsTableTypeCE
= ce
.getChildren(TmfTraceType
.EVENTS_TABLE_TYPE_ELEM
);
161 if (eventsTableTypeCE
.length
!= 1) {
164 String eventsTableType
= eventsTableTypeCE
[0].getAttribute(TmfTraceType
.CLASS_ATTR
);
165 if ((eventsTableType
== null) || (eventsTableType
.length() == 0)) {
168 Bundle bundle
= Platform
.getBundle(ce
.getContributor().getName());
169 Class
<?
> c
= bundle
.loadClass(eventsTableType
);
170 Class
<?
>[] constructorArgs
= new Class
[] { Composite
.class, int.class };
171 Constructor
<?
> constructor
= c
.getConstructor(constructorArgs
);
172 Object
[] args
= new Object
[] { parent
, cacheSize
};
173 return (TmfEventsTable
) constructor
.newInstance(args
);
176 } catch (CoreException e
) {
177 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
178 } catch (InvalidRegistryObjectException e
) {
179 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
180 } catch (SecurityException e
) {
181 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
182 } catch (IllegalArgumentException e
) {
183 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
184 } catch (ClassNotFoundException e
) {
185 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
186 } catch (NoSuchMethodException e
) {
187 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
188 } catch (InstantiationException e
) {
189 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
190 } catch (IllegalAccessException e
) {
191 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
192 } catch (InvocationTargetException e
) {
193 Activator
.getDefault().logError("Error creating events table", e
); //$NON-NLS-1$
195 return new TmfEventsTable(parent
, cacheSize
);
199 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
202 public void setFocus() {
203 fEventsTable
.setFocus();
207 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
209 @SuppressWarnings("rawtypes")
211 public Object
getAdapter(Class adapter
) {
212 if (IGotoMarker
.class.equals(adapter
)) {
215 return super.getAdapter(adapter
);
219 * @see java.lang.Object#toString()
222 @SuppressWarnings("nls")
223 public String
toString() {
224 return "[TmfEventsView]";
227 // ------------------------------------------------------------------------
229 // ------------------------------------------------------------------------
232 * Handler for the experiment selected signal.
235 * The incoming signal
237 @SuppressWarnings("unchecked")
239 public void experimentSelected(TmfExperimentSelectedSignal
<ITmfEvent
> signal
) {
240 // Update the trace reference
241 TmfExperiment
<ITmfEvent
> exp
= (TmfExperiment
<ITmfEvent
>) signal
.getExperiment();
242 if (!exp
.equals(fExperiment
)) {
244 setPartName(fTitlePrefix
+ " - " + fExperiment
.getName()); //$NON-NLS-1$
245 if (fEventsTable
!= null) {
246 fEventsTable
.dispose();
248 fEventsTable
= createEventsTable(fParent
);
249 fEventsTable
.setTrace(fExperiment
, false);
250 fEventsTable
.refreshBookmarks(fExperiment
.getBookmarksFile());
251 if (fExperiment
.getBookmarksFile() != null) {
252 ResourcesPlugin
.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent
.POST_CHANGE
);
259 * Handler for the experiment disposed signal.
262 * The incoming signal
264 @SuppressWarnings("unchecked")
266 public void experimentDisposed(TmfExperimentDisposedSignal
<ITmfEvent
> signal
) {
267 // Clear the trace reference
268 TmfExperiment
<ITmfEvent
> experiment
= (TmfExperiment
<ITmfEvent
>) signal
.getExperiment();
269 if (experiment
.equals(fExperiment
)) {
270 fEventsTable
.setTrace(null, false);
272 Activator
.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() {
275 setPartName(fTitlePrefix
);
279 if ((fExperiment
!= null) && (fExperiment
.getBookmarksFile() != null)) {
280 ResourcesPlugin
.getWorkspace().removeResourceChangeListener(this);
287 public void resourceChanged(final IResourceChangeEvent event
) {
288 if ((fExperiment
== null) || (fExperiment
.getBookmarksFile() == null)) {
292 for (final IMarkerDelta delta
: event
.findMarkerDeltas(IMarker
.BOOKMARK
, false)) {
293 if (delta
.getResource().equals(fExperiment
.getBookmarksFile())) {
294 if (delta
.getKind() == IResourceDelta
.REMOVED
) {
295 final IMarker bookmark
= delta
.getMarker();
296 Display
.getDefault().asyncExec(new Runnable() {
299 fEventsTable
.removeBookmark(bookmark
);
302 } else if (delta
.getKind() == IResourceDelta
.CHANGED
) {
303 Display
.getDefault().asyncExec(new Runnable() {
306 fEventsTable
.getTable().refresh();