import org.simantics.db.WriteGraph;
import org.simantics.db.exception.DatabaseException;
import org.simantics.interop.test.GraphChanges;
+import org.simantics.layer0.Layer0;
import org.simantics.utils.datastructures.Pair;
public class PropertyChange {
protected boolean selected = false;
protected boolean visible = true;
protected boolean enabled = true;
+ protected Object customValue = null;
+
public PropertyChange(GraphChanges changes, Resource left, Statement first, Resource right, Statement second) {
if (first == null && second == null)
if (obj.getClass() != this.getClass())
return false;
PropertyChange c = (PropertyChange)obj;
- return pair.equals(c.pair);
+ if (!leftSubject.equals(c.leftSubject))
+ return false;
+ if (!rightSubject.equals(c.rightSubject))
+ return false;
+ if (pair.first != null && pair.first.equals(c.pair.first))
+ return true;
+ if (pair.second != null && pair.second.equals(c.pair.second))
+ return true;
+ return false;
}
public void apply(WriteGraph graph) throws DatabaseException {
graph.deny(leftSubject, pair.first.getPredicate(),pair.first.getObject());
return;
}
+ Layer0 L0 = Layer0.getInstance(graph);
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());
+ if (graph.isInstanceOf(pair.second.getObject(), L0.Literal)) {
+ Object value = null;
+ Resource type = null;
+ if (customValue != null)
+ value = customValue;
+ else if (graph.hasValue(pair.second.getObject())) {
+ value = graph.getValue(pair.second.getObject());
+ }
+ type = graph.getPossibleType(pair.second.getObject(), L0.Literal);
+
+ Resource pred = _getPredicate();
+ if (value != null) {
+ graph.deny(s, pred);
+ if (type != null) {
+ graph.claimLiteral(s, pred, type, value);
+ } else {
+ graph.claimLiteral(s, pred, value);
+ }
+ } else {
+ graph.deny(s,pred);
+ }
+ applied = true;
+ } else if (graph.isInstanceOf(pair.second.getObject(), L0.SCLValue)) {
+ Resource pred = _getPredicate();
graph.deny(s, pred);
- graph.claimLiteral(s, pred, value);
+ Resource valueResource = graph.newResource();
+ graph.claim(valueResource, L0.InstanceOf, graph.getSingleObject(pair.second.getObject(), L0.InstanceOf));
+ AddDeleteUpdateOp.copyProperties(graph, pair.second.getObject(), valueResource);
+ graph.claim(s, pred, valueResource);
+ applied = true;
} else {
- graph.deny(s,pred);
+ Resource type = graph.getPossibleType(pair.second.getObject(), L0.Value);
+ if (type != null && graph.hasStatement(type, L0.Enumeration, type)) {
+ Resource pred = _getPredicate();
+ graph.deny(s, pred);
+ graph.claim(s, pred, pair.second.getObject());
+ applied = true;
+ }
+
}
- applied = true;
}
+ private Resource _getPredicate() {
+ Resource pred = pair.second.getPredicate();
+ if (getChanges().getComparable().containsRight(pred))
+ pred = getChanges().getComparable().getLeft(pred);
+ return pred;
+ }
+
/**
* Sets selected state.
* @param select
}
/**
- * IS change enabled. Disabled changes do not allow changing selected state.
+ * Is change enabled. Disabled changes do not allow changing selected state.
* @return
*/
- public boolean isEnabled() {
+ public boolean enabled() {
return enabled;
}
return s;
}
+ public Object getCustomValue() {
+ return customValue;
+ }
+
+ public void setCustomValue(Object customValue) {
+ if (applied) {
+ throw new RuntimeException("Cannot change already applied value");
+ }
+ this.customValue = customValue;
+ }
+
}