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
.internal
.tmf
.ui
.TmfUiPlugin
;
25 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomEventsTable
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.experiment
.TmfExperiment
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentDisposedSignal
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceType
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.ui
.ide
.IGotoMarker
;
40 import org
.osgi
.framework
.Bundle
;
43 * <b><u>TmfEventsView</u></b>
46 * TODO: Implement me. Please.
47 * TODO: Handle column selection, sort, ... generically (nothing less...)
48 * TODO: Implement hide/display columns
50 public class TmfEventsView
extends TmfView
{
52 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$
54 private TmfExperiment
<?
> fExperiment
;
55 private TmfEventsTable fEventsTable
;
56 private static final int DEFAULT_CACHE_SIZE
= 100;
57 private String fTitlePrefix
;
58 private Composite fParent
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 public TmfEventsView(int cacheSize
) {
65 super("TmfEventsView"); //$NON-NLS-1$
68 public TmfEventsView() {
69 this(DEFAULT_CACHE_SIZE
);
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 @SuppressWarnings("unchecked")
78 public void createPartControl(Composite parent
) {
81 fTitlePrefix
= getTitle();
83 // If an experiment is already selected, update the table
84 TmfExperiment
<TmfEvent
> experiment
= (TmfExperiment
<TmfEvent
>) TmfExperiment
.getCurrentExperiment();
85 if (experiment
!= null) {
86 experimentSelected(new TmfExperimentSelectedSignal
<TmfEvent
>(this, experiment
));
88 fEventsTable
= createEventsTable(parent
);
93 public void dispose() {
94 if (fEventsTable
!= null) {
95 fEventsTable
.dispose();
101 * Get the events table for an experiment.
102 * If all traces in the experiment are of the same type,
103 * use the extension point specified event table
104 * @param parent the parent Composite
105 * @return an events table of the appropriate type
107 protected TmfEventsTable
createEventsTable(Composite parent
) {
108 if (fExperiment
== null) {
109 return new TmfEventsTable(parent
, DEFAULT_CACHE_SIZE
);
111 int cacheSize
= fExperiment
.getCacheSize();
112 String commonTraceType
= null;
114 for (ITmfTrace
<?
> trace
: fExperiment
.getTraces()) {
115 IResource resource
= trace
.getResource();
116 if (resource
== null) {
117 return new TmfEventsTable(parent
, cacheSize
);
119 String traceType
= resource
.getPersistentProperty(TmfTraceElement
.TRACETYPE
);
120 if (commonTraceType
!= null && !commonTraceType
.equals(traceType
)) {
121 return new TmfEventsTable(parent
, cacheSize
);
123 commonTraceType
= traceType
;
125 if (commonTraceType
== null) {
126 return new TmfEventsTable(parent
, cacheSize
);
128 if (commonTraceType
.startsWith(CustomTxtTrace
.class.getCanonicalName())) {
129 return new CustomEventsTable(((CustomTxtTrace
) fExperiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
131 if (commonTraceType
.startsWith(CustomXmlTrace
.class.getCanonicalName())) {
132 return new CustomEventsTable(((CustomXmlTrace
) fExperiment
.getTraces()[0]).getDefinition(), parent
, cacheSize
);
134 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
135 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(commonTraceType
)) {
136 IConfigurationElement
[] eventsTableTypeCE
= ce
.getChildren(TmfTraceType
.EVENTS_TABLE_TYPE_ELEM
);
137 if (eventsTableTypeCE
.length
!= 1) {
140 String eventsTableType
= eventsTableTypeCE
[0].getAttribute(TmfTraceType
.CLASS_ATTR
);
141 if (eventsTableType
== null || eventsTableType
.length() == 0) {
144 Bundle bundle
= Platform
.getBundle(ce
.getContributor().getName());
145 Class
<?
> c
= bundle
.loadClass(eventsTableType
);
146 Class
<?
>[] constructorArgs
= new Class
[] { Composite
.class, int.class };
147 Constructor
<?
> constructor
= c
.getConstructor(constructorArgs
);
148 Object
[] args
= new Object
[] { parent
, cacheSize
};
149 return (TmfEventsTable
) constructor
.newInstance(args
);
152 } catch (CoreException e
) {
154 } catch (InvalidRegistryObjectException e
) {
156 } catch (SecurityException e
) {
158 } catch (IllegalArgumentException e
) {
160 } catch (ClassNotFoundException e
) {
162 } catch (NoSuchMethodException e
) {
164 } catch (InstantiationException e
) {
166 } catch (IllegalAccessException e
) {
168 } catch (InvocationTargetException e
) {
171 return new TmfEventsTable(parent
, cacheSize
);
175 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
178 public void setFocus() {
179 fEventsTable
.setFocus();
183 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
185 @SuppressWarnings("rawtypes")
187 public Object
getAdapter(Class adapter
) {
188 if (IGotoMarker
.class.equals(adapter
)) {
191 return super.getAdapter(adapter
);
195 * @see java.lang.Object#toString()
198 @SuppressWarnings("nls")
199 public String
toString() {
200 return "[TmfEventsView]";
203 // ------------------------------------------------------------------------
205 // ------------------------------------------------------------------------
207 @SuppressWarnings("unchecked")
209 public void experimentSelected(TmfExperimentSelectedSignal
<TmfEvent
> signal
) {
210 // Update the trace reference
211 TmfExperiment
<TmfEvent
> exp
= (TmfExperiment
<TmfEvent
>) signal
.getExperiment();
212 if (!exp
.equals(fExperiment
)) {
214 setPartName(fTitlePrefix
+ " - " + fExperiment
.getName()); //$NON-NLS-1$
215 if (fEventsTable
!= null) {
216 fEventsTable
.dispose();
218 fEventsTable
= createEventsTable(fParent
);
219 fEventsTable
.setTrace(fExperiment
, false);
220 fEventsTable
.refreshBookmarks(fExperiment
.getBookmarksFile());
225 @SuppressWarnings("unchecked")
227 public void experimentDisposed(TmfExperimentDisposedSignal
<TmfEvent
> signal
) {
228 // Clear the trace reference
229 TmfExperiment
<TmfEvent
> experiment
= (TmfExperiment
<TmfEvent
>) signal
.getExperiment();
230 if (experiment
.equals(fExperiment
)) {
231 fEventsTable
.setTrace(null, false);
233 TmfUiPlugin
.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() {
236 setPartName(fTitlePrefix
);