import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.DoesNotContainValueException;
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
-import org.simantics.db.exception.NoSingleResultException;
import org.simantics.db.exception.ServiceException;
+import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.db.request.Read;
import org.simantics.interop.test.GraphChanges;
import org.simantics.interop.test.GraphComparator;
-import org.simantics.interop.test.NameComparator;
import org.simantics.interop.update.Activator;
import org.simantics.interop.update.model.UpdateNode;
import org.simantics.interop.update.model.UpdateNode.Status;
import org.simantics.interop.update.model.UpdateTree;
import org.simantics.interop.utils.TableUtils;
-import org.simantics.layer0.Layer0;
import org.simantics.ui.workbench.ResourceEditorPart2;
-import org.simantics.utils.datastructures.BijectionMap;
import org.simantics.utils.datastructures.Callback;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.ui.ExceptionUtils;
getSession().asyncRequest(new WriteRequest(){
@Override
public void perform(WriteGraph graph) throws DatabaseException {
+ Layer0Utils.addCommentMetadata(graph, "Apply all model updates");
+ graph.markUndoPoint();
for (Pair<Statement, Statement> mod : changes.getModifications()) {
applyLiteralChange(graph, mod);
}
getSession().asyncRequest(new WriteRequest(){
@Override
public void perform(WriteGraph graph) throws DatabaseException {
+ Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
+ graph.markUndoPoint();
for (Pair<Statement, Statement> mod : selected) {
changes.getModifications().remove(mod);
applyLiteralChange(graph, mod);
public abstract boolean isAdd();
public abstract boolean isDelete();
+ /**
+ * Is parent operation applied before this.
+ * @return
+ */
public abstract boolean requiresParentOps();
+ /**
+ * Is child operation applied before this.
+ * @return
+ */
public abstract boolean requiresSubOps();
+ /**
+ * Is parent operation selected when this is selected
+ * @return
+ */
+ public boolean selectParentOps() {
+ return requiresParentOps();
+ }
+
+ /**
+ * Is child operation selected when this is selected
+ * @return
+ */
+ public boolean selectSubOps() {
+ return requiresSubOps();
+ }
+
public boolean select(boolean select) {
boolean b = _select(select);
if (b)
if (select == selected)
return true;
if (select) {
- if (requiresParentOps()) {
+ if (selectParentOps()) {
for (UpdateOp op : parentOps)
op._select(true);
}
selected = true;
manualSelection = false;
- if (requiresSubOps()) {
+ if (selectSubOps()) {
for (UpdateOp op : subOps)
op._select(true);
}
selected = false;
manualSelection = false;
for (UpdateOp op : subOps) {
- if (op.requiresParentOps())
+ if (op.selectParentOps())
op._select(false);
else if (!op.manualSelection)
op._select(false);
}
for (UpdateOp op : parentOps)
- if (op.requiresSubOps())
+ if (op.selectSubOps())
op._select(false);
return true;
}
}
+ /**
+ * Applies the changes into the database.
+ *
+ * @param g
+ * @throws DatabaseException
+ */
protected abstract void _apply(WriteGraph g) throws DatabaseException;
/**
public abstract class UpdateOperations {
private List<UpdateOp> operations = new ArrayList<UpdateOp>();
- private Map<Resource, UpdateOp> opMap = new HashMap<Resource, UpdateOp>();
+ private Map<Resource, UpdateOp> resourceMap = new HashMap<Resource, UpdateOp>();
+ private Map<Statement, UpdateOp> statementMap = new HashMap<Statement, UpdateOp>();
private GraphChanges changes;
public UpdateOperations(GraphChanges changes) {
}
public UpdateOp getUpdateOp(Resource r) {
- return opMap.get(r);
+ return resourceMap.get(r);
+ }
+
+ public UpdateOp getUpdateOp(Statement s) {
+ return statementMap.get(s);
}
public void applyAll(WriteGraph g) throws DatabaseException {
private void _apply(WriteGraph g, Stack<UpdateOp> stack, UpdateOp op) throws DatabaseException {
if (op.applied())
return;
- if (stack.contains(op))
+ if (stack.contains(op)) {
+ op.apply(g);
return;
+ }
stack.push(op);
if (op.requiresParentOps()) {
for (UpdateOp pop : op.getParentOps())
}
protected void addOp(Resource r, UpdateOp op) {
- opMap.put(r, op);
+ resourceMap.put(r, op);
+ operations.add(op);
+ }
+
+ protected void addOp(Statement s, UpdateOp op) {
+ statementMap.put(s, op);
operations.add(op);
}
protected void replaceOp(Resource r, UpdateOp op) {
- UpdateOp oldOp = opMap.remove(r);
+ UpdateOp oldOp = resourceMap.remove(r);
if (oldOp != null) {
operations.remove(oldOp);
}
- opMap.put(r, op);
+ resourceMap.put(r, op);
operations.add(op);
}
protected UpdateOp getOP(Resource r) {
- return opMap.get(r);
+ return resourceMap.get(r);
+ }
+
+ protected UpdateOp getOP(Statement r) {
+ return statementMap.get(r);
}
public abstract void populate(ReadGraph g) throws DatabaseException;