From 69036b628df63d369733ab8bee9f402835ea1a13 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Fri, 3 Mar 2017 13:17:31 +0200 Subject: [PATCH] Allow binding statement changes to update operations refs #7045 Change-Id: I36cff7c0451cc19934f176ab6db4d30b41636cd4 --- .../update/editor/ModelUpdateEditor.java | 9 +++-- .../interop/update/model/UpdateOp.java | 38 +++++++++++++++++-- .../update/model/UpdateOperations.java | 30 +++++++++++---- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java index a3b6033..8ecaaa7 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java @@ -49,20 +49,17 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.DoesNotContainValueException; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; -import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.exception.ServiceException; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.request.Read; import org.simantics.interop.test.GraphChanges; import org.simantics.interop.test.GraphComparator; -import org.simantics.interop.test.NameComparator; import org.simantics.interop.update.Activator; import org.simantics.interop.update.model.UpdateNode; import org.simantics.interop.update.model.UpdateNode.Status; import org.simantics.interop.update.model.UpdateTree; import org.simantics.interop.utils.TableUtils; -import org.simantics.layer0.Layer0; import org.simantics.ui.workbench.ResourceEditorPart2; -import org.simantics.utils.datastructures.BijectionMap; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.ui.ExceptionUtils; @@ -401,6 +398,8 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { getSession().asyncRequest(new WriteRequest(){ @Override public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, "Apply all model updates"); + graph.markUndoPoint(); for (Pair mod : changes.getModifications()) { applyLiteralChange(graph, mod); } @@ -452,6 +451,8 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { getSession().asyncRequest(new WriteRequest(){ @Override public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, "Apply selected model updates"); + graph.markUndoPoint(); for (Pair mod : selected) { changes.getModifications().remove(mod); applyLiteralChange(graph, mod); 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..46bfcd2 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 @@ -63,9 +63,33 @@ public abstract class UpdateOp { public abstract boolean isAdd(); public abstract boolean 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) @@ -77,14 +101,14 @@ public abstract class UpdateOp { if (select == selected) return true; 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 +117,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; } @@ -120,6 +144,12 @@ public abstract class UpdateOp { } + /** + * Applies the changes into the database. + * + * @param g + * @throws DatabaseException + */ protected abstract void _apply(WriteGraph g) throws DatabaseException; /** diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java index 9c929c5..e24e0cb 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java @@ -21,7 +21,8 @@ import org.simantics.interop.test.GraphChanges; public abstract class UpdateOperations { private List operations = new ArrayList(); - private Map opMap = new HashMap(); + private Map resourceMap = new HashMap(); + private Map statementMap = new HashMap(); private GraphChanges changes; public UpdateOperations(GraphChanges changes) { @@ -29,7 +30,11 @@ public abstract class UpdateOperations { } public UpdateOp getUpdateOp(Resource r) { - return opMap.get(r); + return resourceMap.get(r); + } + + public UpdateOp getUpdateOp(Statement s) { + return statementMap.get(s); } public void applyAll(WriteGraph g) throws DatabaseException { @@ -61,8 +66,10 @@ public abstract class UpdateOperations { private void _apply(WriteGraph g, Stack stack, UpdateOp op) throws DatabaseException { if (op.applied()) return; - if (stack.contains(op)) + if (stack.contains(op)) { + op.apply(g); return; + } stack.push(op); if (op.requiresParentOps()) { for (UpdateOp pop : op.getParentOps()) @@ -85,21 +92,30 @@ public abstract class UpdateOperations { } protected void addOp(Resource r, UpdateOp op) { - opMap.put(r, op); + resourceMap.put(r, op); + operations.add(op); + } + + protected void addOp(Statement s, UpdateOp op) { + statementMap.put(s, op); operations.add(op); } protected void replaceOp(Resource r, UpdateOp op) { - UpdateOp oldOp = opMap.remove(r); + UpdateOp oldOp = resourceMap.remove(r); if (oldOp != null) { operations.remove(oldOp); } - opMap.put(r, op); + resourceMap.put(r, op); operations.add(op); } protected UpdateOp getOP(Resource r) { - return opMap.get(r); + return resourceMap.get(r); + } + + protected UpdateOp getOP(Statement r) { + return statementMap.get(r); } public abstract void populate(ReadGraph g) throws DatabaseException; -- 2.43.2