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=f68f887dca33c98e925862c203dab27926ae5480;hb=refs%2Fchanges%2F00%2F4900%2F1;hp=da78b9016638aceb359281f304cdcf2a8844c0ee;hpb=2a37041c6da8864656e7217dbcc3d6dae8cd65be;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 da78b90..f68f887 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,47 +1,52 @@ 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; import org.simantics.db.Resource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.NoSingleResultException; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; import org.simantics.layer0.Layer0; public class UpdateNode { - public enum Status {EXIST,DELETED,NEW,CONTAINS}; - - - private Status status; + private UpdateNode parent; + private UpdateStatus status; private UpdateOp op; private Resource r; + private String label; + private boolean visible = true; - private Collection children = new ArrayList(); + private List children; /** * * @param resource old Resource if status is DELETED or EXISTS. * @param status * @param changes */ - public UpdateNode(Status status, UpdateOp op) { + public UpdateNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{ this.status = status; this.op = op; this.r = op.getResource(); + init(g); } - public UpdateNode(Status status, Resource r) { + public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException { this.status = status; this.op = null; this.r = r; + init(g); + } + + protected void init(ReadGraph g) throws DatabaseException { + this.label = getLabel(g, r); } public Resource getResource() { @@ -49,35 +54,68 @@ 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); } - public void setStatus(Status status) { + public void setStatus(UpdateStatus status) { this.status = status; } - public Status getStatus() { + public UpdateStatus getStatus() { 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) { + if (!op.getSubOps().contains(node.op)) { + op.addSubOp(node.op); + node.op.addParentOp(op); + } + } + } + + public void sort() { + if (children == null) + return; + Collections.sort(this.children, new Comparator() { + @Override + public int compare(UpdateNode o1, UpdateNode o2) { + return o1.getLabel().compareTo(o2.getLabel()); + } + }); } public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException { return null; } - public String getLabel(ReadGraph graph) throws DatabaseException { - return getLabel(graph,r); + public String getLabel() { + return label; + } + + @Override + public String toString() { + return label; } - protected String getLabel(ReadGraph graph, Resource r) throws ValidationException, ServiceException, NoSingleResultException { + protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException { String label = NameUtils.getSafeLabel(graph, r); if (label.length() == 0) label = NameUtils.getSafeName(graph, r); @@ -89,5 +127,32 @@ public class UpdateNode { public UpdateOp getOp() { return op; } + + public boolean isVisible() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible = visible; + if (op != null) + op.visible = visible; + if (visible) { + if (parent != null && !parent.visible) + parent.setVisible(true); + } else { + if (children != null) + for (UpdateNode n : children) + n.setVisible(false); + } + } + + public void setAllVisible(boolean visible) { + this.visible = visible; + if (op != null) + op.visible = visible; + if (children != null) + for (UpdateNode n : children) + n.setAllVisible(visible); + } }