Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /******************************************************************************* |
e31e01e8 | 2 | * Copyright (c) 2009, 2010 Ericsson |
02023181 | 3 | * |
b0d3496e ASL |
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 | |
02023181 | 8 | * |
b0d3496e ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
abfad0aa | 11 | * Patrick Tasse - Factored out events table |
b0d3496e ASL |
12 | *******************************************************************************/ |
13 | ||
12c155f5 | 14 | package org.eclipse.linuxtools.tmf.ui.views.events; |
b0d3496e | 15 | |
09d11238 PT |
16 | import java.lang.reflect.Constructor; |
17 | import java.lang.reflect.InvocationTargetException; | |
18 | ||
a01c19b8 BH |
19 | import org.eclipse.core.resources.IMarker; |
20 | import org.eclipse.core.resources.IMarkerDelta; | |
09d11238 | 21 | import org.eclipse.core.resources.IResource; |
a01c19b8 BH |
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; | |
09d11238 PT |
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; | |
8fd82db5 | 30 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
d34665f9 FC |
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; | |
e12ecd30 | 34 | import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; |
58b21093 | 35 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
6c13869b FC |
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; | |
09d11238 | 39 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
9e0640dc | 40 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
bfc779a0 | 41 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; |
abfad0aa | 42 | import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; |
12c155f5 | 43 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
b0d3496e | 44 | import org.eclipse.swt.widgets.Composite; |
a01c19b8 | 45 | import org.eclipse.swt.widgets.Display; |
09d11238 PT |
46 | import org.eclipse.ui.ide.IGotoMarker; |
47 | import org.osgi.framework.Bundle; | |
b0d3496e ASL |
48 | |
49 | /** | |
00511ef2 | 50 | * The generic TMF Events View. |
b0d3496e | 51 | * <p> |
00511ef2 FC |
52 | * Support for: |
53 | * <ul> | |
54 | * <li>Traces larger than available memory | |
55 | * <li>Searching and Filtering | |
56 | * <li>Customized table viewers (per trace type) | |
57 | * </ul> | |
b0d3496e | 58 | * |
b0d3496e ASL |
59 | * TODO: Handle column selection, sort, ... generically (nothing less...) |
60 | * TODO: Implement hide/display columns | |
013a5f1c | 61 | * |
00511ef2 FC |
62 | * @version 1.0 |
63 | * @author Francois Chouinard | |
64 | * @author Patrick Tasse | |
b0d3496e | 65 | */ |
a01c19b8 | 66 | public class TmfEventsView extends TmfView implements IResourceChangeListener { |
b0d3496e | 67 | |
013a5f1c | 68 | /** Event View's ID */ |
3b38ea61 | 69 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$ |
b0d3496e | 70 | |
09d11238 | 71 | private TmfExperiment<?> fExperiment; |
abfad0aa | 72 | private TmfEventsTable fEventsTable; |
529ee6a9 | 73 | private static final int DEFAULT_CACHE_SIZE = 100; |
abfad0aa | 74 | private String fTitlePrefix; |
09d11238 | 75 | private Composite fParent; |
02023181 | 76 | |
e31e01e8 | 77 | // ------------------------------------------------------------------------ |
b0d3496e | 78 | // Constructor |
e31e01e8 | 79 | // ------------------------------------------------------------------------ |
b0d3496e | 80 | |
02023181 MK |
81 | /** |
82 | * Create an events view with a cache size | |
83 | * @param cacheSize not used | |
84 | */ | |
e31e01e8 | 85 | public TmfEventsView(int cacheSize) { |
3b38ea61 | 86 | super("TmfEventsView"); //$NON-NLS-1$ |
b0d3496e ASL |
87 | } |
88 | ||
02023181 | 89 | /** |
013a5f1c | 90 | * Default constructor, with a default cache size |
02023181 | 91 | */ |
e31e01e8 FC |
92 | public TmfEventsView() { |
93 | this(DEFAULT_CACHE_SIZE); | |
94 | } | |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // ViewPart | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
e31e01e8 | 100 | @Override |
3b38ea61 | 101 | @SuppressWarnings("unchecked") |
b0d3496e | 102 | public void createPartControl(Composite parent) { |
09d11238 | 103 | fParent = parent; |
abfad0aa FC |
104 | |
105 | fTitlePrefix = getTitle(); | |
02023181 | 106 | |
abfad0aa | 107 | // If an experiment is already selected, update the table |
58b21093 | 108 | TmfExperiment<ITmfEvent> experiment = (TmfExperiment<ITmfEvent>) TmfExperiment.getCurrentExperiment(); |
09d11238 | 109 | if (experiment != null) { |
58b21093 | 110 | experimentSelected(new TmfExperimentSelectedSignal<ITmfEvent>(this, experiment)); |
09d11238 PT |
111 | } else { |
112 | fEventsTable = createEventsTable(parent); | |
abfad0aa | 113 | } |
8d2e2848 FC |
114 | } |
115 | ||
abfad0aa FC |
116 | @Override |
117 | public void dispose() { | |
118 | if (fEventsTable != null) { | |
119 | fEventsTable.dispose(); | |
b0d3496e | 120 | } |
abfad0aa FC |
121 | super.dispose(); |
122 | } | |
b0d3496e | 123 | |
09d11238 PT |
124 | /** |
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 | |
130 | */ | |
131 | protected TmfEventsTable createEventsTable(Composite parent) { | |
132 | if (fExperiment == null) { | |
133 | return new TmfEventsTable(parent, DEFAULT_CACHE_SIZE); | |
134 | } | |
20658947 | 135 | int cacheSize = fExperiment.getCacheSize(); |
09d11238 PT |
136 | String commonTraceType = null; |
137 | try { | |
138 | for (ITmfTrace<?> trace : fExperiment.getTraces()) { | |
a1091415 | 139 | IResource resource = trace.getResource(); |
09d11238 PT |
140 | if (resource == null) { |
141 | return new TmfEventsTable(parent, cacheSize); | |
142 | } | |
e12ecd30 | 143 | String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); |
02023181 | 144 | if ((commonTraceType != null) && !commonTraceType.equals(traceType)) { |
09d11238 PT |
145 | return new TmfEventsTable(parent, cacheSize); |
146 | } | |
147 | commonTraceType = traceType; | |
148 | } | |
149 | if (commonTraceType == null) { | |
150 | return new TmfEventsTable(parent, cacheSize); | |
151 | } | |
152 | if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) { | |
153 | return new CustomEventsTable(((CustomTxtTrace) fExperiment.getTraces()[0]).getDefinition(), parent, cacheSize); | |
154 | } | |
155 | if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) { | |
156 | return new CustomEventsTable(((CustomXmlTrace) fExperiment.getTraces()[0]).getDefinition(), parent, cacheSize); | |
157 | } | |
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) { | |
162 | break; | |
163 | } | |
164 | String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR); | |
02023181 | 165 | if ((eventsTableType == null) || (eventsTableType.length() == 0)) { |
09d11238 PT |
166 | break; |
167 | } | |
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); | |
174 | } | |
175 | } | |
176 | } catch (CoreException e) { | |
8fd82db5 | 177 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 178 | } catch (InvalidRegistryObjectException e) { |
8fd82db5 | 179 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 180 | } catch (SecurityException e) { |
8fd82db5 | 181 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 182 | } catch (IllegalArgumentException e) { |
8fd82db5 | 183 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 184 | } catch (ClassNotFoundException e) { |
8fd82db5 | 185 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 186 | } catch (NoSuchMethodException e) { |
8fd82db5 | 187 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 188 | } catch (InstantiationException e) { |
8fd82db5 | 189 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 190 | } catch (IllegalAccessException e) { |
8fd82db5 | 191 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 192 | } catch (InvocationTargetException e) { |
8fd82db5 | 193 | Activator.getDefault().logError("Error creating events table", e); //$NON-NLS-1$ |
09d11238 | 194 | } |
abfad0aa FC |
195 | return new TmfEventsTable(parent, cacheSize); |
196 | } | |
b0d3496e ASL |
197 | |
198 | /* (non-Javadoc) | |
199 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
200 | */ | |
201 | @Override | |
202 | public void setFocus() { | |
abfad0aa | 203 | fEventsTable.setFocus(); |
b0d3496e ASL |
204 | } |
205 | ||
09d11238 PT |
206 | /* (non-Javadoc) |
207 | * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class) | |
208 | */ | |
209 | @SuppressWarnings("rawtypes") | |
210 | @Override | |
211 | public Object getAdapter(Class adapter) { | |
212 | if (IGotoMarker.class.equals(adapter)) { | |
213 | return fEventsTable; | |
214 | } | |
215 | return super.getAdapter(adapter); | |
216 | } | |
217 | ||
8d2e2848 FC |
218 | /* (non-Javadoc) |
219 | * @see java.lang.Object#toString() | |
220 | */ | |
221 | @Override | |
3b38ea61 | 222 | @SuppressWarnings("nls") |
8d2e2848 FC |
223 | public String toString() { |
224 | return "[TmfEventsView]"; | |
225 | } | |
226 | ||
abfad0aa | 227 | // ------------------------------------------------------------------------ |
b0d3496e | 228 | // Signal handlers |
e31e01e8 | 229 | // ------------------------------------------------------------------------ |
02023181 MK |
230 | |
231 | /** | |
013a5f1c AM |
232 | * Handler for the experiment selected signal. |
233 | * | |
234 | * @param signal | |
235 | * The incoming signal | |
02023181 | 236 | */ |
013a5f1c | 237 | @SuppressWarnings("unchecked") |
abfad0aa | 238 | @TmfSignalHandler |
58b21093 | 239 | public void experimentSelected(TmfExperimentSelectedSignal<ITmfEvent> signal) { |
abfad0aa | 240 | // Update the trace reference |
58b21093 | 241 | TmfExperiment<ITmfEvent> exp = (TmfExperiment<ITmfEvent>) signal.getExperiment(); |
8e31f2d2 | 242 | if (!exp.equals(fExperiment)) { |
09d11238 | 243 | fExperiment = exp; |
8e31f2d2 FC |
244 | setPartName(fTitlePrefix + " - " + fExperiment.getName()); //$NON-NLS-1$ |
245 | if (fEventsTable != null) { | |
09d11238 | 246 | fEventsTable.dispose(); |
8e31f2d2 | 247 | } |
09d11238 PT |
248 | fEventsTable = createEventsTable(fParent); |
249 | fEventsTable.setTrace(fExperiment, false); | |
a1091415 | 250 | fEventsTable.refreshBookmarks(fExperiment.getBookmarksFile()); |
a01c19b8 BH |
251 | if (fExperiment.getBookmarksFile() != null) { |
252 | ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); | |
253 | } | |
09d11238 | 254 | fParent.layout(); |
abfad0aa | 255 | } |
cb866e08 | 256 | } |
9aae0442 | 257 | |
013a5f1c AM |
258 | /** |
259 | * Handler for the experiment disposed signal. | |
260 | * | |
261 | * @param signal | |
262 | * The incoming signal | |
02023181 | 263 | */ |
013a5f1c AM |
264 | @SuppressWarnings("unchecked") |
265 | @TmfSignalHandler | |
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); | |
8e31f2d2 | 271 | |
8fd82db5 | 272 | Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() { |
09d11238 PT |
273 | @Override |
274 | public void run() { | |
275 | setPartName(fTitlePrefix); | |
276 | } | |
277 | }); | |
a01c19b8 BH |
278 | |
279 | if ((fExperiment != null) && (fExperiment.getBookmarksFile() != null)) { | |
280 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); | |
281 | } | |
282 | ||
013a5f1c AM |
283 | } |
284 | } | |
8e31f2d2 | 285 | |
013a5f1c | 286 | @Override |
a01c19b8 | 287 | public void resourceChanged(final IResourceChangeEvent event) { |
02023181 | 288 | if ((fExperiment == null) || (fExperiment.getBookmarksFile() == null)) { |
a01c19b8 BH |
289 | return; |
290 | } | |
291 | ||
02023181 MK |
292 | for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) { |
293 | if (delta.getResource().equals(fExperiment.getBookmarksFile())) { | |
a01c19b8 BH |
294 | if (delta.getKind() == IResourceDelta.REMOVED) { |
295 | final IMarker bookmark = delta.getMarker(); | |
296 | Display.getDefault().asyncExec(new Runnable() { | |
297 | @Override | |
298 | public void run() { | |
299 | fEventsTable.removeBookmark(bookmark); | |
300 | } | |
301 | }); | |
02023181 | 302 | } else if (delta.getKind() == IResourceDelta.CHANGED) { |
a01c19b8 BH |
303 | Display.getDefault().asyncExec(new Runnable() { |
304 | @Override | |
305 | public void run() { | |
306 | fEventsTable.getTable().refresh(); | |
307 | } | |
308 | }); | |
02023181 MK |
309 | } |
310 | } | |
311 | } | |
a01c19b8 | 312 | } |
e6a4cf1b | 313 | } |