1 package org.simantics.interop.update.model;
3 import org.simantics.db.Resource;
4 import org.simantics.db.Statement;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.interop.test.GraphChanges;
8 import org.simantics.utils.datastructures.Pair;
10 public class PropertyChange {
11 protected GraphChanges changes;
12 protected Resource leftSubject;
13 protected Resource rightSubject;
14 protected Pair<Statement, Statement> pair;
15 protected boolean applied = false;
16 protected boolean selected = false;
17 protected boolean visible = true;
20 public PropertyChange(GraphChanges changes, Resource left, Statement first, Resource right, Statement second) {
21 if (first == null && second == null)
22 throw new IllegalArgumentException("At least one of the stamenents must be non null.");
23 if (left == null || right == null)
24 throw new IllegalArgumentException("Subject resources cannot be null.");
25 this.pair = new Pair<Statement, Statement>(first, second);
26 this.changes = changes;
27 this.leftSubject = left;
28 this.rightSubject = right;
31 public PropertyChange(GraphChanges changes, Resource left, Resource right, Pair<Statement, Statement> change) {
32 if (change == null || (change.first == null && change.second == null))
33 throw new IllegalArgumentException("At least one of the stamenents must be non null.");
34 if (left == null || right == null)
35 throw new IllegalArgumentException("Subject resources cannot be null.");
37 this.changes = changes;
38 this.leftSubject = left;
39 this.rightSubject = right;
43 public Resource getFirstSubject() {
47 public Statement getFirst() {
51 public Resource getSecondSubject() {
55 public Statement getSecond() {
59 public Resource getPredicate() {
60 if (pair.first != null)
61 return pair.first.getPredicate();
62 return pair.second.getPredicate();
65 public GraphChanges getChanges() {
70 public int hashCode() {
71 return pair.hashCode();
75 public boolean equals(Object obj) {
78 if (obj.getClass() != this.getClass())
80 PropertyChange c = (PropertyChange)obj;
81 return pair.equals(c.pair);
84 public void apply(WriteGraph graph) throws DatabaseException {
87 if (pair.second == null) {
88 graph.deny(leftSubject, pair.first.getPredicate(),pair.first.getObject());
91 Resource s = leftSubject;
92 //Resource s = changes.getComparable().getLeft(rightSubject);
93 //Resource s = pair.first.getSubject();
94 Resource pred = pair.second.getPredicate();
95 if (graph.hasValue(pair.second.getObject())) {
96 Object value = graph.getValue(pair.second.getObject());
97 graph.claimLiteral(s, pred, value);
105 public boolean select(boolean select) {
108 this.selected = select;
113 public boolean selected() {
117 public boolean applied() {
121 public boolean isVisible() {
125 public void setVisible(boolean visible) {
126 this.visible = visible;
130 public String toString() {
131 String s = "PropertyChange";
132 if (pair.first != null)
133 s += " (" + (leftSubject) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
134 if (pair.second != null)
135 s += " (" + (rightSubject) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")";