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=07a3dc38e35cd98334a4238bc095d6e0154ded72;hb=fc102050c58ff3b3705ac0d32ce224d039f5ce59;hp=25d43592f7491662b349674d0bc80d5d61ce69a8;hpb=ed79a91bdd86658d28be3d50322a0d4d8cff98dc;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 25d4359..07a3dc3 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 @@ -9,30 +9,59 @@ import org.simantics.utils.datastructures.Pair; public class PropertyChange { protected GraphChanges changes; + protected Resource leftSubject; + protected Resource rightSubject; protected Pair 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(first, second); this.changes = changes; + this.leftSubject = left; + this.rightSubject = right; } - public PropertyChange(GraphChanges changes, Pair change) { + public PropertyChange(GraphChanges changes, Resource left, Resource right, Pair 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; } @@ -56,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); @@ -72,22 +103,40 @@ 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; } @@ -96,4 +145,34 @@ public class PropertyChange { this.visible = visible; } + /** + * IS change enabled. Disabled changes do not allow changing selected state. + * @return + */ + public boolean isEnabled() { + 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; + } + }