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 Pair<Statement, Statement> pair;
13 protected boolean applied = false;
14 protected boolean selected = false;
15 protected boolean visible = true;
18 public PropertyChange(GraphChanges changes, Statement first, Statement second) {
19 if (first == null && second == null)
20 throw new IllegalArgumentException("At least one of the stamenents must be non null.");
21 this.pair = new Pair<Statement, Statement>(first, second);
22 this.changes = changes;
25 public PropertyChange(GraphChanges changes, Pair<Statement, Statement> change) {
26 if (change == null || (change.first == null && change.second == null))
27 throw new IllegalArgumentException("At least one of the stamenents must be non null.");
29 this.changes = changes;
32 public Statement getFirst() {
36 public Statement getSecond() {
40 public GraphChanges getChanges() {
45 public int hashCode() {
46 return pair.hashCode();
50 public boolean equals(Object obj) {
53 if (obj.getClass() != this.getClass())
55 PropertyChange c = (PropertyChange)obj;
56 return pair.equals(c.pair);
59 public void apply(WriteGraph graph) throws DatabaseException {
62 if (pair.second == null) {
63 graph.deny(pair.first);
66 Resource s = changes.getComparable().getLeft(pair.second.getSubject());
67 //Resource s = pair.first.getSubject();
68 Resource pred = pair.second.getPredicate();
69 if (graph.hasValue(pair.second.getObject())) {
70 Object value = graph.getValue(pair.second.getObject());
71 graph.claimLiteral(s, pred, value);
79 public boolean select(boolean select) {
82 this.selected = select;
87 public boolean selected() {
91 public boolean applied() {
95 public boolean isVisible() {
99 public void setVisible(boolean visible) {
100 this.visible = visible;
104 public String toString() {
105 String s = "PropertyChange";
106 if (pair.first != null)
107 s += " (" + (pair.first.getSubject()) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
108 if (pair.second != null)
109 s += " (" + (pair.second.getSubject()) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")";