X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateOp.java;h=00d113938bb83c7c3d909b91083a18c0d00f86d3;hb=ed79a91bdd86658d28be3d50322a0d4d8cff98dc;hp=907741c23300b71a60b2504f26676363c05b61df;hpb=2665fb66a324e6d08f28215a4734b95b001927f0;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java index 907741c..00d1139 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOp.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import org.simantics.db.Resource; +import org.simantics.db.Statement; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.interop.test.GraphChanges; @@ -21,6 +22,7 @@ public abstract class UpdateOp { private boolean selected = false; private boolean manualSelection = false; protected boolean applied = false; + protected boolean visible = true; private Collection parentOps = new ArrayList(); private Collection subOps = new ArrayList(); @@ -63,9 +65,37 @@ public abstract class UpdateOp { public abstract boolean isAdd(); public abstract boolean isDelete(); + public boolean isChange() { + return isAdd() || isDelete(); + } + + /** + * Is parent operation applied before this. + * @return + */ public abstract boolean requiresParentOps(); + /** + * Is child operation applied before this. + * @return + */ public abstract boolean requiresSubOps(); + /** + * Is parent operation selected when this is selected + * @return + */ + public boolean selectParentOps() { + return requiresParentOps(); + } + + /** + * Is child operation selected when this is selected + * @return + */ + public boolean selectSubOps() { + return requiresSubOps(); + } + public boolean select(boolean select) { boolean b = _select(select); if (b) @@ -76,15 +106,17 @@ public abstract class UpdateOp { private boolean _select(boolean select) { if (select == selected) return true; + if (applied) + return false; if (select) { - if (requiresParentOps()) { + if (selectParentOps()) { for (UpdateOp op : parentOps) op._select(true); } selected = true; manualSelection = false; - if (requiresSubOps()) { + if (selectSubOps()) { for (UpdateOp op : subOps) op._select(true); } @@ -93,13 +125,13 @@ public abstract class UpdateOp { selected = false; manualSelection = false; for (UpdateOp op : subOps) { - if (op.requiresParentOps()) + if (op.selectParentOps()) op._select(false); else if (!op.manualSelection) op._select(false); } for (UpdateOp op : parentOps) - if (op.requiresSubOps()) + if (op.selectSubOps()) op._select(false); return true; } @@ -112,6 +144,12 @@ public abstract class UpdateOp { public boolean applied() { return applied; } + + public boolean isVisible() { + return visible; + } + + public void apply(WriteGraph g) throws DatabaseException { if (applied) return; @@ -120,6 +158,12 @@ public abstract class UpdateOp { } + /** + * Applies the changes into the database. + * + * @param g + * @throws DatabaseException + */ protected abstract void _apply(WriteGraph g) throws DatabaseException; /** @@ -128,6 +172,12 @@ public abstract class UpdateOp { */ public abstract Resource getResource(); + /** + * Returns resource that this operation is changing. + * @return + */ + public abstract Statement getStatement(); + /** * Returns resource that this operation created during apply operation. If operation did not add anything, this returns null. * @return