From e2f57d7e61d6c52b6341f793f6988c123daa1647 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 30 Mar 2017 17:12:04 +0300 Subject: [PATCH] UpdateList object for property changes refs #7045 Change-Id: Ic1f86ee82e8fd214f8fd29ff00fb828bbf956ab1 --- .../update/editor/ModelUpdateEditor.java | 47 ++++++++++++------- .../interop/update/model/UpdateList.java | 35 ++++++++++++++ .../interop/update/model/UpdateNode.java | 3 -- 3 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java 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(); diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java new file mode 100644 index 0000000..255d9ea --- /dev/null +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java @@ -0,0 +1,35 @@ +package org.simantics.interop.update.model; + +import java.util.Collection; +import java.util.HashSet; + +import org.simantics.db.Statement; +import org.simantics.utils.datastructures.Pair; + +public class UpdateList { + private HashSet> changes; + + public UpdateList() { + changes = new HashSet<>(); + } + + public UpdateList(Collection> changes) { + this.changes = new HashSet<>(changes); + } + + public Collection> getChanges() { + return changes; + } + + public void addChange(Pair change) { + changes.add(change); + } + + public void removeChange(Pair change) { + changes.remove(change); + } + + public void clear() { + changes.clear(); + } +} diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java index fec8e09..159abd8 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java @@ -8,9 +8,6 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.NoSingleResultException; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; import org.simantics.layer0.Layer0; public class UpdateNode { -- 2.47.1