X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Feditor%2FModelUpdateEditor.java;h=18dad814361946b46442952f8172a93e79d88152;hb=e2f57d7e61d6c52b6341f793f6988c123daa1647;hp=dbfb0356251d33dea1c2a03f774ed2f52d81eb49;hpb=ea8430990a15eb2820ed85d637cc7db8dd4fc7d4;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java index dbfb035..18dad81 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java @@ -47,14 +47,12 @@ import org.simantics.db.Statement; 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; @@ -81,6 +79,7 @@ public abstract class ModelUpdateEditor extends Composite{ private GraphChanges changes; private UpdateTree updateTree; + private UpdateList updateList; private Button updateAllButton; private Button updateSelectedButton; @@ -218,12 +217,12 @@ public abstract class ModelUpdateEditor extends Composite{ 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 nr : changes.getModifications()) + if (updateList.getChanges().size() > 0) { + if (selected.contains(updateList.getChanges().iterator().next())) { + for (Pair nr : updateList.getChanges()) selected.remove(nr); } else { - for (Pair nr : changes.getModifications()) + for (Pair nr : updateList.getChanges()) selected.add(nr); } changeViewer.refresh(); @@ -298,6 +297,9 @@ public abstract class ModelUpdateEditor extends Composite{ protected abstract ColumnLabelProvider getLabelProvider(int i); protected abstract Pair 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 filters) { @@ -311,6 +313,10 @@ public abstract class ModelUpdateEditor extends Composite{ return updateTree; } + public UpdateList getUpdateList() { + return updateList; + } + public CheckboxTreeViewer getChangeBrowser() { return changeBrowser; } @@ -405,6 +411,7 @@ public abstract class ModelUpdateEditor extends Composite{ 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()); @@ -412,14 +419,15 @@ public abstract class ModelUpdateEditor extends Composite{ 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); @@ -429,11 +437,11 @@ public abstract class ModelUpdateEditor extends Composite{ public void perform(WriteGraph graph) throws DatabaseException { Layer0Utils.addCommentMetadata(graph, "Apply all model updates"); graph.markUndoPoint(); - for (Pair mod : changes.getModifications()) { + for (Pair mod : updateList.getChanges()) { applyLiteralChange(graph, mod); } selected.clear(); - changes.getModifications().clear(); + updateList.clear(); updateTree.getUpdateOps().applyAll(graph); @@ -460,10 +468,13 @@ public abstract class ModelUpdateEditor extends Composite{ }); } - private void applyLiteralChange(WriteGraph graph, Pair mod) throws DoesNotContainValueException, ServiceException, ManyObjectsForFunctionalRelationException { - + protected void applyLiteralChange(WriteGraph graph, Pair 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); @@ -483,7 +494,7 @@ public abstract class ModelUpdateEditor extends Composite{ Layer0Utils.addCommentMetadata(graph, "Apply selected model updates"); graph.markUndoPoint(); for (Pair mod : selected) { - changes.getModifications().remove(mod); + updateList.removeChange(mod); applyLiteralChange(graph, mod); } selected.clear();