analysis: add menu to go to min or max from the segment start stats
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Wed, 11 May 2016 11:28:37 +0000 (07:28 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Fri, 13 May 2016 00:39:04 +0000 (20:39 -0400)
Change-Id: Ia8d66fdc69a60f93c6e87d417e4798b415a31884
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/statistics/SegmentStoreStatisticsTest.java
analysis/org.eclipse.tracecompass.analysis.timing.core/src/org/eclipse/tracecompass/analysis/timing/core/segmentstore/statistics/SegmentStoreStatistics.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/Messages.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/statistics/messages.properties

index 2bda6263ac49c936a26ee818fc183f692f33f7e7..c48a233ac6cd20228b674615f598934f7ae5d2f7 100644 (file)
@@ -49,6 +49,8 @@ public class SegmentStoreStatisticsTest {
         assertEquals("Standard Deviation", osc.getStdDev(), sss.getStdDev(), ERROR);
         assertEquals("Min", osc.getMin(), sss.getMin());
         assertEquals("Max", osc.getMax(), sss.getMax());
+        assertEquals("Min Segment", osc.getMin(), sss.getMinSegment().getLength());
+        assertEquals("Max Segment", osc.getMax(), sss.getMaxSegment().getLength());
     }
 
     /**
@@ -65,6 +67,8 @@ public class SegmentStoreStatisticsTest {
         assertEquals("Min", 0, sss.getMin());
         assertEquals("Max", 99, sss.getMax());
         assertEquals("Standard Deviation", 29.0, sss.getStdDev(), 0.02);
+        assertEquals("Min Segment", 0, sss.getMinSegment().getLength());
+        assertEquals("Max Segment", 99, sss.getMaxSegment().getLength());
         testOnlineVsOffline(fixture);
     }
 
@@ -90,6 +94,8 @@ public class SegmentStoreStatisticsTest {
         assertEquals("Min", 0, sss.getMin());
         assertEquals("Max", 100, sss.getMax());
         assertEquals("Standard Deviation", 29.3, sss.getStdDev(), 0.01);
+        assertEquals("Min Segment", 0, sss.getMinSegment().getLength());
+        assertEquals("Max Segment", 100, sss.getMaxSegment().getLength());
         testOnlineVsOffline(fixture);
     }
 
index d1f4a1dfbd36a0615239cde5036648c6acdc7b5f..7adbe7255ed4cec61c22a343e0e7eb0b2bad91ae 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics;
 
+import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 
 /**
@@ -19,8 +20,8 @@ import org.eclipse.tracecompass.segmentstore.core.ISegment;
  * @author Bernd Hufmann
  */
 public class SegmentStoreStatistics {
-    private long fMin;
-    private long fMax;
+    private ISegment fMin;
+    private ISegment fMax;
     private long fNbSegments;
     private double fAverage;
     private double fVariance;
@@ -29,8 +30,8 @@ public class SegmentStoreStatistics {
      * Constructor
      */
     public SegmentStoreStatistics() {
-        fMin = Long.MAX_VALUE;
-        fMax = Long.MIN_VALUE;
+        fMin = new BasicSegment(0, Long.MAX_VALUE);
+        fMax = new BasicSegment(Long.MIN_VALUE, 0);
         fNbSegments = 0;
         fAverage = 0.0;
         fVariance = 0.0;
@@ -42,7 +43,7 @@ public class SegmentStoreStatistics {
      * @return minimum value
      */
     public long getMin() {
-        return fMin;
+        return fMin.getLength();
     }
 
     /**
@@ -51,6 +52,24 @@ public class SegmentStoreStatistics {
      * @return maximum value
      */
     public long getMax() {
+        return fMax.getLength();
+    }
+
+    /**
+     * Get segment with minimum length
+     *
+     * @return segment with minimum length
+     */
+    public ISegment getMinSegment() {
+        return fMin;
+    }
+
+    /**
+     * Get segment with maximum length
+     *
+     * @return segment with maximum length
+     */
+    public ISegment getMaxSegment() {
         return fMax;
     }
 
@@ -98,8 +117,10 @@ public class SegmentStoreStatistics {
         /*
          * Min and max are trivial, as well as number of segments
          */
-        fMin = Math.min(fMin, value);
-        fMax = Math.max(fMax, value);
+        long min = fMin.getLength();
+        long max = fMax.getLength();
+        fMin = min <= value ? fMin : segment;
+        fMax = max >= value ? fMax : segment;
 
         fNbSegments++;
         /*
index 775fd3f3691405de3870459a12c8c1dc1fc77413..e832257573ad567c68bfd427fb5bf8a8a7321821 100644 (file)
@@ -18,15 +18,25 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
 import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.SubSecondTimeWithUnitFormat;
 import org.eclipse.tracecompass.internal.analysis.timing.ui.Activator;
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.AbstractTmfTreeViewer;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeColumnDataProvider;
@@ -46,6 +56,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
 
     @Nullable
     private TmfAbstractAnalysisModule fModule;
+    private MenuManager fTablePopupMenuManager;
 
     private static final String[] COLUMN_NAMES = new String[] {
             checkNotNull(Messages.SegmentStoreStatistics_LevelLabel),
@@ -65,6 +76,20 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
     public AbstractSegmentStoreStatisticsViewer(Composite parent) {
         super(parent, false);
         setLabelProvider(new SegmentStoreStatisticsLabelProvider());
+        fTablePopupMenuManager = new MenuManager();
+        fTablePopupMenuManager.setRemoveAllWhenShown(true);
+        fTablePopupMenuManager.addMenuListener(manager -> {
+            TreeViewer viewer = getTreeViewer();
+            ISelection selection = viewer.getSelection();
+            if (selection instanceof IStructuredSelection) {
+                IStructuredSelection sel = (IStructuredSelection) selection;
+                if (manager != null) {
+                    appendToTablePopupMenu(manager, sel);
+                }
+            }
+        });
+        Menu tablePopup = fTablePopupMenuManager.createContextMenu(getTreeViewer().getTree());
+        getTreeViewer().getTree().setMenu(tablePopup);
     }
 
     /** Provides label for the Segment Store tree viewer cells */
@@ -254,6 +279,40 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
         }
     }
 
+    /**
+     * Method to add commands to the context sensitive menu.
+     * @param manager
+     *          the menu manager
+     * @param sel
+     *          the current selection
+     */
+    protected void appendToTablePopupMenu(IMenuManager manager, IStructuredSelection sel) {
+        Object element =  sel.getFirstElement();
+        if ((element instanceof SegmentStoreStatisticsEntry) && !(element instanceof HiddenTreeViewerEntry)) {
+            final SegmentStoreStatisticsEntry segment = (SegmentStoreStatisticsEntry) element;
+            IAction gotoStartTime = new Action(Messages.SegmentStoreStatisticsViewer_GotoMinAction) {
+                @Override
+                public void run() {
+                    long start = segment.getEntry().getMinSegment().getStart();
+                    long end = segment.getEntry().getMinSegment().getEnd();
+                    broadcast(new TmfSelectionRangeUpdatedSignal(AbstractSegmentStoreStatisticsViewer.this, TmfTimestamp.fromNanos(start), TmfTimestamp.fromNanos(end)));
+                }
+            };
+
+            IAction gotoEndTime = new Action(Messages.SegmentStoreStatisticsViewer_GotoMaxAction) {
+                @Override
+                public void run() {
+                    long start = segment.getEntry().getMaxSegment().getStart();
+                    long end = segment.getEntry().getMaxSegment().getEnd();
+                    broadcast(new TmfSelectionRangeUpdatedSignal(AbstractSegmentStoreStatisticsViewer.this, TmfTimestamp.fromNanos(start), TmfTimestamp.fromNanos(end)));
+                }
+            };
+
+            manager.add(gotoStartTime);
+            manager.add(gotoEndTime);
+        }
+    }
+
     /**
      * Formats a double value string
      *
index b18ddbee66abe6e358a038f97f15399c6b4099a3..a508c5ffc19b1c0482485d5cdbae88d3cd1b6d37 100644 (file)
@@ -34,9 +34,12 @@ public class Messages extends NLS {
     public static String SegmentStoreStatistics_AverageLabel;
     /** Name of count column */
     public static String SegmentStoreStatisticsViewer_Count;
-
     /** Name of average column */
     public static String SegmentStoreStatisticsViewer_StandardDeviation;
+    /** Menu item for go to minimum duration */
+    public static String SegmentStoreStatisticsViewer_GotoMinAction;
+    /** Menu item for go to maximum duration */
+    public static String SegmentStoreStatisticsViewer_GotoMaxAction;
 
     static {
         // initialize resource bundle
index 682eb7b5dda36ae15469cbf70ba4f1ff9b946ed8..bbc11cdbe36988505fff294689e52b1f69f97cb0 100644 (file)
@@ -14,4 +14,6 @@ SegmentStoreStatistics_Statistics_MinLabel=Minimum
 SegmentStoreStatistics_MaxLabel=Maximum
 SegmentStoreStatistics_AverageLabel=Average
 SegmentStoreStatisticsViewer_Count=Count
-SegmentStoreStatisticsViewer_StandardDeviation=Standard Deviation
\ No newline at end of file
+SegmentStoreStatisticsViewer_StandardDeviation=Standard Deviation
+SegmentStoreStatisticsViewer_GotoMinAction=Go to minimum
+SegmentStoreStatisticsViewer_GotoMaxAction=Go to maximum
\ No newline at end of file
This page took 0.028904 seconds and 5 git commands to generate.