import org.simantics.interop.update.model.UpdateNode.Status;
-public abstract class UpdateTree {
+public class UpdateTree {
private UpdateNode rootNode;
private Map<Resource,UpdateNode> nodes;
return rootNode;
}
- protected abstract UpdateNode createNode(Status status, Resource r);
- protected abstract UpdateNode createNode(Status status, UpdateOp op);
+ protected UpdateNode createNode(Status status, Resource r) {
+ return new UpdateNode(status, r);
+ }
+
+ protected UpdateNode createNode(Status status, UpdateOp op) {
+ return new UpdateNode(status, op);
+ }
private UpdateNode createNode(Resource r1, Resource r2) {
UpdateNode node = null;
return node;
}
- private boolean connectParent(ReadGraph g, UpdateNode node) throws DatabaseException {
+ protected UpdateNode getNode(Resource r) {
+ return nodes.get(r);
+ }
+
+ protected boolean connectParent(ReadGraph g, UpdateNode node) throws DatabaseException {
UpdateNode parent = null;
while (true) {
Resource parentResource = node.getParentResource(g);
parent = nodes.get(parentResource);
if (parent == null) {
- if (changes.getComparable().containsLeft(parentResource)) {
- parent = createNode(parentResource, changes.getComparable().getRight(parentResource));
- } else if (changes.getComparable().containsRight(parentResource)) {
- parent = createNode(changes.getComparable().getLeft(parentResource) ,parentResource);
- } else {
+ parent = getOrCreate(g, parentResource);
+ if (parent == null)
return false;
- }
//parent.setStatus(Status.CONTAINS);
parent.addChild(node);
node = parent;
}
}
- protected abstract boolean handleCustom(ReadGraph g, UpdateOp op) throws DatabaseException;
+ protected UpdateNode getOrCreate(ReadGraph g, Resource parentResource) throws DatabaseException {
+ UpdateNode parent = nodes.get(parentResource);
+ if (parent == null) {
+ if (changes.getComparable().containsLeft(parentResource)) {
+ parent = createNode(parentResource, changes.getComparable().getRight(parentResource));
+ } else if (changes.getComparable().containsRight(parentResource)) {
+ parent = createNode(changes.getComparable().getLeft(parentResource) ,parentResource);
+ } else {
+ return null;
+ }
+ //parent.setStatus(Status.CONTAINS
+ }
+ return parent;
+ }
+
+
+
+ protected boolean handleCustom(ReadGraph g, UpdateOp op) throws DatabaseException {
+ return false;
+ }
private void populate(ReadGraph g) throws DatabaseException{