+package org.simantics.interop.update.model;
+
+import org.simantics.db.Resource;
+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.utils.datastructures.Pair;
+
+public class PropertyChange {
+ protected GraphChanges changes;
+ protected Pair<Statement, Statement> pair;
+ protected boolean applied = false;
+ protected boolean selected = false;
+
+
+ public PropertyChange(GraphChanges changes, Statement first, Statement second) {
+ this.pair = new Pair<Statement, Statement>(first, second);
+ this.changes = changes;
+ }
+
+ public PropertyChange(GraphChanges changes, Pair<Statement, Statement> change) {
+ this.pair = change;
+ this.changes = changes;
+ }
+
+ public Statement getFirst() {
+ return pair.first;
+ }
+
+ public Statement getSecond() {
+ return pair.second;
+ }
+
+ public GraphChanges getChanges() {
+ return changes;
+ }
+
+ @Override
+ public int hashCode() {
+ return pair.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+ if (obj.getClass() != this.getClass())
+ return false;
+ PropertyChange c = (PropertyChange)obj;
+ return pair.equals(c.pair);
+ }
+
+ public void apply(WriteGraph graph) throws DatabaseException {
+ if (applied)
+ return;
+ if (pair.second == null) {
+ graph.deny(pair.first);
+ return;
+ }
+ Resource s = changes.getComparable().getLeft(pair.second.getSubject());
+ //Resource s = pair.first.getSubject();
+ Resource pred = pair.second.getPredicate();
+ if (graph.hasValue(pair.second.getObject())) {
+ Object value = graph.getValue(pair.second.getObject());
+ graph.claimLiteral(s, pred, value);
+ } else {
+ graph.deny(s,pred);
+ }
+ applied = true;
+
+ }
+
+ public boolean select(boolean select) {
+ if (applied)
+ return false;
+ this.selected = select;
+ return true;
+ }
+
+
+ public boolean selected() {
+ return selected;
+ }
+
+ public boolean applied() {
+ return applied;
+ }
+
+
+}