]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
UpdateList object for property changes
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 30 Mar 2017 14:12:04 +0000 (17:12 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 30 Mar 2017 14:12:04 +0000 (17:12 +0300)
refs #7045

Change-Id: Ic1f86ee82e8fd214f8fd29ff00fb828bbf956ab1

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java [new file with mode: 0644]
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java

index dbfb0356251d33dea1c2a03f774ed2f52d81eb49..18dad814361946b46442952f8172a93e79d88152 100644 (file)
@@ -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<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();
@@ -298,6 +297,9 @@ public abstract class ModelUpdateEditor extends Composite{
        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) {
                
@@ -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<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);
                                
@@ -460,10 +468,13 @@ public abstract class ModelUpdateEditor extends Composite{
                });
        }
        
-       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);
@@ -483,7 +494,7 @@ public abstract class ModelUpdateEditor extends Composite{
                                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();
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 (file)
index 0000000..255d9ea
--- /dev/null
@@ -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<Pair<Statement, Statement>> changes;
+       
+       public UpdateList() {
+               changes = new HashSet<>();
+       }
+       
+       public UpdateList(Collection<Pair<Statement, Statement>> changes) {
+               this.changes = new HashSet<>(changes);
+       }
+       
+       public Collection<Pair<Statement, Statement>> getChanges() {
+               return changes;
+       }
+       
+       public void addChange(Pair<Statement, Statement> change) {
+               changes.add(change);
+       }
+       
+       public void removeChange(Pair<Statement, Statement> change) {
+               changes.remove(change);
+       }
+       
+       public void clear() {
+               changes.clear();
+       }
+}
index fec8e09d6c1f032a4251a0d97ed3017749bd8cbb..159abd8d9f14a0079255d088996ad826072e4e50 100644 (file)
@@ -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 {