]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java
Simple update operation
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / PropertyChange.java
index 491bf5753c8932f8e031fcbe30a523ac70a33fa5..54d2f76f55fe083f1af1f54a904cf0cc79709dd6 100644 (file)
@@ -15,6 +15,8 @@ public class PropertyChange {
        protected boolean applied = false;
        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) {
@@ -89,35 +91,56 @@ public class PropertyChange {
                        return;
                } 
                Resource s = leftSubject;
-               //Resource s = changes.getComparable().getLeft(rightSubject);
-               //Resource s = pair.first.getSubject();
+               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 (graph.hasValue(pair.second.getObject())) {
-                       Object value = graph.getValue(pair.second.getObject());
+               if (value != null) {
+                       graph.deny(s, pred);
                        graph.claimLiteral(s, pred, value);
                } else {
                        graph.deny(s,pred);
                }
                applied = true;
-               
        }
        
+       /**
+        * 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;
        }
@@ -126,14 +149,42 @@ public class PropertyChange {
                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 += " (" + (leftSubject) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
+                       s += " L(" + (leftSubject) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
                if (pair.second != null)
-                       s += " (" + (rightSubject) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")";
+                       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;
        }
        
+       public Object getCustomValue() {
+               return customValue;
+       }
+       
+       public void setCustomValue(Object customValue) {
+               this.customValue = customValue;
+       }
+       
 }