import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.interop.test.GraphChanges;
-import org.simantics.interop.update.model.UpdateNode.Status;
public class UpdateTree {
public UpdateTree(ReadGraph g, GraphChanges changes, UpdateOperations updateOps) throws DatabaseException {
this.changes = changes;
this.nodes = new HashMap<Resource, UpdateNode>();
- this.rootNode = createNode(g, Status.EXIST, changes.getResource1());
+ this.rootNode = createNode(g, UpdateStatus.EXIST, changes.getResource1());
nodes.put(changes.getResource1(), rootNode);
nodes.put(changes.getResource2(), rootNode);
this.updateOps = updateOps;
return changes;
}
- protected UpdateNode createNode(ReadGraph g, Status status, Resource r) throws DatabaseException {
+ protected UpdateNode createNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException {
return new UpdateNode(g,status, r);
}
- protected UpdateNode createNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{
+ protected UpdateNode createNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{
return new UpdateNode(g,status, op);
}
private UpdateNode createNode(ReadGraph g, Resource r1, Resource r2) throws DatabaseException {
UpdateNode node = null;
if (r1 != null && r2 != null) {
- node = createNode(g, Status.EXIST, r1);
+ UpdateOp op = updateOps.getUpdateOp(r1);
+ if (op == null)
+ op = updateOps.getUpdateOp(r2);
+ if (op == null)
+ node = createNode(g, UpdateStatus.EXIST, r1);
+ else
+ node = createNode(g, UpdateStatus.EXIST, op);
nodes.put(r1, node);
nodes.put(r2, node);
} else if (r1 != null) {
- node = createNode(g,Status.DELETED ,updateOps.getUpdateOp(r1));
+ node = createNode(g,UpdateStatus.DELETED ,updateOps.getUpdateOp(r1));
nodes.put(r1, node);
} else if (r2 != null) {
- node = createNode(g,Status.NEW, updateOps.getUpdateOp(r2));
+ node = createNode(g,UpdateStatus.NEW, updateOps.getUpdateOp(r2));
nodes.put(r2, node);
}
return node;
}
public UpdateNode addNode(ReadGraph g, Resource r1, Resource r2) throws DatabaseException {
- if (r1 != null && r2 != null) {
- return null;
- }
if (nodes.containsKey(r1))
return nodes.get(r1);
if (nodes.containsKey(r2))
return node;
}
- protected UpdateNode getNode(Resource r) {
+ public UpdateNode getNode(Resource r) {
return nodes.get(r);
}
if (!handleCustom(g, op)) {
if (op.isAdd()) {
addNode(g, null,op.getResource());
- } else {
+ } else if (op.isDelete()){
addNode(g, op.getResource(), null);
+ } else if (op.isChange()) {
+ Resource l = getChanges().getComparable().containsLeft(op.getResource()) ? op.getResource() :getChanges().getComparable().getLeft(op.getResource());
+ Resource r = getChanges().getComparable().containsRight(op.getResource()) ? op.getResource() :getChanges().getComparable().getRight(op.getResource());
+ addNode(g, l, r);
}
}
}