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