releng: Add 2.1.0 baseline and fix API errors
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / analysis / timing / ui / views / segmentstore / statistics / AbstractSegmentStoreStatisticsViewer.java
index e832257573ad567c68bfd427fb5bf8a8a7321821..5bb0544cf0529cb2a1d124d4250f50803f4b891d 100644 (file)
@@ -16,6 +16,8 @@ import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 import java.text.Format;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.Action;
@@ -30,9 +32,11 @@ 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.AbstractSegmentStatisticsAnalysis;
 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.internal.analysis.timing.ui.views.segmentstore.statistics.Messages;
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
@@ -40,6 +44,7 @@ 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;
+import org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeColumnData;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry;
 
@@ -64,7 +69,8 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
             checkNotNull(Messages.SegmentStoreStatistics_MaxLabel),
             checkNotNull(Messages.SegmentStoreStatistics_AverageLabel),
             checkNotNull(Messages.SegmentStoreStatisticsViewer_StandardDeviation),
-            checkNotNull(Messages.SegmentStoreStatisticsViewer_Count)
+            checkNotNull(Messages.SegmentStoreStatisticsViewer_Count),
+            checkNotNull(Messages.SegmentStoreStatisticsViewer_Total)
     };
 
     /**
@@ -118,6 +124,8 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
                         value = String.valueOf(toFormattedString(entry.getEntry().getStdDev()));
                     } else if (columnIndex == 5) {
                         value = String.valueOf(entry.getEntry().getNbSegments());
+                    } else if (columnIndex == 6) {
+                        value = String.valueOf(toFormattedString(entry.getEntry().getTotal()));
                     }
                 }
             }
@@ -253,6 +261,23 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
                     }
                 });
                 columns.add(column);
+                column = new TmfTreeColumnData(COLUMN_NAMES[6]);
+                column.setAlignment(SWT.RIGHT);
+                column.setComparator(new ViewerComparator() {
+                    @Override
+                    public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) {
+                        if ((e1 == null) || (e2 == null)) {
+                            return 0;
+                        }
+
+                        SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1;
+                        SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2;
+
+                        return Double.compare(n1.getEntry().getTotal(), n2.getEntry().getTotal());
+
+                    }
+                });
+                columns.add(column);
                 column = new TmfTreeColumnData(""); //$NON-NLS-1$
                 columns.add(column);
                 return columns;
@@ -281,13 +306,14 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
 
     /**
      * Method to add commands to the context sensitive menu.
+     *
      * @param manager
-     *          the menu manager
+     *            the menu manager
      * @param sel
-     *          the current selection
+     *            the current selection
      */
     protected void appendToTablePopupMenu(IMenuManager manager, IStructuredSelection sel) {
-        Object element =  sel.getFirstElement();
+        Object element = sel.getFirstElement();
         if ((element instanceof SegmentStoreStatisticsEntry) && !(element instanceof HiddenTreeViewerEntry)) {
             final SegmentStoreStatisticsEntry segment = (SegmentStoreStatisticsEntry) element;
             IAction gotoStartTime = new Action(Messages.SegmentStoreStatisticsViewer_GotoMinAction) {
@@ -359,6 +385,63 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
 
     }
 
+    @Override
+    protected @Nullable ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
+        if (isSelection || (start == end)) {
+            return null;
+        }
+
+        TmfAbstractAnalysisModule analysisModule = getStatisticsAnalysisModule();
+
+        if (getTrace() == null || !(analysisModule instanceof AbstractSegmentStatisticsAnalysis)) {
+            return null;
+        }
+
+        AbstractSegmentStatisticsAnalysis module = (AbstractSegmentStatisticsAnalysis) analysisModule;
+
+        module.waitForCompletion();
+
+        TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$
+        final SegmentStoreStatistics entry = module.getTotalStats();
+        if (entry != null) {
+
+            List<ITmfTreeViewerEntry> entryList = root.getChildren();
+
+            TmfTreeViewerEntry aggregateEntry = new SegmentStoreStatisticsEntry(getTotalLabel(), entry);
+            entryList.add(aggregateEntry);
+            HiddenTreeViewerEntry category = new HiddenTreeViewerEntry(getTypeLabel());
+            aggregateEntry.addChild(category);
+
+            Map<String, SegmentStoreStatistics> perSegmentStats = module.getPerSegmentTypeStats();
+            if (perSegmentStats != null) {
+                for (Entry<String, SegmentStoreStatistics> statsEntry : perSegmentStats.entrySet()) {
+                    category.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
+                }
+            }
+        }
+        return root;
+    }
+
+    /**
+     * Get the type label
+     *
+     * @return the label
+     * @since 1.2
+     */
+    protected String getTypeLabel() {
+        return checkNotNull(Messages.AbstractSegmentStoreStatisticsViewer_types);
+    }
+
+    /**
+     * Get the total column label
+     *
+     * @return the totals column label
+     * @since 1.2
+     */
+    protected String getTotalLabel() {
+        return checkNotNull(Messages.AbstractSegmentStoreStatisticsViewer_total);
+    }
+
     /**
      * Class to define a level in the tree that doesn't have any values.
      */
This page took 0.025495 seconds and 5 git commands to generate.