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=50954ec1ffca968cc3e06a6dfbd1b09a59e4765e;hb=refs%2Fchanges%2F61%2F3761%2F1;hp=00d113938bb83c7c3d909b91083a18c0d00f86d3;hpb=2e5e6f18c3d1182386e69f86b78e5a4179dde18a;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 00d1139..50954ec 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 @@ -23,6 +23,7 @@ public abstract class UpdateOp { private boolean manualSelection = false; protected boolean applied = false; protected boolean visible = true; + protected boolean enabled = true; private Collection parentOps = new ArrayList(); private Collection subOps = new ArrayList(); @@ -68,76 +69,74 @@ public abstract class UpdateOp { 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 + * Should given operation to be applied before this operation. + * @param op * @return */ - public boolean selectParentOps() { - return requiresParentOps(); + public boolean requiresOp(UpdateOp op) { + return false; } /** - * Is child operation selected when this is selected + * Should selection state to be propagated to given op. + * @param op parent or sub op of this. + * @param select selection flag. * @return */ - public boolean selectSubOps() { - return requiresSubOps(); - } + public boolean selectOp(UpdateOp op, boolean select) { + return requiresOp(op); + } public boolean select(boolean select) { + if (!enabled) + return false; + if (!isChange()) + return false; boolean b = _select(select); if (b) manualSelection = true; return b; } - + private boolean _select(boolean select) { if (select == selected) return true; if (applied) return false; if (select) { - if (selectParentOps()) { - for (UpdateOp op : parentOps) - op._select(true); - } - - selected = true; - manualSelection = false; - if (selectSubOps()) { - for (UpdateOp op : subOps) - op._select(true); - } - + selected = true; + manualSelection = false; + for (UpdateOp op : parentOps) { + if (selectOp(op,true)) + op._select(true); + } + for (UpdateOp op : subOps) { + if (selectOp(op,true)) + op._select(true); + } + return true; } else { selected = false; manualSelection = false; for (UpdateOp op : subOps) { - if (op.selectParentOps()) - op._select(false); - else if (!op.manualSelection) - op._select(false); - } + if (selectOp(op, false)) + op._select(false); + else if (!op.manualSelection) + op._select(false); + } for (UpdateOp op : parentOps) - if (op.selectSubOps()) - op._select(false); + if (selectOp(op, false)) + op._select(false); return true; } - return false; } + public boolean selected() { + if (!isChange()) + // Non change operations are not really selected, but the selected flag may be used for selection propagation + return false; return selected; } @@ -149,6 +148,18 @@ public abstract class UpdateOp { return visible; } + /** + * Is change enabled. Disabled changes do not allow changing selected state. + * @return + */ + public boolean enabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + public void apply(WriteGraph g) throws DatabaseException { if (applied) @@ -183,5 +194,19 @@ public abstract class UpdateOp { * @return */ public abstract Resource getCreatedResource(); + + @Override + public String toString() { + String s = this.getClass().getSimpleName(); + if (selected) + s += " selected"; + if (enabled) + s += " enabled"; + if (visible) + s += " visible"; + if (applied) + s += " applied"; + return s; + } }