Commit | Line | Data |
---|---|---|
db4721fb | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 Ericsson |
db4721fb PT |
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 from events view | |
12 | * Francois Chouinard - Replaced Table by TmfVirtualTable | |
13 | * Patrick Tasse - Filter implementation (inspired by www.eclipse.org/mat) | |
ac44ef71 | 14 | * Ansgar Radermacher - Support navigation to model URIs (Bug 396956) |
f47ed727 | 15 | * Bernd Hufmann - Updated call site and model URI implementation |
db4721fb PT |
16 | *******************************************************************************/ |
17 | ||
18 | package org.eclipse.linuxtools.tmf.ui.viewers.events; | |
19 | ||
60fb38b8 | 20 | import java.io.FileNotFoundException; |
db4721fb PT |
21 | import java.util.ArrayList; |
22 | import java.util.Arrays; | |
23 | import java.util.HashMap; | |
24 | import java.util.List; | |
25 | import java.util.Map; | |
26 | import java.util.Map.Entry; | |
27 | import java.util.regex.Pattern; | |
28 | import java.util.regex.PatternSyntaxException; | |
29 | ||
d3de0920 XR |
30 | import org.eclipse.core.commands.Command; |
31 | import org.eclipse.core.commands.ExecutionException; | |
32 | import org.eclipse.core.commands.NotEnabledException; | |
33 | import org.eclipse.core.commands.NotHandledException; | |
34 | import org.eclipse.core.commands.ParameterizedCommand; | |
35 | import org.eclipse.core.commands.common.NotDefinedException; | |
36 | import org.eclipse.core.expressions.IEvaluationContext; | |
db4721fb PT |
37 | import org.eclipse.core.resources.IFile; |
38 | import org.eclipse.core.resources.IMarker; | |
39 | import org.eclipse.core.resources.IResource; | |
60fb38b8 | 40 | import org.eclipse.core.resources.IResourceVisitor; |
ac44ef71 | 41 | import org.eclipse.core.resources.ResourcesPlugin; |
db4721fb | 42 | import org.eclipse.core.runtime.CoreException; |
ac44ef71 | 43 | import org.eclipse.core.runtime.IPath; |
db4721fb PT |
44 | import org.eclipse.core.runtime.IProgressMonitor; |
45 | import org.eclipse.core.runtime.IStatus; | |
93bfd50a | 46 | import org.eclipse.core.runtime.ListenerList; |
ac44ef71 | 47 | import org.eclipse.core.runtime.Path; |
db4721fb PT |
48 | import org.eclipse.core.runtime.Status; |
49 | import org.eclipse.core.runtime.jobs.Job; | |
ac44ef71 AR |
50 | import org.eclipse.emf.common.util.URI; |
51 | import org.eclipse.emf.ecore.EValidator; | |
db4721fb PT |
52 | import org.eclipse.jface.action.Action; |
53 | import org.eclipse.jface.action.IAction; | |
54 | import org.eclipse.jface.action.IMenuListener; | |
55 | import org.eclipse.jface.action.IMenuManager; | |
3f43dc48 | 56 | import org.eclipse.jface.action.IStatusLineManager; |
db4721fb PT |
57 | import org.eclipse.jface.action.MenuManager; |
58 | import org.eclipse.jface.action.Separator; | |
59 | import org.eclipse.jface.dialogs.InputDialog; | |
60 | import org.eclipse.jface.dialogs.MessageDialog; | |
61 | import org.eclipse.jface.resource.FontDescriptor; | |
62 | import org.eclipse.jface.resource.JFaceResources; | |
63 | import org.eclipse.jface.resource.LocalResourceManager; | |
ac44ef71 | 64 | import org.eclipse.jface.util.OpenStrategy; |
93bfd50a | 65 | import org.eclipse.jface.util.SafeRunnable; |
60fb38b8 | 66 | import org.eclipse.jface.viewers.ArrayContentProvider; |
93bfd50a PT |
67 | import org.eclipse.jface.viewers.ISelection; |
68 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
69 | import org.eclipse.jface.viewers.ISelectionProvider; | |
60fb38b8 | 70 | import org.eclipse.jface.viewers.LabelProvider; |
93bfd50a PT |
71 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
72 | import org.eclipse.jface.viewers.StructuredSelection; | |
db4721fb PT |
73 | import org.eclipse.jface.window.Window; |
74 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; | |
75 | import org.eclipse.linuxtools.internal.tmf.ui.Messages; | |
d3de0920 | 76 | import org.eclipse.linuxtools.internal.tmf.ui.commands.ExportToTextCommandHandler; |
3be2946f | 77 | import org.eclipse.linuxtools.internal.tmf.ui.dialogs.MultiLineInputDialog; |
fd3f1eff | 78 | import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider; |
db4721fb PT |
79 | import org.eclipse.linuxtools.tmf.core.component.TmfComponent; |
80 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
81 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; | |
db4721fb | 82 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
f47ed727 BH |
83 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfCallsite; |
84 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup; | |
85 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup; | |
db4721fb PT |
86 | import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter; |
87 | import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode; | |
88 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode; | |
89 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode; | |
90 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode; | |
fd3f1eff AM |
91 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType; |
92 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; | |
faa38350 PT |
93 | import org.eclipse.linuxtools.tmf.core.signal.TmfEventFilterAppliedSignal; |
94 | import org.eclipse.linuxtools.tmf.core.signal.TmfEventSearchAppliedSignal; | |
db4721fb PT |
95 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
96 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
97 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; | |
3bd46eef | 98 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
fd3f1eff | 99 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; |
3bd46eef | 100 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; |
db4721fb | 101 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
db4721fb | 102 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
a3db8436 | 103 | import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation; |
db4721fb PT |
104 | import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsCache.CachedEvent; |
105 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting; | |
106 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; | |
107 | import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener; | |
108 | import org.eclipse.linuxtools.tmf.ui.views.filter.FilterManager; | |
109 | import org.eclipse.linuxtools.tmf.ui.widgets.rawviewer.TmfRawEventViewer; | |
110 | import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData; | |
111 | import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.TmfVirtualTable; | |
112 | import org.eclipse.swt.SWT; | |
113 | import org.eclipse.swt.custom.SashForm; | |
114 | import org.eclipse.swt.custom.TableEditor; | |
115 | import org.eclipse.swt.events.FocusAdapter; | |
116 | import org.eclipse.swt.events.FocusEvent; | |
117 | import org.eclipse.swt.events.KeyAdapter; | |
118 | import org.eclipse.swt.events.KeyEvent; | |
119 | import org.eclipse.swt.events.MouseAdapter; | |
120 | import org.eclipse.swt.events.MouseEvent; | |
121 | import org.eclipse.swt.events.SelectionAdapter; | |
122 | import org.eclipse.swt.events.SelectionEvent; | |
123 | import org.eclipse.swt.graphics.Color; | |
124 | import org.eclipse.swt.graphics.Font; | |
125 | import org.eclipse.swt.graphics.Image; | |
126 | import org.eclipse.swt.graphics.Point; | |
127 | import org.eclipse.swt.graphics.Rectangle; | |
128 | import org.eclipse.swt.layout.FillLayout; | |
129 | import org.eclipse.swt.layout.GridData; | |
130 | import org.eclipse.swt.layout.GridLayout; | |
131 | import org.eclipse.swt.widgets.Composite; | |
132 | import org.eclipse.swt.widgets.Display; | |
133 | import org.eclipse.swt.widgets.Event; | |
134 | import org.eclipse.swt.widgets.Label; | |
135 | import org.eclipse.swt.widgets.Listener; | |
136 | import org.eclipse.swt.widgets.Menu; | |
137 | import org.eclipse.swt.widgets.MessageBox; | |
138 | import org.eclipse.swt.widgets.Shell; | |
139 | import org.eclipse.swt.widgets.TableColumn; | |
140 | import org.eclipse.swt.widgets.TableItem; | |
141 | import org.eclipse.swt.widgets.Text; | |
ac44ef71 | 142 | import org.eclipse.ui.IWorkbenchPage; |
db4721fb | 143 | import org.eclipse.ui.PlatformUI; |
d3de0920 | 144 | import org.eclipse.ui.commands.ICommandService; |
60fb38b8 | 145 | import org.eclipse.ui.dialogs.ListDialog; |
d3de0920 | 146 | import org.eclipse.ui.handlers.IHandlerService; |
ac44ef71 | 147 | import org.eclipse.ui.ide.IDE; |
db4721fb PT |
148 | import org.eclipse.ui.ide.IGotoMarker; |
149 | import org.eclipse.ui.themes.ColorUtil; | |
150 | ||
151 | /** | |
152 | * The generic TMF Events table | |
153 | * | |
154 | * This is a view that will list events that are read from a trace. | |
155 | * | |
156 | * @version 1.0 | |
157 | * @author Francois Chouinard | |
158 | * @author Patrick Tasse | |
93bfd50a | 159 | * @since 2.0 |
db4721fb | 160 | */ |
faa38350 | 161 | public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorSettingsListener, ISelectionProvider { |
db4721fb PT |
162 | |
163 | private static final Image BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath( | |
164 | "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$ | |
165 | private static final Image SEARCH_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$ | |
166 | private static final Image SEARCH_MATCH_IMAGE = Activator.getDefault().getImageFromPath( | |
167 | "icons/elcl16/search_match.gif"); //$NON-NLS-1$ | |
168 | private static final Image SEARCH_MATCH_BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath( | |
169 | "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$ | |
170 | private static final Image FILTER_IMAGE = Activator.getDefault() | |
171 | .getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$ | |
172 | private static final Image STOP_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$ | |
173 | private static final String SEARCH_HINT = Messages.TmfEventsTable_SearchHint; | |
174 | private static final String FILTER_HINT = Messages.TmfEventsTable_FilterHint; | |
175 | private static final int MAX_CACHE_SIZE = 1000; | |
d3de0920 XR |
176 | /** |
177 | * Empty ITmfEventField array, used by {@link #extractItemFields(ITmfEvent)} | |
178 | * @since 2.2 | |
179 | */ | |
180 | public static final ITmfEventField[] EMPTY_FIELD_ARRAY = new TmfEventField[0]; | |
db4721fb PT |
181 | |
182 | /** | |
183 | * The events table search/filter keys | |
184 | * | |
185 | * @version 1.0 | |
186 | * @author Patrick Tasse | |
187 | */ | |
188 | public interface Key { | |
189 | /** Search text */ | |
190 | String SEARCH_TXT = "$srch_txt"; //$NON-NLS-1$ | |
191 | ||
192 | /** Search object */ | |
193 | String SEARCH_OBJ = "$srch_obj"; //$NON-NLS-1$ | |
194 | ||
195 | /** Filter text */ | |
196 | String FILTER_TXT = "$fltr_txt"; //$NON-NLS-1$ | |
197 | ||
198 | /** Filter object */ | |
199 | String FILTER_OBJ = "$fltr_obj"; //$NON-NLS-1$ | |
200 | ||
dadf6e1a | 201 | /** Timestamp */ |
db4721fb PT |
202 | String TIMESTAMP = "$time"; //$NON-NLS-1$ |
203 | ||
204 | /** Rank */ | |
205 | String RANK = "$rank"; //$NON-NLS-1$ | |
206 | ||
207 | /** Field ID */ | |
208 | String FIELD_ID = "$field_id"; //$NON-NLS-1$ | |
209 | ||
210 | /** Bookmark indicator */ | |
211 | String BOOKMARK = "$bookmark"; //$NON-NLS-1$ | |
212 | } | |
213 | ||
214 | /** | |
215 | * The events table search/filter state | |
216 | * | |
217 | * @version 1.0 | |
218 | * @author Patrick Tasse | |
219 | */ | |
220 | public static enum HeaderState { | |
221 | /** A search is being run */ | |
222 | SEARCH, | |
223 | ||
224 | /** A filter is applied */ | |
225 | FILTER | |
226 | } | |
227 | ||
228 | interface Direction { | |
229 | int FORWARD = +1; | |
230 | int BACKWARD = -1; | |
231 | } | |
232 | ||
233 | // ------------------------------------------------------------------------ | |
234 | // Table data | |
235 | // ------------------------------------------------------------------------ | |
236 | ||
a0a88f65 | 237 | /** The virtual event table */ |
db4721fb | 238 | protected TmfVirtualTable fTable; |
a0a88f65 AM |
239 | |
240 | private Composite fComposite; | |
241 | private SashForm fSashForm; | |
242 | private TmfRawEventViewer fRawViewer; | |
243 | private ITmfTrace fTrace; | |
244 | private boolean fPackDone = false; | |
245 | private HeaderState fHeaderState = HeaderState.SEARCH; | |
246 | private long fSelectedRank = 0; | |
3f43dc48 PT |
247 | private ITmfTimestamp fSelectedBeginTimestamp = null; |
248 | private IStatusLineManager fStatusLineManager = null; | |
db4721fb PT |
249 | |
250 | // Filter data | |
a0a88f65 AM |
251 | private long fFilterMatchCount; |
252 | private long fFilterCheckCount; | |
253 | private FilterThread fFilterThread; | |
254 | private boolean fFilterThreadResume = false; | |
255 | private final Object fFilterSyncObj = new Object(); | |
256 | private SearchThread fSearchThread; | |
257 | private final Object fSearchSyncObj = new Object(); | |
db4721fb | 258 | |
93bfd50a PT |
259 | /** |
260 | * List of selection change listeners (element type: <code>ISelectionChangedListener</code>). | |
261 | * | |
262 | * @see #fireSelectionChanged | |
263 | */ | |
264 | private ListenerList selectionChangedListeners = new ListenerList(); | |
265 | ||
db4721fb | 266 | // Bookmark map <Rank, MarkerId> |
507b1336 | 267 | private Map<Long, Long> fBookmarksMap = new HashMap<>(); |
a0a88f65 AM |
268 | private IFile fBookmarksFile; |
269 | private long fPendingGotoRank = -1; | |
db4721fb PT |
270 | |
271 | // SWT resources | |
a0a88f65 AM |
272 | private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources()); |
273 | private Color fGrayColor; | |
274 | private Color fGreenColor; | |
275 | private Font fBoldFont; | |
db4721fb PT |
276 | |
277 | // Table column names | |
a0a88f65 | 278 | private static final String[] COLUMN_NAMES = new String[] { Messages.TmfEventsTable_TimestampColumnHeader, |
db4721fb PT |
279 | Messages.TmfEventsTable_SourceColumnHeader, Messages.TmfEventsTable_TypeColumnHeader, |
280 | Messages.TmfEventsTable_ReferenceColumnHeader, Messages.TmfEventsTable_ContentColumnHeader }; | |
281 | ||
a0a88f65 | 282 | private static final ColumnData[] COLUMN_DATA = new ColumnData[] { new ColumnData(COLUMN_NAMES[0], 100, SWT.LEFT), |
db4721fb PT |
283 | new ColumnData(COLUMN_NAMES[1], 100, SWT.LEFT), new ColumnData(COLUMN_NAMES[2], 100, SWT.LEFT), |
284 | new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT), new ColumnData(COLUMN_NAMES[4], 100, SWT.LEFT) }; | |
285 | ||
286 | // Event cache | |
287 | private final TmfEventsCache fCache; | |
288 | private boolean fCacheUpdateBusy = false; | |
289 | private boolean fCacheUpdatePending = false; | |
290 | private boolean fCacheUpdateCompleted = false; | |
291 | private final Object fCacheUpdateSyncObj = new Object(); | |
292 | ||
293 | private boolean fDisposeOnClose; | |
294 | ||
295 | // ------------------------------------------------------------------------ | |
a0a88f65 | 296 | // Constructors |
db4721fb PT |
297 | // ------------------------------------------------------------------------ |
298 | ||
299 | /** | |
300 | * Basic constructor, will use default column data. | |
301 | * | |
302 | * @param parent | |
303 | * The parent composite UI object | |
304 | * @param cacheSize | |
305 | * The size of the event table cache | |
306 | */ | |
307 | public TmfEventsTable(final Composite parent, final int cacheSize) { | |
308 | this(parent, cacheSize, COLUMN_DATA); | |
309 | } | |
310 | ||
311 | /** | |
312 | * Advanced constructor, where we also define which column data to use. | |
313 | * | |
314 | * @param parent | |
315 | * The parent composite UI object | |
316 | * @param cacheSize | |
317 | * The size of the event table cache | |
318 | * @param columnData | |
319 | * The column data to use for this table | |
320 | */ | |
321 | public TmfEventsTable(final Composite parent, int cacheSize, final ColumnData[] columnData) { | |
322 | super("TmfEventsTable"); //$NON-NLS-1$ | |
323 | ||
324 | fComposite = new Composite(parent, SWT.NONE); | |
325 | final GridLayout gl = new GridLayout(1, false); | |
326 | gl.marginHeight = 0; | |
327 | gl.marginWidth = 0; | |
328 | gl.verticalSpacing = 0; | |
329 | fComposite.setLayout(gl); | |
330 | ||
331 | fSashForm = new SashForm(fComposite, SWT.HORIZONTAL); | |
332 | fSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
333 | ||
334 | // Create a virtual table | |
3f43dc48 | 335 | final int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION; |
db4721fb PT |
336 | fTable = new TmfVirtualTable(fSashForm, style); |
337 | ||
338 | // Set the table layout | |
339 | final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); | |
340 | fTable.setLayoutData(layoutData); | |
341 | ||
342 | // Some cosmetic enhancements | |
343 | fTable.setHeaderVisible(true); | |
344 | fTable.setLinesVisible(true); | |
345 | ||
346 | // Set the columns | |
347 | setColumnHeaders(columnData); | |
348 | ||
349 | // Set the default column field ids if this is not a subclass | |
350 | if (Arrays.equals(columnData, COLUMN_DATA)) { | |
351 | fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP); | |
352 | fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_SOURCE); | |
353 | fTable.getColumns()[2].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE); | |
354 | fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE); | |
355 | fTable.getColumns()[4].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT); | |
356 | } | |
357 | ||
358 | // Set the frozen row for header row | |
359 | fTable.setFrozenRowCount(1); | |
360 | ||
361 | // Create the header row cell editor | |
362 | createHeaderEditor(); | |
363 | ||
364 | // Handle the table item selection | |
365 | fTable.addSelectionListener(new SelectionAdapter() { | |
366 | @Override | |
367 | public void widgetSelected(final SelectionEvent e) { | |
3f43dc48 PT |
368 | if (e.item == null) { |
369 | return; | |
370 | } | |
371 | updateStatusLine(null); | |
372 | if (fTable.getSelectionIndices().length > 0) { | |
373 | if (e.item.getData(Key.RANK) instanceof Long) { | |
374 | fSelectedRank = (Long) e.item.getData(Key.RANK); | |
375 | fRawViewer.selectAndReveal((Long) e.item.getData(Key.RANK)); | |
376 | } | |
377 | if (e.item.getData(Key.TIMESTAMP) instanceof ITmfTimestamp) { | |
378 | final ITmfTimestamp ts = (ITmfTimestamp) e.item.getData(Key.TIMESTAMP); | |
379 | if (fTable.getSelectionIndices().length == 1) { | |
380 | fSelectedBeginTimestamp = ts; | |
381 | } | |
382 | if (fSelectedBeginTimestamp != null) { | |
383 | if (fSelectedBeginTimestamp.compareTo(ts) <= 0) { | |
384 | broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, fSelectedBeginTimestamp, ts)); | |
385 | if (fTable.getSelectionIndices().length == 2) { | |
386 | updateStatusLine(ts.getDelta(fSelectedBeginTimestamp)); | |
387 | } | |
388 | } else { | |
389 | broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, ts, fSelectedBeginTimestamp)); | |
dadf6e1a | 390 | updateStatusLine(fSelectedBeginTimestamp.getDelta(ts)); |
3f43dc48 | 391 | } |
db4721fb | 392 | } |
3f43dc48 PT |
393 | } else { |
394 | if (fTable.getSelectionIndices().length == 1) { | |
395 | fSelectedBeginTimestamp = null; | |
db4721fb PT |
396 | } |
397 | } | |
398 | } | |
3f43dc48 PT |
399 | if (e.item.getData() != null) { |
400 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, new StructuredSelection(e.item.getData()))); | |
401 | } else { | |
402 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, StructuredSelection.EMPTY)); | |
403 | } | |
db4721fb PT |
404 | } |
405 | }); | |
406 | ||
41b5c37f AM |
407 | int realCacheSize = Math.max(cacheSize, Display.getDefault().getBounds().height / fTable.getItemHeight()); |
408 | realCacheSize = Math.min(realCacheSize, MAX_CACHE_SIZE); | |
409 | fCache = new TmfEventsCache(realCacheSize, this); | |
db4721fb PT |
410 | |
411 | // Handle the table item requests | |
412 | fTable.addListener(SWT.SetData, new Listener() { | |
413 | ||
414 | @Override | |
415 | public void handleEvent(final Event event) { | |
416 | ||
417 | final TableItem item = (TableItem) event.item; | |
418 | int index = event.index - 1; // -1 for the header row | |
419 | ||
420 | if (event.index == 0) { | |
421 | setHeaderRowItemData(item); | |
422 | return; | |
423 | } | |
424 | ||
425 | if (fTable.getData(Key.FILTER_OBJ) != null) { | |
426 | if ((event.index == 1) || (event.index == (fTable.getItemCount() - 1))) { | |
427 | setFilterStatusRowItemData(item); | |
428 | return; | |
429 | } | |
430 | index = index - 1; // -1 for top filter status row | |
431 | } | |
432 | ||
433 | final CachedEvent cachedEvent = fCache.getEvent(index); | |
434 | if (cachedEvent != null) { | |
435 | setItemData(item, cachedEvent.event, cachedEvent.rank); | |
436 | return; | |
437 | } | |
438 | ||
439 | // Else, fill the cache asynchronously (and off the UI thread) | |
440 | event.doit = false; | |
441 | } | |
442 | }); | |
443 | ||
444 | fTable.addMouseListener(new MouseAdapter() { | |
445 | @Override | |
446 | public void mouseDoubleClick(final MouseEvent event) { | |
447 | if (event.button != 1) { | |
448 | return; | |
449 | } | |
450 | // Identify the selected row | |
451 | final Point point = new Point(event.x, event.y); | |
452 | final TableItem item = fTable.getItem(point); | |
453 | if (item != null) { | |
454 | final Rectangle imageBounds = item.getImageBounds(0); | |
455 | imageBounds.width = BOOKMARK_IMAGE.getBounds().width; | |
456 | if (imageBounds.contains(point)) { | |
457 | final Long rank = (Long) item.getData(Key.RANK); | |
458 | if (rank != null) { | |
459 | toggleBookmark(rank); | |
460 | } | |
461 | } | |
462 | } | |
463 | } | |
464 | }); | |
465 | ||
466 | final Listener tooltipListener = new Listener () { | |
467 | Shell tooltipShell = null; | |
468 | @Override | |
469 | public void handleEvent(final Event event) { | |
470 | switch (event.type) { | |
471 | case SWT.MouseHover: | |
472 | final TableItem item = fTable.getItem(new Point(event.x, event.y)); | |
473 | if (item == null) { | |
474 | return; | |
475 | } | |
476 | final Long rank = (Long) item.getData(Key.RANK); | |
477 | if (rank == null) { | |
478 | return; | |
479 | } | |
480 | final String tooltipText = (String) item.getData(Key.BOOKMARK); | |
481 | final Rectangle bounds = item.getImageBounds(0); | |
482 | bounds.width = BOOKMARK_IMAGE.getBounds().width; | |
483 | if (!bounds.contains(event.x,event.y)) { | |
484 | return; | |
485 | } | |
486 | if ((tooltipShell != null) && !tooltipShell.isDisposed()) { | |
487 | tooltipShell.dispose(); | |
488 | } | |
489 | tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); | |
490 | tooltipShell.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); | |
491 | final FillLayout layout = new FillLayout(); | |
492 | layout.marginWidth = 2; | |
493 | tooltipShell.setLayout(layout); | |
494 | final Label label = new Label(tooltipShell, SWT.WRAP); | |
495 | String text = rank.toString() + (tooltipText != null ? ": " + tooltipText : ""); //$NON-NLS-1$ //$NON-NLS-2$ | |
496 | label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); | |
497 | label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); | |
498 | label.setText(text); | |
499 | label.addListener(SWT.MouseExit, this); | |
500 | label.addListener(SWT.MouseDown, this); | |
501 | label.addListener(SWT.MouseWheel, this); | |
502 | final Point size = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
503 | /* | |
504 | * Bug in Linux. The coordinates of the event have an origin that excludes the table header but | |
505 | * the method toDisplay() expects coordinates relative to an origin that includes the table header. | |
506 | */ | |
507 | int y = event.y; | |
508 | if (System.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$ | |
509 | y += fTable.getHeaderHeight(); | |
510 | } | |
511 | Point pt = fTable.toDisplay(event.x, y); | |
512 | pt.x += BOOKMARK_IMAGE.getBounds().width; | |
3be2946f | 513 | pt.y += item.getBounds().height; |
db4721fb PT |
514 | tooltipShell.setBounds(pt.x, pt.y, size.x, size.y); |
515 | tooltipShell.setVisible(true); | |
516 | break; | |
517 | case SWT.Dispose: | |
518 | case SWT.KeyDown: | |
519 | case SWT.MouseMove: | |
520 | case SWT.MouseExit: | |
521 | case SWT.MouseDown: | |
522 | case SWT.MouseWheel: | |
523 | if (tooltipShell != null) { | |
524 | tooltipShell.dispose(); | |
525 | tooltipShell = null; | |
526 | } | |
527 | break; | |
528 | default: | |
529 | break; | |
530 | } | |
531 | } | |
532 | }; | |
533 | ||
534 | fTable.addListener(SWT.MouseHover, tooltipListener); | |
535 | fTable.addListener(SWT.Dispose, tooltipListener); | |
536 | fTable.addListener(SWT.KeyDown, tooltipListener); | |
537 | fTable.addListener(SWT.MouseMove, tooltipListener); | |
538 | fTable.addListener(SWT.MouseExit, tooltipListener); | |
539 | fTable.addListener(SWT.MouseDown, tooltipListener); | |
540 | fTable.addListener(SWT.MouseWheel, tooltipListener); | |
541 | ||
542 | // Create resources | |
543 | createResources(); | |
544 | ||
545 | ColorSettingsManager.addColorSettingsListener(this); | |
546 | ||
547 | fTable.setItemCount(1); // +1 for header row | |
548 | ||
549 | fRawViewer = new TmfRawEventViewer(fSashForm, SWT.H_SCROLL | SWT.V_SCROLL); | |
550 | ||
551 | fRawViewer.addSelectionListener(new Listener() { | |
552 | @Override | |
553 | public void handleEvent(final Event e) { | |
554 | if (e.data instanceof Long) { | |
555 | final long rank = (Long) e.data; | |
556 | int index = (int) rank; | |
557 | if (fTable.getData(Key.FILTER_OBJ) != null) { | |
558 | index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row | |
559 | } | |
560 | fTable.setSelection(index + 1); // +1 for header row | |
561 | fSelectedRank = rank; | |
3f43dc48 | 562 | updateStatusLine(null); |
1e1bef82 | 563 | } else if (e.data instanceof ITmfLocation) { |
db4721fb PT |
564 | // DOES NOT WORK: rank undefined in context from seekLocation() |
565 | // ITmfLocation<?> location = (ITmfLocation<?>) e.data; | |
566 | // TmfContext context = fTrace.seekLocation(location); | |
567 | // fTable.setSelection((int) context.getRank()); | |
568 | return; | |
569 | } else { | |
570 | return; | |
571 | } | |
572 | final TableItem[] selection = fTable.getSelection(); | |
573 | if ((selection != null) && (selection.length > 0)) { | |
574 | final TmfTimestamp ts = (TmfTimestamp) fTable.getSelection()[0].getData(Key.TIMESTAMP); | |
575 | if (ts != null) { | |
576 | broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, ts)); | |
577 | } | |
578 | } | |
579 | } | |
580 | }); | |
581 | ||
582 | fSashForm.setWeights(new int[] { 1, 1 }); | |
583 | fRawViewer.setVisible(false); | |
584 | ||
585 | createPopupMenu(); | |
586 | } | |
587 | ||
a0a88f65 AM |
588 | /** |
589 | * Create a pop-up menu. | |
590 | */ | |
db4721fb PT |
591 | protected void createPopupMenu() { |
592 | final IAction showTableAction = new Action(Messages.TmfEventsTable_ShowTableActionText) { | |
593 | @Override | |
594 | public void run() { | |
595 | fTable.setVisible(true); | |
596 | fSashForm.layout(); | |
597 | } | |
598 | }; | |
599 | ||
600 | final IAction hideTableAction = new Action(Messages.TmfEventsTable_HideTableActionText) { | |
601 | @Override | |
602 | public void run() { | |
603 | fTable.setVisible(false); | |
604 | fSashForm.layout(); | |
605 | } | |
606 | }; | |
607 | ||
608 | final IAction showRawAction = new Action(Messages.TmfEventsTable_ShowRawActionText) { | |
609 | @Override | |
610 | public void run() { | |
611 | fRawViewer.setVisible(true); | |
612 | fSashForm.layout(); | |
613 | final int index = fTable.getSelectionIndex(); | |
dadf6e1a | 614 | if (index >= 1) { |
db4721fb PT |
615 | fRawViewer.selectAndReveal(index - 1); |
616 | } | |
617 | } | |
618 | }; | |
619 | ||
620 | final IAction hideRawAction = new Action(Messages.TmfEventsTable_HideRawActionText) { | |
621 | @Override | |
622 | public void run() { | |
623 | fRawViewer.setVisible(false); | |
624 | fSashForm.layout(); | |
625 | } | |
626 | }; | |
627 | ||
029df6e3 | 628 | final IAction openCallsiteAction = new Action(Messages.TmfEventsTable_OpenSourceCodeActionText) { |
60fb38b8 PT |
629 | @Override |
630 | public void run() { | |
631 | final TableItem items[] = fTable.getSelection(); | |
632 | if (items.length != 1) { | |
633 | return; | |
634 | } | |
635 | final TableItem item = items[0]; | |
636 | ||
637 | final Object data = item.getData(); | |
f47ed727 BH |
638 | if (data instanceof ITmfSourceLookup) { |
639 | ITmfSourceLookup event = (ITmfSourceLookup) data; | |
640 | ITmfCallsite cs = event.getCallsite(); | |
60fb38b8 PT |
641 | if (cs == null || cs.getFileName() == null) { |
642 | return; | |
643 | } | |
644 | IMarker marker = null; | |
645 | try { | |
646 | String fileName = cs.getFileName(); | |
647 | final String trimmedPath = fileName.replaceAll("\\.\\./", ""); //$NON-NLS-1$ //$NON-NLS-2$ | |
507b1336 | 648 | final ArrayList<IFile> files = new ArrayList<>(); |
60fb38b8 PT |
649 | ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() { |
650 | @Override | |
651 | public boolean visit(IResource resource) throws CoreException { | |
652 | if (resource instanceof IFile && resource.getFullPath().toString().endsWith(trimmedPath)) { | |
653 | files.add((IFile) resource); | |
654 | } | |
655 | return true; | |
656 | } | |
657 | }); | |
658 | IFile file = null; | |
659 | if (files.size() > 1) { | |
660 | ListDialog dialog = new ListDialog(getTable().getShell()); | |
661 | dialog.setContentProvider(ArrayContentProvider.getInstance()); | |
662 | dialog.setLabelProvider(new LabelProvider() { | |
663 | @Override | |
664 | public String getText(Object element) { | |
665 | return ((IFile) element).getFullPath().toString(); | |
666 | } | |
667 | }); | |
668 | dialog.setInput(files); | |
029df6e3 JCK |
669 | dialog.setTitle(Messages.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle); |
670 | dialog.setMessage(Messages.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle + '\n' + cs.toString()); | |
60fb38b8 PT |
671 | dialog.open(); |
672 | Object[] result = dialog.getResult(); | |
673 | if (result != null && result.length > 0) { | |
674 | file = (IFile) result[0]; | |
675 | } | |
676 | } else if (files.size() == 1) { | |
677 | file = files.get(0); | |
678 | } | |
679 | if (file != null) { | |
680 | marker = file.createMarker(IMarker.MARKER); | |
681 | marker.setAttribute(IMarker.LINE_NUMBER, Long.valueOf(cs.getLineNumber()).intValue()); | |
682 | IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker); | |
683 | marker.delete(); | |
684 | } else if (files.size() == 0){ | |
029df6e3 | 685 | displayException(new FileNotFoundException('\'' + cs.toString() + '\'' + '\n' + Messages.TmfEventsTable_OpenSourceCodeNotFound)); |
60fb38b8 | 686 | } |
60fb38b8 | 687 | } catch (CoreException e) { |
8e95e814 | 688 | displayException(e); |
60fb38b8 PT |
689 | } |
690 | } | |
691 | } | |
692 | }; | |
693 | ||
694 | final IAction openModelAction = new Action(Messages.TmfEventsTable_OpenModelActionText) { | |
ac44ef71 AR |
695 | @Override |
696 | public void run() { | |
697 | ||
698 | final TableItem items[] = fTable.getSelection(); | |
699 | if (items.length != 1) { | |
700 | return; | |
701 | } | |
702 | final TableItem item = items[0]; | |
703 | ||
704 | final Object eventData = item.getData(); | |
f47ed727 BH |
705 | if (eventData instanceof ITmfModelLookup) { |
706 | String modelURI = ((ITmfModelLookup) eventData).getModelUri(); | |
ac44ef71 AR |
707 | |
708 | if (modelURI != null) { | |
709 | IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
710 | ||
711 | IFile file = null; | |
712 | final URI uri = URI.createURI(modelURI); | |
713 | if (uri.isPlatformResource()) { | |
714 | IPath path = new Path(uri.toPlatformString(true)); | |
715 | file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); | |
716 | } else if (uri.isFile() && !uri.isRelative()) { | |
717 | file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( | |
718 | new Path(uri.toFileString())); | |
719 | } | |
720 | ||
721 | if (file != null) { | |
722 | try { | |
723 | /* | |
724 | * create a temporary validation marker on the | |
725 | * model file, remove it afterwards thus, | |
726 | * navigation works with all model editors | |
727 | * supporting the navigation to a marker | |
728 | */ | |
729 | IMarker marker = file.createMarker(EValidator.MARKER); | |
730 | marker.setAttribute(EValidator.URI_ATTRIBUTE, modelURI); | |
731 | marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); | |
732 | ||
733 | IDE.openEditor(activePage, marker, OpenStrategy.activateOnOpen()); | |
734 | marker.delete(); | |
735 | } | |
736 | catch (CoreException e) { | |
737 | displayException(e); | |
738 | } | |
60fb38b8 PT |
739 | } else { |
740 | displayException(new FileNotFoundException('\'' + modelURI + '\'' + '\n' + Messages.TmfEventsTable_OpenModelUnsupportedURI)); | |
ac44ef71 AR |
741 | } |
742 | } | |
743 | } | |
744 | } | |
745 | }; | |
60fb38b8 | 746 | |
d3de0920 XR |
747 | final IAction exportToTextAction = new Action(Messages.TmfEventsTable_Export_to_text) { |
748 | @Override | |
749 | public void run() { | |
750 | IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
751 | IHandlerService handlerService = (IHandlerService) activePage.getActiveEditor().getSite().getService(IHandlerService.class); | |
752 | ICommandService cmdService = (ICommandService) activePage.getActiveEditor().getSite().getService(ICommandService.class); | |
753 | try { | |
507b1336 | 754 | HashMap<String, Object> parameters = new HashMap<>(); |
d3de0920 XR |
755 | StringBuilder header = new StringBuilder(); |
756 | boolean needTab = false; | |
757 | for (TableColumn tc: fTable.getColumns()) { | |
758 | if (needTab) { | |
759 | header.append('\t'); | |
760 | } | |
761 | header.append(tc.getText()); | |
762 | needTab = true; | |
763 | } | |
764 | Command command = cmdService.getCommand(ExportToTextCommandHandler.COMMAND_ID); | |
765 | ParameterizedCommand cmd = ParameterizedCommand.generateCommand(command,parameters); | |
766 | IEvaluationContext context = handlerService.getCurrentState(); | |
767 | context.addVariable(ExportToTextCommandHandler.TMF_EVENT_TABLE_HEADER_ID, header.toString()); | |
768 | context.addVariable(ExportToTextCommandHandler.TMF_EVENT_TABLE_PARAMETER_ID, TmfEventsTable.this); | |
769 | handlerService.executeCommandInContext(cmd, null, context); | |
770 | } catch (ExecutionException e) { | |
771 | displayException(e); | |
772 | } catch (NotDefinedException e) { | |
773 | displayException(e); | |
774 | } catch (NotEnabledException e) { | |
775 | displayException(e); | |
776 | } catch (NotHandledException e) { | |
777 | displayException(e); | |
778 | } | |
779 | } | |
780 | }; | |
781 | ||
db4721fb PT |
782 | final IAction showSearchBarAction = new Action(Messages.TmfEventsTable_ShowSearchBarActionText) { |
783 | @Override | |
784 | public void run() { | |
785 | fHeaderState = HeaderState.SEARCH; | |
786 | fTable.refresh(); | |
787 | } | |
788 | }; | |
789 | ||
790 | final IAction showFilterBarAction = new Action(Messages.TmfEventsTable_ShowFilterBarActionText) { | |
791 | @Override | |
792 | public void run() { | |
793 | fHeaderState = HeaderState.FILTER; | |
794 | fTable.refresh(); | |
795 | } | |
796 | }; | |
797 | ||
798 | final IAction clearFiltersAction = new Action(Messages.TmfEventsTable_ClearFiltersActionText) { | |
799 | @Override | |
800 | public void run() { | |
801 | clearFilters(); | |
802 | } | |
803 | }; | |
804 | ||
805 | class ToggleBookmarkAction extends Action { | |
806 | long fRank; | |
807 | ||
808 | public ToggleBookmarkAction(final String text, final long rank) { | |
809 | super(text); | |
810 | fRank = rank; | |
811 | } | |
812 | ||
813 | @Override | |
814 | public void run() { | |
815 | toggleBookmark(fRank); | |
816 | } | |
817 | } | |
818 | ||
819 | final MenuManager tablePopupMenu = new MenuManager(); | |
820 | tablePopupMenu.setRemoveAllWhenShown(true); | |
821 | tablePopupMenu.addMenuListener(new IMenuListener() { | |
822 | @Override | |
823 | public void menuAboutToShow(final IMenuManager manager) { | |
824 | if (fTable.getSelectionIndex() == 0) { | |
825 | // Right-click on header row | |
826 | if (fHeaderState == HeaderState.FILTER) { | |
827 | tablePopupMenu.add(showSearchBarAction); | |
828 | } else { | |
829 | tablePopupMenu.add(showFilterBarAction); | |
830 | } | |
831 | return; | |
832 | } | |
833 | final Point point = fTable.toControl(Display.getDefault().getCursorLocation()); | |
834 | final TableItem item = fTable.getSelection().length > 0 ? fTable.getSelection()[0] : null; | |
835 | if (item != null) { | |
836 | final Rectangle imageBounds = item.getImageBounds(0); | |
837 | imageBounds.width = BOOKMARK_IMAGE.getBounds().width; | |
838 | if (point.x <= (imageBounds.x + imageBounds.width)) { | |
839 | // Right-click on left margin | |
840 | final Long rank = (Long) item.getData(Key.RANK); | |
841 | if ((rank != null) && (fBookmarksFile != null)) { | |
842 | if (fBookmarksMap.containsKey(rank)) { | |
843 | tablePopupMenu.add(new ToggleBookmarkAction( | |
844 | Messages.TmfEventsTable_RemoveBookmarkActionText, rank)); | |
845 | } else { | |
846 | tablePopupMenu.add(new ToggleBookmarkAction( | |
847 | Messages.TmfEventsTable_AddBookmarkActionText, rank)); | |
848 | } | |
849 | } | |
850 | return; | |
851 | } | |
852 | } | |
60fb38b8 | 853 | |
db4721fb PT |
854 | // Right-click on table |
855 | if (fTable.isVisible() && fRawViewer.isVisible()) { | |
856 | tablePopupMenu.add(hideTableAction); | |
857 | tablePopupMenu.add(hideRawAction); | |
858 | } else if (!fTable.isVisible()) { | |
859 | tablePopupMenu.add(showTableAction); | |
860 | } else if (!fRawViewer.isVisible()) { | |
861 | tablePopupMenu.add(showRawAction); | |
862 | } | |
d3de0920 | 863 | tablePopupMenu.add(exportToTextAction); |
db4721fb | 864 | tablePopupMenu.add(new Separator()); |
60fb38b8 | 865 | |
ac44ef71 | 866 | if (item != null) { |
60fb38b8 | 867 | final Object data = item.getData(); |
f47ed727 BH |
868 | Separator separator = null; |
869 | if (data instanceof ITmfSourceLookup) { | |
870 | ITmfSourceLookup event = (ITmfSourceLookup) data; | |
60fb38b8 PT |
871 | if (event.getCallsite() != null) { |
872 | tablePopupMenu.add(openCallsiteAction); | |
873 | separator = new Separator(); | |
874 | } | |
f47ed727 BH |
875 | } |
876 | ||
877 | if (data instanceof ITmfModelLookup) { | |
878 | ITmfModelLookup event = (ITmfModelLookup) data; | |
879 | if (event.getModelUri() != null) { | |
60fb38b8 PT |
880 | tablePopupMenu.add(openModelAction); |
881 | separator = new Separator(); | |
882 | } | |
f47ed727 | 883 | |
60fb38b8 PT |
884 | if (separator != null) { |
885 | tablePopupMenu.add(separator); | |
ac44ef71 AR |
886 | } |
887 | } | |
888 | } | |
60fb38b8 | 889 | |
db4721fb PT |
890 | tablePopupMenu.add(clearFiltersAction); |
891 | final ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters(); | |
892 | if (savedFilters.length > 0) { | |
893 | final MenuManager subMenu = new MenuManager(Messages.TmfEventsTable_ApplyPresetFilterMenuName); | |
894 | for (final ITmfFilterTreeNode node : savedFilters) { | |
895 | if (node instanceof TmfFilterNode) { | |
896 | final TmfFilterNode filter = (TmfFilterNode) node; | |
897 | subMenu.add(new Action(filter.getFilterName()) { | |
898 | @Override | |
899 | public void run() { | |
900 | applyFilter(filter); | |
901 | } | |
902 | }); | |
903 | } | |
904 | } | |
905 | tablePopupMenu.add(subMenu); | |
906 | } | |
907 | appendToTablePopupMenu(tablePopupMenu, item); | |
908 | } | |
909 | }); | |
910 | ||
911 | final MenuManager rawViewerPopupMenu = new MenuManager(); | |
912 | rawViewerPopupMenu.setRemoveAllWhenShown(true); | |
913 | rawViewerPopupMenu.addMenuListener(new IMenuListener() { | |
914 | @Override | |
915 | public void menuAboutToShow(final IMenuManager manager) { | |
916 | if (fTable.isVisible() && fRawViewer.isVisible()) { | |
917 | rawViewerPopupMenu.add(hideTableAction); | |
918 | rawViewerPopupMenu.add(hideRawAction); | |
919 | } else if (!fTable.isVisible()) { | |
920 | rawViewerPopupMenu.add(showTableAction); | |
921 | } else if (!fRawViewer.isVisible()) { | |
922 | rawViewerPopupMenu.add(showRawAction); | |
923 | } | |
924 | appendToRawPopupMenu(tablePopupMenu); | |
925 | } | |
926 | }); | |
927 | ||
928 | Menu menu = tablePopupMenu.createContextMenu(fTable); | |
929 | fTable.setMenu(menu); | |
930 | ||
931 | menu = rawViewerPopupMenu.createContextMenu(fRawViewer); | |
932 | fRawViewer.setMenu(menu); | |
933 | } | |
934 | ||
f8177ba2 | 935 | |
a0a88f65 AM |
936 | /** |
937 | * Append an item to the event table's pop-up menu. | |
938 | * | |
939 | * @param tablePopupMenu | |
940 | * The menu manager | |
941 | * @param selectedItem | |
942 | * The item to append | |
943 | */ | |
db4721fb PT |
944 | protected void appendToTablePopupMenu(final MenuManager tablePopupMenu, final TableItem selectedItem) { |
945 | // override to append more actions | |
946 | } | |
947 | ||
a0a88f65 AM |
948 | /** |
949 | * Append an item to the raw viewer's pop-up menu. | |
950 | * | |
951 | * @param rawViewerPopupMenu | |
952 | * The menu manager | |
953 | */ | |
db4721fb PT |
954 | protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu) { |
955 | // override to append more actions | |
956 | } | |
957 | ||
958 | @Override | |
959 | public void dispose() { | |
960 | stopSearchThread(); | |
961 | stopFilterThread(); | |
962 | ColorSettingsManager.removeColorSettingsListener(this); | |
963 | fComposite.dispose(); | |
964 | if ((fTrace != null) && fDisposeOnClose) { | |
965 | fTrace.dispose(); | |
966 | } | |
967 | fResourceManager.dispose(); | |
968 | super.dispose(); | |
969 | } | |
970 | ||
971 | /** | |
972 | * Assign a layout data object to this view. | |
973 | * | |
974 | * @param layoutData | |
975 | * The layout data to assign | |
976 | */ | |
977 | public void setLayoutData(final Object layoutData) { | |
978 | fComposite.setLayoutData(layoutData); | |
979 | } | |
980 | ||
981 | /** | |
982 | * Get the virtual table contained in this event table. | |
983 | * | |
984 | * @return The TMF virtual table | |
985 | */ | |
986 | public TmfVirtualTable getTable() { | |
987 | return fTable; | |
988 | } | |
989 | ||
990 | /** | |
991 | * @param columnData | |
992 | * | |
993 | * FIXME: Add support for column selection | |
994 | */ | |
995 | protected void setColumnHeaders(final ColumnData[] columnData) { | |
996 | fTable.setColumnHeaders(columnData); | |
997 | } | |
998 | ||
a0a88f65 AM |
999 | /** |
1000 | * Set a table item's data. | |
1001 | * | |
1002 | * @param item | |
1003 | * The item to set | |
1004 | * @param event | |
1005 | * Which trace event to link with this entry | |
1006 | * @param rank | |
1007 | * Which rank this event has in the trace/experiment | |
1008 | */ | |
db4721fb PT |
1009 | protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) { |
1010 | final ITmfEventField[] fields = extractItemFields(event); | |
1011 | final String[] content = new String[fields.length]; | |
1012 | for (int i = 0; i < fields.length; i++) { | |
1013 | content[i] = fields[i].getValue() != null ? fields[i].getValue().toString() : ""; //$NON-NLS-1$ | |
1014 | } | |
1015 | item.setText(content); | |
93bfd50a | 1016 | item.setData(event); |
db4721fb PT |
1017 | item.setData(Key.TIMESTAMP, new TmfTimestamp(event.getTimestamp())); |
1018 | item.setData(Key.RANK, rank); | |
1019 | ||
1020 | boolean bookmark = false; | |
1021 | final Long markerId = fBookmarksMap.get(rank); | |
1022 | if (markerId != null) { | |
1023 | bookmark = true; | |
1024 | try { | |
1025 | final IMarker marker = fBookmarksFile.findMarker(markerId); | |
1026 | item.setData(Key.BOOKMARK, marker.getAttribute(IMarker.MESSAGE)); | |
1027 | } catch (final CoreException e) { | |
1028 | displayException(e); | |
1029 | } | |
1030 | } else { | |
1031 | item.setData(Key.BOOKMARK, null); | |
1032 | } | |
1033 | ||
1034 | boolean searchMatch = false; | |
1035 | boolean searchNoMatch = false; | |
1036 | final ITmfFilter searchFilter = (ITmfFilter) fTable.getData(Key.SEARCH_OBJ); | |
1037 | if (searchFilter != null) { | |
1038 | if (searchFilter.matches(event)) { | |
1039 | searchMatch = true; | |
1040 | } else { | |
1041 | searchNoMatch = true; | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | final ColorSetting colorSetting = ColorSettingsManager.getColorSetting(event); | |
1046 | if (searchNoMatch) { | |
1047 | item.setForeground(colorSetting.getDimmedForegroundColor()); | |
1048 | item.setBackground(colorSetting.getDimmedBackgroundColor()); | |
1049 | } else { | |
1050 | item.setForeground(colorSetting.getForegroundColor()); | |
1051 | item.setBackground(colorSetting.getBackgroundColor()); | |
1052 | } | |
1053 | ||
1054 | if (searchMatch) { | |
1055 | if (bookmark) { | |
1056 | item.setImage(SEARCH_MATCH_BOOKMARK_IMAGE); | |
1057 | } else { | |
1058 | item.setImage(SEARCH_MATCH_IMAGE); | |
1059 | } | |
1060 | } else if (bookmark) { | |
1061 | item.setImage(BOOKMARK_IMAGE); | |
1062 | } else { | |
1063 | item.setImage((Image) null); | |
1064 | } | |
1065 | } | |
1066 | ||
a0a88f65 AM |
1067 | /** |
1068 | * Set the item data of the header row. | |
1069 | * | |
1070 | * @param item | |
1071 | * The item to use as table header | |
1072 | */ | |
db4721fb PT |
1073 | protected void setHeaderRowItemData(final TableItem item) { |
1074 | String txtKey = null; | |
1075 | if (fHeaderState == HeaderState.SEARCH) { | |
1076 | item.setImage(SEARCH_IMAGE); | |
1077 | txtKey = Key.SEARCH_TXT; | |
1078 | } else if (fHeaderState == HeaderState.FILTER) { | |
1079 | item.setImage(FILTER_IMAGE); | |
1080 | txtKey = Key.FILTER_TXT; | |
1081 | } | |
1082 | item.setForeground(fGrayColor); | |
1083 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
1084 | final TableColumn column = fTable.getColumns()[i]; | |
1085 | final String filter = (String) column.getData(txtKey); | |
1086 | if (filter == null) { | |
1087 | if (fHeaderState == HeaderState.SEARCH) { | |
1088 | item.setText(i, SEARCH_HINT); | |
1089 | } else if (fHeaderState == HeaderState.FILTER) { | |
1090 | item.setText(i, FILTER_HINT); | |
1091 | } | |
1092 | item.setForeground(i, fGrayColor); | |
1093 | item.setFont(i, fTable.getFont()); | |
1094 | } else { | |
1095 | item.setText(i, filter); | |
1096 | item.setForeground(i, fGreenColor); | |
1097 | item.setFont(i, fBoldFont); | |
1098 | } | |
1099 | } | |
1100 | } | |
1101 | ||
a0a88f65 AM |
1102 | /** |
1103 | * Set the item data of the "filter status" row. | |
1104 | * | |
1105 | * @param item | |
1106 | * The item to use as filter status row | |
1107 | */ | |
db4721fb PT |
1108 | protected void setFilterStatusRowItemData(final TableItem item) { |
1109 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
1110 | if (i == 0) { | |
1111 | if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents())) { | |
1112 | item.setImage(FILTER_IMAGE); | |
1113 | } else { | |
1114 | item.setImage(STOP_IMAGE); | |
1115 | } | |
1116 | item.setText(0, fFilterMatchCount + "/" + fFilterCheckCount); //$NON-NLS-1$ | |
1117 | } else { | |
1118 | item.setText(i, ""); //$NON-NLS-1$ | |
1119 | } | |
1120 | } | |
93bfd50a | 1121 | item.setData(null); |
db4721fb PT |
1122 | item.setData(Key.TIMESTAMP, null); |
1123 | item.setData(Key.RANK, null); | |
1124 | item.setForeground(null); | |
1125 | item.setBackground(null); | |
1126 | } | |
1127 | ||
a0a88f65 AM |
1128 | /** |
1129 | * Create an editor for the header. | |
1130 | */ | |
db4721fb PT |
1131 | protected void createHeaderEditor() { |
1132 | final TableEditor tableEditor = fTable.createTableEditor(); | |
1133 | tableEditor.horizontalAlignment = SWT.LEFT; | |
1134 | tableEditor.verticalAlignment = SWT.CENTER; | |
1135 | tableEditor.grabHorizontal = true; | |
1136 | tableEditor.minimumWidth = 50; | |
1137 | ||
1138 | // Handle the header row selection | |
1139 | fTable.addMouseListener(new MouseAdapter() { | |
1140 | int columnIndex; | |
1141 | TableColumn column; | |
1142 | TableItem item; | |
1143 | ||
1144 | @Override | |
1145 | public void mouseDown(final MouseEvent event) { | |
1146 | if (event.button != 1) { | |
1147 | return; | |
1148 | } | |
1149 | // Identify the selected row | |
1150 | final Point point = new Point(event.x, event.y); | |
1151 | item = fTable.getItem(point); | |
1152 | ||
1153 | // Header row selected | |
1154 | if ((item != null) && (fTable.indexOf(item) == 0)) { | |
1155 | ||
1156 | // Icon selected | |
1157 | if (item.getImageBounds(0).contains(point)) { | |
1158 | if (fHeaderState == HeaderState.SEARCH) { | |
1159 | fHeaderState = HeaderState.FILTER; | |
1160 | } else if (fHeaderState == HeaderState.FILTER) { | |
1161 | fHeaderState = HeaderState.SEARCH; | |
1162 | } | |
3f43dc48 | 1163 | fTable.setSelection(0); |
db4721fb PT |
1164 | fTable.refresh(); |
1165 | return; | |
1166 | } | |
1167 | ||
1168 | // Identify the selected column | |
1169 | columnIndex = -1; | |
1170 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
1171 | final Rectangle rect = item.getBounds(i); | |
1172 | if (rect.contains(point)) { | |
1173 | columnIndex = i; | |
1174 | break; | |
1175 | } | |
1176 | } | |
1177 | ||
1178 | if (columnIndex == -1) { | |
1179 | return; | |
1180 | } | |
1181 | ||
1182 | column = fTable.getColumns()[columnIndex]; | |
1183 | ||
1184 | String txtKey = null; | |
1185 | if (fHeaderState == HeaderState.SEARCH) { | |
1186 | txtKey = Key.SEARCH_TXT; | |
1187 | } else if (fHeaderState == HeaderState.FILTER) { | |
1188 | txtKey = Key.FILTER_TXT; | |
1189 | } | |
1190 | ||
1191 | // The control that will be the editor must be a child of the Table | |
1192 | final Text newEditor = (Text) fTable.createTableEditorControl(Text.class); | |
1193 | final String headerString = (String) column.getData(txtKey); | |
1194 | if (headerString != null) { | |
1195 | newEditor.setText(headerString); | |
1196 | } | |
1197 | newEditor.addFocusListener(new FocusAdapter() { | |
1198 | @Override | |
1199 | public void focusLost(final FocusEvent e) { | |
1200 | final boolean changed = updateHeader(newEditor.getText()); | |
1201 | if (changed) { | |
1202 | applyHeader(); | |
1203 | } | |
1204 | } | |
1205 | }); | |
1206 | newEditor.addKeyListener(new KeyAdapter() { | |
1207 | @Override | |
1208 | public void keyPressed(final KeyEvent e) { | |
1209 | if (e.character == SWT.CR) { | |
1210 | updateHeader(newEditor.getText()); | |
1211 | applyHeader(); | |
1212 | } else if (e.character == SWT.ESC) { | |
1213 | tableEditor.getEditor().dispose(); | |
1214 | } | |
1215 | } | |
1216 | }); | |
1217 | newEditor.selectAll(); | |
1218 | newEditor.setFocus(); | |
1219 | tableEditor.setEditor(newEditor, item, columnIndex); | |
1220 | } | |
1221 | } | |
1222 | ||
1223 | /* | |
1224 | * returns true is value was changed | |
1225 | */ | |
1226 | private boolean updateHeader(final String text) { | |
1227 | String objKey = null; | |
1228 | String txtKey = null; | |
1229 | if (fHeaderState == HeaderState.SEARCH) { | |
1230 | objKey = Key.SEARCH_OBJ; | |
1231 | txtKey = Key.SEARCH_TXT; | |
1232 | } else if (fHeaderState == HeaderState.FILTER) { | |
1233 | objKey = Key.FILTER_OBJ; | |
1234 | txtKey = Key.FILTER_TXT; | |
1235 | } | |
1236 | if (text.trim().length() > 0) { | |
1237 | try { | |
1238 | final String regex = TmfFilterMatchesNode.regexFix(text); | |
1239 | Pattern.compile(regex); | |
1240 | if (regex.equals(column.getData(txtKey))) { | |
1241 | tableEditor.getEditor().dispose(); | |
1242 | return false; | |
1243 | } | |
1244 | final TmfFilterMatchesNode filter = new TmfFilterMatchesNode(null); | |
1245 | String fieldId = (String) column.getData(Key.FIELD_ID); | |
1246 | if (fieldId == null) { | |
1247 | fieldId = column.getText(); | |
1248 | } | |
1249 | filter.setField(fieldId); | |
1250 | filter.setRegex(regex); | |
1251 | column.setData(objKey, filter); | |
1252 | column.setData(txtKey, regex); | |
1253 | } catch (final PatternSyntaxException ex) { | |
1254 | tableEditor.getEditor().dispose(); | |
1255 | MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
1256 | ex.getDescription(), ex.getMessage()); | |
1257 | return false; | |
1258 | } | |
1259 | } else { | |
1260 | if (column.getData(txtKey) == null) { | |
1261 | tableEditor.getEditor().dispose(); | |
1262 | return false; | |
1263 | } | |
1264 | column.setData(objKey, null); | |
1265 | column.setData(txtKey, null); | |
1266 | } | |
1267 | return true; | |
1268 | } | |
1269 | ||
1270 | private void applyHeader() { | |
1271 | if (fHeaderState == HeaderState.SEARCH) { | |
1272 | stopSearchThread(); | |
1273 | final TmfFilterAndNode filter = new TmfFilterAndNode(null); | |
3dca7aa5 AM |
1274 | for (final TableColumn col : fTable.getColumns()) { |
1275 | final Object filterObj = col.getData(Key.SEARCH_OBJ); | |
db4721fb PT |
1276 | if (filterObj instanceof ITmfFilterTreeNode) { |
1277 | filter.addChild((ITmfFilterTreeNode) filterObj); | |
1278 | } | |
1279 | } | |
1280 | if (filter.getChildrenCount() > 0) { | |
1281 | fTable.setData(Key.SEARCH_OBJ, filter); | |
1282 | fTable.refresh(); | |
1283 | searchNext(); | |
1284 | fireSearchApplied(filter); | |
1285 | } else { | |
1286 | fTable.setData(Key.SEARCH_OBJ, null); | |
1287 | fTable.refresh(); | |
1288 | fireSearchApplied(null); | |
1289 | } | |
1290 | } else if (fHeaderState == HeaderState.FILTER) { | |
1291 | final TmfFilterAndNode filter = new TmfFilterAndNode(null); | |
3dca7aa5 AM |
1292 | for (final TableColumn col : fTable.getColumns()) { |
1293 | final Object filterObj = col.getData(Key.FILTER_OBJ); | |
db4721fb PT |
1294 | if (filterObj instanceof ITmfFilterTreeNode) { |
1295 | filter.addChild((ITmfFilterTreeNode) filterObj); | |
1296 | } | |
1297 | } | |
1298 | if (filter.getChildrenCount() > 0) { | |
1299 | applyFilter(filter); | |
1300 | } else { | |
1301 | clearFilters(); | |
1302 | } | |
1303 | } | |
1304 | ||
1305 | tableEditor.getEditor().dispose(); | |
1306 | } | |
1307 | }); | |
1308 | ||
1309 | fTable.addKeyListener(new KeyAdapter() { | |
1310 | @Override | |
1311 | public void keyPressed(final KeyEvent e) { | |
1312 | e.doit = false; | |
1313 | if (e.character == SWT.ESC) { | |
1314 | stopFilterThread(); | |
1315 | stopSearchThread(); | |
1316 | fTable.refresh(); | |
1317 | } else if (e.character == SWT.DEL) { | |
1318 | if (fHeaderState == HeaderState.SEARCH) { | |
1319 | stopSearchThread(); | |
1320 | for (final TableColumn column : fTable.getColumns()) { | |
1321 | column.setData(Key.SEARCH_OBJ, null); | |
1322 | column.setData(Key.SEARCH_TXT, null); | |
1323 | } | |
1324 | fTable.setData(Key.SEARCH_OBJ, null); | |
1325 | fTable.refresh(); | |
1326 | fireSearchApplied(null); | |
1327 | } else if (fHeaderState == HeaderState.FILTER) { | |
1328 | clearFilters(); | |
1329 | } | |
1330 | } else if (e.character == SWT.CR) { | |
1331 | if ((e.stateMask & SWT.SHIFT) == 0) { | |
1332 | searchNext(); | |
1333 | } else { | |
1334 | searchPrevious(); | |
1335 | } | |
1336 | } | |
1337 | } | |
1338 | }); | |
1339 | } | |
1340 | ||
a0a88f65 AM |
1341 | /** |
1342 | * Send an event indicating a filter has been applied. | |
1343 | * | |
1344 | * @param filter | |
1345 | * The filter that was just applied | |
1346 | */ | |
db4721fb | 1347 | protected void fireFilterApplied(final ITmfFilter filter) { |
faa38350 | 1348 | broadcast(new TmfEventFilterAppliedSignal(this, fTrace, filter)); |
db4721fb PT |
1349 | } |
1350 | ||
a0a88f65 AM |
1351 | /** |
1352 | * Send an event indicating that a search has been applied. | |
1353 | * | |
1354 | * @param filter | |
1355 | * The search filter that was just applied | |
1356 | */ | |
db4721fb | 1357 | protected void fireSearchApplied(final ITmfFilter filter) { |
faa38350 | 1358 | broadcast(new TmfEventSearchAppliedSignal(this, fTrace, filter)); |
db4721fb PT |
1359 | } |
1360 | ||
a0a88f65 AM |
1361 | /** |
1362 | * Start the filtering thread. | |
1363 | */ | |
db4721fb PT |
1364 | protected void startFilterThread() { |
1365 | synchronized (fFilterSyncObj) { | |
1366 | final ITmfFilterTreeNode filter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ); | |
1367 | if (fFilterThread == null || fFilterThread.filter != filter) { | |
1368 | if (fFilterThread != null) { | |
1369 | fFilterThread.cancel(); | |
1370 | fFilterThreadResume = false; | |
1371 | } | |
1372 | fFilterThread = new FilterThread(filter); | |
1373 | fFilterThread.start(); | |
1374 | } else { | |
1375 | fFilterThreadResume = true; | |
1376 | } | |
1377 | } | |
1378 | } | |
1379 | ||
a0a88f65 AM |
1380 | /** |
1381 | * Stop the filtering thread. | |
1382 | */ | |
db4721fb PT |
1383 | protected void stopFilterThread() { |
1384 | synchronized (fFilterSyncObj) { | |
1385 | if (fFilterThread != null) { | |
1386 | fFilterThread.cancel(); | |
1387 | fFilterThread = null; | |
1388 | fFilterThreadResume = false; | |
1389 | } | |
1390 | } | |
1391 | } | |
1392 | ||
1393 | /** | |
a0a88f65 AM |
1394 | * Apply a filter. |
1395 | * | |
1396 | * @param filter | |
1397 | * The filter to apply | |
db4721fb PT |
1398 | * @since 1.1 |
1399 | */ | |
1400 | protected void applyFilter(ITmfFilter filter) { | |
f29f8868 BH |
1401 | stopFilterThread(); |
1402 | stopSearchThread(); | |
db4721fb PT |
1403 | fFilterMatchCount = 0; |
1404 | fFilterCheckCount = 0; | |
1405 | fCache.applyFilter(filter); | |
1406 | fTable.clearAll(); | |
1407 | fTable.setData(Key.FILTER_OBJ, filter); | |
1408 | fTable.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows | |
1409 | startFilterThread(); | |
1410 | fireFilterApplied(filter); | |
1411 | } | |
1412 | ||
a0a88f65 AM |
1413 | /** |
1414 | * Clear all currently active filters. | |
1415 | */ | |
db4721fb PT |
1416 | protected void clearFilters() { |
1417 | if (fTable.getData(Key.FILTER_OBJ) == null) { | |
1418 | return; | |
1419 | } | |
1420 | stopFilterThread(); | |
1421 | stopSearchThread(); | |
1422 | fCache.clearFilter(); | |
1423 | fTable.clearAll(); | |
1424 | for (final TableColumn column : fTable.getColumns()) { | |
1425 | column.setData(Key.FILTER_OBJ, null); | |
1426 | column.setData(Key.FILTER_TXT, null); | |
1427 | } | |
1428 | fTable.setData(Key.FILTER_OBJ, null); | |
1429 | if (fTrace != null) { | |
1430 | fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row | |
1431 | } else { | |
1432 | fTable.setItemCount(1); // +1 for header row | |
1433 | } | |
1434 | fFilterMatchCount = 0; | |
1435 | fFilterCheckCount = 0; | |
1436 | if (fSelectedRank >= 0) { | |
1437 | fTable.setSelection((int) fSelectedRank + 1); // +1 for header row | |
1438 | } else { | |
1439 | fTable.setSelection(0); | |
1440 | } | |
1441 | fireFilterApplied(null); | |
3f43dc48 | 1442 | updateStatusLine(null); |
db4721fb PT |
1443 | } |
1444 | ||
a0a88f65 AM |
1445 | /** |
1446 | * Wrapper Thread object for the filtering thread. | |
1447 | */ | |
db4721fb PT |
1448 | protected class FilterThread extends Thread { |
1449 | private final ITmfFilterTreeNode filter; | |
fd3f1eff | 1450 | private TmfEventRequest request; |
db4721fb PT |
1451 | private boolean refreshBusy = false; |
1452 | private boolean refreshPending = false; | |
1453 | private final Object syncObj = new Object(); | |
1454 | ||
a0a88f65 AM |
1455 | /** |
1456 | * Constructor. | |
1457 | * | |
1458 | * @param filter | |
1459 | * The filter this thread will be processing | |
1460 | */ | |
db4721fb PT |
1461 | public FilterThread(final ITmfFilterTreeNode filter) { |
1462 | super("Filter Thread"); //$NON-NLS-1$ | |
1463 | this.filter = filter; | |
1464 | } | |
1465 | ||
1466 | @Override | |
1467 | public void run() { | |
1468 | if (fTrace == null) { | |
1469 | return; | |
1470 | } | |
1471 | final int nbRequested = (int) (fTrace.getNbEvents() - fFilterCheckCount); | |
1472 | if (nbRequested <= 0) { | |
1473 | return; | |
1474 | } | |
fd3f1eff AM |
1475 | request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, |
1476 | (int) fFilterCheckCount, nbRequested, ExecutionType.BACKGROUND) { | |
db4721fb PT |
1477 | @Override |
1478 | public void handleData(final ITmfEvent event) { | |
1479 | super.handleData(event); | |
1480 | if (request.isCancelled()) { | |
1481 | return; | |
1482 | } | |
1483 | if (filter.matches(event)) { | |
1484 | final long rank = fFilterCheckCount; | |
1485 | final int index = (int) fFilterMatchCount; | |
1486 | fFilterMatchCount++; | |
bd54d363 | 1487 | fCache.storeEvent(event, rank, index); |
db4721fb PT |
1488 | refreshTable(); |
1489 | } else if ((fFilterCheckCount % 100) == 0) { | |
1490 | refreshTable(); | |
1491 | } | |
1492 | fFilterCheckCount++; | |
1493 | } | |
1494 | }; | |
fd3f1eff | 1495 | ((ITmfEventProvider) fTrace).sendRequest(request); |
db4721fb PT |
1496 | try { |
1497 | request.waitForCompletion(); | |
1498 | } catch (final InterruptedException e) { | |
1499 | } | |
1500 | refreshTable(); | |
1501 | synchronized (fFilterSyncObj) { | |
1502 | fFilterThread = null; | |
1503 | if (fFilterThreadResume) { | |
1504 | fFilterThreadResume = false; | |
1505 | fFilterThread = new FilterThread(filter); | |
1506 | fFilterThread.start(); | |
1507 | } | |
1508 | } | |
1509 | } | |
1510 | ||
a0a88f65 AM |
1511 | /** |
1512 | * Refresh the filter. | |
1513 | */ | |
db4721fb PT |
1514 | public void refreshTable() { |
1515 | synchronized (syncObj) { | |
1516 | if (refreshBusy) { | |
1517 | refreshPending = true; | |
1518 | return; | |
1519 | } | |
1520 | refreshBusy = true; | |
1521 | } | |
1522 | Display.getDefault().asyncExec(new Runnable() { | |
1523 | @Override | |
1524 | public void run() { | |
1525 | if (request.isCancelled()) { | |
1526 | return; | |
1527 | } | |
1528 | if (fTable.isDisposed()) { | |
1529 | return; | |
1530 | } | |
1531 | fTable.setItemCount((int) fFilterMatchCount + 3); // +1 for header row, +2 for top and bottom filter status rows | |
1532 | fTable.refresh(); | |
1533 | synchronized (syncObj) { | |
1534 | refreshBusy = false; | |
1535 | if (refreshPending) { | |
1536 | refreshPending = false; | |
1537 | refreshTable(); | |
1538 | } | |
1539 | } | |
1540 | } | |
1541 | }); | |
1542 | } | |
1543 | ||
a0a88f65 AM |
1544 | /** |
1545 | * Cancel this filtering thread. | |
1546 | */ | |
db4721fb PT |
1547 | public void cancel() { |
1548 | if (request != null) { | |
1549 | request.cancel(); | |
1550 | } | |
1551 | } | |
1552 | } | |
1553 | ||
a0a88f65 AM |
1554 | /** |
1555 | * Go to the next item of a search. | |
1556 | */ | |
db4721fb PT |
1557 | protected void searchNext() { |
1558 | synchronized (fSearchSyncObj) { | |
1559 | if (fSearchThread != null) { | |
1560 | return; | |
1561 | } | |
1562 | final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ); | |
1563 | if (searchFilter == null) { | |
1564 | return; | |
1565 | } | |
1566 | final int selectionIndex = fTable.getSelectionIndex(); | |
1567 | int startIndex; | |
1568 | if (selectionIndex > 0) { | |
1569 | startIndex = selectionIndex; // -1 for header row, +1 for next event | |
1570 | } else { | |
1571 | // header row is selected, start at top event | |
1572 | startIndex = Math.max(0, fTable.getTopIndex() - 1); // -1 for header row | |
1573 | } | |
1574 | final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ); | |
60fb38b8 | 1575 | if (eventFilter != null) { |
db4721fb PT |
1576 | startIndex = Math.max(0, startIndex - 1); // -1 for top filter status row |
1577 | } | |
1578 | fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.FORWARD); | |
1579 | fSearchThread.schedule(); | |
1580 | } | |
1581 | } | |
1582 | ||
a0a88f65 AM |
1583 | /** |
1584 | * Go to the previous item of a search. | |
1585 | */ | |
db4721fb PT |
1586 | protected void searchPrevious() { |
1587 | synchronized (fSearchSyncObj) { | |
1588 | if (fSearchThread != null) { | |
1589 | return; | |
1590 | } | |
1591 | final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ); | |
1592 | if (searchFilter == null) { | |
1593 | return; | |
1594 | } | |
1595 | final int selectionIndex = fTable.getSelectionIndex(); | |
1596 | int startIndex; | |
1597 | if (selectionIndex > 0) { | |
1598 | startIndex = selectionIndex - 2; // -1 for header row, -1 for previous event | |
1599 | } else { | |
1600 | // header row is selected, start at precedent of top event | |
1601 | startIndex = fTable.getTopIndex() - 2; // -1 for header row, -1 for previous event | |
1602 | } | |
1603 | final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ); | |
60fb38b8 | 1604 | if (eventFilter != null) { |
db4721fb PT |
1605 | startIndex = startIndex - 1; // -1 for top filter status row |
1606 | } | |
1607 | fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.BACKWARD); | |
1608 | fSearchThread.schedule(); | |
1609 | } | |
1610 | } | |
1611 | ||
a0a88f65 AM |
1612 | /** |
1613 | * Stop the search thread. | |
1614 | */ | |
db4721fb PT |
1615 | protected void stopSearchThread() { |
1616 | fPendingGotoRank = -1; | |
1617 | synchronized (fSearchSyncObj) { | |
1618 | if (fSearchThread != null) { | |
1619 | fSearchThread.cancel(); | |
1620 | fSearchThread = null; | |
1621 | } | |
1622 | } | |
1623 | } | |
1624 | ||
a0a88f65 AM |
1625 | /** |
1626 | * Wrapper for the search thread. | |
1627 | */ | |
db4721fb | 1628 | protected class SearchThread extends Job { |
a0a88f65 AM |
1629 | |
1630 | private ITmfFilterTreeNode searchFilter; | |
1631 | private ITmfFilterTreeNode eventFilter; | |
1632 | private int startIndex; | |
1633 | private int direction; | |
1634 | private long rank; | |
1635 | private long foundRank = -1; | |
fd3f1eff | 1636 | private TmfEventRequest request; |
ae3ffd37 | 1637 | private ITmfTimestamp foundTimestamp = null; |
db4721fb | 1638 | |
a0a88f65 AM |
1639 | /** |
1640 | * Constructor. | |
1641 | * | |
1642 | * @param searchFilter | |
1643 | * The search filter | |
1644 | * @param eventFilter | |
1645 | * The event filter | |
1646 | * @param startIndex | |
1647 | * The index at which we should start searching | |
1648 | * @param currentRank | |
1649 | * The current rank | |
1650 | * @param direction | |
1651 | * In which direction should we search, forward or backwards | |
1652 | */ | |
1653 | public SearchThread(final ITmfFilterTreeNode searchFilter, | |
1654 | final ITmfFilterTreeNode eventFilter, final int startIndex, | |
db4721fb PT |
1655 | final long currentRank, final int direction) { |
1656 | super(Messages.TmfEventsTable_SearchingJobName); | |
1657 | this.searchFilter = searchFilter; | |
1658 | this.eventFilter = eventFilter; | |
1659 | this.startIndex = startIndex; | |
1660 | this.rank = currentRank; | |
1661 | this.direction = direction; | |
1662 | } | |
1663 | ||
1664 | @Override | |
1665 | protected IStatus run(final IProgressMonitor monitor) { | |
1666 | if (fTrace == null) { | |
1667 | return Status.OK_STATUS; | |
1668 | } | |
1669 | final Display display = Display.getDefault(); | |
1670 | if (startIndex < 0) { | |
1671 | rank = (int) fTrace.getNbEvents() - 1; | |
1672 | } else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3))) { // -1 for header row, -2 for top and bottom filter status rows | |
1673 | rank = 0; | |
1674 | } else { | |
1675 | int idx = startIndex; | |
1676 | while (foundRank == -1) { | |
1677 | final CachedEvent event = fCache.peekEvent(idx); | |
1678 | if (event == null) { | |
1679 | break; | |
1680 | } | |
1681 | rank = event.rank; | |
1682 | if (searchFilter.matches(event.event) && ((eventFilter == null) || eventFilter.matches(event.event))) { | |
1683 | foundRank = event.rank; | |
ae3ffd37 | 1684 | foundTimestamp = event.event.getTimestamp(); |
db4721fb PT |
1685 | break; |
1686 | } | |
1687 | if (direction == Direction.FORWARD) { | |
1688 | idx++; | |
1689 | } else { | |
1690 | idx--; | |
1691 | } | |
1692 | } | |
1693 | if (foundRank == -1) { | |
1694 | if (direction == Direction.FORWARD) { | |
1695 | rank++; | |
1696 | if (rank > (fTrace.getNbEvents() - 1)) { | |
1697 | rank = 0; | |
1698 | } | |
1699 | } else { | |
1700 | rank--; | |
1701 | if (rank < 0) { | |
1702 | rank = (int) fTrace.getNbEvents() - 1; | |
1703 | } | |
1704 | } | |
1705 | } | |
1706 | } | |
1707 | final int startRank = (int) rank; | |
1708 | boolean wrapped = false; | |
1709 | while (!monitor.isCanceled() && (foundRank == -1) && (fTrace != null)) { | |
1710 | int nbRequested = (direction == Direction.FORWARD ? Integer.MAX_VALUE : Math.min((int) rank + 1, fTrace.getCacheSize())); | |
1711 | if (direction == Direction.BACKWARD) { | |
1712 | rank = Math.max(0, rank - fTrace.getCacheSize() + 1); | |
1713 | } | |
fd3f1eff AM |
1714 | request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, |
1715 | (int) rank, nbRequested, ExecutionType.BACKGROUND) { | |
db4721fb PT |
1716 | long currentRank = rank; |
1717 | ||
1718 | @Override | |
1719 | public void handleData(final ITmfEvent event) { | |
1720 | super.handleData(event); | |
1721 | if (searchFilter.matches(event) && ((eventFilter == null) || eventFilter.matches(event))) { | |
1722 | foundRank = currentRank; | |
ae3ffd37 | 1723 | foundTimestamp = event.getTimestamp(); |
db4721fb PT |
1724 | if (direction == Direction.FORWARD) { |
1725 | done(); | |
1726 | return; | |
1727 | } | |
1728 | } | |
1729 | currentRank++; | |
1730 | } | |
1731 | }; | |
fd3f1eff | 1732 | ((ITmfEventProvider) fTrace).sendRequest(request); |
db4721fb PT |
1733 | try { |
1734 | request.waitForCompletion(); | |
1735 | if (request.isCancelled()) { | |
1736 | return Status.OK_STATUS; | |
1737 | } | |
1738 | } catch (final InterruptedException e) { | |
1739 | synchronized (fSearchSyncObj) { | |
1740 | fSearchThread = null; | |
1741 | } | |
1742 | return Status.OK_STATUS; | |
1743 | } | |
1744 | if (foundRank == -1) { | |
1745 | if (direction == Direction.FORWARD) { | |
1746 | if (rank == 0) { | |
1747 | synchronized (fSearchSyncObj) { | |
1748 | fSearchThread = null; | |
1749 | } | |
1750 | return Status.OK_STATUS; | |
1751 | } | |
1752 | nbRequested = (int) rank; | |
1753 | rank = 0; | |
1754 | wrapped = true; | |
1755 | } else { | |
1756 | rank--; | |
1757 | if (rank < 0) { | |
1758 | rank = (int) fTrace.getNbEvents() - 1; | |
1759 | wrapped = true; | |
1760 | } | |
1761 | if ((rank <= startRank) && wrapped) { | |
1762 | synchronized (fSearchSyncObj) { | |
1763 | fSearchThread = null; | |
1764 | } | |
1765 | return Status.OK_STATUS; | |
1766 | } | |
1767 | } | |
1768 | } | |
1769 | } | |
1770 | int index = (int) foundRank; | |
1771 | if (eventFilter != null) { | |
1772 | index = fCache.getFilteredEventIndex(foundRank); | |
1773 | } | |
1774 | final int selection = index + 1 + (eventFilter != null ? +1 : 0); // +1 for header row, +1 for top filter status row | |
1775 | ||
1776 | display.asyncExec(new Runnable() { | |
1777 | @Override | |
1778 | public void run() { | |
1779 | if (monitor.isCanceled()) { | |
1780 | return; | |
1781 | } | |
1782 | if (fTable.isDisposed()) { | |
1783 | return; | |
1784 | } | |
1785 | fTable.setSelection(selection); | |
1786 | fSelectedRank = foundRank; | |
ae3ffd37 PT |
1787 | fRawViewer.selectAndReveal(fSelectedRank); |
1788 | if (foundTimestamp != null) { | |
1789 | broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, foundTimestamp)); | |
1790 | } | |
a56ec2b8 | 1791 | fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, getSelection())); |
db4721fb PT |
1792 | synchronized (fSearchSyncObj) { |
1793 | fSearchThread = null; | |
1794 | } | |
3f43dc48 | 1795 | updateStatusLine(null); |
db4721fb PT |
1796 | } |
1797 | }); | |
1798 | return Status.OK_STATUS; | |
1799 | } | |
1800 | ||
1801 | @Override | |
1802 | protected void canceling() { | |
1803 | request.cancel(); | |
1804 | synchronized (fSearchSyncObj) { | |
1805 | fSearchThread = null; | |
1806 | } | |
1807 | } | |
1808 | } | |
1809 | ||
a0a88f65 AM |
1810 | /** |
1811 | * Create the resources. | |
1812 | */ | |
db4721fb PT |
1813 | protected void createResources() { |
1814 | fGrayColor = fResourceManager.createColor(ColorUtil.blend(fTable.getBackground().getRGB(), fTable | |
1815 | .getForeground().getRGB())); | |
1816 | fGreenColor = fTable.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN); | |
1817 | fBoldFont = fResourceManager.createFont(FontDescriptor.createFrom(fTable.getFont()).setStyle(SWT.BOLD)); | |
1818 | } | |
1819 | ||
a0a88f65 AM |
1820 | /** |
1821 | * Pack the columns. | |
1822 | */ | |
db4721fb PT |
1823 | protected void packColumns() { |
1824 | if (fPackDone) { | |
1825 | return; | |
1826 | } | |
d3bc98ee EB |
1827 | fTable.setRedraw(false); |
1828 | ||
f29f8868 BH |
1829 | boolean isLinux = System.getProperty("os.name").contains("Linux") ? true : false; //$NON-NLS-1$ //$NON-NLS-2$ |
1830 | ||
1831 | TableColumn tableColumns[] = fTable.getColumns(); | |
1832 | for (int i = 0; i < tableColumns.length; i++) { | |
1833 | final TableColumn column = tableColumns[i]; | |
db4721fb PT |
1834 | final int headerWidth = column.getWidth(); |
1835 | column.pack(); | |
f29f8868 BH |
1836 | // Workaround for Linux which doesn't consider the image width of |
1837 | // search/filter row in TableColumn.pack() after having executed | |
1838 | // TableItem.setImage((Image)null) for other rows than search/filter row. | |
1839 | if (isLinux && (i == 0)) { | |
1840 | column.setWidth(column.getWidth() + SEARCH_IMAGE.getBounds().width); | |
1841 | } | |
1842 | ||
db4721fb PT |
1843 | if (column.getWidth() < headerWidth) { |
1844 | column.setWidth(headerWidth); | |
1845 | } | |
1846 | } | |
d3bc98ee EB |
1847 | |
1848 | fTable.setRedraw(true); | |
db4721fb PT |
1849 | fPackDone = true; |
1850 | } | |
1851 | ||
d3de0920 XR |
1852 | /** |
1853 | * Extract the fields of an event (item in the table). | |
1854 | * | |
1855 | * @param event | |
1856 | * The event to extract from | |
1857 | * @return The array of fields | |
1858 | * @since 2.2 | |
1859 | */ | |
1860 | public final ITmfEventField[] getItemFields(final ITmfEvent event) { | |
1861 | return extractItemFields(event); | |
1862 | } | |
1863 | ||
db4721fb | 1864 | /** |
a0a88f65 AM |
1865 | * Extract the fields of an event (item in the table). |
1866 | * | |
db4721fb | 1867 | * @param event |
a0a88f65 AM |
1868 | * The event to extract from |
1869 | * @return The array of fields | |
db4721fb PT |
1870 | * |
1871 | * FIXME: Add support for column selection | |
1872 | */ | |
1873 | protected ITmfEventField[] extractItemFields(final ITmfEvent event) { | |
d3de0920 | 1874 | ITmfEventField[] fields = EMPTY_FIELD_ARRAY; |
db4721fb PT |
1875 | if (event != null) { |
1876 | final String timestamp = event.getTimestamp().toString(); | |
1877 | final String source = event.getSource(); | |
1878 | final String type = event.getType().getName(); | |
1879 | final String reference = event.getReference(); | |
a4a6acf4 | 1880 | final String content = event.getContent().toString(); |
db4721fb | 1881 | fields = new TmfEventField[] { |
214cc822 AM |
1882 | new TmfEventField(ITmfEvent.EVENT_FIELD_TIMESTAMP, timestamp, null), |
1883 | new TmfEventField(ITmfEvent.EVENT_FIELD_SOURCE, source, null), | |
1884 | new TmfEventField(ITmfEvent.EVENT_FIELD_TYPE, type, null), | |
1885 | new TmfEventField(ITmfEvent.EVENT_FIELD_REFERENCE, reference, null), | |
1886 | new TmfEventField(ITmfEvent.EVENT_FIELD_CONTENT, content, null) | |
db4721fb PT |
1887 | }; |
1888 | } | |
1889 | return fields; | |
1890 | } | |
1891 | ||
1892 | /** | |
1893 | * Notify this table that is got the UI focus. | |
1894 | */ | |
1895 | public void setFocus() { | |
1896 | fTable.setFocus(); | |
1897 | } | |
1898 | ||
1899 | /** | |
1900 | * Assign a new trace to this event table. | |
1901 | * | |
1902 | * @param trace | |
1903 | * The trace to assign to this event table | |
1904 | * @param disposeOnClose | |
1905 | * true if the trace should be disposed when the table is | |
1906 | * disposed | |
1907 | */ | |
1908 | public void setTrace(final ITmfTrace trace, final boolean disposeOnClose) { | |
1909 | if ((fTrace != null) && fDisposeOnClose) { | |
1910 | fTrace.dispose(); | |
1911 | } | |
1912 | fTrace = trace; | |
1913 | fPackDone = false; | |
1914 | fSelectedRank = 0; | |
1915 | fDisposeOnClose = disposeOnClose; | |
1916 | ||
1917 | // Perform the updates on the UI thread | |
1918 | fTable.getDisplay().syncExec(new Runnable() { | |
1919 | @Override | |
1920 | public void run() { | |
1921 | fTable.removeAll(); | |
1922 | fCache.setTrace(fTrace); // Clear the cache | |
1923 | if (fTrace != null) { | |
1924 | if (!fTable.isDisposed() && (fTrace != null)) { | |
1925 | if (fTable.getData(Key.FILTER_OBJ) == null) { | |
1926 | fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row | |
1927 | } else { | |
1928 | stopFilterThread(); | |
1929 | fFilterMatchCount = 0; | |
1930 | fFilterCheckCount = 0; | |
1931 | fTable.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows | |
1932 | startFilterThread(); | |
1933 | } | |
1934 | } | |
db4721fb | 1935 | } |
ea279a69 | 1936 | fRawViewer.setTrace(fTrace); |
db4721fb PT |
1937 | } |
1938 | }); | |
1939 | } | |
1940 | ||
3f43dc48 PT |
1941 | /** |
1942 | * Assign the status line manager | |
1943 | * | |
1944 | * @param statusLineManager | |
1945 | * The status line manager, or null to disable status line messages | |
4b121c48 | 1946 | * @since 2.1 |
3f43dc48 PT |
1947 | */ |
1948 | public void setStatusLineManager(IStatusLineManager statusLineManager) { | |
1949 | if (fStatusLineManager != null && statusLineManager == null) { | |
1950 | fStatusLineManager.setMessage(""); //$NON-NLS-1$ | |
1951 | } | |
1952 | fStatusLineManager = statusLineManager; | |
1953 | } | |
1954 | ||
1955 | private void updateStatusLine(ITmfTimestamp delta) { | |
1956 | if (fStatusLineManager != null) { | |
1957 | if (delta != null) { | |
1958 | fStatusLineManager.setMessage("\u0394: " + delta); //$NON-NLS-1$ | |
1959 | } else { | |
1960 | fStatusLineManager.setMessage(null); | |
1961 | } | |
1962 | } | |
1963 | } | |
1964 | ||
db4721fb PT |
1965 | // ------------------------------------------------------------------------ |
1966 | // Event cache | |
1967 | // ------------------------------------------------------------------------ | |
1968 | ||
1969 | /** | |
1970 | * Notify that the event cache has been updated | |
1971 | * | |
1972 | * @param completed | |
1973 | * Also notify if the populating of the cache is complete, or | |
1974 | * not. | |
1975 | */ | |
1976 | public void cacheUpdated(final boolean completed) { | |
1977 | synchronized (fCacheUpdateSyncObj) { | |
1978 | if (fCacheUpdateBusy) { | |
1979 | fCacheUpdatePending = true; | |
1980 | fCacheUpdateCompleted = completed; | |
1981 | return; | |
1982 | } | |
1983 | fCacheUpdateBusy = true; | |
1984 | } | |
1985 | // Event cache is now updated. Perform update on the UI thread | |
1986 | if (!fTable.isDisposed()) { | |
1987 | fTable.getDisplay().asyncExec(new Runnable() { | |
1988 | @Override | |
1989 | public void run() { | |
1990 | if (!fTable.isDisposed()) { | |
1991 | fTable.refresh(); | |
1992 | packColumns(); | |
1993 | } | |
1994 | if (completed) { | |
1995 | populateCompleted(); | |
1996 | } | |
1997 | synchronized (fCacheUpdateSyncObj) { | |
1998 | fCacheUpdateBusy = false; | |
1999 | if (fCacheUpdatePending) { | |
2000 | fCacheUpdatePending = false; | |
2001 | cacheUpdated(fCacheUpdateCompleted); | |
2002 | } | |
2003 | } | |
2004 | } | |
2005 | }); | |
2006 | } | |
2007 | } | |
2008 | ||
a0a88f65 AM |
2009 | /** |
2010 | * Callback for when populating the table is complete. | |
2011 | */ | |
db4721fb PT |
2012 | protected void populateCompleted() { |
2013 | // Nothing by default; | |
2014 | } | |
2015 | ||
93bfd50a PT |
2016 | // ------------------------------------------------------------------------ |
2017 | // ISelectionProvider | |
2018 | // ------------------------------------------------------------------------ | |
2019 | ||
93bfd50a PT |
2020 | /** |
2021 | * @since 2.0 | |
2022 | */ | |
2023 | @Override | |
2024 | public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
2025 | selectionChangedListeners.add(listener); | |
2026 | } | |
2027 | ||
93bfd50a PT |
2028 | /** |
2029 | * @since 2.0 | |
2030 | */ | |
2031 | @Override | |
2032 | public ISelection getSelection() { | |
2033 | if (fTable == null || fTable.isDisposed()) { | |
2034 | return StructuredSelection.EMPTY; | |
2035 | } | |
507b1336 | 2036 | List<Object> list = new ArrayList<>(fTable.getSelection().length); |
93bfd50a PT |
2037 | for (TableItem item : fTable.getSelection()) { |
2038 | if (item.getData() != null) { | |
2039 | list.add(item.getData()); | |
2040 | } | |
2041 | } | |
2042 | return new StructuredSelection(list); | |
2043 | } | |
2044 | ||
93bfd50a PT |
2045 | /** |
2046 | * @since 2.0 | |
2047 | */ | |
2048 | @Override | |
2049 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { | |
2050 | selectionChangedListeners.remove(listener); | |
2051 | } | |
2052 | ||
93bfd50a PT |
2053 | /** |
2054 | * @since 2.0 | |
2055 | */ | |
2056 | @Override | |
2057 | public void setSelection(ISelection selection) { | |
2058 | // not implemented | |
2059 | } | |
2060 | ||
2061 | /** | |
2062 | * Notifies any selection changed listeners that the viewer's selection has changed. | |
2063 | * Only listeners registered at the time this method is called are notified. | |
2064 | * | |
2065 | * @param event a selection changed event | |
2066 | * | |
2067 | * @see ISelectionChangedListener#selectionChanged | |
2068 | * @since 2.0 | |
2069 | */ | |
2070 | protected void fireSelectionChanged(final SelectionChangedEvent event) { | |
2071 | Object[] listeners = selectionChangedListeners.getListeners(); | |
2072 | for (int i = 0; i < listeners.length; ++i) { | |
2073 | final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; | |
2074 | SafeRunnable.run(new SafeRunnable() { | |
faa38350 | 2075 | @Override |
93bfd50a PT |
2076 | public void run() { |
2077 | l.selectionChanged(event); | |
2078 | } | |
2079 | }); | |
2080 | } | |
2081 | } | |
2082 | ||
db4721fb PT |
2083 | // ------------------------------------------------------------------------ |
2084 | // Bookmark handling | |
2085 | // ------------------------------------------------------------------------ | |
2086 | ||
2087 | /** | |
2088 | * Add a bookmark to this event table. | |
2089 | * | |
2090 | * @param bookmarksFile | |
2091 | * The file to use for the bookmarks | |
2092 | */ | |
2093 | public void addBookmark(final IFile bookmarksFile) { | |
2094 | fBookmarksFile = bookmarksFile; | |
2095 | final TableItem[] selection = fTable.getSelection(); | |
2096 | if (selection.length > 0) { | |
2097 | final TableItem tableItem = selection[0]; | |
2098 | if (tableItem.getData(Key.RANK) != null) { | |
2099 | final StringBuffer defaultMessage = new StringBuffer(); | |
2100 | for (int i = 0; i < fTable.getColumns().length; i++) { | |
60fb38b8 | 2101 | if (i > 0) { |
db4721fb PT |
2102 | defaultMessage.append(", "); //$NON-NLS-1$ |
2103 | } | |
2104 | defaultMessage.append(tableItem.getText(i)); | |
2105 | } | |
3be2946f PT |
2106 | final InputDialog dialog = new MultiLineInputDialog( |
2107 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
2108 | Messages.TmfEventsTable_AddBookmarkDialogTitle, | |
2109 | Messages.TmfEventsTable_AddBookmarkDialogMessage, | |
2110 | defaultMessage.toString()); | |
db4721fb PT |
2111 | if (dialog.open() == Window.OK) { |
2112 | final String message = dialog.getValue(); | |
2113 | try { | |
2114 | final IMarker bookmark = bookmarksFile.createMarker(IMarker.BOOKMARK); | |
2115 | if (bookmark.exists()) { | |
2116 | bookmark.setAttribute(IMarker.MESSAGE, message.toString()); | |
2117 | final long rank = (Long) tableItem.getData(Key.RANK); | |
2118 | final int location = (int) rank; | |
2119 | bookmark.setAttribute(IMarker.LOCATION, (Integer) location); | |
2120 | fBookmarksMap.put(rank, bookmark.getId()); | |
2121 | fTable.refresh(); | |
2122 | } | |
2123 | } catch (final CoreException e) { | |
2124 | displayException(e); | |
2125 | } | |
2126 | } | |
2127 | } | |
2128 | } | |
2129 | ||
2130 | } | |
2131 | ||
2132 | /** | |
2133 | * Remove a bookmark from this event table. | |
2134 | * | |
2135 | * @param bookmark | |
2136 | * The bookmark to remove | |
2137 | */ | |
2138 | public void removeBookmark(final IMarker bookmark) { | |
2139 | for (final Entry<Long, Long> entry : fBookmarksMap.entrySet()) { | |
2140 | if (entry.getValue().equals(bookmark.getId())) { | |
2141 | fBookmarksMap.remove(entry.getKey()); | |
2142 | fTable.refresh(); | |
2143 | return; | |
2144 | } | |
2145 | } | |
2146 | } | |
2147 | ||
2148 | private void toggleBookmark(final long rank) { | |
2149 | if (fBookmarksFile == null) { | |
2150 | return; | |
2151 | } | |
2152 | if (fBookmarksMap.containsKey(rank)) { | |
2153 | final Long markerId = fBookmarksMap.remove(rank); | |
2154 | fTable.refresh(); | |
2155 | try { | |
2156 | final IMarker bookmark = fBookmarksFile.findMarker(markerId); | |
2157 | if (bookmark != null) { | |
2158 | bookmark.delete(); | |
2159 | } | |
2160 | } catch (final CoreException e) { | |
2161 | displayException(e); | |
2162 | } | |
2163 | } else { | |
2164 | addBookmark(fBookmarksFile); | |
2165 | } | |
2166 | } | |
2167 | ||
2168 | /** | |
2169 | * Refresh the bookmarks assigned to this trace, from the contents of a | |
2170 | * bookmark file. | |
2171 | * | |
2172 | * @param bookmarksFile | |
2173 | * The bookmark file to use | |
2174 | */ | |
2175 | public void refreshBookmarks(final IFile bookmarksFile) { | |
2176 | fBookmarksFile = bookmarksFile; | |
2177 | if (bookmarksFile == null) { | |
2178 | fBookmarksMap.clear(); | |
2179 | fTable.refresh(); | |
2180 | return; | |
2181 | } | |
2182 | try { | |
2183 | fBookmarksMap.clear(); | |
2184 | for (final IMarker bookmark : bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) { | |
2185 | final int location = bookmark.getAttribute(IMarker.LOCATION, -1); | |
2186 | if (location != -1) { | |
2187 | final long rank = location; | |
2188 | fBookmarksMap.put(rank, bookmark.getId()); | |
2189 | } | |
2190 | } | |
2191 | fTable.refresh(); | |
2192 | } catch (final CoreException e) { | |
2193 | displayException(e); | |
2194 | } | |
2195 | } | |
2196 | ||
2197 | @Override | |
2198 | public void gotoMarker(final IMarker marker) { | |
2199 | final int rank = marker.getAttribute(IMarker.LOCATION, -1); | |
2200 | if (rank != -1) { | |
2201 | int index = rank; | |
2202 | if (fTable.getData(Key.FILTER_OBJ) != null) { | |
2203 | index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row | |
2204 | } else if (rank >= fTable.getItemCount()) { | |
2205 | fPendingGotoRank = rank; | |
2206 | } | |
a56ec2b8 | 2207 | fSelectedRank = rank; |
db4721fb | 2208 | fTable.setSelection(index + 1); // +1 for header row |
3f43dc48 | 2209 | updateStatusLine(null); |
db4721fb PT |
2210 | } |
2211 | } | |
2212 | ||
2213 | // ------------------------------------------------------------------------ | |
2214 | // Listeners | |
2215 | // ------------------------------------------------------------------------ | |
2216 | ||
db4721fb PT |
2217 | @Override |
2218 | public void colorSettingsChanged(final ColorSetting[] colorSettings) { | |
2219 | fTable.refresh(); | |
2220 | } | |
2221 | ||
db4721fb PT |
2222 | // ------------------------------------------------------------------------ |
2223 | // Signal handlers | |
2224 | // ------------------------------------------------------------------------ | |
2225 | ||
db4721fb PT |
2226 | /** |
2227 | * Handler for the trace updated signal | |
2228 | * | |
2229 | * @param signal | |
2230 | * The incoming signal | |
2231 | */ | |
2232 | @TmfSignalHandler | |
2233 | public void traceUpdated(final TmfTraceUpdatedSignal signal) { | |
2234 | if ((signal.getTrace() != fTrace) || fTable.isDisposed()) { | |
2235 | return; | |
2236 | } | |
2237 | // Perform the refresh on the UI thread | |
2238 | Display.getDefault().asyncExec(new Runnable() { | |
2239 | @Override | |
2240 | public void run() { | |
2241 | if (!fTable.isDisposed() && (fTrace != null)) { | |
2242 | if (fTable.getData(Key.FILTER_OBJ) == null) { | |
2243 | fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row | |
2244 | if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row | |
2245 | fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row | |
2246 | fPendingGotoRank = -1; | |
3f43dc48 | 2247 | updateStatusLine(null); |
db4721fb PT |
2248 | } |
2249 | } else { | |
2250 | startFilterThread(); | |
2251 | } | |
2252 | } | |
2253 | if (!fRawViewer.isDisposed() && (fTrace != null)) { | |
2254 | fRawViewer.refreshEventCount(); | |
2255 | } | |
2256 | } | |
2257 | }); | |
2258 | } | |
2259 | ||
2260 | /** | |
2261 | * Handler for the time synch signal. | |
2262 | * | |
2263 | * @param signal | |
2264 | * The incoming signal | |
2265 | */ | |
2266 | @TmfSignalHandler | |
2267 | public void currentTimeUpdated(final TmfTimeSynchSignal signal) { | |
2268 | if ((signal.getSource() != this) && (fTrace != null) && (!fTable.isDisposed())) { | |
2269 | ||
2270 | // Create a request for one event that will be queued after other ongoing requests. When this request is completed | |
2271 | // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents | |
2272 | // the method fTrace.getRank() from interfering and delaying ongoing requests. | |
fd3f1eff AM |
2273 | final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class, |
2274 | TmfTimeRange.ETERNITY, 0, 1, ExecutionType.FOREGROUND) { | |
db4721fb | 2275 | |
0fcf3b09 | 2276 | TmfTimestamp ts = new TmfTimestamp(signal.getBeginTime()); |
db4721fb PT |
2277 | |
2278 | @Override | |
2279 | public void handleData(final ITmfEvent event) { | |
2280 | super.handleData(event); | |
2281 | } | |
2282 | ||
2283 | @Override | |
5419a136 | 2284 | public void handleCompleted() { |
db4721fb PT |
2285 | super.handleCompleted(); |
2286 | if (fTrace == null) { | |
2287 | return; | |
2288 | } | |
2289 | ||
2290 | // Verify if the event is within the trace range and adjust if necessary | |
2291 | ITmfTimestamp timestamp = ts; | |
2292 | if (timestamp.compareTo(fTrace.getStartTime(), true) == -1) { | |
2293 | timestamp = fTrace.getStartTime(); | |
2294 | } | |
2295 | if (timestamp.compareTo(fTrace.getEndTime(), true) == 1) { | |
2296 | timestamp = fTrace.getEndTime(); | |
2297 | } | |
2298 | ||
2299 | // Get the rank of the selected event in the table | |
2300 | final ITmfContext context = fTrace.seekEvent(timestamp); | |
2301 | final long rank = context.getRank(); | |
4c9f2944 | 2302 | context.dispose(); |
db4721fb PT |
2303 | fSelectedRank = rank; |
2304 | ||
2305 | fTable.getDisplay().asyncExec(new Runnable() { | |
2306 | @Override | |
2307 | public void run() { | |
2308 | // Return if table is disposed | |
2309 | if (fTable.isDisposed()) { | |
2310 | return; | |
2311 | } | |
2312 | ||
2313 | int index = (int) rank; | |
2314 | if (fTable.isDisposed()) { | |
2315 | return; | |
2316 | } | |
60fb38b8 | 2317 | if (fTable.getData(Key.FILTER_OBJ) != null) { |
db4721fb PT |
2318 | index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row |
2319 | } | |
2320 | fTable.setSelection(index + 1); // +1 for header row | |
2321 | fRawViewer.selectAndReveal(rank); | |
3f43dc48 | 2322 | updateStatusLine(null); |
db4721fb PT |
2323 | } |
2324 | }); | |
2325 | } | |
2326 | }; | |
2327 | ||
fd3f1eff | 2328 | ((ITmfEventProvider) fTrace).sendRequest(subRequest); |
db4721fb PT |
2329 | } |
2330 | } | |
2331 | ||
2332 | // ------------------------------------------------------------------------ | |
2333 | // Error handling | |
2334 | // ------------------------------------------------------------------------ | |
2335 | ||
2336 | /** | |
2337 | * Display an exception in a message box | |
2338 | * | |
2339 | * @param e the exception | |
2340 | */ | |
2341 | private static void displayException(final Exception e) { | |
2342 | final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); | |
60fb38b8 | 2343 | mb.setText(e.getClass().getSimpleName()); |
db4721fb PT |
2344 | mb.setMessage(e.getMessage()); |
2345 | mb.open(); | |
2346 | } | |
2347 | ||
f8177ba2 FC |
2348 | /** |
2349 | * @since 2.0 | |
2350 | */ | |
2351 | public void refresh() { | |
2352 | fCache.clear(); | |
2353 | fTable.refresh(); | |
2354 | fTable.redraw(); | |
2355 | } | |
db4721fb | 2356 | } |