tmf: Make TimeGraphEntry implementation less restrictive
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 11 Jul 2014 17:31:07 +0000 (13:31 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 18 Jul 2014 14:01:48 +0000 (10:01 -0400)
A TimeGraphEntry's parent and children no longer have to be instances
of TimeGraphEntry. They can now be any type of ITimeGraphEntry.

The method addChild(int, ITimeGraphEntry) is added to insert a child at
any position.

Change-Id: I8144c7f06505c3a2a4c56264e1543fab84a77be5
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/29829
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java

index e077c6c183ff5506c222349cd95632213cc45064..a5d05fd77436cf50487a67e6839747a325a5e16d 100644 (file)
@@ -571,8 +571,8 @@ public class ControlFlowView extends AbstractTimeGraphView {
         return list;
     }
 
-    private ControlFlowEntry findEntry(List<TimeGraphEntry> entryList, ITmfTrace trace, int threadId) {
-        for (TimeGraphEntry entry : entryList) {
+    private ControlFlowEntry findEntry(List<? extends ITimeGraphEntry> entryList, ITmfTrace trace, int threadId) {
+        for (ITimeGraphEntry entry : entryList) {
             if (entry instanceof ControlFlowEntry) {
                 ControlFlowEntry controlFlowEntry = (ControlFlowEntry) entry;
                 if (controlFlowEntry.getThreadId() == threadId && controlFlowEntry.getTrace() == trace) {
index c7a8aee7e7af617af202af868d9b8e386eeb542a..fca686524d9ccee24b842155b5bce8f5331f032d 100644 (file)
@@ -182,7 +182,7 @@ public class ResourcesEntry extends TimeGraphEntry implements Comparable<ITimeGr
         }
 
         rEntry.setParent(this);
-        getChildren().add(index, rEntry);
+        addChild(index, rEntry);
     }
 
     @Override
index 1d4df72dd24e8700b0b8d768bbb4a8f3a3d9896b..37011c90bbe9eedfdc2d530bd8391b278cc12907 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
@@ -173,17 +174,20 @@ public class ResourcesView extends AbstractTimeGraphView {
                 refresh();
             }
             long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth());
-            for (TimeGraphEntry entry : traceEntry.getChildren()) {
+            for (ITimeGraphEntry child : traceEntry.getChildren()) {
                 if (monitor.isCanceled()) {
                     return;
                 }
-                List<ITimeEvent> eventList = getEventList(entry, start, endTime, resolution, monitor);
-                if (eventList != null) {
-                    for (ITimeEvent event : eventList) {
-                        entry.addEvent(event);
+                if (child instanceof TimeGraphEntry) {
+                    TimeGraphEntry entry = (TimeGraphEntry) child;
+                    List<ITimeEvent> eventList = getEventList(entry, start, endTime, resolution, monitor);
+                    if (eventList != null) {
+                        for (ITimeEvent event : eventList) {
+                            entry.addEvent(event);
+                        }
                     }
+                    redraw();
                 }
-                redraw();
             }
 
             start = end;
index 563a2fe7598b3955701342c3473e689792ca485a..684b30627d68fb3d9767a73ceeeaf12420822598 100644 (file)
@@ -244,7 +244,7 @@ public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer
         }
 
         entry.setParent(this);
-        getChildren().add(index, entry);
+        addChild(index, entry);
     }
 
     /**
index e67fa5cd6f5ba80d1a2222f5e08afd617484a77e..de83071fbd9a637df890c9897b241efc6705d510 100644 (file)
@@ -429,7 +429,7 @@ public class XmlTimeGraphView extends AbstractTimeGraphView {
         traceEntry.setEventList(eventList);
         redraw();
 
-        for (TimeGraphEntry entry : traceEntry.getChildren()) {
+        for (ITimeGraphEntry entry : traceEntry.getChildren()) {
             if (monitor.isCanceled()) {
                 return;
             }
index 608236301601fca5bac618eea053444d51f30c84..2be3af061ac53f1667b45324773cc5425c224082 100644 (file)
@@ -706,7 +706,7 @@ public class CallStackView extends TmfView {
                         ITmfStateInterval stackInterval = ss.querySingleState(beginTime, quark);
                         if (beginTime == stackInterval.getStartTime()) {
                             int stackLevel = stackInterval.getStateValue().unboxInt();
-                            CallStackEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
+                            ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
                             fTimeGraphCombo.setSelection(selectedEntry);
                             viewer.getTimeGraphControl().fireSelectionChanged();
                             break;
@@ -840,11 +840,11 @@ public class CallStackView extends TmfView {
             refresh();
         }
         for (ThreadEntry threadEntry : entryList) {
-            for (CallStackEntry callStackEntry : threadEntry.getChildren()) {
+            for (ITimeGraphEntry callStackEntry : threadEntry.getChildren()) {
                 if (monitor.isCanceled()) {
                     return;
                 }
-                buildStatusEvents(trace, callStackEntry, monitor);
+                buildStatusEvents(trace, (CallStackEntry) callStackEntry, monitor);
             }
         }
     }
@@ -938,7 +938,8 @@ public class CallStackView extends TmfView {
                 continue;
             }
             long queryTime = Math.max(ss.getStartTime(), Math.min(ss.getCurrentEndTime(), time));
-            for (CallStackEntry callStackEntry : threadEntry.getChildren()) {
+            for (ITimeGraphEntry child : threadEntry.getChildren()) {
+                CallStackEntry callStackEntry = (CallStackEntry) child;
                 try {
                     ITmfStateInterval stackLevelInterval = ss.querySingleState(queryTime, callStackEntry.getQuark());
                     ITmfStateValue nameValue = stackLevelInterval.getStateValue();
@@ -1109,7 +1110,7 @@ public class CallStackView extends TmfView {
                             viewer.setSelectedTimeNotify(newTime, true);
                             stackInterval = ss.querySingleState(Math.min(ss.getCurrentEndTime(), newTime), quark);
                             int stackLevel = stackInterval.getStateValue().unboxInt();
-                            CallStackEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
+                            ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
                             fTimeGraphCombo.setSelection(selectedEntry);
                             viewer.getTimeGraphControl().fireSelectionChanged();
                             startZoomThread(viewer.getTime0(), viewer.getTime1());
@@ -1160,7 +1161,7 @@ public class CallStackView extends TmfView {
                             }
                             viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
                             int stackLevel = stackInterval.getStateValue().unboxInt();
-                            CallStackEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
+                            ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
                             fTimeGraphCombo.setSelection(selectedEntry);
                             viewer.getTimeGraphControl().fireSelectionChanged();
                             startZoomThread(viewer.getTime0(), viewer.getTime1());
index be8f16c14cab146b193223accbd787d7a57cd2f2..5bf2169d3f83ea3cde696038c648c8e3d27edc08 100644 (file)
@@ -495,11 +495,13 @@ public abstract class AbstractTimeGraphView extends TmfView {
                 }
             }
             redraw();
-            for (TimeGraphEntry child : entry.getChildren()) {
+            for (ITimeGraphEntry child : entry.getChildren()) {
                 if (fMonitor.isCanceled()) {
                     return;
                 }
-                zoom(child, monitor);
+                if (child instanceof TimeGraphEntry) {
+                    zoom((TimeGraphEntry) child, monitor);
+                }
             }
         }
 
index 2b4b583ab95206b886c03d86c281e519df42ca31..d4ae0509664d4d42f153166540d099c5c22bf967 100644 (file)
@@ -26,10 +26,10 @@ import java.util.concurrent.CopyOnWriteArrayList;
 public class TimeGraphEntry implements ITimeGraphEntry {
 
     /** Entry's parent */
-    private TimeGraphEntry fParent = null;
+    private ITimeGraphEntry fParent = null;
 
     /** List of child entries */
-    private final List<TimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
+    private final List<ITimeGraphEntry> fChildren = new CopyOnWriteArrayList<>();
 
     /** Name of this entry (text to show) */
     private String fName;
@@ -68,17 +68,33 @@ public class TimeGraphEntry implements ITimeGraphEntry {
      *
      * @param entry The new parent entry
      */
+    /*
+     * TODO: This method can be removed in the next major API version.
+     */
     protected void setParent(TimeGraphEntry entry) {
         fParent = entry;
     }
 
+    /**
+     * Sets the entry's parent
+     *
+     * @param entry The new parent entry
+     * @since 3.1
+     */
+    /*
+     * TODO: This method should be added to the interface in the next major API version.
+     */
+    protected void setParent(ITimeGraphEntry entry) {
+        fParent = entry;
+    }
+
     @Override
     public boolean hasChildren() {
         return fChildren.size() > 0;
     }
 
     @Override
-    public List<TimeGraphEntry> getChildren() {
+    public List<? extends ITimeGraphEntry> getChildren() {
         return fChildren;
     }
 
@@ -201,11 +217,44 @@ public class TimeGraphEntry implements ITimeGraphEntry {
      * @param child
      *            The child entry
      */
+    /*
+     * TODO: This method can be removed in the next major API version.
+     */
     public void addChild(TimeGraphEntry child) {
         child.fParent = this;
         fChildren.add(child);
     }
 
+    /**
+     * Add a child entry to this one
+     *
+     * @param child
+     *            The child entry
+     * @since 3.1
+     */
+    public void addChild(ITimeGraphEntry child) {
+        if (child instanceof TimeGraphEntry) {
+            ((TimeGraphEntry) child).fParent = this;
+        }
+        fChildren.add(child);
+    }
+
+    /**
+     * Add a child entry to this one at the specified position
+     *
+     * @param index
+     *            Index at which the specified entry is to be inserted
+     * @param child
+     *            The child entry
+     * @since 3.1
+     */
+    public void addChild(int index, ITimeGraphEntry child) {
+        if (child instanceof TimeGraphEntry) {
+            ((TimeGraphEntry) child).fParent = this;
+        }
+        fChildren.add(index, child);
+    }
+
     @Override
     public String toString() {
         return getClass().getSimpleName() + '(' + fName + ')';
This page took 0.034089 seconds and 5 git commands to generate.