]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java
Handle asserted property statements
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / ModelUpdate.java
index 2149fc5dd5710ce207efab5378683e9f6583de15..5f400df4c653285946551ea0f2addf8c4c81f497 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.interop.update.model;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Deque;
 import java.util.List;
 import java.util.Map.Entry;
@@ -17,6 +18,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.request.Read;
 import org.simantics.interop.test.GraphChanges;
+import org.simantics.interop.test.GraphChanges.Modification;
 import org.simantics.interop.test.GraphComparator;
 import org.simantics.utils.datastructures.BijectionMap;
 import org.simantics.utils.datastructures.Pair;
@@ -70,7 +72,7 @@ public abstract class ModelUpdate {
                                showWarning(result2.second);
                        comparator2.test(getSession());
                        changes2 = comparator2.getChanges();
-                       changes2 = getSession().syncRequest(new FilterChangesRead(changes2, filters));
+                       changes2 = getSession().syncRequest(createFilterRead(changes2, filters));
                        updateTree2 = getUpdateTree(changes2);
                        updateList2 = getUpdateList(changes2);
                        
@@ -81,7 +83,7 @@ public abstract class ModelUpdate {
                                showWarning(result3.second);
                        comparator3.test(getSession());
                        changes3 = comparator3.getChanges();
-                       changes3 = getSession().syncRequest(new FilterChangesRead(changes3, filters));
+                       changes3 = getSession().syncRequest(createFilterRead(changes3, filters));
                }
                
                Pair<GraphComparator,String> result = getChanges(oldModel,newModel);
@@ -123,7 +125,7 @@ public abstract class ModelUpdate {
                }
                comparator.test(getSession());
                changes = comparator.getChanges();
-               changes = getSession().syncRequest(new FilterChangesRead(changes, filters));
+               changes = getSession().syncRequest(createFilterRead(changes, filters));
                updateTree = getUpdateTree(changes);
                updateList = getUpdateList(changes);
                if (userFilters.size() != 0) {
@@ -145,6 +147,10 @@ public abstract class ModelUpdate {
                
        }
        
+       public List<ChangeFilter> getFilters() {
+               return Collections.unmodifiableList(filters);
+       }
+       
        /**
         * Adds an user filter. Use refreshUserFilters() to apply the changes.
         * @param filter
@@ -168,6 +174,10 @@ public abstract class ModelUpdate {
                userFilters.clear();
        }
        
+       public List<ChangeFilter> getUserFilters() {
+               return userFilters;
+       }
+       
        public void refreshUserFilters() throws DatabaseException{
                // use user filters to set visible flags of changes.
                // First, set all changes visible.
@@ -185,7 +195,7 @@ public abstract class ModelUpdate {
                        // Create filtered changes
                        List<ChangeFilter> combined = new ArrayList<>(filters);
                        combined.addAll(userFilters);
-                       GraphChanges filteredChanges = getSession().syncRequest(new FilterChangesRead(changes, combined));
+                       GraphChanges filteredChanges = getSession().syncRequest(createFilterRead(changes, combined));
                        UpdateTree updateTreeF = getUpdateTree(filteredChanges);
                        UpdateList updateListF = getUpdateList(filteredChanges);
                        // hide changes that are not contained within the filtered changes.
@@ -231,8 +241,13 @@ public abstract class ModelUpdate {
                        for (PropertyChange rc : r) {
                                if (comparable.containsRight(rc))
                                        continue;
-                               if (lc.getFirst().equals(rc.getFirst())) {
+                               if (lc.getFirst() != null && lc.getFirst().equals(rc.getFirst())) {
                                        comparable.map(lc, rc);
+                                       break;
+                               }
+                               if (lc.getSecond() != null && lc.getSecond().equals(rc.getSecond())) {
+                                       comparable.map(lc, rc);
+                                       break;
                                }
                        }
                }
@@ -329,9 +344,13 @@ public abstract class ModelUpdate {
                return Simantics.getSession();
        }
        
+       public Read<GraphChanges> createFilterRead(GraphChanges changes, List<ChangeFilter> filters) {
+               return new FilterChangesRead(changes, filters);
+       }
+       
        
        
-       private class FilterChangesRead implements Read<GraphChanges> {
+       public static class FilterChangesRead implements Read<GraphChanges> {
                private GraphChanges changes;
                private List<ChangeFilter> filters;
                
@@ -347,7 +366,7 @@ public abstract class ModelUpdate {
                
                /**
                 * Filters changes:
-                * 1. Changes that are not essential for model update (changes that can be found when the models are axcatly the same)
+                * 1. Changes that are not essential for model update (changes that can be found when the models are exactly the same)
                 * 2. Runs custom filters for value changes. 
                 * 
                 * @param g
@@ -358,9 +377,9 @@ public abstract class ModelUpdate {
                protected GraphChanges filterChanges(ReadGraph g, GraphChanges changes) throws DatabaseException 
            {
                        
-                       List<Pair<Statement,Statement>> modifications = new ArrayList<Pair<Statement,Statement>>();
+                       List<Modification> modifications = new ArrayList<Modification>();
                        
-               for (Pair<Statement, Statement> mod : changes.getModifications()) {
+               for (Modification mod : changes.getModifications()) {
                        
                        boolean accept = true;
                        for (ChangeFilter filter : filters) {
@@ -379,7 +398,7 @@ public abstract class ModelUpdate {
 
        
        public interface ChangeFilter {
-               public boolean accept(ReadGraph g, Pair<Statement, Statement> change) throws DatabaseException;
+               public boolean accept(ReadGraph g, Modification change) throws DatabaseException;
        }
 
        
@@ -403,12 +422,12 @@ public abstract class ModelUpdate {
                }
                
                @Override
-               public boolean accept(ReadGraph g, Pair<Statement, Statement> change) throws DatabaseException {
+               public boolean accept(ReadGraph g, Modification change) throws DatabaseException {
                        //filter floating point values that have less than 1% difference.
-                       if (!g.hasValue(change.first.getObject()) || !g.hasValue(change.second.getObject()))
+                       if (!g.hasValue(change.getLeftStm().getObject()) || !g.hasValue(change.getRightStm().getObject()))
                                return true;
-               Object v1 = g.getValue(change.first.getObject());
-               Object v2 = g.getValue(change.second.getObject());
+               Object v1 = g.getValue(change.getLeftStm().getObject());
+               Object v2 = g.getValue(change.getRightStm().getObject());
                
                if (v1 instanceof Double && v2 instanceof Double) {
                        double d1 = (Double)v1;
@@ -457,7 +476,7 @@ public abstract class ModelUpdate {
                        if (pair.getFirst() != null) {
                                boolean found = false;
                                for (PropertyChange pair2 : updateList2.getChanges()) {
-                                       if (pair.getFirst().equals(pair2.getSecond())) {
+                                       if (pair.getFirst() != null && pair.getFirst().equals(pair2.getSecond())) {
                                                found = true;
                                                break;
                                        }