tmf: Bug 484042: Fix source code lookup within the workspace
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / events / TmfEventsTable.java
index 1b4287e27ab9d7b47254a4e985c38c0dc90bdc4e..87e306b41960d31d06584a7562987f032de5ba3b 100644 (file)
@@ -152,7 +152,6 @@ import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
@@ -233,8 +232,8 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
 
     private final class ColumnMovedListener extends ControlAdapter {
         /*
-         * Make sure that the margin column is always first and keep the
-         * column order variable up to date.
+         * Make sure that the margin column is always first and keep the column
+         * order variable up to date.
          */
         @Override
         public void controlMoved(ControlEvent e) {
@@ -460,13 +459,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
             GC gc = event.gc;
             Color background = item.getBackground(event.index);
             /*
-             * Paint the background if it is not the default system color.
-             * In Windows, if you let the widget draw the background, it
-             * will not show the item's background color if the item is
-             * selected or hot. If there are no style ranges and the item
-             * background is the default system color, we do not want to
-             * paint it or otherwise we would override the platform theme
-             * (e.g. alternating colors).
+             * Paint the background if it is not the default system color. In
+             * Windows, if you let the widget draw the background, it will not
+             * show the item's background color if the item is selected or hot.
+             * If there are no style ranges and the item background is the
+             * default system color, we do not want to paint it or otherwise we
+             * would override the platform theme (e.g. alternating colors).
              */
             if (styleRanges != null || !background.equals(item.getParent().getBackground())) {
                 // we will paint the table item's background
@@ -479,9 +477,9 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
 
             /*
              * We will paint the table item's foreground. In Windows, if you
-             * paint the background but let the widget draw the foreground,
-             * it will override your background, unless the item is selected
-             * or hot.
+             * paint the background but let the widget draw the foreground, it
+             * will override your background, unless the item is selected or
+             * hot.
              */
             event.detail &= ~SWT.FOREGROUND;
 
@@ -556,8 +554,8 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                 /*
                  * Bug in Linux. The coordinates of the event have an origin
                  * that excludes the table header but the method toDisplay()
-                 * expects coordinates relative to an origin that includes
-                 * the table header.
+                 * expects coordinates relative to an origin that includes the
+                 * table header.
                  */
                 int y = event.y;
                 if (IS_LINUX) {
@@ -590,8 +588,8 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      * The events table search/filter/data keys
      *
      * @author Patrick Tasse
-     * @noimplement This interface only contains Event Table specific
-     *              static definitions.
+     * @noimplement This interface only contains Event Table specific static
+     *              definitions.
      */
     public interface Key {
 
@@ -771,10 +769,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     }
 
     @Deprecated
-    private static @NonNull Iterable<ITmfEventAspect> convertFromColumnData(
+    private static @NonNull Iterable<ITmfEventAspect<?>> convertFromColumnData(
             org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
 
-        ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
+        ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
         for (org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.ColumnData col : columnData) {
             String fieldName = col.header;
             if (fieldName != null) {
@@ -800,7 +798,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      *            </p>
      */
     public TmfEventsTable(final Composite parent, int cacheSize,
-            @NonNull Iterable<ITmfEventAspect> aspects) {
+            @NonNull Iterable<ITmfEventAspect<?>> aspects) {
         super("TmfEventsTable"); //$NON-NLS-1$
 
         fComposite = new Composite(parent, SWT.NONE);
@@ -862,7 +860,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         fTable.setLinesVisible(true);
 
         // Setup the columns
-        for (ITmfEventAspect aspect : aspects) {
+        for (ITmfEventAspect<?> aspect : aspects) {
             if (aspect != null) {
                 fColumns.add(new TmfEventTableColumn(aspect));
             }
@@ -951,6 +949,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         fRawViewer.setVisible(false);
 
         createPopupMenu();
+
+        fComposite.addDisposeListener((e) -> {
+            internalDispose();
+        });
     }
 
     /**
@@ -1137,10 +1139,11 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                          */
                         IMarker marker = null;
                         final ArrayList<IFile> files = new ArrayList<>();
+                        IPath p = new Path(trimmedPath);
                         ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
                             @Override
                             public boolean visit(IResource resource) throws CoreException {
-                                if (resource instanceof IFile && resource.getFullPath().toString().endsWith(trimmedPath)) {
+                                if (resource instanceof IFile && resource.getFullPath().toString().endsWith(p.lastSegment())) {
                                     files.add((IFile) resource);
                                 }
                                 return true;
@@ -1479,16 +1482,19 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
 
     @Override
     public void dispose() {
+        fComposite.dispose();
+    }
+
+    private void internalDispose() {
         stopSearchThread();
         stopFilterThread();
         PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(this);
         ColorSettingsManager.removeColorSettingsListener(this);
-        fComposite.dispose();
+        fCache.clear();
         if ((fTrace != null) && fDisposeOnClose) {
             fTrace.dispose();
         }
         fResourceManager.dispose();
-        fRawViewer.dispose();
         if (fRawViewerPopupMenuManager != null) {
             fRawViewerPopupMenuManager.dispose();
         }
@@ -1552,7 +1558,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         }
         item.setText(itemStrings);
         item.setData(tmfEvent);
-        item.setData(Key.TIMESTAMP, new TmfTimestamp(tmfEvent.getTimestamp()));
+        item.setData(Key.TIMESTAMP, tmfEvent.getTimestamp());
         item.setData(Key.RANK, rank);
 
         final Collection<Long> markerIds = fBookmarksMap.get(rank);
@@ -1820,7 +1826,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                             return false;
                         }
                         final TmfFilterMatchesNode filter = new TmfFilterMatchesNode(null);
-                        ITmfEventAspect aspect = (ITmfEventAspect) column.getData(Key.ASPECT);
+                        ITmfEventAspect<?> aspect = (ITmfEventAspect<?>) column.getData(Key.ASPECT);
                         filter.setEventAspect(aspect);
                         filter.setRegex(regex);
                         column.setData(Key.SEARCH_OBJ, filter);
@@ -2553,10 +2559,16 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
 
     /**
      * Pack the columns.
+     *
+     * @return
+     *            Whether or not a pack was done in this call. Otherwise, it was already done by a
+     *            previous call
+     *
+     * @since 2.0
      */
-    protected void packColumns() {
+    protected boolean packColumns() {
         if (fPackDone) {
-            return;
+            return false;
         }
         fTable.setRedraw(false);
         try {
@@ -2571,6 +2583,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
             fTable.setRedraw(true);
         }
         fPackDone = true;
+        return true;
     }
 
     private void packMarginColumn() {
@@ -2600,8 +2613,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     /**
      * Returns true if the column is a visible event column.
      *
-     * @param column the column
-     * @return false if the column is the margin column or hidden, true otherwise
+     * @param column
+     *            the column
+     * @return false if the column is the margin column or hidden, true
+     *         otherwise
      */
     private static boolean isVisibleEventColumn(TableColumn column) {
         if (column.getData(Key.ASPECT) == TmfMarginColumn.MARGIN_ASPECT) {
@@ -2949,7 +2964,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                                 bookmark.setAttribute(IMarker.MESSAGE, message.toString());
                                 bookmark.setAttribute(IMarker.LOCATION, location);
                                 bookmark.setAttribute(ITmfMarker.MARKER_RANK, rank.toString());
-                                bookmark.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(new TmfNanoTimestamp(timestamp).getValue()));
+                                bookmark.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(timestamp.toNanos()));
                                 bookmark.setAttribute(ITmfMarker.MARKER_COLOR, dialog.getColorValue().toString());
                                 id[0] = bookmark.getId();
                             }
@@ -3074,10 +3089,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         try {
             String timeString = marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null);
             long time = Long.parseLong(timeString);
-            tsBegin = new TmfNanoTimestamp(time);
+            tsBegin = TmfTimestamp.fromNanos(time);
             String durationString = marker.getAttribute(ITmfMarker.MARKER_DURATION, (String) null);
             long duration = Long.parseLong(durationString);
-            tsEnd = new TmfNanoTimestamp(time + duration);
+            tsEnd = TmfTimestamp.fromNanos(time + duration);
         } catch (NumberFormatException e) {
             /* ignored */
         }
@@ -3179,8 +3194,8 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
             final TmfEventRequest subRequest = new TmfEventRequest(ITmfEvent.class,
                     TmfTimeRange.ETERNITY, 0, 1, ExecutionType.FOREGROUND) {
 
-                TmfTimestamp ts = new TmfTimestamp(signal.getBeginTime());
-                TmfTimestamp tf = new TmfTimestamp(signal.getEndTime());
+                ITmfTimestamp ts = signal.getBeginTime();
+                ITmfTimestamp tf = signal.getEndTime();
 
                 @Override
                 public void handleSuccess() {
@@ -3231,7 +3246,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                         contextEnd = fTrace.seekEvent(te);
                         rankEnd = contextEnd.getRank();
                         contextEnd.dispose();
-                        /* To include all events at the begin time, seek at the next nanosecond and then use the previous rank */
+                        /*
+                         * To include all events at the begin time, seek at the
+                         * next nanosecond and then use the previous rank
+                         */
                         tb = timestampBegin.normalize(1, ITmfTimestamp.NANOSECOND_SCALE);
                         if (tb.compareTo(fTrace.getEndTime()) <= 0) {
                             contextBegin = fTrace.seekEvent(tb);
@@ -3241,14 +3259,20 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                             rankBegin = ITmfContext.UNKNOWN_RANK;
                         }
                         rankBegin = (rankBegin == ITmfContext.UNKNOWN_RANK ? fTrace.getNbEvents() : rankBegin) - 1;
-                        /* If no events in selection range, select only the next event */
+                        /*
+                         * If no events in selection range, select only the next
+                         * event
+                         */
                         rankBegin = rankBegin >= rankEnd ? rankBegin : rankEnd;
                     } else {
                         tb = timestampBegin;
                         contextBegin = fTrace.seekEvent(tb);
                         rankBegin = contextBegin.getRank();
                         contextBegin.dispose();
-                        /* To include all events at the end time, seek at the next nanosecond and then use the previous rank */
+                        /*
+                         * To include all events at the end time, seek at the
+                         * next nanosecond and then use the previous rank
+                         */
                         te = timestampEnd.normalize(1, ITmfTimestamp.NANOSECOND_SCALE);
                         if (te.compareTo(fTrace.getEndTime()) <= 0) {
                             contextEnd = fTrace.seekEvent(te);
@@ -3258,7 +3282,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                             rankEnd = ITmfContext.UNKNOWN_RANK;
                         }
                         rankEnd = (rankEnd == ITmfContext.UNKNOWN_RANK ? fTrace.getNbEvents() : rankEnd) - 1;
-                        /* If no events in selection range, select only the next event */
+                        /*
+                         * If no events in selection range, select only the next
+                         * event
+                         */
                         rankEnd = rankEnd >= rankBegin ? rankEnd : rankBegin;
                     }
                     return new Pair<>(Long.valueOf(rankBegin), Long.valueOf(rankEnd));
@@ -3328,7 +3355,8 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      */
     private static final class TmfMarginColumn extends TmfEventTableColumn {
 
-        private static final @NonNull ITmfEventAspect MARGIN_ASPECT = new ITmfEventAspect() {
+        private static final @NonNull ITmfEventAspect<String> MARGIN_ASPECT =
+                new ITmfEventAspect<String>() {
 
             @Override
             public String getName() {
This page took 0.030224 seconds and 5 git commands to generate.