Fix searching and filtering in TMF events table (bug 377558)
[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.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.ITmfEvent;
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;
41
42 /**
43 * <b><u>TmfEventsView</u></b>
44 * <p>
45 *
46 * TODO: Implement me. Please.
47 * TODO: Handle column selection, sort, ... generically (nothing less...)
48 * TODO: Implement hide/display columns
49 */
50 public class TmfEventsView extends TmfView {
51
52 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$
53
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;
59
60 // ------------------------------------------------------------------------
61 // Constructor
62 // ------------------------------------------------------------------------
63
64 public TmfEventsView(int cacheSize) {
65 super("TmfEventsView"); //$NON-NLS-1$
66 }
67
68 public TmfEventsView() {
69 this(DEFAULT_CACHE_SIZE);
70 }
71
72 // ------------------------------------------------------------------------
73 // ViewPart
74 // ------------------------------------------------------------------------
75
76 @Override
77 @SuppressWarnings("unchecked")
78 public void createPartControl(Composite parent) {
79 fParent = parent;
80
81 fTitlePrefix = getTitle();
82
83 // If an experiment is already selected, update the table
84 TmfExperiment<ITmfEvent> experiment = (TmfExperiment<ITmfEvent>) TmfExperiment.getCurrentExperiment();
85 if (experiment != null) {
86 experimentSelected(new TmfExperimentSelectedSignal<ITmfEvent>(this, experiment));
87 } else {
88 fEventsTable = createEventsTable(parent);
89 }
90 }
91
92 @Override
93 public void dispose() {
94 if (fEventsTable != null) {
95 fEventsTable.dispose();
96 }
97 super.dispose();
98 }
99
100 /**
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
106 */
107 protected TmfEventsTable createEventsTable(Composite parent) {
108 if (fExperiment == null) {
109 return new TmfEventsTable(parent, DEFAULT_CACHE_SIZE);
110 }
111 int cacheSize = fExperiment.getIndexPageSize();
112 String commonTraceType = null;
113 try {
114 for (ITmfTrace<?> trace : fExperiment.getTraces()) {
115 IResource resource = trace.getResource();
116 if (resource == null) {
117 return new TmfEventsTable(parent, cacheSize);
118 }
119 String traceType = resource.getPersistentProperty(TmfTraceElement.TRACETYPE);
120 if (commonTraceType != null && !commonTraceType.equals(traceType)) {
121 return new TmfEventsTable(parent, cacheSize);
122 }
123 commonTraceType = traceType;
124 }
125 if (commonTraceType == null) {
126 return new TmfEventsTable(parent, cacheSize);
127 }
128 if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {
129 return new CustomEventsTable(((CustomTxtTrace) fExperiment.getTraces()[0]).getDefinition(), parent, cacheSize);
130 }
131 if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {
132 return new CustomEventsTable(((CustomXmlTrace) fExperiment.getTraces()[0]).getDefinition(), parent, cacheSize);
133 }
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) {
138 break;
139 }
140 String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);
141 if (eventsTableType == null || eventsTableType.length() == 0) {
142 break;
143 }
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);
150 }
151 }
152 } catch (CoreException e) {
153 e.printStackTrace();
154 } catch (InvalidRegistryObjectException e) {
155 e.printStackTrace();
156 } catch (SecurityException e) {
157 e.printStackTrace();
158 } catch (IllegalArgumentException e) {
159 e.printStackTrace();
160 } catch (ClassNotFoundException e) {
161 e.printStackTrace();
162 } catch (NoSuchMethodException e) {
163 e.printStackTrace();
164 } catch (InstantiationException e) {
165 e.printStackTrace();
166 } catch (IllegalAccessException e) {
167 e.printStackTrace();
168 } catch (InvocationTargetException e) {
169 e.printStackTrace();
170 }
171 return new TmfEventsTable(parent, cacheSize);
172 }
173
174 /* (non-Javadoc)
175 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
176 */
177 @Override
178 public void setFocus() {
179 fEventsTable.setFocus();
180 }
181
182 /* (non-Javadoc)
183 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
184 */
185 @SuppressWarnings("rawtypes")
186 @Override
187 public Object getAdapter(Class adapter) {
188 if (IGotoMarker.class.equals(adapter)) {
189 return fEventsTable;
190 }
191 return super.getAdapter(adapter);
192 }
193
194 /* (non-Javadoc)
195 * @see java.lang.Object#toString()
196 */
197 @Override
198 @SuppressWarnings("nls")
199 public String toString() {
200 return "[TmfEventsView]";
201 }
202
203 // ------------------------------------------------------------------------
204 // Signal handlers
205 // ------------------------------------------------------------------------
206
207 @SuppressWarnings("unchecked")
208 @TmfSignalHandler
209 public void experimentSelected(TmfExperimentSelectedSignal<ITmfEvent> signal) {
210 // Update the trace reference
211 TmfExperiment<ITmfEvent> exp = (TmfExperiment<ITmfEvent>) signal.getExperiment();
212 if (!exp.equals(fExperiment)) {
213 fExperiment = exp;
214 setPartName(fTitlePrefix + " - " + fExperiment.getName()); //$NON-NLS-1$
215 if (fEventsTable != null) {
216 fEventsTable.dispose();
217 }
218 fEventsTable = createEventsTable(fParent);
219 fEventsTable.setTrace(fExperiment, false);
220 fEventsTable.refreshBookmarks(fExperiment.getBookmarksFile());
221 fParent.layout();
222 }
223 }
224
225 @SuppressWarnings("unchecked")
226 @TmfSignalHandler
227 public void experimentDisposed(TmfExperimentDisposedSignal<ITmfEvent> signal) {
228 // Clear the trace reference
229 TmfExperiment<ITmfEvent> experiment = (TmfExperiment<ITmfEvent>) signal.getExperiment();
230 if (experiment.equals(fExperiment)) {
231 fEventsTable.setTrace(null, false);
232
233 TmfUiPlugin.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() {
234 @Override
235 public void run() {
236 setPartName(fTitlePrefix);
237 }
238 });
239 }
240 }
241
242 }
This page took 0.038931 seconds and 5 git commands to generate.