From ca99df4266f28ae07fd4c30edb2831da65b79ffd Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 12 Oct 2017 18:02:36 +0300 Subject: [PATCH] SCL bindings for model update --- .../scl/Interop/Update.scl | 154 ++++++++++++++++++ .../update/editor/ModelUpdateEditor.java | 14 +- .../interop/update/model/UpdateNode.java | 13 +- .../interop/update/model/UpdateOp.java | 4 + .../interop/update/model/UpdateStatus.java | 3 + .../interop/update/model/UpdateTree.java | 13 +- org.simantics.interop/META-INF/MANIFEST.MF | 2 +- 7 files changed, 180 insertions(+), 23 deletions(-) create mode 100644 org.simantics.interop.update/scl/Interop/Update.scl create mode 100644 org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateStatus.java diff --git a/org.simantics.interop.update/scl/Interop/Update.scl b/org.simantics.interop.update/scl/Interop/Update.scl new file mode 100644 index 0000000..e04cb34 --- /dev/null +++ b/org.simantics.interop.update/scl/Interop/Update.scl @@ -0,0 +1,154 @@ +import "Simantics/All" +import "JavaBuiltin" + + +importJava "org.simantics.interop.update.model.ModelUpdate" where + data ModelUpdate + + @JavaName getUpdateTree + getUpdateTree :: ModelUpdate -> UpdateTree + + @JavaName getUpdateList + getUpdateList :: ModelUpdate -> UpdateList + + @JavaName getChanges + getGraphChanges :: ModelUpdate -> GraphChanges + + @JavaName applyAll + applyAllUpdates :: ModelUpdate -> () + + @JavaName applySelected + applySelectedUpdates :: ModelUpdate -> () + +importJava "org.simantics.interop.update.model.UpdateTree" where + data UpdateTree + + @JavaName getRootNode + getRootNode :: UpdateTree -> UpdateNode + +importJava "org.simantics.interop.update.model.UpdateList" where + data UpdateList + + @JavaName getChanges + getListChanges :: UpdateList -> [Pair] + + @JavaName getSelected + getListSelected :: UpdateList -> MSet.T Pair + + @JavaName addSelected + addListSelected :: UpdateList -> Pair -> () + + @JavaName removeSelected + removeListSelected :: UpdateList -> Pair -> () + + @JavaName isSelected + isListSelected :: UpdateList -> Pair -> Boolean + +importJava "org.simantics.interop.test.GraphChanges" where + data GraphChanges + + @JavaName getComparable + getComparable :: GraphChanges -> BijectionMap + + @JavaName getAdditions + getAdditions :: GraphChanges -> [Statement] + + @JavaName getDeletions + getDeletions :: GraphChanges -> [Statement] + + @JavaName getModifications + getModifications :: GraphChanges -> [Pair] + +importJava "org.simantics.interop.update.model.UpdateNode" where + data UpdateNode + + @JavaName getResource + getNodeResource :: UpdateNode -> Resource + + @JavaName getStatus + getNodeStatus :: UpdateNode -> UpdateStatus + + @JavaName getLabel + getNodeLabel :: UpdateNode -> String + + @JavaName getOp + getNodeOp :: UpdateNode -> Maybe UpdateOp + + @JavaName getChildren + getNodeChildren :: UpdateNode -> [UpdateNode] + + + +importJava "org.simantics.interop.update.model.UpdateStatus" where + data UpdateStatus + @JavaName EXIST + S_EXIST::UpdateStatus + @JavaName DELETED + S_DELETED::UpdateStatus + @JavaName NEW + S_NEW::UpdateStatus + @JavaName CONTAINS + S_CONTAINS::UpdateStatus + +importJava "org.simantics.interop.update.model.UpdateOp" where + data UpdateOp + + @JavaName applied + opApplied :: UpdateOp -> Boolean + + @JavaName selected + opSelected :: UpdateOp -> Boolean + + @JavaName "select" + opSelect :: UpdateOp -> Boolean -> Boolean + + @JavaName isAdd + opIsAdd :: UpdateOp -> Boolean + + @JavaName isDelete + opIsDelete :: UpdateOp -> Boolean + + @JavaName isChange + opIsChange :: UpdateOp -> Boolean + +importJava "org.simantics.utils.datastructures.Pair" where + data Pair + + @JavaName first + getFirst :: Pair -> Maybe a + + @JavaName second + getSecond :: Pair -> Maybe b + +importJava "org.simantics.utils.datastructures.BijectionMap" where + data BijectionMap + + @JavaName containsLeft + containsLeft :: BijectionMap -> l -> Boolean + + @JavaName containsRight + containsRight :: BijectionMap -> r -> Boolean + + @JavaName contains + contains :: BijectionMap -> l -> r -> Boolean + + @JavaName getLeft + getLeft :: BijectionMap -> r -> Maybe l + + @JavaName getRight + getRight :: BijectionMap -> l -> Maybe r + +importJava "java.lang.Object" where + data Object + + @JavaName getClass + getClass :: Object -> Class + +importJava "java.lang.Class" where + data Class + + @JavaName getName + getClassName :: Class -> String + + @JavaName getSimpleName + getSimpleClassName :: Class -> String \ No newline at end of file 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 4e30b22..5a6646e 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 @@ -51,12 +51,12 @@ import org.simantics.db.request.Read; import org.simantics.interop.test.GraphChanges; import org.simantics.interop.update.Activator; import org.simantics.interop.update.model.ModelUpdate; +import org.simantics.interop.update.model.ModelUpdate.WarningListener; import org.simantics.interop.update.model.UpdateList; import org.simantics.interop.update.model.UpdateNode; -import org.simantics.interop.update.model.UpdateNode.Status; import org.simantics.interop.update.model.UpdateOp; +import org.simantics.interop.update.model.UpdateStatus; import org.simantics.interop.update.model.UpdateTree; -import org.simantics.interop.update.model.ModelUpdate.WarningListener; import org.simantics.interop.utils.TableUtils; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Callback; @@ -340,7 +340,7 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList UpdateNode n = nodeStack.pop(); if (n.getOp() != null) { UpdateOp op = n.getOp(); - if (!op.isAdd() && !op.isDelete()) { + if (!op.isChange()) { changeBrowser.setGrayed(n, true); changeBrowser.setChecked(n, true); } else { @@ -595,12 +595,12 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList @Override public Color getBackground(Object element) { final UpdateNode node = (UpdateNode)element; - Status status = node.getStatus(); - if (status == Status.CONTAINS) + UpdateStatus status = node.getStatus(); + if (status == UpdateStatus.CONTAINS) return containsColor; - if (status == Status.DELETED) + if (status == UpdateStatus.DELETED) return deletedColor; - if (status == Status.NEW) + if (status == UpdateStatus.NEW) return addedColor; return null; } 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 159abd8..cc996a2 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 @@ -12,10 +12,7 @@ import org.simantics.layer0.Layer0; public class UpdateNode { - public enum Status {EXIST,DELETED,NEW,CONTAINS}; - - - private Status status; + private UpdateStatus status; private UpdateOp op; private Resource r; private String label; @@ -28,7 +25,7 @@ public class UpdateNode { * @param status * @param changes */ - public UpdateNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{ + public UpdateNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{ this.status = status; this.op = op; @@ -36,7 +33,7 @@ public class UpdateNode { this.label = getLabel(g, r); } - public UpdateNode(ReadGraph g, Status status, Resource r) throws DatabaseException { + public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException { this.status = status; this.op = null; @@ -53,11 +50,11 @@ public class UpdateNode { return g.getPossibleObject(r, l0.PartOf); } - public void setStatus(Status status) { + public void setStatus(UpdateStatus status) { this.status = status; } - public Status getStatus() { + public UpdateStatus getStatus() { return status; } 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 46bfcd2..72e1785 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,6 +63,10 @@ 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 diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateStatus.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateStatus.java new file mode 100644 index 0000000..77703f7 --- /dev/null +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateStatus.java @@ -0,0 +1,3 @@ +package org.simantics.interop.update.model; + +public enum UpdateStatus {EXIST,DELETED,NEW,CONTAINS} \ No newline at end of file diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java index 7396672..8163306 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java @@ -7,7 +7,6 @@ import org.simantics.db.ReadGraph; 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 { @@ -21,7 +20,7 @@ public class UpdateTree { public UpdateTree(ReadGraph g, GraphChanges changes, UpdateOperations updateOps) throws DatabaseException { this.changes = changes; this.nodes = new HashMap(); - 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; @@ -41,25 +40,25 @@ public class UpdateTree { 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); + node = createNode(g, UpdateStatus.EXIST, r1); 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; diff --git a/org.simantics.interop/META-INF/MANIFEST.MF b/org.simantics.interop/META-INF/MANIFEST.MF index 677e9e4..e61106c 100644 --- a/org.simantics.interop/META-INF/MANIFEST.MF +++ b/org.simantics.interop/META-INF/MANIFEST.MF @@ -24,7 +24,7 @@ Require-Bundle: org.eclipse.ui, org.simantics.structural.ontology;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy -Export-Package: org.simantics.interop.browsing, +Export-Package: org.simantics.interop.stubs, org.simantics.interop.test, org.simantics.interop.utils -- 2.45.2