summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMathieu Denis2012-08-21 17:09:36 (EDT)
committer Alexandre Montplaisir2012-08-22 15:58:03 (EDT)
commit2de8425ebdc38d6d268b6b84ad44a272e7e1f490 (patch)
treed748865d686b83383b700a6ece25c2e5fa774991
parent5f90ea16ce2a6706bf17ce3a47869595666c7fa4 (diff)
downloadorg.eclipse.linuxtools-2de8425ebdc38d6d268b6b84ad44a272e7e1f490.zip
org.eclipse.linuxtools-2de8425ebdc38d6d268b6b84ad44a272e7e1f490.tar.gz
org.eclipse.linuxtools-2de8425ebdc38d6d268b6b84ad44a272e7e1f490.tar.bz2
tmf: Refactor the statistics
Manage the viewer input directly in the viewer rather than in the view. Change-Id: I2ed5ee303036d384939d5a2a121e30462c9c9fb7 Signed-off-by: Mathieu Denis <mathieu.denis@polymtl.ca> Reviewed-on: https://git.eclipse.org/r/7332 Reviewed-by: Bernd Hufmann <bhufmann@gmail.com> IP-Clean: Bernd Hufmann <bhufmann@gmail.com> Tested-by: Bernd Hufmann <bhufmann@gmail.com> Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java74
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java8
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java67
3 files changed, 67 insertions, 82 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
index ba4b9c3..f2770b6 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java
@@ -51,6 +51,8 @@ import org.eclipse.swt.widgets.Listener;
/**
* A basic viewer to display statistics in the statistics view.
*
+ * It is linked to a single ITmfTrace until its disposal.
+ *
* @author Mathieu Denis
* @version 2.0
* @since 2.0
@@ -202,6 +204,7 @@ public class TmfStatisticsViewer extends TmfViewer {
fProcessAll = (trace instanceof TmfExperiment);
initContent(parent);
+ initInput();
}
/*
@@ -221,6 +224,9 @@ public class TmfStatisticsViewer extends TmfViewer {
*/
cancelOngoingRequest(fRequestRange);
cancelOngoingRequest(fRequest);
+
+ // Clean the model
+ TmfStatisticsTreeRootFactory.removeStatTreeRoot(getTreeID());
}
/**
@@ -384,17 +390,6 @@ public class TmfStatisticsViewer extends TmfViewer {
}
/**
- * Sets or clears the input for this viewer.
- *
- * @param input
- * The input of this viewer, or <code>null</code> if none
- */
- public void setInput(TmfStatisticsTreeNode input) {
- resetUpdateSynchronization();
- fTreeViewer.setInput(input);
- }
-
- /**
* Cancels the request if it is not already completed
*
* @param request
@@ -525,6 +520,63 @@ public class TmfStatisticsViewer extends TmfViewer {
}
/**
+ * Initializes the input for the tree viewer.
+ *
+ * @param input
+ * The input of this viewer, or <code>null</code> if none
+ */
+ protected void initInput() {
+ String treeID = getTreeID();
+ TmfStatisticsTreeNode experimentTreeNode;
+ if (TmfStatisticsTreeRootFactory.containsTreeRoot(treeID)) {
+ // The experiment root is already present
+ experimentTreeNode = TmfStatisticsTreeRootFactory.getStatTreeRoot(treeID);
+
+ // Checks if the trace is already in the statistics tree.
+ int numNodeTraces = experimentTreeNode.getNbChildren();
+
+ int numTraces = 1;
+ ITmfTrace[] trace = { fTrace };
+ // For experiment, gets all the traces within it
+ if (fTrace instanceof TmfExperiment) {
+ TmfExperiment experiment = (TmfExperiment) fTrace;
+ numTraces = experiment.getTraces().length;
+ trace = experiment.getTraces();
+ }
+
+ if (numTraces == numNodeTraces) {
+ boolean same = true;
+ /*
+ * Checks if the experiment contains the same traces as when
+ * previously selected.
+ */
+ for (int i = 0; i < numTraces; i++) {
+ String traceName = trace[i].getName();
+ if (!experimentTreeNode.containsChild(traceName)) {
+ same = false;
+ break;
+ }
+ }
+
+ if (same) {
+ // No need to reload data, all traces are already loaded
+ fTreeViewer.setInput(experimentTreeNode);
+ return;
+ }
+ // Clears the old content to start over
+ experimentTreeNode.reset();
+ }
+ } else {
+ // Creates a new tree
+ experimentTreeNode = TmfStatisticsTreeRootFactory.addStatsTreeRoot(treeID, getStatisticData());
+ }
+
+ // Sets the input to a clean data model
+ fTreeViewer.setInput(experimentTreeNode);
+ resetUpdateSynchronization();
+ }
+
+ /**
* Tells if the viewer is listening to a trace from the selected experiment.
*
* @param traceName
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java
index 1e7eca4..130d847 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeRootFactory.java
@@ -76,15 +76,15 @@ public class TmfStatisticsTreeRootFactory {
* trace.
* @param statsData
* The information about the trace
+ * @return The newly created root node of the trace statistics tree, or null if something went wrong
*/
- public static void addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) {
+ public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) {
if (traceUniqueId == null || statsData == null) {
- return;
+ return null;
}
-
fTreeInstances.put(traceUniqueId, statsData);
// if called for the first time, create the root node
- statsData.getOrCreate(AbsTmfStatisticsTree.ROOT);
+ return statsData.getOrCreate(AbsTmfStatisticsTree.ROOT);
}
/**
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java
index 68b4820..45a03ae 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsView.java
@@ -28,7 +28,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
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.viewers.statistics.model.TmfStatisticsTreeNode;
import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeRootFactory;
import org.eclipse.linuxtools.tmf.ui.views.TmfView;
import org.eclipse.linuxtools.tmf.ui.widgets.tabsview.TmfViewerFolder;
@@ -149,16 +148,6 @@ public class TmfStatisticsView extends TmfView {
createStatisticsViewers();
fStatsViewers.layout();
- TmfStatisticsViewer statViewer;
- for (ITmfViewer viewer : fStatsViewers.getViewers()) {
- if (!(viewer instanceof TmfStatisticsViewer)) {
- Activator.getDefault().logError("Error - cannot cast viewer to a statistics viewer"); //$NON-NLS-1$
- continue;
- }
- statViewer = (TmfStatisticsViewer) viewer;
- setInput(statViewer, fExperiment.getTraces());
- }
-
if (fRequestData) {
TmfExperimentRangeUpdatedSignal updateSignal = new TmfExperimentRangeUpdatedSignal(null, fExperiment, fExperiment.getTimeRange());
TmfStatisticsViewer statsViewer;
@@ -179,62 +168,6 @@ public class TmfStatisticsView extends TmfView {
}
}
- /**
- * Initializes the viewer with the information received.
- *
- * @param statViewer
- * The statistics viewer for which the input will be set
- * @param traces
- * The list of traces to add in the tree.
- * @since 2.0
- */
- public void setInput(TmfStatisticsViewer statViewer, ITmfTrace[] traces) {
- String treeID = statViewer.getTreeID();
- if (TmfStatisticsTreeRootFactory.containsTreeRoot(treeID)) {
- // The experiment root is already present
- TmfStatisticsTreeNode experimentTreeNode = TmfStatisticsTreeRootFactory.getStatTreeRoot(treeID);
-
- // check if there is partial data loaded in the experiment
- int numTraces = traces.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
- statViewer.setInput(experimentTreeNode);
-
- return;
- }
- experimentTreeNode.reset();
- }
- } else {
- TmfStatisticsTreeRootFactory.addStatsTreeRoot(treeID, statViewer.getStatisticData());
- }
-
- TmfStatisticsTreeNode treeModelRoot = TmfStatisticsTreeRootFactory.getStatTreeRoot(treeID);
-
- // if the model has contents, clear to start over
- if (treeModelRoot.hasChildren()) {
- treeModelRoot.reset();
- }
-
- // set input to a clean data model
- statViewer.setInput(treeModelRoot);
- }
-
/*
* (non-Javadoc)
*