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