From 961c51d828eace5c9ab9db9499f0af9a78f16192 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 13 Jan 2020 11:20:24 +0200 Subject: [PATCH] Allow UpdateOps to describe parent resource gitlab #21 Change-Id: Idef9b151b3719268e97c63a6376f0945a0a9a8d1 --- .../simantics/interop/update/model/UpdateNode.java | 5 +++++ .../org/simantics/interop/update/model/UpdateOp.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java index b786586..54d6b2c 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java @@ -52,6 +52,11 @@ public class UpdateNode { } public Resource getParentResource(ReadGraph g) throws DatabaseException { + if (op != null) { + Resource parent = op.getParentResource(g); + if (parent != null) + return parent; + } Layer0 l0 = Layer0.getInstance(g); return g.getPossibleObject(r, l0.PartOf); } 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 3b633c2..2bd3718 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,11 +4,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.simantics.db.ReadGraph; 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; +import org.simantics.layer0.Layer0; /** * Base class for update operations (adding and deleting objects) @@ -60,11 +62,15 @@ public abstract class UpdateOp { public void addParentOp(UpdateOp op) { assert (!op.equals(this)); + if (parentOps.contains(op)) + return; parentOps.add(op); } public void addSubOp(UpdateOp op) { assert (!op.equals(this)); + if (subOps.contains(op)) + return; subOps.add(op); } @@ -212,6 +218,12 @@ public abstract class UpdateOp { */ public abstract Resource getCreatedResource(); + public Resource getParentResource(ReadGraph g) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + return g.getPossibleObject(getResource(), l0.PartOf); + } + + @Override public String toString() { String s = this.getClass().getSimpleName(); -- 2.47.1