From a3188982483140452c679df5faae68f595ef93d9 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 11 Jul 2014 13:31:07 -0400 Subject: [PATCH] tmf: Make TimeGraphEntry implementation less restrictive 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 Reviewed-on: https://git.eclipse.org/r/29829 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam --- .../ui/views/controlflow/ControlFlowView.java | 4 +- .../ui/views/resources/ResourcesEntry.java | 2 +- .../ui/views/resources/ResourcesView.java | 16 ++++-- .../xml/ui/views/timegraph/XmlEntry.java | 2 +- .../ui/views/timegraph/XmlTimeGraphView.java | 2 +- .../tmf/ui/views/callstack/CallStackView.java | 13 +++-- .../timegraph/AbstractTimeGraphView.java | 6 +- .../timegraph/model/TimeGraphEntry.java | 55 ++++++++++++++++++- 8 files changed, 78 insertions(+), 22 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java index e077c6c183..a5d05fd774 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java @@ -571,8 +571,8 @@ public class ControlFlowView extends AbstractTimeGraphView { return list; } - private ControlFlowEntry findEntry(List entryList, ITmfTrace trace, int threadId) { - for (TimeGraphEntry entry : entryList) { + private ControlFlowEntry findEntry(List entryList, ITmfTrace trace, int threadId) { + for (ITimeGraphEntry entry : entryList) { if (entry instanceof ControlFlowEntry) { ControlFlowEntry controlFlowEntry = (ControlFlowEntry) entry; if (controlFlowEntry.getThreadId() == threadId && controlFlowEntry.getTrace() == trace) { diff --git a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java index c7a8aee7e7..fca686524d 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java +++ b/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java @@ -182,7 +182,7 @@ public class ResourcesEntry extends TimeGraphEntry implements Comparable 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 eventList = getEventList(entry, start, endTime, resolution, monitor); + if (eventList != null) { + for (ITimeEvent event : eventList) { + entry.addEvent(event); + } } + redraw(); } - redraw(); } start = end; diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java index 563a2fe759..684b30627d 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java +++ b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java @@ -244,7 +244,7 @@ public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer } entry.setParent(this); - getChildren().add(index, entry); + addChild(index, entry); } /** diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java index e67fa5cd6f..de83071fbd 100644 --- a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java +++ b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java @@ -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; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java index 6082363016..2be3af061a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/callstack/CallStackView.java @@ -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()); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java index be8f16c14c..5bf2169d3f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java @@ -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); + } } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java index 2b4b583ab9..d4ae050966 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/model/TimeGraphEntry.java @@ -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 fChildren = new CopyOnWriteArrayList<>(); + private final List 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 getChildren() { + public List 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 + ')'; -- 2.34.1