Updated fix for bug 371528: Updates for bookmarks, editor for experiments, accelerato...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / events / TmfEventsView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 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 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Factored out events table
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.views.events;
15
16 import java.lang.reflect.Constructor;
17 import java.lang.reflect.InvocationTargetException;
18
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;
42
43 /**
44 * <b><u>TmfEventsView</u></b>
45 * <p>
46 *
47 * TODO: Implement me. Please.
48 * TODO: Handle column selection, sort, ... generically (nothing less...)
49 * TODO: Implement hide/display columns
50 */
51 public class TmfEventsView extends TmfView {
52
53 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$
54
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;
60
61 // ------------------------------------------------------------------------
62 // Constructor
63 // ------------------------------------------------------------------------
64
65 public TmfEventsView(int cacheSize) {
66 super("TmfEventsView"); //$NON-NLS-1$
67 }
68
69 public TmfEventsView() {
70 this(DEFAULT_CACHE_SIZE);
71 }
72
73 // ------------------------------------------------------------------------
74 // ViewPart
75 // ------------------------------------------------------------------------
76
77 @Override
78 @SuppressWarnings("unchecked")
79 public void createPartControl(Composite parent) {
80 fParent = parent;
81
82 fTitlePrefix = getTitle();
83
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));
88 } else {
89 fEventsTable = createEventsTable(parent);
90 }
91 }
92
93 @Override
94 public void dispose() {
95 if (fEventsTable != null) {
96 fEventsTable.dispose();
97 }
98 super.dispose();
99 }
100
101 /**
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
107 */
108 protected TmfEventsTable createEventsTable(Composite parent) {
109 if (fExperiment == null) {
110 return new TmfEventsTable(parent, DEFAULT_CACHE_SIZE);
111 }
112 int cacheSize = fExperiment.getCacheSize();
113 String commonTraceType = null;
114 try {
115 for (ITmfTrace<?> trace : fExperiment.getTraces()) {
116 IResource resource = null;
117 if (trace instanceof TmfTrace) {
118 resource = ((TmfTrace<?>) trace).getResource();
119 }
120 if (resource == null) {
121 return new TmfEventsTable(parent, cacheSize);
122 }
123 String traceType = resource.getPersistentProperty(TmfTraceElement.TRACETYPE);
124 if (commonTraceType != null && !commonTraceType.equals(traceType)) {
125 return new TmfEventsTable(parent, cacheSize);
126 }
127 commonTraceType = traceType;
128 }
129 if (commonTraceType == null) {
130 return new TmfEventsTable(parent, cacheSize);
131 }
132 if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {
133 return new CustomEventsTable(((CustomTxtTrace) fExperiment.getTraces()[0]).getDefinition(), parent, cacheSize);
134 }
135 if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {
136 return new CustomEventsTable(((CustomXmlTrace) fExperiment.getTraces()[0]).getDefinition(), parent, cacheSize);
137 }
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) {
142 break;
143 }
144 String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);
145 if (eventsTableType == null || eventsTableType.length() == 0) {
146 break;
147 }
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);
154 }
155 }
156 } catch (CoreException e) {
157 e.printStackTrace();
158 } catch (InvalidRegistryObjectException e) {
159 e.printStackTrace();
160 } catch (SecurityException e) {
161 e.printStackTrace();
162 } catch (IllegalArgumentException e) {
163 e.printStackTrace();
164 } catch (ClassNotFoundException e) {
165 e.printStackTrace();
166 } catch (NoSuchMethodException e) {
167 e.printStackTrace();
168 } catch (InstantiationException e) {
169 e.printStackTrace();
170 } catch (IllegalAccessException e) {
171 e.printStackTrace();
172 } catch (InvocationTargetException e) {
173 e.printStackTrace();
174 }
175 return new TmfEventsTable(parent, cacheSize);
176 }
177
178 /* (non-Javadoc)
179 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
180 */
181 @Override
182 public void setFocus() {
183 fEventsTable.setFocus();
184 }
185
186 /* (non-Javadoc)
187 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
188 */
189 @SuppressWarnings("rawtypes")
190 @Override
191 public Object getAdapter(Class adapter) {
192 if (IGotoMarker.class.equals(adapter)) {
193 return fEventsTable;
194 }
195 return super.getAdapter(adapter);
196 }
197
198 /* (non-Javadoc)
199 * @see java.lang.Object#toString()
200 */
201 @Override
202 @SuppressWarnings("nls")
203 public String toString() {
204 return "[TmfEventsView]";
205 }
206
207 // ------------------------------------------------------------------------
208 // Signal handlers
209 // ------------------------------------------------------------------------
210
211 @SuppressWarnings("unchecked")
212 @TmfSignalHandler
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)) {
217 fExperiment = exp;
218 setPartName(fTitlePrefix + " - " + fExperiment.getName()); //$NON-NLS-1$
219 if (fEventsTable != null) {
220 fEventsTable.dispose();
221 }
222 fEventsTable = createEventsTable(fParent);
223 fEventsTable.setTrace(fExperiment, false);
224 fEventsTable.refreshBookmarks(fExperiment.getResource());
225 fParent.layout();
226 }
227 }
228
229 @SuppressWarnings("unchecked")
230 @TmfSignalHandler
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);
236
237 TmfUiPlugin.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() {
238 @Override
239 public void run() {
240 setPartName(fTitlePrefix);
241 }
242 });
243 }
244 }
245
246 }
This page took 0.035302 seconds and 5 git commands to generate.