Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Montplaisir2014-05-21 18:26:47 -0400
committerAlexandre Montplaisir2014-05-27 13:16:57 -0400
commit90dc143b4da84a76901d9992f75a3a7a600d0c24 (patch)
tree1bda6dddf6d5b5f2b784f124f36bb513069a43e5
parentf8cc353674628f647c628d004d233bbf9337ac29 (diff)
downloadorg.eclipse.linuxtools-90dc143b4da84a76901d9992f75a3a7a600d0c24.tar.gz
org.eclipse.linuxtools-90dc143b4da84a76901d9992f75a3a7a600d0c24.tar.xz
org.eclipse.linuxtools-90dc143b4da84a76901d9992f75a3a7a600d0c24.zip
lttng: Sort the entries in the Resources View
Make the ResourcesEntry Comparable, so that the view can specify how they should be sorted when entries are added to the list. This also works for entries that are being added while the trace is being read ("live" reading). Change-Id: I5a99652b5b755ea9f2e76e32167ad0d15b76a320 Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-on: https://git.eclipse.org/r/27071 Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java49
1 files changed, 40 insertions, 9 deletions
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java
index df157ba2f4..a4769b801e 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesEntry.java
@@ -14,6 +14,7 @@
package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
/**
@@ -21,7 +22,7 @@ import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
*
* @author Patrick Tasse
*/
-public class ResourcesEntry extends TimeGraphEntry {
+public class ResourcesEntry extends TimeGraphEntry implements Comparable<ITimeGraphEntry> {
/** Type of resource */
public static enum Type {
@@ -154,21 +155,51 @@ public class ResourcesEntry extends TimeGraphEntry {
* @param entry
* The entry to add
*/
- public void addChild(ResourcesEntry entry) {
+ @Override
+ public void addChild(TimeGraphEntry entry) {
+ // FIXME This check won't be necessary once all ITimeGraphEntry's are
+ // made Comparable.
+ if (!(entry instanceof ResourcesEntry)) {
+ throw new IllegalArgumentException();
+ }
+ ResourcesEntry rEntry = (ResourcesEntry) entry;
+
+ /*
+ * Insert in the array, keeping the elements sorted
+ * (CopyOnWriteArrayList doesn't support Collections#sort,
+ * unfortunately).
+ */
int index;
for (index = 0; index < getChildren().size(); index++) {
ResourcesEntry other = (ResourcesEntry) getChildren().get(index);
- if (entry.getType().compareTo(other.getType()) < 0) {
+ if (rEntry.compareTo(other) < 0) {
break;
- } else if (entry.getType().equals(other.getType())) {
- if (entry.getId() < other.getId()) {
- break;
- }
}
}
- entry.setParent(this);
- getChildren().add(index, entry);
+ rEntry.setParent(this);
+ getChildren().add(index, rEntry);
+ }
+
+ @Override
+ public int compareTo(ITimeGraphEntry other) {
+ if (!(other instanceof ResourcesEntry)) {
+ /* Should not happen, but if it does, put those entries at the end */
+ return -1;
+ }
+ ResourcesEntry o = (ResourcesEntry) other;
+
+ /*
+ * Resources entry names should all be of type "ABC 123"
+ *
+ * We want to filter on the Type first (the "ABC" part), then on the ID
+ * ("123") in numerical order (so we get 1,2,10 and not 1,10,2).
+ */
+ int ret = this.getType().compareTo(o.getType());
+ if (ret != 0) {
+ return ret;
+ }
+ return Integer.compare(this.getId(), o.getId());
}
}

Back to the top