tmf : add of a range selection from other sources for the tmfEventsTable
authorJean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tue, 6 Oct 2015 14:09:47 +0000 (10:09 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 6 Jan 2016 18:41:24 +0000 (13:41 -0500)
Only the events within the range will be selected. If there is no event
within the range of the selection, we select the next event outside of
the range. For a single selection, the event at or the next event after
the requested timestamp is selected.

Change-Id: I1294da7e5d653477502ca45f9430a5e5c8583187
Signed-off-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/57526
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/virtualtable/TmfVirtualTable.java

index 56bb78530a20ace7a11ebf0af627b91b9d8f7014..f71a9d8fbb659e0212aaf457e2195f9909c23e15 100644 (file)
@@ -161,6 +161,7 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
 import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
+import org.eclipse.tracecompass.tmf.core.util.Pair;
 import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsCache.CachedEvent;
 import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn;
 import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSetting;
@@ -169,8 +170,8 @@ import org.eclipse.tracecompass.tmf.ui.views.colors.IColorSettingsListener;
 import org.eclipse.tracecompass.tmf.ui.views.filter.FilterManager;
 import org.eclipse.tracecompass.tmf.ui.widgets.rawviewer.TmfRawEventViewer;
 import org.eclipse.tracecompass.tmf.ui.widgets.virtualtable.TmfVirtualTable;
-import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPartSite;
 import org.eclipse.ui.PlatformUI;
@@ -3076,11 +3077,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                     TmfTimeRange.ETERNITY, 0, 1, ExecutionType.FOREGROUND) {
 
                 TmfTimestamp ts = new TmfTimestamp(signal.getBeginTime());
-
-                @Override
-                public void handleData(final ITmfEvent event) {
-                    super.handleData(event);
-                }
+                TmfTimestamp tf = new TmfTimestamp(signal.getEndTime());
 
                 @Override
                 public void handleSuccess() {
@@ -3089,23 +3086,82 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                         return;
                     }
 
-                    /*
-                     * Verify if the event is within the trace range and adjust
-                     * if necessary
-                     */
-                    ITmfTimestamp timestamp = ts;
-                    if (timestamp.compareTo(fTrace.getStartTime()) == -1) {
-                        timestamp = fTrace.getStartTime();
+                    final Pair<Long, Long> selection = getSelectedRanks();
+                    updateDisplayWithSelection(selection.getFirst().longValue(), selection.getSecond().longValue());
+                }
+
+                /**
+                 * Verify if the event is within the trace range and adjust if
+                 * necessary.
+                 *
+                 * @return A pair of rank representing the selected area
+                 **/
+                private Pair<Long, Long> getSelectedRanks() {
+
+                    /* Clamp the timestamp value to fit inside of the trace */
+                    ITmfTimestamp timestampBegin = ts;
+                    if (timestampBegin.compareTo(fTrace.getStartTime()) < 0) {
+                        timestampBegin = fTrace.getStartTime();
                     }
-                    if (timestamp.compareTo(fTrace.getEndTime()) == 1) {
-                        timestamp = fTrace.getEndTime();
+                    if (timestampBegin.compareTo(fTrace.getEndTime()) > 0) {
+                        timestampBegin = fTrace.getEndTime();
                     }
 
-                    // Get the rank of the selected event in the table
-                    final ITmfContext context = fTrace.seekEvent(timestamp);
-                    final long rank = context.getRank();
-                    context.dispose();
+                    ITmfTimestamp timestampEnd = tf;
+                    if (timestampEnd.compareTo(fTrace.getStartTime()) < 0) {
+                        timestampEnd = fTrace.getStartTime();
+                    }
+                    if (timestampEnd.compareTo(fTrace.getEndTime()) > 0) {
+                        timestampEnd = fTrace.getEndTime();
+                    }
 
+                    ITmfTimestamp tb;
+                    ITmfTimestamp te;
+                    long rankBegin;
+                    long rankEnd;
+                    ITmfContext contextBegin;
+                    ITmfContext contextEnd;
+
+                    /* Adjust the rank of the selection to the right range */
+                    if (timestampBegin.compareTo(timestampEnd) > 0) {
+                        te = timestampEnd;
+                        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 */
+                        tb = timestampBegin.normalize(1, ITmfTimestamp.NANOSECOND_SCALE);
+                        if (tb.compareTo(fTrace.getEndTime()) <= 0) {
+                            contextBegin = fTrace.seekEvent(tb);
+                            rankBegin = contextBegin.getRank();
+                            contextBegin.dispose();
+                        } else {
+                            rankBegin = ITmfContext.UNKNOWN_RANK;
+                        }
+                        rankBegin = (rankBegin == ITmfContext.UNKNOWN_RANK ? fTrace.getNbEvents() : rankBegin) - 1;
+                        /* 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 */
+                        te = timestampEnd.normalize(1, ITmfTimestamp.NANOSECOND_SCALE);
+                        if (te.compareTo(fTrace.getEndTime()) <= 0) {
+                            contextEnd = fTrace.seekEvent(te);
+                            rankEnd = contextEnd.getRank();
+                            contextEnd.dispose();
+                        } else {
+                            rankEnd = ITmfContext.UNKNOWN_RANK;
+                        }
+                        rankEnd = (rankEnd == ITmfContext.UNKNOWN_RANK ? fTrace.getNbEvents() : rankEnd) - 1;
+                        /* 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));
+                }
+
+                private void updateDisplayWithSelection(final long rankBegin, final long rankEnd) {
                     PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                         @Override
                         public void run() {
@@ -3114,16 +3170,20 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                                 return;
                             }
 
-                            fSelectedRank = rank;
-                            fSelectedBeginRank = fSelectedRank;
-                            int index = (int) rank;
+                            fSelectedRank = rankEnd;
+                            long toReveal = fSelectedBeginRank != rankBegin ? rankBegin : rankEnd;
+                            fSelectedBeginRank = rankBegin;
+                            int indexBegin = (int) rankBegin;
+                            int indexEnd = (int) rankEnd;
+
                             if (fTable.getData(Key.FILTER_OBJ) != null) {
                                 /* +1 for top filter status row */
-                                index = fCache.getFilteredEventIndex(rank) + 1;
+                                indexBegin = fCache.getFilteredEventIndex(rankBegin) + 1;
+                                indexEnd = rankEnd == rankBegin ? indexBegin : fCache.getFilteredEventIndex(rankEnd) + 1;
                             }
                             /* +1 for header row */
-                            fTable.setSelection(index + 1);
-                            fRawViewer.selectAndReveal(rank);
+                            fTable.setSelectionRange(indexBegin + 1, indexEnd + 1);
+                            fRawViewer.selectAndReveal(toReveal);
                             updateStatusLine(null);
                         }
                     });
index fdbe8c4a19dea6b502cc9851a0209416a7e7b94e..c1abdb5f4fdb671fb4193cdf8e90ee6f36b91eef 100644 (file)
@@ -1097,21 +1097,45 @@ public class TmfVirtualTable extends Composite {
      * </ul>
      */
     public void setSelection(int index) {
-        if (fTableItemCount > 0) {
-            int i = Math.min(index, fTableItemCount - 1);
-            i = Math.max(i, 0);
+        setSelectionRange(index, index);
+    }
 
-            fSelectedEventRank = i;
-            fSelectedBeginRank = fSelectedEventRank;
-            if ((i < fTableTopEventRank + fFrozenRowCount && i >= fFrozenRowCount) ||
-                    (i >= fTableTopEventRank + fFullyVisibleRows)) {
+    /**
+     * Selects a range of items starting at the given zero-relative index in the
+     * receiver. The current selection is first cleared, then the new items are
+     * selected, and if necessary the receiver is scrolled to make the new
+     * selection visible.
+     *
+     * @param beginIndex
+     *            The index of the first item in the selection range
+     * @param endIndex
+     *            The index of the last item in the selection range
+     *
+     * @exception SWTException
+     *                <ul>
+     *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+     *                disposed</li>
+     *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+     *                thread that created the receiver</li>
+     *                </ul>
+     * @since 2.0
+     */
+    public void setSelectionRange(int beginIndex, int endIndex) {
+        if (fTableItemCount > 0) {
+            int begin = Math.max(Math.min(beginIndex, fTableItemCount - 1), 0);
+            int end =   Math.max(Math.min(endIndex, fTableItemCount - 1), 0);
+            int selection = fSelectedBeginRank != begin ? begin : end;
+
+            fSelectedBeginRank = begin;
+            fSelectedEventRank = end;
+            if ((selection < fTableTopEventRank + fFrozenRowCount && selection >= fFrozenRowCount) ||
+                    (selection >= fTableTopEventRank + fFullyVisibleRows)) {
                 int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows);
-                fTableTopEventRank = Math.max(0, Math.min(lastPageTopEntryRank, i - fFrozenRowCount - fFullyVisibleRows / 2));
+                fTableTopEventRank = Math.max(0, Math.min(lastPageTopEntryRank, selection - fFrozenRowCount - fFullyVisibleRows / 2));
             }
             if (fFullyVisibleRows < fTableItemCount) {
                 fSlider.setSelection(fTableTopEventRank);
             }
-
             refreshTable();
         }
     }
This page took 0.029995 seconds and 5 git commands to generate.