import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.DoesNotContainValueException;
-import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
-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.update.Activator;
+import org.simantics.interop.update.model.UpdateList;
import org.simantics.interop.update.model.UpdateNode;
import org.simantics.interop.update.model.UpdateNode.Status;
import org.simantics.interop.update.model.UpdateOp;
private GraphChanges changes;
private UpdateTree updateTree;
+ private UpdateList updateList;
private Button updateAllButton;
private Button updateSelectedButton;
selection.getColumn().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (changes.getModifications().size() > 0) {
- if (selected.contains(changes.getModifications().get(0))) {
- for (Pair<Statement, Statement> nr : changes.getModifications())
+ if (updateList.getChanges().size() > 0) {
+ if (selected.contains(updateList.getChanges().iterator().next())) {
+ for (Pair<Statement, Statement> nr : updateList.getChanges())
selected.remove(nr);
} else {
- for (Pair<Statement, Statement> nr : changes.getModifications())
+ for (Pair<Statement, Statement> nr : updateList.getChanges())
selected.add(nr);
}
changeViewer.refresh();
protected abstract ColumnLabelProvider getLabelProvider(int i);
protected abstract Pair<GraphComparator,Boolean> getChanges(Resource r1, Resource r2) throws DatabaseException;
protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException;
+ protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException {
+ return new UpdateList(changes.getModifications());
+ }
protected void addFilters(List<ChangeFilter> filters) {
return updateTree;
}
+ public UpdateList getUpdateList() {
+ return updateList;
+ }
+
public CheckboxTreeViewer getChangeBrowser() {
return changeBrowser;
}
changes = comparator.getChanges();
changes = getSession().syncRequest(new FilterChangesRead(changes));
updateTree = getUpdateTree(changes);
+ updateList = getUpdateList(changes);
} catch (DatabaseException e) {
Text text = new Text(this, SWT.MULTI);
text.setText(e.getMessage());
return;
}
-
-
- changeViewer.setInput(changes.getModifications());
- changeBrowser.setInput(updateTree);
+ setInputs();
+
refreshChecked();
}
-
+ protected void setInputs() {
+ changeViewer.setInput(updateList.getChanges());
+ changeBrowser.setInput(updateTree);
+ }
private void applyAll() {
updateAllButton.setEnabled(false);
public void perform(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply all model updates");
graph.markUndoPoint();
- for (Pair<Statement, Statement> mod : changes.getModifications()) {
+ for (Pair<Statement, Statement> mod : updateList.getChanges()) {
applyLiteralChange(graph, mod);
}
selected.clear();
- changes.getModifications().clear();
+ updateList.clear();
updateTree.getUpdateOps().applyAll(graph);
});
}
- private void applyLiteralChange(WriteGraph graph, Pair<Statement, Statement> mod) throws DoesNotContainValueException, ServiceException, ManyObjectsForFunctionalRelationException {
-
+ protected void applyLiteralChange(WriteGraph graph, Pair<Statement, Statement> mod) throws DatabaseException {
+ if (mod.second == null) {
+ graph.deny(mod.first);
+ return;
+ }
Resource s = changes.getComparable().getLeft(mod.second.getSubject());
- Resource pred = mod.first.getPredicate();
+ Resource pred = mod.second.getPredicate();
if (graph.hasValue(mod.second.getObject())) {
Object value = graph.getValue(mod.second.getObject());
graph.claimLiteral(s, pred, value);
Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
graph.markUndoPoint();
for (Pair<Statement, Statement> mod : selected) {
- changes.getModifications().remove(mod);
+ updateList.removeChange(mod);
applyLiteralChange(graph, mod);
}
selected.clear();