X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateNode.java;h=5bf0cd4ec8e298d963a0267bd434888032da78e0;hb=7010cce1f5f206a9dc74bdffa0ec6267d1be1d04;hp=b786586c9a3daef1c2b562707e1b07779d107a54;hpb=c276677539e2b4111a072a2e6f6c4e8aa3e65b30;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java index b786586..5bf0cd4 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java @@ -1,7 +1,9 @@ package org.simantics.interop.update.model; import java.util.ArrayList; -import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import org.eclipse.jface.resource.ImageDescriptor; import org.simantics.db.ReadGraph; @@ -20,7 +22,7 @@ public class UpdateNode { private boolean visible = true; - private Collection children = new ArrayList(); + private List children; /** * * @param resource old Resource if status is DELETED or EXISTS. @@ -52,6 +54,11 @@ public class UpdateNode { } public Resource getParentResource(ReadGraph g) throws DatabaseException { + if (op != null) { + Resource parent = op.getParentResource(g); + if (parent != null) + return parent; + } Layer0 l0 = Layer0.getInstance(g); return g.getPossibleObject(r, l0.PartOf); } @@ -64,11 +71,16 @@ public class UpdateNode { return status; } - public Collection getChildren() { + @SuppressWarnings("unchecked") + public List getChildren() { + if (children == null) + return Collections.EMPTY_LIST; return children; } public void addChild(UpdateNode node) { + if (children == null) + children = new ArrayList(2); children.add(node); node.parent = this; if (op != null && node.op != null) { @@ -78,6 +90,30 @@ public class UpdateNode { } } } + + public void sort() { + if (children == null) + return; + Comparator comparator = new Comparator() { + @Override + public int compare(UpdateNode o1, UpdateNode o2) { + return o1.getLabel().compareTo(o2.getLabel()); + } + }; + Collections.sort(this.children, comparator ); + for (UpdateNode n : this.children) { + n.sort(comparator); + } + } + + public void sort(Comparator comparator ) { + if (children == null) + return; + Collections.sort(this.children, comparator ); + for (UpdateNode n : this.children) { + n.sort(comparator); + } + } public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException { return null; @@ -117,17 +153,19 @@ public class UpdateNode { if (parent != null && !parent.visible) parent.setVisible(true); } else { - for (UpdateNode n : children) - n.setVisible(false); + if (children != null) + for (UpdateNode n : children) + n.setVisible(false); } } public void setAllVisible(boolean visible) { - this.visible = visible; - if (op != null) - op.visible = visible; - for (UpdateNode n : children) - n.setAllVisible(visible); - } + this.visible = visible; + if (op != null) + op.visible = visible; + if (children != null) + for (UpdateNode n : children) + n.setAllVisible(visible); + } }