tmf: Expose TmfExperiment.getTraces() up to ITmfTrace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statistics / TmfStatisticsView.java
index 8f1beb0ff2331c79897130f9c7db801f218cf3df..8fd763493eabf5691f336c1bf48790ce9778db3b 100755 (executable)
 /*******************************************************************************
- * Copyright (c) 2011 Ericsson
- * 
+ * Copyright (c) 2011, 2012 Ericsson
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
- *   Mathieu Denis      (mathieu.denis@polymtl.ca)  - Generalized version based on LTTng
+ *   Mathieu Denis <mathieu.denis@polymtl.ca> - Generalized version based on LTTng
  *   Bernd Hufmann - Updated to use trace reference in TmfEvent and streaming
+ *   Mathieu Denis - New request added to update the statistics from the selected time range
+ *   Mathieu Denis - Generalization of the view to instantiate a viewer specific to a trace type
+ *
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.views.statistics;
 
-import java.util.Vector;
-
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.TreeViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal;
-import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
+import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfStartSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.ui.viewers.ITmfViewer;
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.TmfStatisticsViewer;
 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.AbsTmfStatisticsTree;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.ITmfColumnDataProvider;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseColumnData;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseColumnDataProvider;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseStatisticsTree;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeNode;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeRootFactory;
-import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfTreeContentProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.tabsview.TmfViewerFolder;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
 
 /**
- * <b><u>TmfStatisticsView</u></b>
- * <p>
  * The generic Statistics View displays statistics for any kind of traces.
- * 
- * It is implemented according to the MVC pattern. - The model is a TmfStatisticsTreeNode built by the State Manager. - The view is built with a
- * TreeViewer. - The controller that keeps model and view synchronized is an observer of the model.
- * </p>
+ *
+ * It is implemented according to the MVC pattern. - The model is a
+ * TmfStatisticsTreeNode built by the State Manager. - The view is built with a
+ * TreeViewer. - The controller that keeps model and view synchronized is an
+ * observer of the model.
+ *
+ * @version 2.0
+ * @author Mathieu Denis
  */
 public class TmfStatisticsView extends TmfView {
+
     /**
-     * The ID correspond to the package in which this class is embedded
+     * The ID corresponds to the package in which this class is embedded.
      */
     public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.statistics"; //$NON-NLS-1$
 
-    // view name
+    /**
+     * The view name.
+     */
     public static final String TMF_STATISTICS_VIEW = "StatisticsView"; //$NON-NLS-1$
 
-    // Refresh frequency
-    protected static final Long STATS_INPUT_CHANGED_REFRESH = 5000L;
-    
-    // Default PAGE_SIZE
-    protected static final int PAGE_SIZE = 50000; // For background request
-    
-    // The actual tree to display
-    protected TreeViewer fTreeViewer;
-    // Stores the request to the experiment
-    protected ITmfEventRequest<TmfEvent> fRequest = null;
-
-    // Update synchronization parameters (used for streaming)
-    protected boolean fStatisticsUpdateBusy = false;
-    protected boolean fStatisticsUpdatePending = false;
-    protected TmfTimeRange fStatisticsUpdateRange = null;
-    protected final Object fStatisticsUpdateSyncObj = new Object();
-
-    // Flag to force request the data from trace
-    protected boolean fRequestData = false; 
-
-    
-    // Object to store the cursor while waiting for the experiment to load
-    private Cursor fWaitCursor = null;
-
-    // Stores the number of instance
-    private static int fCountInstance = 0;
+    /**
+     * The viewer that builds the columns to show the statistics.
+     *
+     * @since 2.0
+     */
+    protected final TmfViewerFolder fStatsViewers;
 
-    // Number of this instance. Used as an instance ID
-    private int fInstanceNb;
-    
+    /**
+     * Stores a reference to the selected trace.
+     */
+    private ITmfTrace fTrace;
 
     /**
      * Constructor of a statistics view.
-     * 
-     * @param viewName
-     *            The name to give to the view.
+     *
+     * @param viewName The name to give to the view.
      */
     public TmfStatisticsView(String viewName) {
         super(viewName);
-        fCountInstance++;
-        fInstanceNb = fCountInstance;
+        /*
+         * Create a fake parent for initialization purpose, than set the parent
+         * as soon as createPartControl is called.
+         */
+        Composite temporaryParent = new Shell();
+        fStatsViewers = new TmfViewerFolder(temporaryParent);
     }
 
     /**
@@ -122,456 +94,213 @@ public class TmfStatisticsView extends TmfView {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+     *
+     * @see
+     * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
      */
     @Override
     public void createPartControl(Composite parent) {
-        final Vector<TmfBaseColumnData> columnDataList = getColumnDataProvider().getColumnData();
-        parent.setLayout(new FillLayout());
+        fStatsViewers.setParent(parent);
+        createStatisticsViewers();
 
-        fTreeViewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-        fTreeViewer.setContentProvider(new TmfTreeContentProvider());
-        fTreeViewer.getTree().setHeaderVisible(true);
-        fTreeViewer.setUseHashlookup(true);
-
-        for (final TmfBaseColumnData columnData : columnDataList) {
-            final TreeViewerColumn treeColumn = new TreeViewerColumn(fTreeViewer, columnData.getAlignment());
-            treeColumn.getColumn().setText(columnData.getHeader());
-            treeColumn.getColumn().setWidth(columnData.getWidth());
-            treeColumn.getColumn().setToolTipText(columnData.getTooltip());
-
-            if (columnData.getComparator() != null) {
-                treeColumn.getColumn().addSelectionListener(new SelectionAdapter() {
-                    @Override
-                    public void widgetSelected(SelectionEvent e) {
-                        if (fTreeViewer.getTree().getSortDirection() == SWT.UP || fTreeViewer.getTree().getSortColumn() != treeColumn.getColumn()) {
-                            fTreeViewer.setComparator(columnData.getComparator());
-                            fTreeViewer.getTree().setSortDirection(SWT.DOWN);
-                        } else {
-                            fTreeViewer.setComparator(new ViewerComparator() {
-                                @Override
-                                public int compare(Viewer viewer, Object e1, Object e2) {
-                                    return -1 * columnData.getComparator().compare(viewer, e1, e2);
-                                }
-                            });
-                            fTreeViewer.getTree().setSortDirection(SWT.UP);
-                        }
-                        fTreeViewer.getTree().setSortColumn(treeColumn.getColumn());
-                    }
-                });
-            }
-            treeColumn.setLabelProvider(columnData.getLabelProvider());
+        ITmfTrace trace = getActiveTrace();
+        if (trace != null) {
+            traceSelected(new TmfTraceSelectedSignal(this, trace));
         }
-
-        // Handler that will draw the bar charts.
-        fTreeViewer.getTree().addListener(SWT.EraseItem, new Listener() {
-            @Override
-            public void handleEvent(Event event) {
-                if (columnDataList.get(event.index).getPercentageProvider() != null) {
-                    TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) event.item.getData();
-
-                    double percentage = columnDataList.get(event.index).getPercentageProvider().getPercentage(node);
-                    if (percentage == 0) {
-                        return;
-                    }
-
-                    if ((event.detail & SWT.SELECTED) > 0) {
-                        Color oldForeground = event.gc.getForeground();
-                        event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
-                        event.gc.fillRectangle(event.x, event.y, event.width, event.height);
-                        event.gc.setForeground(oldForeground);
-                        event.detail &= ~SWT.SELECTED;
-                    }
-
-                    int barWidth = (int) ((fTreeViewer.getTree().getColumn(1).getWidth() - 8) * percentage);
-                    int oldAlpha = event.gc.getAlpha();
-                    Color oldForeground = event.gc.getForeground();
-                    Color oldBackground = event.gc.getBackground();
-                    event.gc.setAlpha(64);
-                    event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_BLUE));
-                    event.gc.setBackground(event.item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
-                    event.gc.fillGradientRectangle(event.x, event.y, barWidth, event.height, true);
-                    event.gc.drawRectangle(event.x, event.y, barWidth, event.height);
-                    event.gc.setForeground(oldForeground);
-                    event.gc.setBackground(oldBackground);
-                    event.gc.setAlpha(oldAlpha);
-                    event.detail &= ~SWT.BACKGROUND;
-                }
-            }
-        });
-
-        fTreeViewer.setComparator(columnDataList.get(0).getComparator());
-        fTreeViewer.getTree().setSortColumn(fTreeViewer.getTree().getColumn(0));
-        fTreeViewer.getTree().setSortDirection(SWT.DOWN);
-
-        // Read current data if any available
-        TmfExperiment<?> experiment = TmfExperiment.getCurrentExperiment();
-        if (experiment != null) {
-            fRequestData = true;
-            // Insert the statistics data into the tree
-            @SuppressWarnings({ "rawtypes", "unchecked" })
-            TmfExperimentSelectedSignal<?> signal = new TmfExperimentSelectedSignal(this, experiment);
-            experimentSelected(signal);
-         }
     }
 
     /*
      * (non-Javadoc)
+     *
      * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#dispose()
      */
     @Override
     public void dispose() {
         super.dispose();
-        if (fWaitCursor != null) {
-            fWaitCursor.dispose();
-        }
-
-        // clean the model
-        TmfStatisticsTreeRootFactory.removeAll();
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
-     */
-    @Override
-    public void setFocus() {
-        fTreeViewer.getTree().setFocus();
+        fStatsViewers.dispose();
     }
 
     /**
-     * Refresh the view.
-     */
-    public void modelInputChanged(boolean complete) {
-        // Ignore update if disposed
-        if (fTreeViewer.getTree().isDisposed())
-            return;
-
-        fTreeViewer.getTree().getDisplay().asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                if (!fTreeViewer.getTree().isDisposed())
-                    fTreeViewer.refresh();
-            }
-        });
-        
-        if (complete) {
-            sendPendingUpdate();
-        }
-    }
-
-    /**
-     * Called when an experiment request has failed or has been canceled Remove the data retrieved from the experiment from the statistics tree.
-     * 
-     * @param name
-     *            the experiment name
-     */
-    public void modelIncomplete(String name) {
-        Object input = fTreeViewer.getInput();
-        if (input != null && input instanceof TmfStatisticsTreeNode) {
-            // The data from this experiment is invalid and shall be removed to
-            // refresh upon next selection
-            TmfStatisticsTreeRootFactory.removeStatTreeRoot(getTreeID(name));
-
-            // Reset synchronization information
-            resetUpdateSynchronization();
-            modelInputChanged(false);
-        }
-        waitCursor(false);
-    }
-
-    /**
-     * If the user choose another experiment, the current must be disposed.
-     * 
+     * Handler called when an trace is opened.
+     *
      * @param signal
+     *            Contains the information about the selection.
+     * @since 2.0
      */
     @TmfSignalHandler
-    public void experimentDisposed(TmfExperimentDisposedSignal<? extends TmfEvent> signal) {
-        if (signal.getExperiment() != TmfExperiment.getCurrentExperiment()) {
-            return;
-        }
-        cancelOngoingRequest();
+    public void traceOpened(TmfTraceOpenedSignal signal) {
+        /*
+         * Dispose the current viewer and adapt the new one to the trace
+         * type of the trace opened
+         */
+        fStatsViewers.clear();
+        // Update the current trace
+        fTrace = signal.getTrace();
+        createStatisticsViewers();
+        fStatsViewers.layout();
     }
 
     /**
-     * Handler called when an experiment is selected. Checks if the experiment has changed and requests the selected experiment if it has not yet been
+     * Handler called when an trace is selected. Checks if the trace
+     * has changed and requests the selected trace if it has not yet been
      * cached.
-     * 
+     *
      * @param signal
-     *            contains the information about the selection.
+     *            Contains the information about the selection.
+     * @since 2.0
      */
     @TmfSignalHandler
-    public void experimentSelected(TmfExperimentSelectedSignal<? extends TmfEvent> signal) {
-        if (signal != null) {
-            TmfExperiment<?> experiment = signal.getExperiment();
-            String experimentName = experiment.getName();
-
-            if (TmfStatisticsTreeRootFactory.containsTreeRoot(getTreeID(experimentName))) {
-                // The experiment root is already present
-                TmfStatisticsTreeNode experimentTreeNode = TmfStatisticsTreeRootFactory.getStatTreeRoot(getTreeID(experimentName));
-
-                @SuppressWarnings("rawtypes")
-                ITmfTrace[] traces = experiment.getTraces();
-
-                // check if there is partial data loaded in the experiment
-                int numTraces = experiment.getTraces().length;
-                int numNodeTraces = experimentTreeNode.getNbChildren();
-
-                if (numTraces == numNodeTraces) {
-                    boolean same = true;
-                    // Detect if the experiment contains the same traces as when
-                    // previously selected
-                    for (int i = 0; i < numTraces; i++) {
-                        String traceName = traces[i].getName();
-                        if (!experimentTreeNode.containsChild(traceName)) {
-                            same = false;
-                            break;
-                        }
-                    }
-
-                    if (same) {
-                        // no need to reload data, all traces are already loaded
-                        fTreeViewer.setInput(experimentTreeNode);
-                        
-                        resetUpdateSynchronization();
-
-                        return;
-                    }
-                    experimentTreeNode.reset();
-                }
-            } else {
-                TmfStatisticsTreeRootFactory.addStatsTreeRoot(getTreeID(experimentName), getStatisticData());
+    public void traceSelected(TmfTraceSelectedSignal signal) {
+        // Does not reload the same trace if already opened
+        if (signal.getTrace() != fTrace) {
+            /*
+             * Dispose the current viewer and adapt the new one to the trace
+             * type of the trace selected
+             */
+            fStatsViewers.clear();
+            // Update the current trace
+            fTrace = signal.getTrace();
+            createStatisticsViewers();
+            fStatsViewers.layout();
+
+            TmfTraceRangeUpdatedSignal updateSignal = new TmfTraceRangeUpdatedSignal(this, fTrace, fTrace.getTimeRange());
+
+            // Synchronizes the requests to make them coalesced
+            if (fTrace instanceof TmfDataProvider) {
+                ((TmfDataProvider) fTrace).startSynch(new TmfStartSynchSignal(0));
             }
-
-            resetUpdateSynchronization();
-
-            TmfStatisticsTreeNode treeModelRoot = TmfStatisticsTreeRootFactory.getStatTreeRoot(getTreeID(experiment.getName()));
-
-            // if the model has contents, clear to start over
-            if (treeModelRoot.hasChildren()) {
-                treeModelRoot.reset();
+            for (ITmfViewer viewer : fStatsViewers.getViewers()) {
+                TmfStatisticsViewer statsViewer = (TmfStatisticsViewer) viewer;
+                statsViewer.sendPartialRequestOnNextUpdate();
+                statsViewer.traceRangeUpdated(updateSignal);
             }
-
-            // set input to a clean data model
-            fTreeViewer.setInput(treeModelRoot);
-            
-            if (fRequestData) {
-                requestData(experiment, experiment.getTimeRange());
-                fRequestData = false;
+            if (fTrace instanceof TmfDataProvider) {
+                ((TmfDataProvider) fTrace).endSynch(new TmfEndSynchSignal(0));
+            }
+        } else {
+            /*
+             * If the same trace is reselected, sends a notification to
+             * the viewers to make sure they reload correctly their partial
+             * event count.
+             */
+            for (ITmfViewer viewer : fStatsViewers.getViewers()) {
+                TmfStatisticsViewer statsViewer = (TmfStatisticsViewer) viewer;
+                // Will update the partial event count if needed.
+                statsViewer.sendPartialRequestOnNextUpdate();
             }
         }
     }
 
     /**
-     * @param signal
+     * @param signal the incoming signal
+     * @since 2.0
      */
-    @SuppressWarnings("unchecked")
     @TmfSignalHandler
-    public void experimentRangeUpdated(TmfExperimentRangeUpdatedSignal signal) {
-        TmfExperiment<TmfEvent> experiment = (TmfExperiment<TmfEvent>) signal.getExperiment();
-        // validate
-        if (! experiment.equals(TmfExperiment.getCurrentExperiment())) {
+    public void traceClosed(TmfTraceClosedSignal signal) {
+        if (signal.getTrace() != fTrace) {
             return;
         }
 
-        requestData(experiment, signal.getRange());
-    }
-
-    
-    /**
-     * Return the size of the request when performing background request.
-     * 
-     * @return the block size for background request.
-     */
-    protected int getIndexPageSize() {
-        return PAGE_SIZE;
-    }
-
-    /**
-     * 
-     * @return the quantity of data to retrieve before a refresh of the view is performed.
-     */
-    protected long getInputChangedRefresh() {
-        return STATS_INPUT_CHANGED_REFRESH;
-    }
-
-    /**
-     * This method can be overridden to implement another way to represent the statistics data and to retrieve the information for display.
-     * 
-     * @return a TmfStatisticsData object.
-     */
-    protected AbsTmfStatisticsTree getStatisticData() {
-        return new TmfBaseStatisticsTree();
-    }
+        // Clear the internal data
+        fTrace = null;
 
-    /**
-     * This method can be overridden to change the representation of the data in the columns.
-     * 
-     * @return an object implementing ITmfBaseColumnDataProvider.
-     */
-    protected ITmfColumnDataProvider getColumnDataProvider() {
-        return new TmfBaseColumnDataProvider();
+        // Clear the UI widgets
+        fStatsViewers.clear();  // Also cancels ongoing requests
+        createStatisticsViewers();
+        fStatsViewers.layout();
     }
 
-    /**
-     * Construct the ID based on the experiment name
-     * @param experimentName the name of the trace name to show in the view 
-     * @return a view ID
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
      */
-    protected String getTreeID(String experimentName) {
-        return experimentName + fInstanceNb;
+    @Override
+    public void setFocus() {
+        fStatsViewers.setFocus();
     }
 
     /**
-     * When the experiment is loading the cursor will be different so the user know the processing is not finished yet.
-     * 
-     * @param waitInd
-     *            indicates if we need to show the waiting cursor, or the default one
+     * Creates the statistics viewers for all traces in an experiment and
+     * populates a viewer folder. Each viewer is placed in a different tab and
+     * the first one is selected automatically.
+     *
+     * It uses the extension point that defines the statistics viewer to build
+     * from the trace type. If no viewer is defined, another tab won't be
+     * created, since the global viewer already contains all the basic
+     * statistics. If there is no trace selected, a global statistics viewer will
+     * still be created.
+     *
+     * @since 2.0
      */
-    protected void waitCursor(final boolean waitInd) {
-        if ((fTreeViewer == null) || (fTreeViewer.getTree().isDisposed())) {
-            return;
-        }
-
-        Display display = fTreeViewer.getControl().getDisplay();
-        if (fWaitCursor == null) {
-            fWaitCursor = new Cursor(display, SWT.CURSOR_WAIT);
-        }
-
-        // Perform the updates on the UI thread
-        display.asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                if ((fTreeViewer != null) && (!fTreeViewer.getTree().isDisposed())) {
-                    Cursor cursor = null; /* indicates default */
-                    if (waitInd) {
-                        cursor = fWaitCursor;
-                    }
-                    fTreeViewer.getControl().setCursor(cursor);
-                }
+    protected void createStatisticsViewers() {
+        // Default style for the tabs that will be created
+        int defaultStyle = SWT.NONE;
+
+        // The folder composite that will contain the tabs
+        Composite folder = fStatsViewers.getParentFolder();
+
+        // Instantiation of the global viewer
+        TmfStatisticsViewer globalViewer = getGlobalViewer();
+        if (fTrace != null) {
+            if (globalViewer != null) {
+                // Shows the name of the trace in the global tab
+                globalViewer.init(folder, Messages.TmfStatisticsView_GlobalTabName + " - " + fTrace.getName(), fTrace); //$NON-NLS-1$
             }
-        });
-    }
-
-    /**
-     * Perform the request for an experiment and populates the statistics tree with event.
-     * @param experiment experiment for which we need the statistics data.
-     * @param time range to request
-     */
-    @SuppressWarnings("unchecked")
-    protected void requestData(final TmfExperiment<?> experiment, TmfTimeRange timeRange) {
-        if (experiment != null) {
-
-            // Check if update is already ongoing
-            if (checkUpdateBusy(timeRange)) {
-                return;
+            fStatsViewers.addTab(globalViewer, Messages.TmfStatisticsView_GlobalTabName, defaultStyle);
+
+            String traceName;
+            IResource traceResource;
+            ITmfTrace[] traces = fTrace.getTraces();
+            // Creates a statistics viewer for each trace.
+            for (ITmfTrace trace : traces) {
+                traceName = trace.getName();
+                traceResource = trace.getResource();
+                TmfStatisticsViewer viewer = getStatisticsViewer(traceResource);
+                /*
+                 * Adds a new viewer only if there is one defined for the
+                 * selected trace type, since the global tab already contains
+                 * all the basic event counts for the trace(s)
+                 */
+                if (viewer != null) {
+                    viewer.init(folder, traceName, trace);
+                    fStatsViewers.addTab(viewer, viewer.getName(), defaultStyle);
+                }
             }
-
-            int index = 0;
-            for (TmfStatisticsTreeNode node : ((TmfStatisticsTreeNode) fTreeViewer.getInput()).getChildren()) {
-                index += (int) node.getValue().nbEvents;
+        } else {
+            if (globalViewer != null) {
+                // There is no trace selected. Shows an empty global tab
+                globalViewer.init(folder, Messages.TmfStatisticsView_GlobalTabName, fTrace);
             }
-
-            // Preparation of the event request
-            fRequest = new TmfEventRequest<TmfEvent>(TmfEvent.class, timeRange, index, TmfDataRequest.ALL_DATA, getIndexPageSize(), ExecutionType.BACKGROUND) {
-
-                @Override
-                public void handleData(TmfEvent data) {
-                    super.handleData(data);
-                    if (data != null) {
-                        AbsTmfStatisticsTree statisticsData = TmfStatisticsTreeRootFactory.getStatTree(getTreeID(experiment.getName()));
-                        
-                        final String traceName = data.getParentTrace().getName();
-                        ITmfExtraEventInfo extraInfo = new ITmfExtraEventInfo() {
-                            @Override
-                            public String getTraceName() {
-                                if (traceName == null) {
-                                    return Messages.TmfStatisticsView_UnknownTraceName;
-                                }
-                                return traceName;
-                            }
-                        };
-                        statisticsData.registerEvent(data, extraInfo);
-                        statisticsData.increase(data, extraInfo, 1);
-                        // Refresh View
-                        if ((getNbRead() % getInputChangedRefresh()) == 0) {
-                            modelInputChanged(false);
-                        }
-                    }
-                }
-
-                @Override
-                public void handleSuccess() {
-                    super.handleSuccess();
-                    modelInputChanged(true);
-                    waitCursor(false);
-                }
-
-                @Override
-                public void handleFailure() {
-                    super.handleFailure();
-                    modelIncomplete(experiment.getName());
-                }
-
-                @Override
-                public void handleCancel() {
-                    super.handleCancel();
-                    modelIncomplete(experiment.getName());
-                }
-            };
-            ((TmfExperiment<TmfEvent>) experiment).sendRequest((ITmfDataRequest<TmfEvent>) fRequest);
-            waitCursor(true);
-        }
-    }
-
-    /**
-     * Cancels the current ongoing request
-     */
-    protected void cancelOngoingRequest() {
-        if (fRequest != null && !fRequest.isCompleted()) {
-            fRequest.cancel();
-        }
-    }
-    
-    /**
-     * Reset update synchronization information
-     */
-    protected void resetUpdateSynchronization() {
-        synchronized (fStatisticsUpdateSyncObj) {
-            fStatisticsUpdateBusy = false;
-            fStatisticsUpdatePending = false;
+            fStatsViewers.addTab(globalViewer, Messages.TmfStatisticsView_GlobalTabName, defaultStyle);
         }
+        // Makes the global viewer visible
+        fStatsViewers.setSelection(0);
     }
 
     /**
-     * Checks if statistic update is ongoing. If it is ongoing the new time range is stored as pending 
-     * 
-     * @param timeRange - new time range
-     * @return true if statistic update is ongoing else false 
+     * Retrieves and instantiates a viewer based on his plug-in definition for a
+     * specific trace type. It is specific to the statistics viewer.
+     *
+     * It only calls the 0-parameter constructor without performing any other
+     * initialization on the viewer.
+     *
+     * @param resource
+     *            The resource where to find the information about the trace
+     *            properties
+     * @return a new statistics viewer based on his plug-in definition, or null
+     *         if no statistics definition was found for the trace type.
+     * @since 2.0
      */
-    protected boolean checkUpdateBusy(TmfTimeRange timeRange) {
-        synchronized (fStatisticsUpdateSyncObj) {
-            if (fStatisticsUpdateBusy) {
-                fStatisticsUpdatePending = true;
-                fStatisticsUpdateRange = timeRange;
-                return true;
-            } 
-            fStatisticsUpdateBusy = true;
-            return false;
-        }
+    protected static TmfStatisticsViewer getStatisticsViewer(IResource resource) {
+        return (TmfStatisticsViewer) TmfTraceType.getTraceTypeElement(resource, TmfTraceType.STATISTICS_VIEWER_ELEM);
     }
 
     /**
-     * Sends pending request (if any)
+     * @return The class to use to instantiate the global statistics viewer
+     * @since 2.0
      */
-    protected void sendPendingUpdate() {
-        synchronized (fStatisticsUpdateSyncObj) {
-            fStatisticsUpdateBusy = false;
-            if (fStatisticsUpdatePending) {
-                fStatisticsUpdatePending = false;
-                requestData(TmfExperiment.getCurrentExperiment(), fStatisticsUpdateRange);
-            }
-        }
+    protected TmfStatisticsViewer getGlobalViewer() {
+        return new TmfStatisticsViewer();
     }
-
 }
This page took 0.043931 seconds and 5 git commands to generate.