rcp: bug 471162: Add Error Log view to RCP
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / events / TmfEventsTable.java
CommitLineData
db4721fb 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2010, 2015 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:
baafe54c
AM
10 * Francois Chouinard - Initial API and implementation, replaced Table by TmfVirtualTable
11 * Patrick Tasse - Factored out from events view,
12 * Filter implementation (inspired by www.eclipse.org/mat)
ac44ef71 13 * Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
f47ed727 14 * Bernd Hufmann - Updated call site and model URI implementation
baafe54c 15 * Alexandre Montplaisir - Update to new column API
346ffed7 16 * Matthew Khouzam - Add hide columns
db4721fb
PT
17 *******************************************************************************/
18
2bdf0193 19package org.eclipse.tracecompass.tmf.ui.viewers.events;
db4721fb 20
5db5a3a4
AM
21import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
22
60fb38b8 23import java.io.FileNotFoundException;
9ba0a108 24import java.lang.reflect.InvocationTargetException;
db4721fb 25import java.util.ArrayList;
2db176a0 26import java.util.Collection;
db4721fb 27import java.util.HashMap;
baafe54c 28import java.util.LinkedList;
db4721fb 29import java.util.List;
db4721fb 30import java.util.Map.Entry;
110d44a1 31import java.util.regex.Matcher;
db4721fb
PT
32import java.util.regex.Pattern;
33import java.util.regex.PatternSyntaxException;
34
d3de0920
XR
35import org.eclipse.core.commands.Command;
36import org.eclipse.core.commands.ExecutionException;
37import org.eclipse.core.commands.NotEnabledException;
38import org.eclipse.core.commands.NotHandledException;
39import org.eclipse.core.commands.ParameterizedCommand;
40import org.eclipse.core.commands.common.NotDefinedException;
41import org.eclipse.core.expressions.IEvaluationContext;
db4721fb
PT
42import org.eclipse.core.resources.IFile;
43import org.eclipse.core.resources.IMarker;
44import org.eclipse.core.resources.IResource;
60fb38b8 45import org.eclipse.core.resources.IResourceVisitor;
ac44ef71 46import org.eclipse.core.resources.ResourcesPlugin;
db4721fb 47import org.eclipse.core.runtime.CoreException;
ac44ef71 48import org.eclipse.core.runtime.IPath;
db4721fb
PT
49import org.eclipse.core.runtime.IProgressMonitor;
50import org.eclipse.core.runtime.IStatus;
93bfd50a 51import org.eclipse.core.runtime.ListenerList;
ac44ef71 52import org.eclipse.core.runtime.Path;
db4721fb
PT
53import org.eclipse.core.runtime.Status;
54import org.eclipse.core.runtime.jobs.Job;
ac44ef71
AR
55import org.eclipse.emf.common.util.URI;
56import org.eclipse.emf.ecore.EValidator;
46671228 57import org.eclipse.jdt.annotation.NonNull;
db4721fb
PT
58import org.eclipse.jface.action.Action;
59import org.eclipse.jface.action.IAction;
60import org.eclipse.jface.action.IMenuListener;
61import org.eclipse.jface.action.IMenuManager;
3f43dc48 62import org.eclipse.jface.action.IStatusLineManager;
db4721fb
PT
63import org.eclipse.jface.action.MenuManager;
64import org.eclipse.jface.action.Separator;
65import org.eclipse.jface.dialogs.InputDialog;
66import org.eclipse.jface.dialogs.MessageDialog;
9ba0a108 67import org.eclipse.jface.operation.IRunnableWithProgress;
bb7c657f 68import org.eclipse.jface.resource.ColorRegistry;
812e7197 69import org.eclipse.jface.resource.FontRegistry;
db4721fb
PT
70import org.eclipse.jface.resource.JFaceResources;
71import org.eclipse.jface.resource.LocalResourceManager;
812e7197 72import org.eclipse.jface.util.IPropertyChangeListener;
ac44ef71 73import org.eclipse.jface.util.OpenStrategy;
812e7197 74import org.eclipse.jface.util.PropertyChangeEvent;
93bfd50a 75import org.eclipse.jface.util.SafeRunnable;
60fb38b8 76import org.eclipse.jface.viewers.ArrayContentProvider;
93bfd50a
PT
77import org.eclipse.jface.viewers.ISelection;
78import org.eclipse.jface.viewers.ISelectionChangedListener;
79import org.eclipse.jface.viewers.ISelectionProvider;
60fb38b8 80import org.eclipse.jface.viewers.LabelProvider;
93bfd50a
PT
81import org.eclipse.jface.viewers.SelectionChangedEvent;
82import org.eclipse.jface.viewers.StructuredSelection;
db4721fb 83import org.eclipse.jface.window.Window;
db4721fb
PT
84import org.eclipse.swt.SWT;
85import org.eclipse.swt.custom.SashForm;
110d44a1 86import org.eclipse.swt.custom.StyleRange;
db4721fb 87import org.eclipse.swt.custom.TableEditor;
6817308e
PT
88import org.eclipse.swt.events.ControlAdapter;
89import org.eclipse.swt.events.ControlEvent;
db4721fb
PT
90import org.eclipse.swt.events.FocusAdapter;
91import org.eclipse.swt.events.FocusEvent;
92import org.eclipse.swt.events.KeyAdapter;
93import org.eclipse.swt.events.KeyEvent;
94import org.eclipse.swt.events.MouseAdapter;
95import org.eclipse.swt.events.MouseEvent;
96import org.eclipse.swt.events.SelectionAdapter;
97import org.eclipse.swt.events.SelectionEvent;
98import org.eclipse.swt.graphics.Color;
99import org.eclipse.swt.graphics.Font;
110d44a1 100import org.eclipse.swt.graphics.GC;
db4721fb
PT
101import org.eclipse.swt.graphics.Image;
102import org.eclipse.swt.graphics.Point;
103import org.eclipse.swt.graphics.Rectangle;
104import org.eclipse.swt.layout.FillLayout;
105import org.eclipse.swt.layout.GridData;
106import org.eclipse.swt.layout.GridLayout;
107import org.eclipse.swt.widgets.Composite;
108import org.eclipse.swt.widgets.Display;
109import org.eclipse.swt.widgets.Event;
110import org.eclipse.swt.widgets.Label;
111import org.eclipse.swt.widgets.Listener;
112import org.eclipse.swt.widgets.Menu;
113import org.eclipse.swt.widgets.MessageBox;
114import org.eclipse.swt.widgets.Shell;
115import org.eclipse.swt.widgets.TableColumn;
116import org.eclipse.swt.widgets.TableItem;
117import org.eclipse.swt.widgets.Text;
6cfc180e 118import org.eclipse.tracecompass.common.core.NonNullUtils;
2bdf0193
AM
119import org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter;
120import org.eclipse.tracecompass.internal.tmf.ui.Activator;
121import org.eclipse.tracecompass.internal.tmf.ui.Messages;
9ba0a108 122import org.eclipse.tracecompass.internal.tmf.ui.commands.CopyToClipboardOperation;
2bdf0193
AM
123import org.eclipse.tracecompass.internal.tmf.ui.commands.ExportToTextCommandHandler;
124import org.eclipse.tracecompass.internal.tmf.ui.dialogs.MultiLineInputDialog;
125import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider;
126import org.eclipse.tracecompass.tmf.core.component.TmfComponent;
127import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
9447c7ee 128import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
40dfafb3 129import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
2bdf0193
AM
130import org.eclipse.tracecompass.tmf.core.event.collapse.ITmfCollapsibleEvent;
131import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite;
132import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
133import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
134import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
135import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode;
136import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode;
137import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
138import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
139import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType;
140import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
141import org.eclipse.tracecompass.tmf.core.signal.TmfEventFilterAppliedSignal;
142import org.eclipse.tracecompass.tmf.core.signal.TmfEventSearchAppliedSignal;
143import org.eclipse.tracecompass.tmf.core.signal.TmfEventSelectedSignal;
97c71024 144import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
bb7c657f 145import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
2bdf0193
AM
146import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal;
147import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
148import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
149import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
150import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
151import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
b04903a2 152import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
2bdf0193
AM
153import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
154import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
155import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsCache.CachedEvent;
156import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn;
2bdf0193
AM
157import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSetting;
158import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSettingsManager;
159import org.eclipse.tracecompass.tmf.ui.views.colors.IColorSettingsListener;
160import org.eclipse.tracecompass.tmf.ui.views.filter.FilterManager;
161import org.eclipse.tracecompass.tmf.ui.widgets.rawviewer.TmfRawEventViewer;
162import org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.TmfVirtualTable;
ac44ef71 163import org.eclipse.ui.IWorkbenchPage;
db4721fb 164import org.eclipse.ui.PlatformUI;
d3de0920 165import org.eclipse.ui.commands.ICommandService;
60fb38b8 166import org.eclipse.ui.dialogs.ListDialog;
d3de0920 167import org.eclipse.ui.handlers.IHandlerService;
ac44ef71 168import org.eclipse.ui.ide.IDE;
db4721fb
PT
169import org.eclipse.ui.ide.IGotoMarker;
170import org.eclipse.ui.themes.ColorUtil;
812e7197 171import org.eclipse.ui.themes.IThemeManager;
db4721fb 172
2db176a0
PT
173import com.google.common.base.Joiner;
174import com.google.common.collect.HashMultimap;
baafe54c 175import com.google.common.collect.ImmutableList;
2db176a0
PT
176import com.google.common.collect.Multimap;
177
db4721fb
PT
178/**
179 * The generic TMF Events table
180 *
181 * This is a view that will list events that are read from a trace.
182 *
db4721fb
PT
183 * @author Francois Chouinard
184 * @author Patrick Tasse
185 */
812e7197 186public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorSettingsListener, ISelectionProvider, IPropertyChangeListener {
db4721fb 187
cf37ad9f
AM
188 /**
189 * Empty string array, used by {@link #getItemStrings}.
cf37ad9f 190 */
46671228 191 protected static final @NonNull String[] EMPTY_STRING_ARRAY = new String[0];
cf37ad9f 192
baafe54c
AM
193 /**
194 * Empty string
baafe54c
AM
195 */
196 protected static final @NonNull String EMPTY_STRING = ""; //$NON-NLS-1$
197
03142470
BH
198 private static final boolean IS_LINUX = System.getProperty("os.name").contains("Linux") ? true : false; //$NON-NLS-1$ //$NON-NLS-2$
199
812e7197 200 private static final String FONT_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
bb7c657f 201 private static final String HIGHLIGHT_COLOR_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.color.eventtable.highlight"; //$NON-NLS-1$
812e7197 202
db4721fb
PT
203 private static final Image BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath(
204 "icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
205 private static final Image SEARCH_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
206 private static final Image SEARCH_MATCH_IMAGE = Activator.getDefault().getImageFromPath(
207 "icons/elcl16/search_match.gif"); //$NON-NLS-1$
208 private static final Image SEARCH_MATCH_BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath(
209 "icons/elcl16/search_match_bookmark.gif"); //$NON-NLS-1$
8b7eb3cd 210 private static final Image FILTER_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/filter_items.gif"); //$NON-NLS-1$
db4721fb
PT
211 private static final Image STOP_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/stop.gif"); //$NON-NLS-1$
212 private static final String SEARCH_HINT = Messages.TmfEventsTable_SearchHint;
213 private static final String FILTER_HINT = Messages.TmfEventsTable_FilterHint;
214 private static final int MAX_CACHE_SIZE = 1000;
215
03142470
BH
216 private static final int MARGIN_COLUMN_INDEX = 0;
217 private static final int FILTER_SUMMARY_INDEX = 1;
218 private static final int EVENT_COLUMNS_START_INDEX = MARGIN_COLUMN_INDEX + 1;
219
db4721fb 220 /**
346ffed7 221 * The events table search/filter/data keys
db4721fb
PT
222 *
223 * @version 1.0
224 * @author Patrick Tasse
225 */
226 public interface Key {
227 /** Search text */
228 String SEARCH_TXT = "$srch_txt"; //$NON-NLS-1$
229
230 /** Search object */
231 String SEARCH_OBJ = "$srch_obj"; //$NON-NLS-1$
232
233 /** Filter text */
234 String FILTER_TXT = "$fltr_txt"; //$NON-NLS-1$
235
236 /** Filter object */
237 String FILTER_OBJ = "$fltr_obj"; //$NON-NLS-1$
238
dadf6e1a 239 /** Timestamp */
db4721fb
PT
240 String TIMESTAMP = "$time"; //$NON-NLS-1$
241
242 /** Rank */
243 String RANK = "$rank"; //$NON-NLS-1$
244
db4721fb
PT
245 /** Bookmark indicator */
246 String BOOKMARK = "$bookmark"; //$NON-NLS-1$
c409f16b
AM
247
248 /** Event aspect represented by this column */
249 String ASPECT = "$aspect"; //$NON-NLS-1$
110d44a1 250
8b7eb3cd
MK
251 /**
252 * Table item list of style ranges
253 *
254 * @since 1.0
255 */
110d44a1 256 String STYLE_RANGES = "$style_ranges"; //$NON-NLS-1$
346ffed7
MK
257
258 /**
259 * The width of a table item
260 *
261 * @since 1.0
262 */
263 String WIDTH = "$width"; //$NON-NLS-1$
db4721fb
PT
264 }
265
266 /**
267 * The events table search/filter state
268 *
269 * @version 1.0
270 * @author Patrick Tasse
271 */
272 public static enum HeaderState {
273 /** A search is being run */
274 SEARCH,
275
276 /** A filter is applied */
277 FILTER
278 }
279
280 interface Direction {
281 int FORWARD = +1;
282 int BACKWARD = -1;
283 }
284
285 // ------------------------------------------------------------------------
286 // Table data
287 // ------------------------------------------------------------------------
288
a0a88f65 289 /** The virtual event table */
db4721fb 290 protected TmfVirtualTable fTable;
a0a88f65
AM
291
292 private Composite fComposite;
293 private SashForm fSashForm;
294 private TmfRawEventViewer fRawViewer;
295 private ITmfTrace fTrace;
574f43ad 296 private volatile boolean fPackDone = false;
a0a88f65 297 private HeaderState fHeaderState = HeaderState.SEARCH;
9ba0a108
PT
298 private long fSelectedRank = -1;
299 private long fSelectedBeginRank = -1;
3f43dc48
PT
300 private ITmfTimestamp fSelectedBeginTimestamp = null;
301 private IStatusLineManager fStatusLineManager = null;
db4721fb
PT
302
303 // Filter data
a0a88f65
AM
304 private long fFilterMatchCount;
305 private long fFilterCheckCount;
306 private FilterThread fFilterThread;
307 private boolean fFilterThreadResume = false;
308 private final Object fFilterSyncObj = new Object();
309 private SearchThread fSearchThread;
310 private final Object fSearchSyncObj = new Object();
db4721fb 311
93bfd50a 312 /**
8b7eb3cd
MK
313 * List of selection change listeners (element type:
314 * <code>ISelectionChangedListener</code>).
93bfd50a
PT
315 *
316 * @see #fireSelectionChanged
317 */
318 private ListenerList selectionChangedListeners = new ListenerList();
319
db4721fb 320 // Bookmark map <Rank, MarkerId>
2db176a0 321 private Multimap<Long, Long> fBookmarksMap = HashMultimap.create();
a0a88f65
AM
322 private IFile fBookmarksFile;
323 private long fPendingGotoRank = -1;
db4721fb
PT
324
325 // SWT resources
a0a88f65
AM
326 private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
327 private Color fGrayColor;
328 private Color fGreenColor;
bb7c657f 329 private Color fHighlightColor;
812e7197 330 private Font fFont;
a0a88f65 331 private Font fBoldFont;
db4721fb 332
baafe54c 333 private final List<TmfEventTableColumn> fColumns = new LinkedList<>();
db4721fb
PT
334
335 // Event cache
336 private final TmfEventsCache fCache;
337 private boolean fCacheUpdateBusy = false;
338 private boolean fCacheUpdatePending = false;
339 private boolean fCacheUpdateCompleted = false;
340 private final Object fCacheUpdateSyncObj = new Object();
341
14665360
PT
342 // Keep track of column order, it is needed after table is disposed
343 private int[] fColumnOrder;
344
db4721fb
PT
345 private boolean fDisposeOnClose;
346
346ffed7
MK
347 private Menu fHeaderMenu;
348
349 private Menu fTablePopup;
350
351 private Menu fRawTablePopup;
352
db4721fb 353 // ------------------------------------------------------------------------
a0a88f65 354 // Constructors
db4721fb
PT
355 // ------------------------------------------------------------------------
356
357 /**
baafe54c 358 * Basic constructor, using the default set of columns
db4721fb
PT
359 *
360 * @param parent
361 * The parent composite UI object
362 * @param cacheSize
363 * The size of the event table cache
364 */
365 public TmfEventsTable(final Composite parent, final int cacheSize) {
b04903a2 366 this(parent, cacheSize, TmfTrace.BASE_ASPECTS);
db4721fb
PT
367 }
368
369 /**
baafe54c 370 * Legacy constructor, using ColumnData to define columns
db4721fb
PT
371 *
372 * @param parent
373 * The parent composite UI object
374 * @param cacheSize
375 * The size of the event table cache
376 * @param columnData
40dfafb3 377 * The column data array
baafe54c
AM
378 * @deprecated Deprecated constructor, use
379 * {@link #TmfEventsTable(Composite, int, Collection)}
380 */
381 @Deprecated
382 public TmfEventsTable(final Composite parent, int cacheSize,
2bdf0193 383 final org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
baafe54c
AM
384 /*
385 * We'll do a "best-effort" to keep trace types still using this API to
8b7eb3cd
MK
386 * keep working, by defining a TmfEventTableColumn for each ColumnData
387 * they passed.
baafe54c
AM
388 */
389 this(parent, cacheSize, convertFromColumnData(columnData));
390 }
391
392 @Deprecated
8192209b 393 private static @NonNull Iterable<ITmfEventAspect> convertFromColumnData(
2bdf0193 394 org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
baafe54c 395
b04903a2 396 ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
2bdf0193 397 for (org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData col : columnData) {
9447c7ee
AM
398 String fieldName = col.header;
399 if (fieldName != null) {
40dfafb3 400 builder.add(new TmfContentFieldAspect(fieldName, fieldName));
baafe54c
AM
401 }
402 }
5db5a3a4 403 return checkNotNull(builder.build());
baafe54c
AM
404 }
405
406 /**
407 * Standard constructor, where we define which columns to use.
408 *
409 * @param parent
410 * The parent composite UI object
411 * @param cacheSize
412 * The size of the event table cache
b04903a2
AM
413 * @param aspects
414 * The event aspects to display in this table. One column per
415 * aspect will be created.
baafe54c
AM
416 * <p>
417 * The iteration order of this collection will correspond to the
b04903a2 418 * initial ordering of the columns in the table.
baafe54c 419 * </p>
db4721fb 420 */
baafe54c 421 public TmfEventsTable(final Composite parent, int cacheSize,
8192209b 422 @NonNull Iterable<ITmfEventAspect> aspects) {
db4721fb
PT
423 super("TmfEventsTable"); //$NON-NLS-1$
424
425 fComposite = new Composite(parent, SWT.NONE);
426 final GridLayout gl = new GridLayout(1, false);
427 gl.marginHeight = 0;
428 gl.marginWidth = 0;
429 gl.verticalSpacing = 0;
430 fComposite.setLayout(gl);
431
432 fSashForm = new SashForm(fComposite, SWT.HORIZONTAL);
433 fSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
434
435 // Create a virtual table
3f43dc48 436 final int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION;
db4721fb
PT
437 fTable = new TmfVirtualTable(fSashForm, style);
438
439 // Set the table layout
440 final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
441 fTable.setLayoutData(layoutData);
442
443 // Some cosmetic enhancements
444 fTable.setHeaderVisible(true);
445 fTable.setLinesVisible(true);
446
baafe54c 447 // Setup the columns
8192209b
AM
448 for (ITmfEventAspect aspect : aspects) {
449 if (aspect != null) {
450 fColumns.add(new TmfEventTableColumn(aspect));
b04903a2 451 }
db4721fb
PT
452 }
453
03142470
BH
454 TmfMarginColumn collapseCol = new TmfMarginColumn();
455 fColumns.add(MARGIN_COLUMN_INDEX, collapseCol);
456
346ffed7 457 fHeaderMenu = new Menu(fTable);
baafe54c 458 // Create the UI columns in the table
2fcd5eea
AM
459 for (TmfEventTableColumn col : fColumns) {
460 TableColumn column = fTable.newTableColumn(SWT.LEFT);
461 column.setText(col.getHeaderName());
462 column.setToolTipText(col.getHeaderTooltip());
c409f16b 463 column.setData(Key.ASPECT, col.getEventAspect());
2fcd5eea 464 column.pack();
03142470
BH
465 if (col instanceof TmfMarginColumn) {
466 column.setResizable(false);
6817308e
PT
467 } else {
468 column.setMoveable(true);
be42703d 469 column.setData(Key.WIDTH, -1);
03142470 470 }
14665360
PT
471 column.addControlListener(new ControlAdapter() {
472 /*
8b7eb3cd
MK
473 * Make sure that the margin column is always first and keep the
474 * column order variable up to date.
14665360
PT
475 */
476 @Override
477 public void controlMoved(ControlEvent e) {
478 int[] order = fTable.getColumnOrder();
479 if (order[0] == MARGIN_COLUMN_INDEX) {
480 fColumnOrder = order;
481 return;
482 }
483 for (int i = order.length - 1; i > 0; i--) {
484 if (order[i] == MARGIN_COLUMN_INDEX) {
485 order[i] = order[i - 1];
486 order[i - 1] = MARGIN_COLUMN_INDEX;
487 }
488 }
489 fTable.setColumnOrder(order);
490 fColumnOrder = fTable.getColumnOrder();
491 }
492 });
2fcd5eea 493 }
14665360 494 fColumnOrder = fTable.getColumnOrder();
baafe54c 495
db4721fb
PT
496 // Set the frozen row for header row
497 fTable.setFrozenRowCount(1);
498
499 // Create the header row cell editor
500 createHeaderEditor();
501
502 // Handle the table item selection
503 fTable.addSelectionListener(new SelectionAdapter() {
504 @Override
505 public void widgetSelected(final SelectionEvent e) {
3f43dc48
PT
506 if (e.item == null) {
507 return;
508 }
509 updateStatusLine(null);
510 if (fTable.getSelectionIndices().length > 0) {
511 if (e.item.getData(Key.RANK) instanceof Long) {
512 fSelectedRank = (Long) e.item.getData(Key.RANK);
513 fRawViewer.selectAndReveal((Long) e.item.getData(Key.RANK));
9ba0a108
PT
514 } else {
515 fSelectedRank = -1;
516 }
517 if (fTable.getSelectionIndices().length == 1) {
518 fSelectedBeginRank = fSelectedRank;
3f43dc48
PT
519 }
520 if (e.item.getData(Key.TIMESTAMP) instanceof ITmfTimestamp) {
6cfc180e 521 final ITmfTimestamp ts = NonNullUtils.checkNotNull((ITmfTimestamp) e.item.getData(Key.TIMESTAMP));
3f43dc48
PT
522 if (fTable.getSelectionIndices().length == 1) {
523 fSelectedBeginTimestamp = ts;
524 }
6cfc180e
GB
525 ITmfTimestamp selectedBeginTimestamp = fSelectedBeginTimestamp;
526 if (selectedBeginTimestamp != null) {
85203d74
PT
527 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, selectedBeginTimestamp, ts));
528 if (fTable.getSelectionIndices().length == 2) {
529 updateStatusLine(ts.getDelta(selectedBeginTimestamp));
3f43dc48 530 }
db4721fb 531 }
3f43dc48
PT
532 } else {
533 if (fTable.getSelectionIndices().length == 1) {
534 fSelectedBeginTimestamp = null;
db4721fb
PT
535 }
536 }
537 }
6b44794a
MK
538 if (e.item.getData() instanceof ITmfEvent) {
539 broadcast(new TmfEventSelectedSignal(TmfEventsTable.this, (ITmfEvent) e.item.getData()));
3f43dc48
PT
540 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, new StructuredSelection(e.item.getData())));
541 } else {
542 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, StructuredSelection.EMPTY));
543 }
db4721fb
PT
544 }
545 });
546
41b5c37f
AM
547 int realCacheSize = Math.max(cacheSize, Display.getDefault().getBounds().height / fTable.getItemHeight());
548 realCacheSize = Math.min(realCacheSize, MAX_CACHE_SIZE);
549 fCache = new TmfEventsCache(realCacheSize, this);
db4721fb
PT
550
551 // Handle the table item requests
552 fTable.addListener(SWT.SetData, new Listener() {
553
554 @Override
555 public void handleEvent(final Event event) {
556
557 final TableItem item = (TableItem) event.item;
558 int index = event.index - 1; // -1 for the header row
559
560 if (event.index == 0) {
561 setHeaderRowItemData(item);
562 return;
563 }
564
565 if (fTable.getData(Key.FILTER_OBJ) != null) {
566 if ((event.index == 1) || (event.index == (fTable.getItemCount() - 1))) {
567 setFilterStatusRowItemData(item);
568 return;
569 }
8b7eb3cd
MK
570 /* -1 for top filter status row */
571 index = index - 1;
db4721fb
PT
572 }
573
574 final CachedEvent cachedEvent = fCache.getEvent(index);
575 if (cachedEvent != null) {
03142470 576 setItemData(item, cachedEvent, cachedEvent.rank);
db4721fb
PT
577 return;
578 }
579
580 // Else, fill the cache asynchronously (and off the UI thread)
581 event.doit = false;
582 }
583 });
584
346ffed7
MK
585 fTable.addListener(SWT.MenuDetect, new Listener() {
586 @Override
587 public void handleEvent(Event event) {
588 Point pt = fTable.getDisplay().map(null, fTable, new Point(event.x, event.y));
589 Rectangle clientArea = fTable.getClientArea();
590 boolean header = clientArea.y <= pt.y && pt.y < (clientArea.y + fTable.getHeaderHeight());
591 fTable.setMenu(header ? fHeaderMenu : fTablePopup);
592 }
593 });
594
db4721fb
PT
595 fTable.addMouseListener(new MouseAdapter() {
596 @Override
597 public void mouseDoubleClick(final MouseEvent event) {
598 if (event.button != 1) {
599 return;
600 }
601 // Identify the selected row
602 final Point point = new Point(event.x, event.y);
603 final TableItem item = fTable.getItem(point);
604 if (item != null) {
605 final Rectangle imageBounds = item.getImageBounds(0);
606 imageBounds.width = BOOKMARK_IMAGE.getBounds().width;
607 if (imageBounds.contains(point)) {
608 final Long rank = (Long) item.getData(Key.RANK);
609 if (rank != null) {
610 toggleBookmark(rank);
611 }
612 }
613 }
614 }
615 });
616
8b7eb3cd 617 final Listener tooltipListener = new Listener() {
db4721fb 618 Shell tooltipShell = null;
8b7eb3cd 619
db4721fb
PT
620 @Override
621 public void handleEvent(final Event event) {
622 switch (event.type) {
8b7eb3cd
MK
623 case SWT.MouseHover:
624 final TableItem item = fTable.getItem(new Point(event.x, event.y));
625 if (item == null) {
626 return;
627 }
628 final Long rank = (Long) item.getData(Key.RANK);
629 if (rank == null) {
630 return;
631 }
632 final String tooltipText = (String) item.getData(Key.BOOKMARK);
633 final Rectangle bounds = item.getImageBounds(0);
634 bounds.width = BOOKMARK_IMAGE.getBounds().width;
635 if (!bounds.contains(event.x, event.y)) {
636 return;
637 }
638 if ((tooltipShell != null) && !tooltipShell.isDisposed()) {
639 tooltipShell.dispose();
640 }
641 tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
642 tooltipShell.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
643 final FillLayout layout = new FillLayout();
644 layout.marginWidth = 2;
645 tooltipShell.setLayout(layout);
646 final Label label = new Label(tooltipShell, SWT.WRAP);
647 String text = rank.toString() + (tooltipText != null ? ": " + tooltipText : EMPTY_STRING); //$NON-NLS-1$
648 label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
649 label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
650 label.setText(text);
651 label.addListener(SWT.MouseExit, this);
652 label.addListener(SWT.MouseDown, this);
653 label.addListener(SWT.MouseWheel, this);
654 final Point size = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
655 /*
656 * Bug in Linux. The coordinates of the event have an origin
657 * that excludes the table header but the method toDisplay()
658 * expects coordinates relative to an origin that includes
659 * the table header.
660 */
661 int y = event.y;
662 if (IS_LINUX) {
663 y += fTable.getHeaderHeight();
664 }
665 Point pt = fTable.toDisplay(event.x, y);
666 pt.x += BOOKMARK_IMAGE.getBounds().width;
667 pt.y += item.getBounds().height;
668 tooltipShell.setBounds(pt.x, pt.y, size.x, size.y);
669 tooltipShell.setVisible(true);
670 break;
671 case SWT.Dispose:
672 case SWT.KeyDown:
673 case SWT.MouseMove:
674 case SWT.MouseExit:
675 case SWT.MouseDown:
676 case SWT.MouseWheel:
677 if (tooltipShell != null) {
678 tooltipShell.dispose();
679 tooltipShell = null;
680 }
681 break;
682 default:
683 break;
db4721fb
PT
684 }
685 }
686 };
687
688 fTable.addListener(SWT.MouseHover, tooltipListener);
689 fTable.addListener(SWT.Dispose, tooltipListener);
690 fTable.addListener(SWT.KeyDown, tooltipListener);
691 fTable.addListener(SWT.MouseMove, tooltipListener);
692 fTable.addListener(SWT.MouseExit, tooltipListener);
693 fTable.addListener(SWT.MouseDown, tooltipListener);
694 fTable.addListener(SWT.MouseWheel, tooltipListener);
695
110d44a1
PT
696 fTable.addListener(SWT.EraseItem, new Listener() {
697 @Override
698 public void handleEvent(Event event) {
699 TableItem item = (TableItem) event.item;
700 List<?> styleRanges = (List<?>) item.getData(Key.STYLE_RANGES);
701
702 GC gc = event.gc;
703 Color background = item.getBackground(event.index);
704 /*
705 * Paint the background if it is not the default system color.
706 * In Windows, if you let the widget draw the background, it
707 * will not show the item's background color if the item is
708 * selected or hot. If there are no style ranges and the item
709 * background is the default system color, we do not want to
710 * paint it or otherwise we would override the platform theme
711 * (e.g. alternating colors).
712 */
4c27e423 713 if (styleRanges != null || !background.equals(item.getParent().getBackground())) {
110d44a1
PT
714 // we will paint the table item's background
715 event.detail &= ~SWT.BACKGROUND;
716
717 // paint the item's default background
718 gc.setBackground(background);
719 gc.fillRectangle(event.x, event.y, event.width, event.height);
720 }
721
722 /*
8b7eb3cd
MK
723 * We will paint the table item's foreground. In Windows, if you
724 * paint the background but let the widget draw the foreground,
725 * it will override your background, unless the item is selected
726 * or hot.
110d44a1
PT
727 */
728 event.detail &= ~SWT.FOREGROUND;
729
730 // paint the highlighted background for all style ranges
731 if (styleRanges != null) {
732 Rectangle textBounds = item.getTextBounds(event.index);
733 String text = item.getText(event.index);
734 for (Object o : styleRanges) {
735 if (o instanceof StyleRange) {
736 StyleRange styleRange = (StyleRange) o;
737 if (styleRange.data.equals(event.index)) {
738 int startIndex = styleRange.start;
739 int endIndex = startIndex + styleRange.length;
740 int startX = gc.stringExtent(text.substring(0, startIndex)).x;
741 int endX = gc.stringExtent(text.substring(0, endIndex)).x;
742 gc.setBackground(styleRange.background);
743 gc.fillRectangle(textBounds.x + startX, textBounds.y, (endX - startX), textBounds.height);
744 }
745 }
746 }
747 }
748 }
749 });
750
751 fTable.addListener(SWT.PaintItem, new Listener() {
752 @Override
753 public void handleEvent(Event event) {
754 TableItem item = (TableItem) event.item;
755
756 // we promised to paint the table item's foreground
757 GC gc = event.gc;
758 Image image = item.getImage(event.index);
759 if (image != null) {
760 Rectangle imageBounds = item.getImageBounds(event.index);
761 /*
762 * The image bounds don't match the default image position.
763 */
4c27e423
PT
764 if (IS_LINUX) {
765 gc.drawImage(image, imageBounds.x + 1, imageBounds.y + 3);
766 } else {
767 gc.drawImage(image, imageBounds.x, imageBounds.y + 1);
768 }
110d44a1
PT
769 }
770 gc.setForeground(item.getForeground(event.index));
771 gc.setFont(item.getFont(event.index));
772 String text = item.getText(event.index);
773 Rectangle textBounds = item.getTextBounds(event.index);
774 /*
775 * The text bounds don't match the default text position.
776 */
4c27e423
PT
777 if (IS_LINUX) {
778 gc.drawText(text, textBounds.x + 1, textBounds.y + 3, true);
779 } else {
780 gc.drawText(text, textBounds.x - 1, textBounds.y + 2, true);
781 }
110d44a1
PT
782 }
783 });
784
db4721fb
PT
785 // Create resources
786 createResources();
787
812e7197 788 initializeFonts();
bb7c657f 789 initializeColors();
812e7197
PT
790 PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(this);
791
db4721fb
PT
792 ColorSettingsManager.addColorSettingsListener(this);
793
794 fTable.setItemCount(1); // +1 for header row
795
796 fRawViewer = new TmfRawEventViewer(fSashForm, SWT.H_SCROLL | SWT.V_SCROLL);
797
798 fRawViewer.addSelectionListener(new Listener() {
799 @Override
800 public void handleEvent(final Event e) {
7df9ba27
PT
801 if (fTrace == null) {
802 return;
803 }
804 long rank;
db4721fb 805 if (e.data instanceof Long) {
7df9ba27 806 rank = (Long) e.data;
1e1bef82 807 } else if (e.data instanceof ITmfLocation) {
7df9ba27 808 rank = findRank((ITmfLocation) e.data);
db4721fb
PT
809 } else {
810 return;
811 }
7df9ba27
PT
812 int index = (int) rank;
813 if (fTable.getData(Key.FILTER_OBJ) != null) {
814 // +1 for top filter status row
815 index = fCache.getFilteredEventIndex(rank) + 1;
816 }
817 // +1 for header row
818 fTable.setSelection(index + 1);
819 fSelectedRank = rank;
9ba0a108 820 fSelectedBeginRank = fSelectedRank;
7df9ba27 821 updateStatusLine(null);
db4721fb
PT
822 final TableItem[] selection = fTable.getSelection();
823 if ((selection != null) && (selection.length > 0)) {
476a18ba
PT
824 TableItem item = fTable.getSelection()[0];
825 final TmfTimestamp ts = (TmfTimestamp) item.getData(Key.TIMESTAMP);
db4721fb 826 if (ts != null) {
97c71024 827 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, ts));
db4721fb 828 }
476a18ba
PT
829 if (item.getData() instanceof ITmfEvent) {
830 broadcast(new TmfEventSelectedSignal(TmfEventsTable.this, (ITmfEvent) item.getData()));
831 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, new StructuredSelection(item.getData())));
832 } else {
833 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, StructuredSelection.EMPTY));
834 }
db4721fb
PT
835 }
836 }
7df9ba27
PT
837
838 private long findRank(final ITmfLocation selectedLocation) {
839 final double selectedRatio = fTrace.getLocationRatio(selectedLocation);
840 long low = 0;
841 long high = fTrace.getNbEvents();
842 long rank = high / 2;
843 double ratio = -1;
844 while (ratio != selectedRatio) {
845 ITmfContext context = fTrace.seekEvent(rank);
846 ratio = fTrace.getLocationRatio(context.getLocation());
847 context.dispose();
848 if (ratio < selectedRatio) {
849 low = rank;
850 rank = (rank + high) / 2;
851 } else if (ratio > selectedRatio) {
852 high = rank;
853 rank = (rank + low) / 2;
854 }
855 if ((high - low) < 2) {
856 break;
857 }
858 }
859 return rank;
860 }
db4721fb
PT
861 });
862
863 fSashForm.setWeights(new int[] { 1, 1 });
864 fRawViewer.setVisible(false);
865
866 createPopupMenu();
867 }
868
346ffed7
MK
869 /**
870 * Checked menu creator to make columns visible or not.
871 *
872 * @param parent
873 * the parent menu
874 * @param column
875 * the column
876 */
be42703d
MK
877 private static IAction createHeaderAction(final TableColumn column) {
878 final IAction columnMenuAction = new Action(column.getText(), IAction.AS_CHECK_BOX) {
346ffed7 879 @Override
be42703d
MK
880 public void run() {
881 if (isChecked()) {
346ffed7
MK
882 column.setWidth((int) column.getData(Key.WIDTH));
883 column.setResizable(true);
884 } else {
885 column.setData(Key.WIDTH, column.getWidth());
886 column.setWidth(0);
887 column.setResizable(false);
888 }
889 }
be42703d
MK
890 };
891 columnMenuAction.setChecked(column.getResizable());
892 return columnMenuAction;
346ffed7
MK
893 }
894
be42703d
MK
895 private IAction createResetHeaderAction() {
896 return new Action(Messages.TmfEventsTable_ShowAll) {
346ffed7 897 @Override
be42703d 898 public void run() {
346ffed7
MK
899 for (TableColumn column : fTable.getColumns()) {
900 final Object widthVal = column.getData(Key.WIDTH);
901 if (widthVal instanceof Integer) {
902 Integer width = (Integer) widthVal;
903 if (!column.getResizable()) {
904 column.setWidth(width);
905 column.setResizable(true);
906 /*
907 * This is because Linux always resizes the last
908 * column to fill in the void, this means that
909 * hiding a column resizes others and we can have 10
910 * columns that are 1000 pixels wide by hiding the
911 * last one progressively.
912 */
913 if (IS_LINUX) {
914 column.pack();
915 }
916 }
917 }
918 }
346ffed7 919 }
be42703d 920 };
346ffed7
MK
921 }
922
baafe54c
AM
923 // ------------------------------------------------------------------------
924 // Operations
925 // ------------------------------------------------------------------------
926
a0a88f65
AM
927 /**
928 * Create a pop-up menu.
929 */
a890f499 930 private void createPopupMenu() {
9ba0a108
PT
931 final IAction copyAction = new Action(Messages.TmfEventsTable_CopyToClipboardActionText) {
932 @Override
933 public void run() {
934 ITmfTrace trace = fTrace;
935 if (trace == null || (fSelectedRank == -1 && fSelectedBeginRank == -1)) {
936 return;
937 }
938
939 List<TmfEventTableColumn> columns = new ArrayList<>();
940 for (int i : fTable.getColumnOrder()) {
941 TableColumn column = fTable.getColumns()[i];
942 // Omit the margin column and hidden columns
943 if (i >= EVENT_COLUMNS_START_INDEX && (column.getResizable() || column.getWidth() > 0)) {
944 columns.add(fColumns.get(i));
945 }
946 }
947
948 long start = Math.min(fSelectedBeginRank, fSelectedRank);
949 long end = Math.max(fSelectedBeginRank, fSelectedRank);
950 final ITmfFilter filter = (ITmfFilter) fTable.getData(Key.FILTER_OBJ);
951 IRunnableWithProgress operation = new CopyToClipboardOperation(trace, filter, columns, start, end);
952 try {
953 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation);
954 } catch (InvocationTargetException e) {
955 Activator.getDefault().logError("Invocation target exception copying to clipboard ", e); //$NON-NLS-1$
956 } catch (InterruptedException e) {
957 /* ignored */
958 }
959 }
960 };
961
db4721fb
PT
962 final IAction showTableAction = new Action(Messages.TmfEventsTable_ShowTableActionText) {
963 @Override
964 public void run() {
965 fTable.setVisible(true);
966 fSashForm.layout();
967 }
968 };
969
970 final IAction hideTableAction = new Action(Messages.TmfEventsTable_HideTableActionText) {
971 @Override
972 public void run() {
973 fTable.setVisible(false);
974 fSashForm.layout();
975 }
976 };
977
978 final IAction showRawAction = new Action(Messages.TmfEventsTable_ShowRawActionText) {
979 @Override
980 public void run() {
981 fRawViewer.setVisible(true);
982 fSashForm.layout();
983 final int index = fTable.getSelectionIndex();
dadf6e1a 984 if (index >= 1) {
db4721fb
PT
985 fRawViewer.selectAndReveal(index - 1);
986 }
987 }
988 };
989
990 final IAction hideRawAction = new Action(Messages.TmfEventsTable_HideRawActionText) {
991 @Override
992 public void run() {
993 fRawViewer.setVisible(false);
994 fSashForm.layout();
995 }
996 };
997
029df6e3 998 final IAction openCallsiteAction = new Action(Messages.TmfEventsTable_OpenSourceCodeActionText) {
60fb38b8
PT
999 @Override
1000 public void run() {
1001 final TableItem items[] = fTable.getSelection();
1002 if (items.length != 1) {
1003 return;
1004 }
1005 final TableItem item = items[0];
1006
1007 final Object data = item.getData();
f47ed727
BH
1008 if (data instanceof ITmfSourceLookup) {
1009 ITmfSourceLookup event = (ITmfSourceLookup) data;
1010 ITmfCallsite cs = event.getCallsite();
60fb38b8
PT
1011 if (cs == null || cs.getFileName() == null) {
1012 return;
1013 }
1014 IMarker marker = null;
1015 try {
1016 String fileName = cs.getFileName();
03142470 1017 final String trimmedPath = fileName.replaceAll("\\.\\./", EMPTY_STRING); //$NON-NLS-1$
507b1336 1018 final ArrayList<IFile> files = new ArrayList<>();
60fb38b8
PT
1019 ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
1020 @Override
1021 public boolean visit(IResource resource) throws CoreException {
1022 if (resource instanceof IFile && resource.getFullPath().toString().endsWith(trimmedPath)) {
1023 files.add((IFile) resource);
1024 }
1025 return true;
1026 }
1027 });
1028 IFile file = null;
1029 if (files.size() > 1) {
1030 ListDialog dialog = new ListDialog(getTable().getShell());
1031 dialog.setContentProvider(ArrayContentProvider.getInstance());
1032 dialog.setLabelProvider(new LabelProvider() {
1033 @Override
1034 public String getText(Object element) {
1035 return ((IFile) element).getFullPath().toString();
1036 }
1037 });
1038 dialog.setInput(files);
029df6e3
JCK
1039 dialog.setTitle(Messages.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle);
1040 dialog.setMessage(Messages.TmfEventsTable_OpenSourceCodeSelectFileDialogTitle + '\n' + cs.toString());
60fb38b8
PT
1041 dialog.open();
1042 Object[] result = dialog.getResult();
1043 if (result != null && result.length > 0) {
1044 file = (IFile) result[0];
1045 }
1046 } else if (files.size() == 1) {
1047 file = files.get(0);
1048 }
1049 if (file != null) {
1050 marker = file.createMarker(IMarker.MARKER);
1051 marker.setAttribute(IMarker.LINE_NUMBER, Long.valueOf(cs.getLineNumber()).intValue());
1052 IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker);
1053 marker.delete();
8b7eb3cd 1054 } else if (files.size() == 0) {
029df6e3 1055 displayException(new FileNotFoundException('\'' + cs.toString() + '\'' + '\n' + Messages.TmfEventsTable_OpenSourceCodeNotFound));
60fb38b8 1056 }
60fb38b8 1057 } catch (CoreException e) {
8e95e814 1058 displayException(e);
60fb38b8
PT
1059 }
1060 }
1061 }
1062 };
1063
1064 final IAction openModelAction = new Action(Messages.TmfEventsTable_OpenModelActionText) {
ac44ef71
AR
1065 @Override
1066 public void run() {
1067
1068 final TableItem items[] = fTable.getSelection();
1069 if (items.length != 1) {
1070 return;
1071 }
1072 final TableItem item = items[0];
1073
1074 final Object eventData = item.getData();
f47ed727
BH
1075 if (eventData instanceof ITmfModelLookup) {
1076 String modelURI = ((ITmfModelLookup) eventData).getModelUri();
ac44ef71
AR
1077
1078 if (modelURI != null) {
1079 IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
1080
1081 IFile file = null;
1082 final URI uri = URI.createURI(modelURI);
1083 if (uri.isPlatformResource()) {
1084 IPath path = new Path(uri.toPlatformString(true));
1085 file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
1086 } else if (uri.isFile() && !uri.isRelative()) {
1087 file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
1088 new Path(uri.toFileString()));
1089 }
1090
1091 if (file != null) {
1092 try {
1093 /*
1094 * create a temporary validation marker on the
1095 * model file, remove it afterwards thus,
1096 * navigation works with all model editors
1097 * supporting the navigation to a marker
1098 */
1099 IMarker marker = file.createMarker(EValidator.MARKER);
1100 marker.setAttribute(EValidator.URI_ATTRIBUTE, modelURI);
1101 marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
1102
1103 IDE.openEditor(activePage, marker, OpenStrategy.activateOnOpen());
1104 marker.delete();
8b7eb3cd 1105 } catch (CoreException e) {
ac44ef71
AR
1106 displayException(e);
1107 }
60fb38b8
PT
1108 } else {
1109 displayException(new FileNotFoundException('\'' + modelURI + '\'' + '\n' + Messages.TmfEventsTable_OpenModelUnsupportedURI));
ac44ef71
AR
1110 }
1111 }
1112 }
1113 }
1114 };
60fb38b8 1115
d3de0920
XR
1116 final IAction exportToTextAction = new Action(Messages.TmfEventsTable_Export_to_text) {
1117 @Override
1118 public void run() {
1119 IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
346fa221
MAL
1120 Object handlerServiceObject = activePage.getActiveEditor().getSite().getService(IHandlerService.class);
1121 IHandlerService handlerService = (IHandlerService) handlerServiceObject;
1122 Object cmdServiceObject = activePage.getActiveEditor().getSite().getService(ICommandService.class);
1123 ICommandService cmdService = (ICommandService) cmdServiceObject;
d3de0920 1124 try {
507b1336 1125 HashMap<String, Object> parameters = new HashMap<>();
d3de0920 1126 Command command = cmdService.getCommand(ExportToTextCommandHandler.COMMAND_ID);
03142470
BH
1127 ParameterizedCommand cmd = ParameterizedCommand.generateCommand(command, parameters);
1128
d3de0920 1129 IEvaluationContext context = handlerService.getCurrentState();
6817308e
PT
1130 List<TmfEventTableColumn> exportColumns = new ArrayList<>();
1131 for (int i : fTable.getColumnOrder()) {
9ba0a108
PT
1132 TableColumn column = fTable.getColumns()[i];
1133 // Omit the margin column and hidden columns
1134 if (i >= EVENT_COLUMNS_START_INDEX && (column.getResizable() || column.getWidth() > 0)) {
6817308e
PT
1135 exportColumns.add(fColumns.get(i));
1136 }
1137 }
03142470
BH
1138 context.addVariable(ExportToTextCommandHandler.TMF_EVENT_TABLE_COLUMNS_ID, exportColumns);
1139
d3de0920 1140 handlerService.executeCommandInContext(cmd, null, context);
23c625f1 1141 } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
d3de0920
XR
1142 displayException(e);
1143 }
1144 }
1145 };
1146
db4721fb
PT
1147 final IAction showSearchBarAction = new Action(Messages.TmfEventsTable_ShowSearchBarActionText) {
1148 @Override
1149 public void run() {
1150 fHeaderState = HeaderState.SEARCH;
1151 fTable.refresh();
110d44a1 1152 fTable.redraw();
db4721fb
PT
1153 }
1154 };
1155
1156 final IAction showFilterBarAction = new Action(Messages.TmfEventsTable_ShowFilterBarActionText) {
1157 @Override
1158 public void run() {
1159 fHeaderState = HeaderState.FILTER;
1160 fTable.refresh();
110d44a1 1161 fTable.redraw();
db4721fb
PT
1162 }
1163 };
1164
1165 final IAction clearFiltersAction = new Action(Messages.TmfEventsTable_ClearFiltersActionText) {
1166 @Override
1167 public void run() {
1168 clearFilters();
1169 }
1170 };
1171
03142470
BH
1172 final IAction collapseAction = new Action(Messages.TmfEventsTable_CollapseFilterMenuName) {
1173 @Override
1174 public void run() {
1175 applyFilter(new TmfCollapseFilter());
1176 }
1177 };
1178
db4721fb 1179 class ToggleBookmarkAction extends Action {
0126a8ca 1180 Long fRank;
db4721fb 1181
0126a8ca 1182 public ToggleBookmarkAction(final String text, final Long rank) {
db4721fb
PT
1183 super(text);
1184 fRank = rank;
1185 }
1186
1187 @Override
1188 public void run() {
1189 toggleBookmark(fRank);
1190 }
1191 }
1192
be42703d
MK
1193 final MenuManager headerPopupMenu = new MenuManager();
1194 headerPopupMenu.setRemoveAllWhenShown(true);
1195 headerPopupMenu.addMenuListener(new IMenuListener() {
1196 @Override
1197 public void menuAboutToShow(IMenuManager manager) {
1198 for (int index : fTable.getColumnOrder()) {
1199 if (fTable.getColumns()[index].getData(Key.WIDTH) != null) {
1200 headerPopupMenu.add(createHeaderAction(fTable.getColumns()[index]));
1201 }
1202 }
1203 headerPopupMenu.add(new Separator());
1204 headerPopupMenu.add(createResetHeaderAction());
1205 }
1206 });
1207
db4721fb
PT
1208 final MenuManager tablePopupMenu = new MenuManager();
1209 tablePopupMenu.setRemoveAllWhenShown(true);
1210 tablePopupMenu.addMenuListener(new IMenuListener() {
1211 @Override
1212 public void menuAboutToShow(final IMenuManager manager) {
9ba0a108 1213 if (fTable.getSelectionIndices().length == 1 && fTable.getSelectionIndices()[0] == 0) {
db4721fb
PT
1214 // Right-click on header row
1215 if (fHeaderState == HeaderState.FILTER) {
1216 tablePopupMenu.add(showSearchBarAction);
1217 } else {
1218 tablePopupMenu.add(showFilterBarAction);
1219 }
1220 return;
1221 }
1222 final Point point = fTable.toControl(Display.getDefault().getCursorLocation());
1223 final TableItem item = fTable.getSelection().length > 0 ? fTable.getSelection()[0] : null;
1224 if (item != null) {
1225 final Rectangle imageBounds = item.getImageBounds(0);
1226 imageBounds.width = BOOKMARK_IMAGE.getBounds().width;
1227 if (point.x <= (imageBounds.x + imageBounds.width)) {
1228 // Right-click on left margin
1229 final Long rank = (Long) item.getData(Key.RANK);
1230 if ((rank != null) && (fBookmarksFile != null)) {
1231 if (fBookmarksMap.containsKey(rank)) {
1232 tablePopupMenu.add(new ToggleBookmarkAction(
1233 Messages.TmfEventsTable_RemoveBookmarkActionText, rank));
1234 } else {
1235 tablePopupMenu.add(new ToggleBookmarkAction(
1236 Messages.TmfEventsTable_AddBookmarkActionText, rank));
1237 }
1238 }
1239 return;
1240 }
1241 }
60fb38b8 1242
db4721fb 1243 // Right-click on table
9ba0a108
PT
1244 if (fSelectedRank != -1 && fSelectedBeginRank != -1) {
1245 tablePopupMenu.add(copyAction);
1246 tablePopupMenu.add(new Separator());
1247 }
db4721fb
PT
1248 if (fTable.isVisible() && fRawViewer.isVisible()) {
1249 tablePopupMenu.add(hideTableAction);
1250 tablePopupMenu.add(hideRawAction);
1251 } else if (!fTable.isVisible()) {
1252 tablePopupMenu.add(showTableAction);
1253 } else if (!fRawViewer.isVisible()) {
1254 tablePopupMenu.add(showRawAction);
1255 }
d3de0920 1256 tablePopupMenu.add(exportToTextAction);
db4721fb 1257 tablePopupMenu.add(new Separator());
60fb38b8 1258
ac44ef71 1259 if (item != null) {
60fb38b8 1260 final Object data = item.getData();
f47ed727
BH
1261 Separator separator = null;
1262 if (data instanceof ITmfSourceLookup) {
1263 ITmfSourceLookup event = (ITmfSourceLookup) data;
60fb38b8
PT
1264 if (event.getCallsite() != null) {
1265 tablePopupMenu.add(openCallsiteAction);
1266 separator = new Separator();
1267 }
f47ed727
BH
1268 }
1269
1270 if (data instanceof ITmfModelLookup) {
1271 ITmfModelLookup event = (ITmfModelLookup) data;
1272 if (event.getModelUri() != null) {
60fb38b8
PT
1273 tablePopupMenu.add(openModelAction);
1274 separator = new Separator();
1275 }
f47ed727 1276
60fb38b8
PT
1277 if (separator != null) {
1278 tablePopupMenu.add(separator);
ac44ef71
AR
1279 }
1280 }
1281 }
60fb38b8 1282
8b7eb3cd
MK
1283 /*
1284 * Only show collapse filter if at least one trace can be
1285 * collapsed.
1286 */
03142470
BH
1287 boolean isCollapsible = false;
1288 if (fTrace != null) {
c14c0757 1289 for (ITmfTrace trace : TmfTraceManager.getTraceSet(fTrace)) {
8b7eb3cd 1290 Class<? extends ITmfEvent> eventClass = trace.getEventType();
03142470
BH
1291 isCollapsible = ITmfCollapsibleEvent.class.isAssignableFrom(eventClass);
1292 if (isCollapsible) {
1293 break;
1294 }
1295 }
1296 }
1297
1298 if (isCollapsible && !(fTable.getData(Key.FILTER_OBJ) instanceof TmfCollapseFilter)) {
1299 tablePopupMenu.add(collapseAction);
1300 tablePopupMenu.add(new Separator());
1301 }
1302
db4721fb
PT
1303 tablePopupMenu.add(clearFiltersAction);
1304 final ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters();
1305 if (savedFilters.length > 0) {
1306 final MenuManager subMenu = new MenuManager(Messages.TmfEventsTable_ApplyPresetFilterMenuName);
1307 for (final ITmfFilterTreeNode node : savedFilters) {
1308 if (node instanceof TmfFilterNode) {
1309 final TmfFilterNode filter = (TmfFilterNode) node;
1310 subMenu.add(new Action(filter.getFilterName()) {
1311 @Override
1312 public void run() {
1313 applyFilter(filter);
1314 }
1315 });
1316 }
1317 }
1318 tablePopupMenu.add(subMenu);
1319 }
1320 appendToTablePopupMenu(tablePopupMenu, item);
1321 }
1322 });
1323
1324 final MenuManager rawViewerPopupMenu = new MenuManager();
1325 rawViewerPopupMenu.setRemoveAllWhenShown(true);
1326 rawViewerPopupMenu.addMenuListener(new IMenuListener() {
1327 @Override
1328 public void menuAboutToShow(final IMenuManager manager) {
1329 if (fTable.isVisible() && fRawViewer.isVisible()) {
1330 rawViewerPopupMenu.add(hideTableAction);
1331 rawViewerPopupMenu.add(hideRawAction);
1332 } else if (!fTable.isVisible()) {
1333 rawViewerPopupMenu.add(showTableAction);
1334 } else if (!fRawViewer.isVisible()) {
1335 rawViewerPopupMenu.add(showRawAction);
1336 }
1337 appendToRawPopupMenu(tablePopupMenu);
1338 }
1339 });
1340
be42703d
MK
1341 fHeaderMenu = headerPopupMenu.createContextMenu(fTable);
1342
346ffed7
MK
1343 fTablePopup = tablePopupMenu.createContextMenu(fTable);
1344 fTable.setMenu(fTablePopup);
db4721fb 1345
346ffed7
MK
1346 fRawTablePopup = rawViewerPopupMenu.createContextMenu(fRawViewer);
1347 fRawViewer.setMenu(fRawTablePopup);
db4721fb
PT
1348 }
1349
a0a88f65
AM
1350 /**
1351 * Append an item to the event table's pop-up menu.
1352 *
1353 * @param tablePopupMenu
1354 * The menu manager
1355 * @param selectedItem
1356 * The item to append
1357 */
db4721fb
PT
1358 protected void appendToTablePopupMenu(final MenuManager tablePopupMenu, final TableItem selectedItem) {
1359 // override to append more actions
1360 }
1361
a0a88f65
AM
1362 /**
1363 * Append an item to the raw viewer's pop-up menu.
1364 *
1365 * @param rawViewerPopupMenu
1366 * The menu manager
1367 */
db4721fb
PT
1368 protected void appendToRawPopupMenu(final MenuManager rawViewerPopupMenu) {
1369 // override to append more actions
1370 }
1371
1372 @Override
1373 public void dispose() {
1374 stopSearchThread();
1375 stopFilterThread();
812e7197 1376 PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(this);
db4721fb
PT
1377 ColorSettingsManager.removeColorSettingsListener(this);
1378 fComposite.dispose();
1379 if ((fTrace != null) && fDisposeOnClose) {
1380 fTrace.dispose();
1381 }
1382 fResourceManager.dispose();
3a97628a 1383 fRawViewer.dispose();
db4721fb
PT
1384 super.dispose();
1385 }
1386
1387 /**
1388 * Assign a layout data object to this view.
1389 *
1390 * @param layoutData
1391 * The layout data to assign
1392 */
1393 public void setLayoutData(final Object layoutData) {
1394 fComposite.setLayoutData(layoutData);
1395 }
1396
1397 /**
1398 * Get the virtual table contained in this event table.
1399 *
1400 * @return The TMF virtual table
1401 */
1402 public TmfVirtualTable getTable() {
1403 return fTable;
1404 }
1405
1406 /**
1407 * @param columnData
baafe54c
AM
1408 * columnData
1409 * @deprecated The column headers are now set at the constructor, this
1410 * shouldn't be called anymore.
db4721fb 1411 */
baafe54c 1412 @Deprecated
8b7eb3cd 1413 protected void setColumnHeaders(final org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
baafe54c 1414 /* No-op */
db4721fb
PT
1415 }
1416
a0a88f65
AM
1417 /**
1418 * Set a table item's data.
1419 *
1420 * @param item
1421 * The item to set
1422 * @param event
1423 * Which trace event to link with this entry
1424 * @param rank
1425 * Which rank this event has in the trace/experiment
1426 */
db4721fb 1427 protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) {
03142470 1428 String[] itemStrings = getItemStrings(fColumns, event);
32528869
BH
1429
1430 // Get the actual ITmfEvent from the CachedEvent
1431 ITmfEvent tmfEvent = event;
1432 if (event instanceof CachedEvent) {
1433 tmfEvent = ((CachedEvent) event).event;
1434 }
03142470 1435 item.setText(itemStrings);
32528869
BH
1436 item.setData(tmfEvent);
1437 item.setData(Key.TIMESTAMP, new TmfTimestamp(tmfEvent.getTimestamp()));
db4721fb
PT
1438 item.setData(Key.RANK, rank);
1439
2db176a0
PT
1440 final Collection<Long> markerIds = fBookmarksMap.get(rank);
1441 if (!markerIds.isEmpty()) {
1442 Joiner joiner = Joiner.on("\n -").skipNulls(); //$NON-NLS-1$
1443 List<Object> parts = new ArrayList<>();
1444 if (markerIds.size() > 1) {
1445 parts.add(Messages.TmfEventsTable_MultipleBookmarksToolTip);
1446 }
db4721fb 1447 try {
2db176a0
PT
1448 for (long markerId : markerIds) {
1449 final IMarker marker = fBookmarksFile.findMarker(markerId);
1450 parts.add(marker.getAttribute(IMarker.MESSAGE));
1451 }
1452 } catch (CoreException e) {
db4721fb
PT
1453 displayException(e);
1454 }
2db176a0 1455 item.setData(Key.BOOKMARK, joiner.join(parts));
db4721fb
PT
1456 } else {
1457 item.setData(Key.BOOKMARK, null);
1458 }
1459
1460 boolean searchMatch = false;
1461 boolean searchNoMatch = false;
1462 final ITmfFilter searchFilter = (ITmfFilter) fTable.getData(Key.SEARCH_OBJ);
1463 if (searchFilter != null) {
32528869 1464 if (searchFilter.matches(tmfEvent)) {
db4721fb
PT
1465 searchMatch = true;
1466 } else {
1467 searchNoMatch = true;
1468 }
1469 }
1470
32528869 1471 final ColorSetting colorSetting = ColorSettingsManager.getColorSetting(tmfEvent);
db4721fb
PT
1472 if (searchNoMatch) {
1473 item.setForeground(colorSetting.getDimmedForegroundColor());
1474 item.setBackground(colorSetting.getDimmedBackgroundColor());
1475 } else {
1476 item.setForeground(colorSetting.getForegroundColor());
1477 item.setBackground(colorSetting.getBackgroundColor());
1478 }
812e7197 1479 item.setFont(fFont);
db4721fb
PT
1480
1481 if (searchMatch) {
2db176a0 1482 if (!markerIds.isEmpty()) {
db4721fb
PT
1483 item.setImage(SEARCH_MATCH_BOOKMARK_IMAGE);
1484 } else {
1485 item.setImage(SEARCH_MATCH_IMAGE);
1486 }
2db176a0 1487 } else if (!markerIds.isEmpty()) {
db4721fb
PT
1488 item.setImage(BOOKMARK_IMAGE);
1489 } else {
1490 item.setImage((Image) null);
1491 }
03142470 1492
110d44a1
PT
1493 List<StyleRange> styleRanges = new ArrayList<>();
1494 for (int index = 0; index < fTable.getColumns().length; index++) {
1495 TableColumn column = fTable.getColumns()[index];
1496 String regex = null;
1497 if (fHeaderState == HeaderState.FILTER) {
1498 regex = (String) column.getData(Key.FILTER_TXT);
1499 } else if (searchMatch) {
1500 regex = (String) column.getData(Key.SEARCH_TXT);
1501 }
1502 if (regex != null) {
110d44a1
PT
1503 String text = item.getText(index);
1504 try {
1505 Pattern pattern = Pattern.compile(regex);
1506 Matcher matcher = pattern.matcher(text);
1507 while (matcher.find()) {
1508 int start = matcher.start();
1509 int length = matcher.end() - start;
1510 Color foreground = colorSetting.getForegroundColor();
bb7c657f 1511 Color background = fHighlightColor;
110d44a1
PT
1512 StyleRange styleRange = new StyleRange(start, length, foreground, background);
1513 styleRange.data = index;
1514 styleRanges.add(styleRange);
1515 }
1516 } catch (PatternSyntaxException e) {
1517 /* ignored */
1518 }
1519 }
1520 }
1521 if (styleRanges.isEmpty()) {
1522 item.setData(Key.STYLE_RANGES, null);
1523 } else {
1524 item.setData(Key.STYLE_RANGES, styleRanges);
1525 }
1526 item.getParent().redraw();
1527
03142470
BH
1528 if ((itemStrings[MARGIN_COLUMN_INDEX] != null) && !itemStrings[MARGIN_COLUMN_INDEX].isEmpty()) {
1529 packMarginColumn();
1530 }
db4721fb
PT
1531 }
1532
a0a88f65
AM
1533 /**
1534 * Set the item data of the header row.
1535 *
1536 * @param item
1537 * The item to use as table header
1538 */
db4721fb
PT
1539 protected void setHeaderRowItemData(final TableItem item) {
1540 String txtKey = null;
1541 if (fHeaderState == HeaderState.SEARCH) {
1542 item.setImage(SEARCH_IMAGE);
1543 txtKey = Key.SEARCH_TXT;
1544 } else if (fHeaderState == HeaderState.FILTER) {
1545 item.setImage(FILTER_IMAGE);
1546 txtKey = Key.FILTER_TXT;
1547 }
1548 item.setForeground(fGrayColor);
03142470
BH
1549 // Ignore collapse and image column
1550 for (int i = EVENT_COLUMNS_START_INDEX; i < fTable.getColumns().length; i++) {
db4721fb
PT
1551 final TableColumn column = fTable.getColumns()[i];
1552 final String filter = (String) column.getData(txtKey);
1553 if (filter == null) {
1554 if (fHeaderState == HeaderState.SEARCH) {
1555 item.setText(i, SEARCH_HINT);
1556 } else if (fHeaderState == HeaderState.FILTER) {
1557 item.setText(i, FILTER_HINT);
1558 }
1559 item.setForeground(i, fGrayColor);
812e7197 1560 item.setFont(i, fFont);
db4721fb
PT
1561 } else {
1562 item.setText(i, filter);
1563 item.setForeground(i, fGreenColor);
1564 item.setFont(i, fBoldFont);
1565 }
1566 }
1567 }
1568
a0a88f65
AM
1569 /**
1570 * Set the item data of the "filter status" row.
1571 *
1572 * @param item
1573 * The item to use as filter status row
1574 */
db4721fb
PT
1575 protected void setFilterStatusRowItemData(final TableItem item) {
1576 for (int i = 0; i < fTable.getColumns().length; i++) {
03142470 1577 if (i == MARGIN_COLUMN_INDEX) {
db4721fb
PT
1578 if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents())) {
1579 item.setImage(FILTER_IMAGE);
1580 } else {
1581 item.setImage(STOP_IMAGE);
1582 }
03142470
BH
1583 }
1584
1585 if (i == FILTER_SUMMARY_INDEX) {
1586 item.setText(FILTER_SUMMARY_INDEX, fFilterMatchCount + "/" + fFilterCheckCount); //$NON-NLS-1$
db4721fb 1587 } else {
03142470 1588 item.setText(i, EMPTY_STRING);
db4721fb
PT
1589 }
1590 }
93bfd50a 1591 item.setData(null);
db4721fb
PT
1592 item.setData(Key.TIMESTAMP, null);
1593 item.setData(Key.RANK, null);
110d44a1 1594 item.setData(Key.STYLE_RANGES, null);
db4721fb
PT
1595 item.setForeground(null);
1596 item.setBackground(null);
812e7197 1597 item.setFont(fFont);
db4721fb
PT
1598 }
1599
a0a88f65
AM
1600 /**
1601 * Create an editor for the header.
1602 */
a890f499 1603 private void createHeaderEditor() {
db4721fb
PT
1604 final TableEditor tableEditor = fTable.createTableEditor();
1605 tableEditor.horizontalAlignment = SWT.LEFT;
1606 tableEditor.verticalAlignment = SWT.CENTER;
1607 tableEditor.grabHorizontal = true;
1608 tableEditor.minimumWidth = 50;
1609
1610 // Handle the header row selection
1611 fTable.addMouseListener(new MouseAdapter() {
1612 int columnIndex;
1613 TableColumn column;
1614 TableItem item;
1615
1616 @Override
1617 public void mouseDown(final MouseEvent event) {
1618 if (event.button != 1) {
1619 return;
1620 }
1621 // Identify the selected row
1622 final Point point = new Point(event.x, event.y);
1623 item = fTable.getItem(point);
1624
1625 // Header row selected
1626 if ((item != null) && (fTable.indexOf(item) == 0)) {
1627
8ec1247f
BH
1628 // Margin column selected
1629 if (item.getBounds(0).contains(point)) {
db4721fb
PT
1630 if (fHeaderState == HeaderState.SEARCH) {
1631 fHeaderState = HeaderState.FILTER;
1632 } else if (fHeaderState == HeaderState.FILTER) {
1633 fHeaderState = HeaderState.SEARCH;
1634 }
3f43dc48 1635 fTable.setSelection(0);
db4721fb 1636 fTable.refresh();
110d44a1 1637 fTable.redraw();
db4721fb
PT
1638 return;
1639 }
1640
1641 // Identify the selected column
1642 columnIndex = -1;
1643 for (int i = 0; i < fTable.getColumns().length; i++) {
1644 final Rectangle rect = item.getBounds(i);
1645 if (rect.contains(point)) {
1646 columnIndex = i;
1647 break;
1648 }
1649 }
1650
1651 if (columnIndex == -1) {
1652 return;
1653 }
1654
1655 column = fTable.getColumns()[columnIndex];
1656
1657 String txtKey = null;
1658 if (fHeaderState == HeaderState.SEARCH) {
1659 txtKey = Key.SEARCH_TXT;
1660 } else if (fHeaderState == HeaderState.FILTER) {
1661 txtKey = Key.FILTER_TXT;
1662 }
1663
8b7eb3cd
MK
1664 /*
1665 * The control that will be the editor must be a child of
1666 * the Table
1667 */
db4721fb
PT
1668 final Text newEditor = (Text) fTable.createTableEditorControl(Text.class);
1669 final String headerString = (String) column.getData(txtKey);
1670 if (headerString != null) {
1671 newEditor.setText(headerString);
1672 }
1673 newEditor.addFocusListener(new FocusAdapter() {
1674 @Override
1675 public void focusLost(final FocusEvent e) {
1676 final boolean changed = updateHeader(newEditor.getText());
1677 if (changed) {
1678 applyHeader();
1679 }
1680 }
1681 });
1682 newEditor.addKeyListener(new KeyAdapter() {
1683 @Override
1684 public void keyPressed(final KeyEvent e) {
1685 if (e.character == SWT.CR) {
1686 updateHeader(newEditor.getText());
1687 applyHeader();
d81b17ea 1688
8b7eb3cd
MK
1689 /*
1690 * Set focus on the table so that the next
1691 * carriage return goes to the next result
1692 */
d81b17ea 1693 TmfEventsTable.this.getTable().setFocus();
db4721fb
PT
1694 } else if (e.character == SWT.ESC) {
1695 tableEditor.getEditor().dispose();
1696 }
1697 }
1698 });
1699 newEditor.selectAll();
1700 newEditor.setFocus();
1701 tableEditor.setEditor(newEditor, item, columnIndex);
1702 }
1703 }
1704
1705 /*
1706 * returns true is value was changed
1707 */
17dd85d7 1708 private boolean updateHeader(final String regex) {
db4721fb
PT
1709 String objKey = null;
1710 String txtKey = null;
1711 if (fHeaderState == HeaderState.SEARCH) {
1712 objKey = Key.SEARCH_OBJ;
1713 txtKey = Key.SEARCH_TXT;
1714 } else if (fHeaderState == HeaderState.FILTER) {
1715 objKey = Key.FILTER_OBJ;
1716 txtKey = Key.FILTER_TXT;
1717 }
17dd85d7 1718 if (regex.length() > 0) {
db4721fb 1719 try {
db4721fb
PT
1720 Pattern.compile(regex);
1721 if (regex.equals(column.getData(txtKey))) {
1722 tableEditor.getEditor().dispose();
1723 return false;
1724 }
ec34bf48 1725 final TmfFilterMatchesNode filter = new TmfFilterMatchesNode(null);
c409f16b
AM
1726 ITmfEventAspect aspect = (ITmfEventAspect) column.getData(Key.ASPECT);
1727 filter.setEventAspect(aspect);
db4721fb
PT
1728 filter.setRegex(regex);
1729 column.setData(objKey, filter);
1730 column.setData(txtKey, regex);
1731 } catch (final PatternSyntaxException ex) {
1732 tableEditor.getEditor().dispose();
1733 MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
1734 ex.getDescription(), ex.getMessage());
1735 return false;
1736 }
1737 } else {
1738 if (column.getData(txtKey) == null) {
1739 tableEditor.getEditor().dispose();
1740 return false;
1741 }
1742 column.setData(objKey, null);
1743 column.setData(txtKey, null);
1744 }
1745 return true;
1746 }
1747
1748 private void applyHeader() {
1749 if (fHeaderState == HeaderState.SEARCH) {
1750 stopSearchThread();
1751 final TmfFilterAndNode filter = new TmfFilterAndNode(null);
3dca7aa5
AM
1752 for (final TableColumn col : fTable.getColumns()) {
1753 final Object filterObj = col.getData(Key.SEARCH_OBJ);
db4721fb
PT
1754 if (filterObj instanceof ITmfFilterTreeNode) {
1755 filter.addChild((ITmfFilterTreeNode) filterObj);
1756 }
1757 }
1758 if (filter.getChildrenCount() > 0) {
1759 fTable.setData(Key.SEARCH_OBJ, filter);
1760 fTable.refresh();
1761 searchNext();
1762 fireSearchApplied(filter);
1763 } else {
1764 fTable.setData(Key.SEARCH_OBJ, null);
1765 fTable.refresh();
1766 fireSearchApplied(null);
1767 }
1768 } else if (fHeaderState == HeaderState.FILTER) {
1769 final TmfFilterAndNode filter = new TmfFilterAndNode(null);
3dca7aa5
AM
1770 for (final TableColumn col : fTable.getColumns()) {
1771 final Object filterObj = col.getData(Key.FILTER_OBJ);
db4721fb
PT
1772 if (filterObj instanceof ITmfFilterTreeNode) {
1773 filter.addChild((ITmfFilterTreeNode) filterObj);
1774 }
1775 }
1776 if (filter.getChildrenCount() > 0) {
1777 applyFilter(filter);
1778 } else {
1779 clearFilters();
1780 }
1781 }
1782
1783 tableEditor.getEditor().dispose();
1784 }
1785 });
1786
1787 fTable.addKeyListener(new KeyAdapter() {
1788 @Override
1789 public void keyPressed(final KeyEvent e) {
1790 e.doit = false;
1791 if (e.character == SWT.ESC) {
1792 stopFilterThread();
1793 stopSearchThread();
1794 fTable.refresh();
1795 } else if (e.character == SWT.DEL) {
1796 if (fHeaderState == HeaderState.SEARCH) {
1797 stopSearchThread();
1798 for (final TableColumn column : fTable.getColumns()) {
1799 column.setData(Key.SEARCH_OBJ, null);
1800 column.setData(Key.SEARCH_TXT, null);
1801 }
1802 fTable.setData(Key.SEARCH_OBJ, null);
1803 fTable.refresh();
1804 fireSearchApplied(null);
1805 } else if (fHeaderState == HeaderState.FILTER) {
1806 clearFilters();
1807 }
1808 } else if (e.character == SWT.CR) {
1809 if ((e.stateMask & SWT.SHIFT) == 0) {
1810 searchNext();
1811 } else {
1812 searchPrevious();
1813 }
1814 }
1815 }
1816 });
1817 }
1818
a0a88f65
AM
1819 /**
1820 * Send an event indicating a filter has been applied.
1821 *
1822 * @param filter
1823 * The filter that was just applied
1824 */
db4721fb 1825 protected void fireFilterApplied(final ITmfFilter filter) {
faa38350 1826 broadcast(new TmfEventFilterAppliedSignal(this, fTrace, filter));
db4721fb
PT
1827 }
1828
a0a88f65
AM
1829 /**
1830 * Send an event indicating that a search has been applied.
1831 *
1832 * @param filter
1833 * The search filter that was just applied
1834 */
db4721fb 1835 protected void fireSearchApplied(final ITmfFilter filter) {
faa38350 1836 broadcast(new TmfEventSearchAppliedSignal(this, fTrace, filter));
db4721fb
PT
1837 }
1838
a0a88f65
AM
1839 /**
1840 * Start the filtering thread.
1841 */
db4721fb
PT
1842 protected void startFilterThread() {
1843 synchronized (fFilterSyncObj) {
1844 final ITmfFilterTreeNode filter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);
1845 if (fFilterThread == null || fFilterThread.filter != filter) {
1846 if (fFilterThread != null) {
1847 fFilterThread.cancel();
1848 fFilterThreadResume = false;
1849 }
1850 fFilterThread = new FilterThread(filter);
1851 fFilterThread.start();
1852 } else {
1853 fFilterThreadResume = true;
1854 }
1855 }
1856 }
1857
a0a88f65
AM
1858 /**
1859 * Stop the filtering thread.
1860 */
db4721fb
PT
1861 protected void stopFilterThread() {
1862 synchronized (fFilterSyncObj) {
1863 if (fFilterThread != null) {
1864 fFilterThread.cancel();
1865 fFilterThread = null;
1866 fFilterThreadResume = false;
1867 }
1868 }
1869 }
1870
1871 /**
a0a88f65
AM
1872 * Apply a filter.
1873 *
1874 * @param filter
1875 * The filter to apply
db4721fb
PT
1876 */
1877 protected void applyFilter(ITmfFilter filter) {
f29f8868
BH
1878 stopFilterThread();
1879 stopSearchThread();
db4721fb
PT
1880 fFilterMatchCount = 0;
1881 fFilterCheckCount = 0;
1882 fCache.applyFilter(filter);
1883 fTable.clearAll();
1884 fTable.setData(Key.FILTER_OBJ, filter);
8b7eb3cd
MK
1885 /* +1 for header row, +2 for top and bottom filter status rows */
1886 fTable.setItemCount(3);
db4721fb
PT
1887 startFilterThread();
1888 fireFilterApplied(filter);
1889 }
1890
a0a88f65
AM
1891 /**
1892 * Clear all currently active filters.
1893 */
db4721fb
PT
1894 protected void clearFilters() {
1895 if (fTable.getData(Key.FILTER_OBJ) == null) {
1896 return;
1897 }
1898 stopFilterThread();
1899 stopSearchThread();
1900 fCache.clearFilter();
1901 fTable.clearAll();
1902 for (final TableColumn column : fTable.getColumns()) {
1903 column.setData(Key.FILTER_OBJ, null);
1904 column.setData(Key.FILTER_TXT, null);
1905 }
1906 fTable.setData(Key.FILTER_OBJ, null);
1907 if (fTrace != null) {
8b7eb3cd
MK
1908 /* +1 for header row */
1909 fTable.setItemCount((int) fTrace.getNbEvents() + 1);
db4721fb 1910 } else {
8b7eb3cd
MK
1911 /* +1 for header row */
1912 fTable.setItemCount(1);
db4721fb
PT
1913 }
1914 fFilterMatchCount = 0;
1915 fFilterCheckCount = 0;
1916 if (fSelectedRank >= 0) {
8b7eb3cd
MK
1917 /* +1 for header row */
1918 fTable.setSelection((int) fSelectedRank + 1);
db4721fb
PT
1919 } else {
1920 fTable.setSelection(0);
1921 }
1922 fireFilterApplied(null);
3f43dc48 1923 updateStatusLine(null);
03142470
BH
1924
1925 // Set original width
1926 fTable.getColumns()[MARGIN_COLUMN_INDEX].setWidth(0);
1927 packMarginColumn();
db4721fb
PT
1928 }
1929
a0a88f65
AM
1930 /**
1931 * Wrapper Thread object for the filtering thread.
1932 */
db4721fb
PT
1933 protected class FilterThread extends Thread {
1934 private final ITmfFilterTreeNode filter;
fd3f1eff 1935 private TmfEventRequest request;
db4721fb
PT
1936 private boolean refreshBusy = false;
1937 private boolean refreshPending = false;
1938 private final Object syncObj = new Object();
1939
a0a88f65
AM
1940 /**
1941 * Constructor.
1942 *
1943 * @param filter
1944 * The filter this thread will be processing
1945 */
db4721fb
PT
1946 public FilterThread(final ITmfFilterTreeNode filter) {
1947 super("Filter Thread"); //$NON-NLS-1$
1948 this.filter = filter;
1949 }
1950
1951 @Override
1952 public void run() {
1953 if (fTrace == null) {
1954 return;
1955 }
1956 final int nbRequested = (int) (fTrace.getNbEvents() - fFilterCheckCount);
1957 if (nbRequested <= 0) {
1958 return;
1959 }
fd3f1eff
AM
1960 request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY,
1961 (int) fFilterCheckCount, nbRequested, ExecutionType.BACKGROUND) {
db4721fb
PT
1962 @Override
1963 public void handleData(final ITmfEvent event) {
1964 super.handleData(event);
1965 if (request.isCancelled()) {
1966 return;
1967 }
03142470 1968 boolean refresh = false;
db4721fb
PT
1969 if (filter.matches(event)) {
1970 final long rank = fFilterCheckCount;
1971 final int index = (int) fFilterMatchCount;
1972 fFilterMatchCount++;
bd54d363 1973 fCache.storeEvent(event, rank, index);
03142470
BH
1974 refresh = true;
1975 } else {
1976 if (filter instanceof TmfCollapseFilter) {
1977 fCache.updateCollapsedEvent((int) fFilterMatchCount - 1);
1978 }
1979 }
1980
1981 if (refresh || (fFilterCheckCount % 100) == 0) {
db4721fb
PT
1982 refreshTable();
1983 }
1984 fFilterCheckCount++;
1985 }
1986 };
fd3f1eff 1987 ((ITmfEventProvider) fTrace).sendRequest(request);
db4721fb
PT
1988 try {
1989 request.waitForCompletion();
1990 } catch (final InterruptedException e) {
1991 }
1992 refreshTable();
1993 synchronized (fFilterSyncObj) {
1994 fFilterThread = null;
1995 if (fFilterThreadResume) {
1996 fFilterThreadResume = false;
1997 fFilterThread = new FilterThread(filter);
1998 fFilterThread.start();
1999 }
2000 }
2001 }
2002
a0a88f65
AM
2003 /**
2004 * Refresh the filter.
2005 */
db4721fb
PT
2006 public void refreshTable() {
2007 synchronized (syncObj) {
2008 if (refreshBusy) {
2009 refreshPending = true;
2010 return;
2011 }
2012 refreshBusy = true;
2013 }
2014 Display.getDefault().asyncExec(new Runnable() {
2015 @Override
2016 public void run() {
2017 if (request.isCancelled()) {
2018 return;
2019 }
2020 if (fTable.isDisposed()) {
2021 return;
2022 }
8b7eb3cd
MK
2023 /*
2024 * +1 for header row, +2 for top and bottom filter status
2025 * rows
2026 */
2027 fTable.setItemCount((int) fFilterMatchCount + 3);
db4721fb
PT
2028 fTable.refresh();
2029 synchronized (syncObj) {
2030 refreshBusy = false;
2031 if (refreshPending) {
2032 refreshPending = false;
2033 refreshTable();
2034 }
2035 }
2036 }
2037 });
2038 }
2039
a0a88f65
AM
2040 /**
2041 * Cancel this filtering thread.
2042 */
db4721fb
PT
2043 public void cancel() {
2044 if (request != null) {
2045 request.cancel();
2046 }
2047 }
2048 }
2049
a0a88f65
AM
2050 /**
2051 * Go to the next item of a search.
2052 */
db4721fb
PT
2053 protected void searchNext() {
2054 synchronized (fSearchSyncObj) {
2055 if (fSearchThread != null) {
2056 return;
2057 }
2058 final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ);
2059 if (searchFilter == null) {
2060 return;
2061 }
2062 final int selectionIndex = fTable.getSelectionIndex();
2063 int startIndex;
2064 if (selectionIndex > 0) {
8b7eb3cd
MK
2065 /* -1 for header row, +1 for next event */
2066 startIndex = selectionIndex;
db4721fb 2067 } else {
8b7eb3cd
MK
2068 /*
2069 * header row is selected, start at top event
2070 */
2071 /* -1 for header row */
2072 startIndex = Math.max(0, fTable.getTopIndex() - 1);
db4721fb
PT
2073 }
2074 final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);
60fb38b8 2075 if (eventFilter != null) {
8b7eb3cd
MK
2076 // -1 for top filter status row
2077 startIndex = Math.max(0, startIndex - 1);
db4721fb
PT
2078 }
2079 fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.FORWARD);
2080 fSearchThread.schedule();
2081 }
2082 }
2083
a0a88f65
AM
2084 /**
2085 * Go to the previous item of a search.
2086 */
db4721fb
PT
2087 protected void searchPrevious() {
2088 synchronized (fSearchSyncObj) {
2089 if (fSearchThread != null) {
2090 return;
2091 }
2092 final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ);
2093 if (searchFilter == null) {
2094 return;
2095 }
2096 final int selectionIndex = fTable.getSelectionIndex();
2097 int startIndex;
2098 if (selectionIndex > 0) {
8b7eb3cd
MK
2099 /* -1 for header row, -1 for previous event */
2100 startIndex = selectionIndex - 2;
db4721fb 2101 } else {
8b7eb3cd
MK
2102 /*
2103 * Header row is selected, start at precedent of top event
2104 */
2105 /* -1 for header row, -1 for previous event */
2106 startIndex = fTable.getTopIndex() - 2;
db4721fb
PT
2107 }
2108 final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);
60fb38b8 2109 if (eventFilter != null) {
8b7eb3cd
MK
2110 /* -1 for top filter status row */
2111 startIndex = startIndex - 1;
db4721fb
PT
2112 }
2113 fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.BACKWARD);
2114 fSearchThread.schedule();
2115 }
2116 }
2117
a0a88f65
AM
2118 /**
2119 * Stop the search thread.
2120 */
db4721fb
PT
2121 protected void stopSearchThread() {
2122 fPendingGotoRank = -1;
2123 synchronized (fSearchSyncObj) {
2124 if (fSearchThread != null) {
2125 fSearchThread.cancel();
2126 fSearchThread = null;
2127 }
2128 }
2129 }
2130
a0a88f65
AM
2131 /**
2132 * Wrapper for the search thread.
2133 */
db4721fb 2134 protected class SearchThread extends Job {
a0a88f65
AM
2135
2136 private ITmfFilterTreeNode searchFilter;
2137 private ITmfFilterTreeNode eventFilter;
2138 private int startIndex;
2139 private int direction;
2140 private long rank;
2141 private long foundRank = -1;
fd3f1eff 2142 private TmfEventRequest request;
ae3ffd37 2143 private ITmfTimestamp foundTimestamp = null;
db4721fb 2144
a0a88f65
AM
2145 /**
2146 * Constructor.
2147 *
2148 * @param searchFilter
2149 * The search filter
2150 * @param eventFilter
2151 * The event filter
2152 * @param startIndex
2153 * The index at which we should start searching
2154 * @param currentRank
2155 * The current rank
2156 * @param direction
2157 * In which direction should we search, forward or backwards
2158 */
2159 public SearchThread(final ITmfFilterTreeNode searchFilter,
2160 final ITmfFilterTreeNode eventFilter, final int startIndex,
db4721fb
PT
2161 final long currentRank, final int direction) {
2162 super(Messages.TmfEventsTable_SearchingJobName);
2163 this.searchFilter = searchFilter;
2164 this.eventFilter = eventFilter;
2165 this.startIndex = startIndex;
2166 this.rank = currentRank;
2167 this.direction = direction;
2168 }
2169
2170 @Override
2171 protected IStatus run(final IProgressMonitor monitor) {
f4e06774
FLN
2172 final ITmfTrace trace = fTrace;
2173 if (trace == null) {
db4721fb
PT
2174 return Status.OK_STATUS;
2175 }
2176 final Display display = Display.getDefault();
2177 if (startIndex < 0) {
f4e06774 2178 rank = (int) trace.getNbEvents() - 1;
8b7eb3cd
MK
2179 /*
2180 * -1 for header row, -3 for header and top and bottom filter
2181 * status rows
2182 */
2183 } else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3))) {
db4721fb
PT
2184 rank = 0;
2185 } else {
2186 int idx = startIndex;
2187 while (foundRank == -1) {
2188 final CachedEvent event = fCache.peekEvent(idx);
2189 if (event == null) {
2190 break;
2191 }
2192 rank = event.rank;
2193 if (searchFilter.matches(event.event) && ((eventFilter == null) || eventFilter.matches(event.event))) {
2194 foundRank = event.rank;
ae3ffd37 2195 foundTimestamp = event.event.getTimestamp();
db4721fb
PT
2196 break;
2197 }
2198 if (direction == Direction.FORWARD) {
2199 idx++;
2200 } else {
2201 idx--;
2202 }
2203 }
2204 if (foundRank == -1) {
2205 if (direction == Direction.FORWARD) {
2206 rank++;
f4e06774 2207 if (rank > (trace.getNbEvents() - 1)) {
db4721fb
PT
2208 rank = 0;
2209 }
2210 } else {
2211 rank--;
2212 if (rank < 0) {
f4e06774 2213 rank = (int) trace.getNbEvents() - 1;
db4721fb
PT
2214 }
2215 }
2216 }
2217 }
2218 final int startRank = (int) rank;
2219 boolean wrapped = false;
f4e06774
FLN
2220 while (!monitor.isCanceled() && (foundRank == -1)) {
2221 int nbRequested = (direction == Direction.FORWARD ? Integer.MAX_VALUE : Math.min((int) rank + 1, trace.getCacheSize()));
db4721fb 2222 if (direction == Direction.BACKWARD) {
f4e06774 2223 rank = Math.max(0, rank - trace.getCacheSize() + 1);
db4721fb 2224 }
fd3f1eff
AM
2225 request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY,
2226 (int) rank, nbRequested, ExecutionType.BACKGROUND) {
db4721fb
PT
2227 long currentRank = rank;
2228
2229 @Override
2230 public void handleData(final ITmfEvent event) {
2231 super.handleData(event);
2232 if (searchFilter.matches(event) && ((eventFilter == null) || eventFilter.matches(event))) {
2233 foundRank = currentRank;
ae3ffd37 2234 foundTimestamp = event.getTimestamp();
db4721fb
PT
2235 if (direction == Direction.FORWARD) {
2236 done();
2237 return;
2238 }
2239 }
2240 currentRank++;
2241 }
2242 };
f4e06774 2243 ((ITmfEventProvider) trace).sendRequest(request);
db4721fb
PT
2244 try {
2245 request.waitForCompletion();
2246 if (request.isCancelled()) {
2247 return Status.OK_STATUS;
2248 }
2249 } catch (final InterruptedException e) {
2250 synchronized (fSearchSyncObj) {
2251 fSearchThread = null;
2252 }
2253 return Status.OK_STATUS;
2254 }
2255 if (foundRank == -1) {
2256 if (direction == Direction.FORWARD) {
2257 if (rank == 0) {
2258 synchronized (fSearchSyncObj) {
2259 fSearchThread = null;
2260 }
2261 return Status.OK_STATUS;
2262 }
2263 nbRequested = (int) rank;
2264 rank = 0;
2265 wrapped = true;
2266 } else {
2267 rank--;
2268 if (rank < 0) {
f4e06774 2269 rank = (int) trace.getNbEvents() - 1;
db4721fb
PT
2270 wrapped = true;
2271 }
2272 if ((rank <= startRank) && wrapped) {
2273 synchronized (fSearchSyncObj) {
2274 fSearchThread = null;
2275 }
2276 return Status.OK_STATUS;
2277 }
2278 }
2279 }
2280 }
2281 int index = (int) foundRank;
2282 if (eventFilter != null) {
2283 index = fCache.getFilteredEventIndex(foundRank);
2284 }
8b7eb3cd
MK
2285 /* +1 for header row, +1 for top filter status row */
2286 final int selection = index + 1 + (eventFilter != null ? +1 : 0);
db4721fb
PT
2287
2288 display.asyncExec(new Runnable() {
2289 @Override
2290 public void run() {
2291 if (monitor.isCanceled()) {
2292 return;
2293 }
2294 if (fTable.isDisposed()) {
2295 return;
2296 }
2297 fTable.setSelection(selection);
2298 fSelectedRank = foundRank;
9ba0a108 2299 fSelectedBeginRank = fSelectedRank;
ae3ffd37
PT
2300 fRawViewer.selectAndReveal(fSelectedRank);
2301 if (foundTimestamp != null) {
97c71024 2302 broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, foundTimestamp));
ae3ffd37 2303 }
a56ec2b8 2304 fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, getSelection()));
db4721fb
PT
2305 synchronized (fSearchSyncObj) {
2306 fSearchThread = null;
2307 }
3f43dc48 2308 updateStatusLine(null);
db4721fb
PT
2309 }
2310 });
2311 return Status.OK_STATUS;
2312 }
2313
2314 @Override
2315 protected void canceling() {
2316 request.cancel();
2317 synchronized (fSearchSyncObj) {
2318 fSearchThread = null;
2319 }
2320 }
2321 }
2322
a0a88f65
AM
2323 /**
2324 * Create the resources.
2325 */
a890f499 2326 private void createResources() {
8b7eb3cd 2327 fGrayColor = fResourceManager.createColor(ColorUtil.blend(fTable.getBackground().getRGB(), fTable.getForeground().getRGB()));
db4721fb 2328 fGreenColor = fTable.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN);
812e7197
PT
2329 }
2330
2331 /**
2332 * Initialize the fonts.
812e7197 2333 */
a890f499 2334 private void initializeFonts() {
812e7197
PT
2335 FontRegistry fontRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
2336 fFont = fontRegistry.get(FONT_DEFINITION_ID);
2337 fBoldFont = fontRegistry.getBold(FONT_DEFINITION_ID);
2338 fTable.setFont(fFont);
2339 /* Column header font cannot be set. See Bug 63038 */
2340 }
2341
bb7c657f
PT
2342 /**
2343 * Initialize the colors.
bb7c657f 2344 */
a890f499 2345 private void initializeColors() {
bb7c657f
PT
2346 ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
2347 fHighlightColor = colorRegistry.get(HIGHLIGHT_COLOR_DEFINITION_ID);
2348 }
2349
812e7197
PT
2350 /**
2351 * @since 1.0
2352 */
2353 @Override
2354 public void propertyChange(PropertyChangeEvent event) {
2355 if ((IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) ||
2356 (FONT_DEFINITION_ID.equals(event.getProperty()))) {
2357 initializeFonts();
2358 fTable.refresh();
2359 }
bb7c657f
PT
2360 if ((IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) ||
2361 (HIGHLIGHT_COLOR_DEFINITION_ID.equals(event.getProperty()))) {
2362 initializeColors();
2363 fTable.refresh();
2364 }
db4721fb
PT
2365 }
2366
a0a88f65
AM
2367 /**
2368 * Pack the columns.
2369 */
db4721fb
PT
2370 protected void packColumns() {
2371 if (fPackDone) {
2372 return;
2373 }
d3bc98ee 2374 fTable.setRedraw(false);
03142470
BH
2375 try {
2376 TableColumn tableColumns[] = fTable.getColumns();
2377 for (int i = 0; i < tableColumns.length; i++) {
2378 final TableColumn column = tableColumns[i];
2379 packSingleColumn(i, column);
2380 }
346ffed7 2381
03142470
BH
2382 } finally {
2383 // Make sure that redraw is always enabled.
2384 fTable.setRedraw(true);
2385 }
2386 fPackDone = true;
2387 }
d3bc98ee 2388
03142470
BH
2389 private void packMarginColumn() {
2390 TableColumn[] columns = fTable.getColumns();
2391 if (columns.length > 0) {
2392 packSingleColumn(0, columns[0]);
2393 }
2394 }
f29f8868 2395
03142470
BH
2396 private void packSingleColumn(int i, final TableColumn column) {
2397 final int headerWidth = column.getWidth();
2398 column.pack();
8b7eb3cd
MK
2399 /*
2400 * Workaround for Linux which doesn't consider the image width of
2401 * search/filter row in TableColumn.pack() after having executed
2402 * TableItem.setImage(null) for other rows than search/filter row.
2403 */
03142470
BH
2404 boolean isCollapseFilter = fTable.getData(Key.FILTER_OBJ) instanceof TmfCollapseFilter;
2405 if (IS_LINUX && (i == 0) && isCollapseFilter) {
2406 column.setWidth(column.getWidth() + SEARCH_IMAGE.getBounds().width);
db4721fb 2407 }
d3bc98ee 2408
03142470
BH
2409 if (column.getWidth() < headerWidth) {
2410 column.setWidth(headerWidth);
2411 }
db4721fb
PT
2412 }
2413
d3de0920 2414 /**
baafe54c
AM
2415 * Get the array of item strings (e.g., what to display in each cell of the
2416 * table row) corresponding to the columns and trace event passed in
2417 * parameter. The order of the Strings in the returned array will correspond
2418 * to the iteration order of 'columns'.
d3de0920 2419 *
baafe54c
AM
2420 * <p>
2421 * To ensure consistent results, make sure only call this within a scope
2422 * synchronized on 'columns'! If the order of 'columns' changes right after
2423 * this method is called, the returned value won't be ordered correctly
2424 * anymore.
2425 */
2426 private static String[] getItemStrings(List<TmfEventTableColumn> columns, ITmfEvent event) {
2427 if (event == null) {
2428 return EMPTY_STRING_ARRAY;
2429 }
2430 synchronized (columns) {
2431 List<String> itemStrings = new ArrayList<>(columns.size());
2432 for (TmfEventTableColumn column : columns) {
03142470
BH
2433 ITmfEvent passedEvent = event;
2434 if (!(column instanceof TmfMarginColumn) && (event instanceof CachedEvent)) {
8b7eb3cd
MK
2435 /*
2436 * Make sure that the event object from the trace is passed
2437 * to all columns but the TmfMarginColumn
2438 */
03142470
BH
2439 passedEvent = ((CachedEvent) event).event;
2440 }
2441 if (passedEvent == null) {
2442 itemStrings.add(EMPTY_STRING);
2443 } else {
2444 itemStrings.add(column.getItemString(passedEvent));
2445 }
2446
baafe54c
AM
2447 }
2448 return itemStrings.toArray(new String[0]);
2449 }
2450 }
2451
2452 /**
2453 * Get the contents of the row in the events table corresponding to an
2454 * event. The order of the elements corresponds to the current order of the
2455 * columns.
a0a88f65 2456 *
db4721fb 2457 * @param event
cf37ad9f
AM
2458 * The event printed in this row
2459 * @return The event row entries
db4721fb 2460 */
cf37ad9f 2461 public String[] getItemStrings(ITmfEvent event) {
6817308e
PT
2462 List<TmfEventTableColumn> columns = new ArrayList<>();
2463 for (int i : fTable.getColumnOrder()) {
2464 columns.add(fColumns.get(i));
2465 }
2466 return getItemStrings(columns, event);
db4721fb
PT
2467 }
2468
14665360 2469 /**
8b7eb3cd
MK
2470 * Returns an array of zero-relative integers that map the creation order of
2471 * the receiver's columns to the order in which they are currently being
2472 * displayed.
14665360 2473 * <p>
8b7eb3cd
MK
2474 * Specifically, the indices of the returned array represent the current
2475 * visual order of the columns, and the contents of the array represent the
2476 * creation order of the columns.
14665360
PT
2477 *
2478 * @return the current visual order of the receiver's columns
2479 * @since 1.0
2480 */
2481 public int[] getColumnOrder() {
2482 return fColumnOrder;
2483 }
2484
2485 /**
8b7eb3cd
MK
2486 * Sets the order that the columns in the receiver should be displayed in to
2487 * the given argument which is described in terms of the zero-relative
2488 * ordering of when the columns were added.
14665360 2489 * <p>
8b7eb3cd
MK
2490 * Specifically, the contents of the array represent the original position
2491 * of each column at the time its creation.
14665360 2492 *
8b7eb3cd
MK
2493 * @param order
2494 * the new order to display the columns
14665360
PT
2495 * @since 1.0
2496 */
2497 public void setColumnOrder(int[] order) {
2498 if (order == null || order.length != fTable.getColumns().length) {
2499 return;
2500 }
2501 fTable.setColumnOrder(order);
2502 fColumnOrder = fTable.getColumnOrder();
2503 }
2504
db4721fb
PT
2505 /**
2506 * Notify this table that is got the UI focus.
2507 */
2508 public void setFocus() {
2509 fTable.setFocus();
2510 }
2511
2512 /**
2513 * Assign a new trace to this event table.
2514 *
2515 * @param trace
2516 * The trace to assign to this event table
2517 * @param disposeOnClose
2518 * true if the trace should be disposed when the table is
2519 * disposed
2520 */
2521 public void setTrace(final ITmfTrace trace, final boolean disposeOnClose) {
2522 if ((fTrace != null) && fDisposeOnClose) {
2523 fTrace.dispose();
2524 }
2525 fTrace = trace;
2526 fPackDone = false;
db4721fb
PT
2527 fDisposeOnClose = disposeOnClose;
2528
2529 // Perform the updates on the UI thread
2530 fTable.getDisplay().syncExec(new Runnable() {
2531 @Override
2532 public void run() {
9ba0a108
PT
2533 fSelectedRank = -1;
2534 fSelectedBeginRank = -1;
db4721fb 2535 fTable.removeAll();
f4e06774
FLN
2536 fCache.setTrace(trace); // Clear the cache
2537 if (trace != null) {
2538 if (!fTable.isDisposed()) {
db4721fb 2539 if (fTable.getData(Key.FILTER_OBJ) == null) {
8b7eb3cd 2540 // +1 for header row
f4e06774 2541 fTable.setItemCount((int) trace.getNbEvents() + 1);
db4721fb
PT
2542 } else {
2543 stopFilterThread();
2544 fFilterMatchCount = 0;
2545 fFilterCheckCount = 0;
8b7eb3cd
MK
2546 /*
2547 * +1 for header row, +2 for top and bottom filter
2548 * status rows
2549 */
2550 fTable.setItemCount(3);
db4721fb
PT
2551 startFilterThread();
2552 }
2553 }
db4721fb 2554 }
f4e06774 2555 fRawViewer.setTrace(trace);
db4721fb
PT
2556 }
2557 });
2558 }
2559
3f43dc48
PT
2560 /**
2561 * Assign the status line manager
2562 *
2563 * @param statusLineManager
8b7eb3cd
MK
2564 * The status line manager, or null to disable status line
2565 * messages
3f43dc48
PT
2566 */
2567 public void setStatusLineManager(IStatusLineManager statusLineManager) {
2568 if (fStatusLineManager != null && statusLineManager == null) {
03142470 2569 fStatusLineManager.setMessage(EMPTY_STRING);
3f43dc48
PT
2570 }
2571 fStatusLineManager = statusLineManager;
2572 }
2573
2574 private void updateStatusLine(ITmfTimestamp delta) {
2575 if (fStatusLineManager != null) {
2576 if (delta != null) {
2577 fStatusLineManager.setMessage("\u0394: " + delta); //$NON-NLS-1$
2578 } else {
2579 fStatusLineManager.setMessage(null);
2580 }
2581 }
2582 }
2583
db4721fb
PT
2584 // ------------------------------------------------------------------------
2585 // Event cache
2586 // ------------------------------------------------------------------------
2587
2588 /**
2589 * Notify that the event cache has been updated
2590 *
2591 * @param completed
2592 * Also notify if the populating of the cache is complete, or
2593 * not.
2594 */
2595 public void cacheUpdated(final boolean completed) {
2596 synchronized (fCacheUpdateSyncObj) {
2597 if (fCacheUpdateBusy) {
2598 fCacheUpdatePending = true;
2599 fCacheUpdateCompleted = completed;
2600 return;
2601 }
2602 fCacheUpdateBusy = true;
2603 }
2604 // Event cache is now updated. Perform update on the UI thread
2605 if (!fTable.isDisposed()) {
2606 fTable.getDisplay().asyncExec(new Runnable() {
2607 @Override
2608 public void run() {
2609 if (!fTable.isDisposed()) {
2610 fTable.refresh();
2611 packColumns();
2612 }
2613 if (completed) {
2614 populateCompleted();
2615 }
2616 synchronized (fCacheUpdateSyncObj) {
2617 fCacheUpdateBusy = false;
2618 if (fCacheUpdatePending) {
2619 fCacheUpdatePending = false;
2620 cacheUpdated(fCacheUpdateCompleted);
2621 }
2622 }
2623 }
2624 });
2625 }
2626 }
2627
a0a88f65
AM
2628 /**
2629 * Callback for when populating the table is complete.
2630 */
db4721fb
PT
2631 protected void populateCompleted() {
2632 // Nothing by default;
2633 }
2634
93bfd50a
PT
2635 // ------------------------------------------------------------------------
2636 // ISelectionProvider
2637 // ------------------------------------------------------------------------
2638
93bfd50a
PT
2639 @Override
2640 public void addSelectionChangedListener(ISelectionChangedListener listener) {
2641 selectionChangedListeners.add(listener);
2642 }
2643
93bfd50a
PT
2644 @Override
2645 public ISelection getSelection() {
2646 if (fTable == null || fTable.isDisposed()) {
2647 return StructuredSelection.EMPTY;
2648 }
507b1336 2649 List<Object> list = new ArrayList<>(fTable.getSelection().length);
93bfd50a
PT
2650 for (TableItem item : fTable.getSelection()) {
2651 if (item.getData() != null) {
2652 list.add(item.getData());
2653 }
2654 }
2655 return new StructuredSelection(list);
2656 }
2657
93bfd50a
PT
2658 @Override
2659 public void removeSelectionChangedListener(ISelectionChangedListener listener) {
2660 selectionChangedListeners.remove(listener);
2661 }
2662
93bfd50a
PT
2663 @Override
2664 public void setSelection(ISelection selection) {
2665 // not implemented
2666 }
2667
2668 /**
8b7eb3cd
MK
2669 * Notifies any selection changed listeners that the viewer's selection has
2670 * changed. Only listeners registered at the time this method is called are
2671 * notified.
93bfd50a 2672 *
8b7eb3cd
MK
2673 * @param event
2674 * a selection changed event
93bfd50a
PT
2675 *
2676 * @see ISelectionChangedListener#selectionChanged
93bfd50a
PT
2677 */
2678 protected void fireSelectionChanged(final SelectionChangedEvent event) {
2679 Object[] listeners = selectionChangedListeners.getListeners();
2680 for (int i = 0; i < listeners.length; ++i) {
2681 final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
2682 SafeRunnable.run(new SafeRunnable() {
faa38350 2683 @Override
93bfd50a
PT
2684 public void run() {
2685 l.selectionChanged(event);
2686 }
2687 });
2688 }
2689 }
2690
db4721fb
PT
2691 // ------------------------------------------------------------------------
2692 // Bookmark handling
2693 // ------------------------------------------------------------------------
2694
2695 /**
2696 * Add a bookmark to this event table.
2697 *
2698 * @param bookmarksFile
2699 * The file to use for the bookmarks
2700 */
2701 public void addBookmark(final IFile bookmarksFile) {
2702 fBookmarksFile = bookmarksFile;
2703 final TableItem[] selection = fTable.getSelection();
2704 if (selection.length > 0) {
2705 final TableItem tableItem = selection[0];
2706 if (tableItem.getData(Key.RANK) != null) {
2707 final StringBuffer defaultMessage = new StringBuffer();
2708 for (int i = 0; i < fTable.getColumns().length; i++) {
60fb38b8 2709 if (i > 0) {
db4721fb
PT
2710 defaultMessage.append(", "); //$NON-NLS-1$
2711 }
2712 defaultMessage.append(tableItem.getText(i));
2713 }
3be2946f
PT
2714 final InputDialog dialog = new MultiLineInputDialog(
2715 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
2716 Messages.TmfEventsTable_AddBookmarkDialogTitle,
2717 Messages.TmfEventsTable_AddBookmarkDialogMessage,
2718 defaultMessage.toString());
db4721fb
PT
2719 if (dialog.open() == Window.OK) {
2720 final String message = dialog.getValue();
2721 try {
2722 final IMarker bookmark = bookmarksFile.createMarker(IMarker.BOOKMARK);
2723 if (bookmark.exists()) {
2724 bookmark.setAttribute(IMarker.MESSAGE, message.toString());
0126a8ca
AM
2725 final Long rank = (Long) tableItem.getData(Key.RANK);
2726 final int location = rank.intValue();
2727 bookmark.setAttribute(IMarker.LOCATION, Integer.valueOf(location));
db4721fb
PT
2728 fBookmarksMap.put(rank, bookmark.getId());
2729 fTable.refresh();
2730 }
2731 } catch (final CoreException e) {
2732 displayException(e);
2733 }
2734 }
2735 }
2736 }
2737
2738 }
2739
2740 /**
2741 * Remove a bookmark from this event table.
2742 *
2743 * @param bookmark
2744 * The bookmark to remove
2745 */
2746 public void removeBookmark(final IMarker bookmark) {
2db176a0 2747 for (final Entry<Long, Long> entry : fBookmarksMap.entries()) {
db4721fb 2748 if (entry.getValue().equals(bookmark.getId())) {
2db176a0 2749 fBookmarksMap.remove(entry.getKey(), entry.getValue());
db4721fb
PT
2750 fTable.refresh();
2751 return;
2752 }
2753 }
2754 }
2755
0126a8ca 2756 private void toggleBookmark(final Long rank) {
db4721fb
PT
2757 if (fBookmarksFile == null) {
2758 return;
2759 }
2760 if (fBookmarksMap.containsKey(rank)) {
2db176a0 2761 final Collection<Long> markerIds = fBookmarksMap.removeAll(rank);
db4721fb
PT
2762 fTable.refresh();
2763 try {
2db176a0
PT
2764 for (long markerId : markerIds) {
2765 final IMarker bookmark = fBookmarksFile.findMarker(markerId);
2766 if (bookmark != null) {
2767 bookmark.delete();
2768 }
db4721fb
PT
2769 }
2770 } catch (final CoreException e) {
2771 displayException(e);
2772 }
2773 } else {
2774 addBookmark(fBookmarksFile);
2775 }
2776 }
2777
2778 /**
2779 * Refresh the bookmarks assigned to this trace, from the contents of a
2780 * bookmark file.
2781 *
2782 * @param bookmarksFile
2783 * The bookmark file to use
2784 */
2785 public void refreshBookmarks(final IFile bookmarksFile) {
2786 fBookmarksFile = bookmarksFile;
2787 if (bookmarksFile == null) {
2788 fBookmarksMap.clear();
2789 fTable.refresh();
2790 return;
2791 }
2792 try {
2793 fBookmarksMap.clear();
2794 for (final IMarker bookmark : bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO)) {
2795 final int location = bookmark.getAttribute(IMarker.LOCATION, -1);
2796 if (location != -1) {
2797 final long rank = location;
2798 fBookmarksMap.put(rank, bookmark.getId());
2799 }
2800 }
2801 fTable.refresh();
2802 } catch (final CoreException e) {
2803 displayException(e);
2804 }
2805 }
2806
2807 @Override
2808 public void gotoMarker(final IMarker marker) {
2809 final int rank = marker.getAttribute(IMarker.LOCATION, -1);
2810 if (rank != -1) {
2811 int index = rank;
2812 if (fTable.getData(Key.FILTER_OBJ) != null) {
8b7eb3cd
MK
2813 // +1 for top filter status row
2814 index = fCache.getFilteredEventIndex(rank) + 1;
db4721fb
PT
2815 } else if (rank >= fTable.getItemCount()) {
2816 fPendingGotoRank = rank;
2817 }
a56ec2b8 2818 fSelectedRank = rank;
9ba0a108 2819 fSelectedBeginRank = fSelectedRank;
db4721fb 2820 fTable.setSelection(index + 1); // +1 for header row
3f43dc48 2821 updateStatusLine(null);
db4721fb
PT
2822 }
2823 }
2824
2825 // ------------------------------------------------------------------------
2826 // Listeners
2827 // ------------------------------------------------------------------------
2828
db4721fb
PT
2829 @Override
2830 public void colorSettingsChanged(final ColorSetting[] colorSettings) {
2831 fTable.refresh();
2832 }
2833
db4721fb
PT
2834 // ------------------------------------------------------------------------
2835 // Signal handlers
2836 // ------------------------------------------------------------------------
2837
db4721fb
PT
2838 /**
2839 * Handler for the trace updated signal
2840 *
2841 * @param signal
2842 * The incoming signal
2843 */
2844 @TmfSignalHandler
2845 public void traceUpdated(final TmfTraceUpdatedSignal signal) {
2846 if ((signal.getTrace() != fTrace) || fTable.isDisposed()) {
2847 return;
2848 }
2849 // Perform the refresh on the UI thread
2850 Display.getDefault().asyncExec(new Runnable() {
2851 @Override
2852 public void run() {
2853 if (!fTable.isDisposed() && (fTrace != null)) {
2854 if (fTable.getData(Key.FILTER_OBJ) == null) {
8b7eb3cd
MK
2855 /* +1 for header row */
2856 fTable.setItemCount((int) fTrace.getNbEvents() + 1);
2857 /* +1 for header row */
2858 if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) {
2859 /* +1 for header row */
2860 fTable.setSelection((int) fPendingGotoRank + 1);
db4721fb 2861 fPendingGotoRank = -1;
3f43dc48 2862 updateStatusLine(null);
db4721fb
PT
2863 }
2864 } else {
2865 startFilterThread();
2866 }
2867 }
2868 if (!fRawViewer.isDisposed() && (fTrace != null)) {
2869 fRawViewer.refreshEventCount();
2870 }
2871 }
2872 });
2873 }
2874
2875 /**
97c71024 2876 * Handler for the selection range signal.
db4721fb
PT
2877 *
2878 * @param signal
2879 * The incoming signal
97c71024 2880 * @since 1.0
db4721fb
PT
2881 */
2882 @TmfSignalHandler
97c71024 2883 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) {
db4721fb
PT
2884 if ((signal.getSource() != this) && (fTrace != null) && (!fTable.isDisposed())) {
2885
8b7eb3cd
MK
2886 /*
2887 * Create a request for one event that will be queued after other
2888 * ongoing requests. When this request is completed do the work to
2889 * select the actual event with the timestamp specified in the
2890 * signal. This procedure prevents the method fTrace.getRank() from
2891 * interfering and delaying ongoing requests.
2892 */
fd3f1eff
AM
2893 final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class,
2894 TmfTimeRange.ETERNITY, 0, 1, ExecutionType.FOREGROUND) {
db4721fb 2895
0fcf3b09 2896 TmfTimestamp ts = new TmfTimestamp(signal.getBeginTime());
db4721fb
PT
2897
2898 @Override
2899 public void handleData(final ITmfEvent event) {
2900 super.handleData(event);
2901 }
2902
2903 @Override
73fce654
AM
2904 public void handleSuccess() {
2905 super.handleSuccess();
db4721fb
PT
2906 if (fTrace == null) {
2907 return;
2908 }
2909
8b7eb3cd
MK
2910 /*
2911 * Verify if the event is within the trace range and adjust
2912 * if necessary
2913 */
db4721fb 2914 ITmfTimestamp timestamp = ts;
065cc19b 2915 if (timestamp.compareTo(fTrace.getStartTime()) == -1) {
db4721fb
PT
2916 timestamp = fTrace.getStartTime();
2917 }
065cc19b 2918 if (timestamp.compareTo(fTrace.getEndTime()) == 1) {
db4721fb
PT
2919 timestamp = fTrace.getEndTime();
2920 }
2921
2922 // Get the rank of the selected event in the table
2923 final ITmfContext context = fTrace.seekEvent(timestamp);
2924 final long rank = context.getRank();
4c9f2944 2925 context.dispose();
db4721fb
PT
2926
2927 fTable.getDisplay().asyncExec(new Runnable() {
2928 @Override
2929 public void run() {
2930 // Return if table is disposed
2931 if (fTable.isDisposed()) {
2932 return;
2933 }
2934
9ba0a108
PT
2935 fSelectedRank = rank;
2936 fSelectedBeginRank = fSelectedRank;
db4721fb 2937 int index = (int) rank;
60fb38b8 2938 if (fTable.getData(Key.FILTER_OBJ) != null) {
8b7eb3cd
MK
2939 /* +1 for top filter status row */
2940 index = fCache.getFilteredEventIndex(rank) + 1;
db4721fb 2941 }
8b7eb3cd
MK
2942 /* +1 for header row */
2943 fTable.setSelection(index + 1);
db4721fb 2944 fRawViewer.selectAndReveal(rank);
3f43dc48 2945 updateStatusLine(null);
db4721fb
PT
2946 }
2947 });
2948 }
2949 };
2950
fd3f1eff 2951 ((ITmfEventProvider) fTrace).sendRequest(subRequest);
db4721fb
PT
2952 }
2953 }
2954
2955 // ------------------------------------------------------------------------
2956 // Error handling
2957 // ------------------------------------------------------------------------
2958
2959 /**
2960 * Display an exception in a message box
2961 *
8b7eb3cd
MK
2962 * @param e
2963 * the exception
db4721fb
PT
2964 */
2965 private static void displayException(final Exception e) {
2966 final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
60fb38b8 2967 mb.setText(e.getClass().getSimpleName());
db4721fb
PT
2968 mb.setMessage(e.getMessage());
2969 mb.open();
2970 }
2971
f8177ba2 2972 /**
ae09c4ad 2973 * Refresh the table
f8177ba2
FC
2974 */
2975 public void refresh() {
2976 fCache.clear();
2977 fTable.refresh();
2978 fTable.redraw();
2979 }
03142470
BH
2980
2981 /**
9447c7ee
AM
2982 * Margin column for images and special text (e.g. collapse count)
2983 */
2984 private static final class TmfMarginColumn extends TmfEventTableColumn {
2985
2986 private static final @NonNull ITmfEventAspect MARGIN_ASPECT = new ITmfEventAspect() {
2987
2988 @Override
2989 public String getName() {
2990 return EMPTY_STRING;
2991 }
2992
2993 @Override
2994 public String resolve(ITmfEvent event) {
2995 if (!(event instanceof CachedEvent) || ((CachedEvent) event).repeatCount == 0) {
2996 return EMPTY_STRING;
2997 }
2998 return "+" + ((CachedEvent) event).repeatCount; //$NON-NLS-1$
2999 }
3000
3001 @Override
3002 public String getHelpText() {
3003 return EMPTY_STRING;
3004 }
9447c7ee
AM
3005 };
3006
3007 /**
3008 * Constructor
3009 */
3010 public TmfMarginColumn() {
3011 super(MARGIN_ASPECT);
3012 }
3013 }
03142470 3014
db4721fb 3015}
This page took 2.142163 seconds and 5 git commands to generate.