X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FPropertyChange.java;h=be6e5e0bbda38498fd22388d6dc6e2ed31dd4b45;hb=37acf1273cdf0be148b22625db2baa15a4077d0b;hp=07a3dc38e35cd98334a4238bc095d6e0154ded72;hpb=7f27fe15240dbb56d9525671c44468cdbc934199;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java index 07a3dc3..be6e5e0 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java @@ -5,6 +5,7 @@ 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; import org.simantics.utils.datastructures.Pair; public class PropertyChange { @@ -16,6 +17,8 @@ public class PropertyChange { protected boolean selected = false; protected boolean visible = true; protected boolean enabled = true; + protected Object customValue = null; + public PropertyChange(GraphChanges changes, Resource left, Statement first, Resource right, Statement second) { if (first == null && second == null) @@ -78,7 +81,15 @@ public class PropertyChange { if (obj.getClass() != this.getClass()) return false; PropertyChange c = (PropertyChange)obj; - return pair.equals(c.pair); + if (!leftSubject.equals(c.leftSubject)) + return false; + if (!rightSubject.equals(c.rightSubject)) + return false; + if (pair.first != null && pair.first.equals(c.pair.first)) + return true; + if (pair.second != null && pair.second.equals(c.pair.second)) + return true; + return false; } public void apply(WriteGraph graph) throws DatabaseException { @@ -88,18 +99,44 @@ public class PropertyChange { graph.deny(leftSubject, pair.first.getPredicate(),pair.first.getObject()); return; } + Layer0 L0 = Layer0.getInstance(graph); Resource s = leftSubject; - //Resource s = changes.getComparable().getLeft(rightSubject); - //Resource s = pair.first.getSubject(); - Resource pred = pair.second.getPredicate(); - if (graph.hasValue(pair.second.getObject())) { - Object value = graph.getValue(pair.second.getObject()); + if (graph.isInstanceOf(pair.second.getObject(), L0.Literal)) { + Object value = null; + if (customValue != null) + value = customValue; + else if (graph.hasValue(pair.second.getObject())) { + value = graph.getValue(pair.second.getObject()); + } + Resource pred = pair.second.getPredicate(); + if (getChanges().getComparable().containsRight(pred)) + pred = getChanges().getComparable().getLeft(pred); + + if (value != null) { + graph.deny(s, pred); + graph.claimLiteral(s, pred, value); + } else { + graph.deny(s,pred); + } + applied = true; + } else if (graph.isInstanceOf(pair.second.getObject(), L0.SCLValue)) { + Resource pred = pair.second.getPredicate(); graph.deny(s, pred); - graph.claimLiteral(s, pred, value); + Resource valueResource = graph.newResource(); + graph.claim(valueResource, L0.InstanceOf, graph.getSingleObject(pair.second.getObject(), L0.InstanceOf)); + AddDeleteUpdateOp.copyProperties(graph, pair.second.getObject(), valueResource); + graph.claim(s, pred, valueResource); + applied = true; } else { - graph.deny(s,pred); + Resource type = graph.getPossibleType(pair.second.getObject(), L0.Value); + if (type != null && graph.hasStatement(type, L0.Enumeration, type)) { + Resource pred = pair.second.getPredicate(); + graph.deny(s, pred); + graph.claim(s, pred, pair.second.getObject()); + applied = true; + } + } - applied = true; } @@ -146,10 +183,10 @@ public class PropertyChange { } /** - * IS change enabled. Disabled changes do not allow changing selected state. + * Is change enabled. Disabled changes do not allow changing selected state. * @return */ - public boolean isEnabled() { + public boolean enabled() { return enabled; } @@ -175,4 +212,15 @@ public class PropertyChange { return s; } + public Object getCustomValue() { + return customValue; + } + + public void setCustomValue(Object customValue) { + if (applied) { + throw new RuntimeException("Cannot change already applied value"); + } + this.customValue = customValue; + } + }