]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java
Added support for filtering changes
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / PropertyChange.java
1 package org.simantics.interop.update.model;
2
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;
9
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;
16         
17         
18         public PropertyChange(GraphChanges changes, Statement first, Statement second) {
19                 this.pair = new Pair<Statement, Statement>(first, second);
20                 this.changes = changes;
21         }
22         
23         public PropertyChange(GraphChanges changes, Pair<Statement, Statement> change) {
24                 this.pair = change;
25                 this.changes = changes;
26         }
27         
28         public Statement getFirst() {
29                 return pair.first;
30         }
31         
32         public Statement getSecond() {
33                 return pair.second;
34         }
35         
36         public GraphChanges getChanges() {
37                 return changes;
38         }
39         
40         @Override
41         public int hashCode() {
42                 return pair.hashCode();
43         }
44         
45         @Override
46         public boolean equals(Object obj) {
47                 if (obj == null)
48                         return false;
49                 if (obj.getClass() != this.getClass())
50                         return false;
51                 PropertyChange c = (PropertyChange)obj;
52                 return pair.equals(c.pair);
53         }
54         
55         public void apply(WriteGraph graph) throws DatabaseException {
56                 if (applied)
57                         return;
58                 if (pair.second == null) {
59                         graph.deny(pair.first);
60                         return;
61                 } 
62                 Resource s = changes.getComparable().getLeft(pair.second.getSubject());
63                 //Resource s = pair.first.getSubject();
64                 Resource pred = pair.second.getPredicate();
65                 if (graph.hasValue(pair.second.getObject())) {
66                         Object value = graph.getValue(pair.second.getObject());
67                         graph.claimLiteral(s, pred, value);
68                 } else {
69                         graph.deny(s,pred);
70                 }
71                 applied = true;
72                 
73         }
74         
75         public boolean select(boolean select) {
76                 if (applied)
77                         return false;
78                 this.selected = select;
79                 return true;
80         }
81         
82         
83         public boolean selected() {
84                 return selected;
85         }
86         
87         public boolean applied() {
88                 return applied;
89         }
90         
91         public boolean isVisible() {
92                 return visible;
93         }
94         
95         public void setVisible(boolean visible) {
96                 this.visible = visible;
97         }
98         
99 }