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