]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java
Prevent changing custom value after the change has been applied
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / PropertyChange.java
index 9a95984ed76986707b4991d18f2301d451c7f647..b9555484e51481a5d733b41b742cee68a541a562 100644 (file)
@@ -81,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 {
@@ -101,6 +109,9 @@ public class PropertyChange {
                                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);
@@ -195,6 +206,9 @@ public class PropertyChange {
        }
        
        public void setCustomValue(Object customValue) {
+               if (applied) {
+                       throw new RuntimeException("Cannot change already applied value");
+               }
                this.customValue = customValue;
        }