]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java
Added enabled flag for UpdateOp
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / PropertyChange.java
index 9867a396601c5557f1f1ee9c363bf98f18983eb3..947f516849ea7c6beea0f4ad5b982eb85d15985b 100644 (file)
@@ -9,29 +9,59 @@ import org.simantics.utils.datastructures.Pair;
 
 public class PropertyChange {
        protected GraphChanges changes;
+       protected Resource leftSubject;
+       protected Resource rightSubject;
        protected Pair<Statement, Statement> pair;
        protected boolean applied = false;
        protected boolean selected = false;
+       protected boolean visible = true;
+       protected boolean enabled = true;
        
-       
-       public PropertyChange(GraphChanges changes, Statement first, Statement second) {
+       public PropertyChange(GraphChanges changes, Resource left, Statement first, Resource right, Statement second) {
+               if (first == null && second == null)
+                       throw new IllegalArgumentException("At least one of the stamenents must be non null.");
+               if (left == null || right == null)
+                       throw new IllegalArgumentException("Subject resources cannot be null.");
                this.pair = new Pair<Statement, Statement>(first, second);
                this.changes = changes;
+               this.leftSubject = left;
+               this.rightSubject = right;
        }
        
-       public PropertyChange(GraphChanges changes, Pair<Statement, Statement> change) {
+       public PropertyChange(GraphChanges changes, Resource left, Resource right, Pair<Statement, Statement> change) {
+               if (change == null || (change.first == null && change.second == null))
+                       throw new IllegalArgumentException("At least one of the stamenents must be non null.");
+               if (left == null || right == null)
+                       throw new IllegalArgumentException("Subject resources cannot be null.");
                this.pair = change;
                this.changes = changes;
+               this.leftSubject = left;
+               this.rightSubject = right;
+       }
+       
+       
+       public Resource getFirstSubject() {
+               return leftSubject;
        }
        
        public Statement getFirst() {
                return pair.first;
        }
        
+       public Resource getSecondSubject() {
+               return rightSubject;
+       }
+       
        public Statement getSecond() {
                return pair.second;
        }
        
+       public Resource getPredicate() {
+           if (pair.first != null)
+               return pair.first.getPredicate();
+           return pair.second.getPredicate();
+       }
+       
        public GraphChanges getChanges() {
                return changes;
        }
@@ -55,14 +85,16 @@ public class PropertyChange {
                if (applied)
                        return;
                if (pair.second == null) {
-                       graph.deny(pair.first);
+                       graph.deny(leftSubject, pair.first.getPredicate(),pair.first.getObject());
                        return;
                } 
-               Resource s = changes.getComparable().getLeft(pair.second.getSubject());
+               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());
+                       graph.deny(s, pred);
                        graph.claimLiteral(s, pred, value);
                } else {
                        graph.deny(s,pred);
@@ -71,21 +103,76 @@ public class PropertyChange {
                
        }
        
+       /**
+        * Sets selected state. 
+        * @param select
+        * @return true if selection state was changed
+        */
        public boolean select(boolean select) {
+           if (!enabled)
+               return false;
                if (applied)
                        return false;
                this.selected = select;
                return true;
        }
        
-       
+       /**
+        * Is change selected.
+        * @return
+        */
        public boolean selected() {
                return selected;
        }
        
+       /**
+        * Has change been applied
+        * @return
+        */
        public boolean applied() {
                return applied;
        }
        
+       /**
+        * Is change visible
+        * @return
+        */
+       public boolean isVisible() {
+               return visible;
+       }
+       
+       public void setVisible(boolean visible) {
+               this.visible = visible;
+       }
+       
+       /**
+        * Is change enabled. Disabled changes do not allow changing selected state.
+        * @return
+        */
+       public boolean enabled() {
+        return enabled;
+    }
+       
+       public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+       
+       @Override
+       public String toString() {
+               String s = "PropertyChange";
+               if (pair.first != null)
+                       s += " L(" + (leftSubject) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
+               if (pair.second != null)
+                       s += " R(" + (rightSubject) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")";
+               if (selected)
+                   s += " selected";
+               if (enabled)
+                   s += " enabled";
+               if (visible)
+            s += " visible";
+               if (applied)
+                   s += " applied";
+               return s;
+       }
        
 }