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
.IResource
;
20 import org
.eclipse
.core
.runtime
.CoreException
;
21 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
22 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
23 import org
.eclipse
.core
.runtime
.Platform
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.experiment
.TmfExperiment
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentDisposedSignal
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfTraceType
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
39 import org
.eclipse
.swt
.widgets
.Composite
;
40 import org
.eclipse
.ui
.ide
.IGotoMarker
;
41 import org
.osgi
.framework
.Bundle
;
44 * <b><u>TmfEventsView</u></b>
47 * TODO: Implement me. Please.
48 * TODO: Handle column selection, sort, ... generically (nothing less...)
49 * TODO: Implement hide/display columns
51 public class TmfEventsView
extends TmfView
{
53 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$
55 private TmfExperiment
<?
> fExperiment
;
56 private TmfEventsTable fEventsTable
;
57 private static final int DEFAULT_CACHE_SIZE
= 100;
58 private String fTitlePrefix
;
59 private Composite fParent
;
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 public TmfEventsView(int cacheSize
) {
66 super("TmfEventsView"); //$NON-NLS-1$
69 public TmfEventsView() {
70 this(DEFAULT_CACHE_SIZE
);
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 @SuppressWarnings("unchecked")
79 public void createPartControl(Composite parent
) {
82 fTitlePrefix
= getTitle();
84 // If an experiment is already selected, update the table
85 TmfExperiment
<TmfEvent
> experiment
= (TmfExperiment
<TmfEvent
>) TmfExperiment
.getCurrentExperiment();
86 if (experiment
!= null) {
87 experimentSelected(new TmfExperimentSelectedSignal
<TmfEvent
>(this, experiment
));
89 fEventsTable
= createEventsTable(parent
);
94 public void dispose() {
95 if (fEventsTable
!= null) {
96 fEventsTable
.dispose();
102 * Get the events table for an experiment.
103 * If all traces in the experiment are of the same type,
104 * use the extension point specified event table
105 * @param parent the parent Composite
106 * @return an events table of the appropriate type
108 protected TmfEventsTable
createEventsTable(Composite parent
) {
109 if (fExperiment
== null) {
110 return new TmfEventsTable(parent
, DEFAULT_CACHE_SIZE
);
112 int cacheSize
= fExperiment
.getCacheSize();
113 String commonTraceType
= null;
115 for (ITmfTrace
<?
> trace
: fExperiment
.getTraces()) {
116 IResource resource
= null;
117 if (trace
instanceof TmfTrace
) {
118 resource
= ((TmfTrace
<?
>) trace
).getResource();
120 if (resource
== null) {
121 return new TmfEventsTable(parent
, cacheSize
);
123 String traceType
= resource
.getPersistentProperty(TmfTraceElement
.TRACETYPE
);
124 if (commonTraceType
!= null && !commonTraceType
.equals(traceType
)) {
125 return new TmfEventsTable(parent
, cacheSize
);
127 commonTraceType
= traceType
;
129 if (commonTraceType
== null) {
130 return new TmfEventsTable(parent
, cacheSize
);
132 if (commonTraceType
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
133 return new CustomEventsTable(((CustomTxtTrace
) fExperiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
135 if (commonTraceType
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
136 return new CustomEventsTable(((CustomXmlTrace
) fExperiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
138 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
139 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(commonTraceType
)) {
140 IConfigurationElement
[] eventsTableTypeCE
= ce
.getChildren(TmfTraceType
.EVENTS_TABLE_TYPE_ELEM
);
141 if (eventsTableTypeCE
.length
!= 1) {
144 String eventsTableType
= eventsTableTypeCE
[0].getAttribute(TmfTraceType
.CLASS_ATTR
);
145 if (eventsTableType
== null || eventsTableType
.length() == 0) {
148 Bundle bundle
= Platform
.getBundle(ce
.getContributor().getName());
149 Class
<?
> c
= bundle
.loadClass(eventsTableType
);
150 Class
<?
>[] constructorArgs
= new Class
[] { Composite
.class, int.class };
151 Constructor
<?
> constructor
= c
.getConstructor(constructorArgs
);
152 Object
[] args
= new Object
[] { parent
, cacheSize
};
153 return (TmfEventsTable
) constructor
.newInstance(args
);
156 } catch (CoreException e
) {
158 } catch (InvalidRegistryObjectException e
) {
160 } catch (SecurityException e
) {
162 } catch (IllegalArgumentException e
) {
164 } catch (ClassNotFoundException e
) {
166 } catch (NoSuchMethodException e
) {
168 } catch (InstantiationException e
) {
170 } catch (IllegalAccessException e
) {
172 } catch (InvocationTargetException e
) {
175 return new TmfEventsTable(parent
, cacheSize
);
179 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
182 public void setFocus() {
183 fEventsTable
.setFocus();
187 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
189 @SuppressWarnings("rawtypes")
191 public Object
getAdapter(Class adapter
) {
192 if (IGotoMarker
.class.equals(adapter
)) {
195 return super.getAdapter(adapter
);
199 * @see java.lang.Object#toString()
202 @SuppressWarnings("nls")
203 public String
toString() {
204 return "[TmfEventsView]";
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
211 @SuppressWarnings("unchecked")
213 public void experimentSelected(TmfExperimentSelectedSignal
<TmfEvent
> signal
) {
214 // Update the trace reference
215 TmfExperiment
<TmfEvent
> exp
= (TmfExperiment
<TmfEvent
>) signal
.getExperiment();
216 if (!exp
.equals(fExperiment
)) {
218 setPartName(fTitlePrefix
+ " - " + fExperiment
.getName()); //$NON-NLS-1$
219 if (fEventsTable
!= null) {
220 fEventsTable
.dispose();
222 fEventsTable
= createEventsTable(fParent
);
223 fEventsTable
.setTrace(fExperiment
, false);
224 fEventsTable
.refreshBookmarks(fExperiment
.getResource());
229 @SuppressWarnings("unchecked")
231 public void experimentDisposed(TmfExperimentDisposedSignal
<TmfEvent
> signal
) {
232 // Clear the trace reference
233 TmfExperiment
<TmfEvent
> experiment
= (TmfExperiment
<TmfEvent
>) signal
.getExperiment();
234 if (experiment
.equals(fExperiment
)) {
235 fEventsTable
.setTrace(null, false);
237 TmfUiPlugin
.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() {
240 setPartName(fTitlePrefix
);