]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Add post processing step to bind property and structural changes 20/3620/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 20 Nov 2019 17:30:15 +0000 (19:30 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 26 Nov 2019 15:54:29 +0000 (15:54 +0000)
Additionally added enabled flag for PropertyChanges

gitlab #16

Change-Id: I7ac9c999471ab934cc26bd36d920940cb91cb528
(cherry picked from commit 7f27fe15240dbb56d9525671c44468cdbc934199)

org.simantics.interop.update/scl/Interop/Update.scl
org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java
org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java

index e2ee353fb7de1b589081b187e8e1d5f7d033d012..5769840732f490814d95316da74231067da393a4 100644 (file)
@@ -119,9 +119,15 @@ importJava "org.simantics.interop.update.model.PropertyChange" where
   @JavaName getSecondSubject
   getSecondSubject :: PropertyChange -> <Proc> Resource
   
-  @JavaName isVisible
+  @JavaName isVisible  
   pcVisible :: PropertyChange -> <Proc> Boolean
   
+  @JavaName isEnabled  
+  pcEnabled :: PropertyChange -> <Proc> Boolean
+  
+  @JavaName setEnabled
+  pcEnable :: PropertyChange -> Boolean -> <Proc> ()
+  
 
 importJava "org.simantics.interop.update.model.UpdateNode" where
   data UpdateNode
index 7cd2afd06784e49dacdd1b7a2d31b721af66357f..2cb2883ce4f0773e6fd9e5f37dabd0bfa81b0f1b 100644 (file)
@@ -74,8 +74,9 @@ public abstract class ModelUpdate {
                        comparator2.test(getSession());
                        changes2 = comparator2.getChanges();
                        changes2 = getSession().syncRequest(createFilterRead(changes2, filters));
-                       updateTree2 = getUpdateTree(changes2);
-                       updateList2 = getUpdateList(changes2);
+                       Pair<UpdateTree, UpdateList> chg2 = createChangeObjects(changes2);
+                       updateTree2 = chg2.first;
+                       updateList2 = chg2.second;
                        
                        // compare the original and the new model
                        Pair<GraphComparator,String> result3 = getChanges(originalModel,newModel);
@@ -127,8 +128,9 @@ public abstract class ModelUpdate {
                comparator.test(getSession());
                changes = comparator.getChanges();
                changes = getSession().syncRequest(createFilterRead(changes, filters));
-               updateTree = getUpdateTree(changes);
-               updateList = getUpdateList(changes);
+               Pair<UpdateTree, UpdateList> chg = createChangeObjects(changes);
+        updateTree = chg.first;
+        updateList = chg.second;
                if (userFilters.size() != 0) {
                        refreshUserFilters();
                }
@@ -250,11 +252,24 @@ public abstract class ModelUpdate {
        }
        
        protected abstract Pair<GraphComparator,String> getChanges(Resource r1, Resource r2)  throws DatabaseException;
+       
+       protected Pair<UpdateTree, UpdateList> createChangeObjects(GraphChanges changes) throws DatabaseException{
+           UpdateTree updateTree = getUpdateTree(changes);
+        UpdateList updateList = getUpdateList(changes);
+        postProcess(updateTree, updateList);
+        return new Pair<UpdateTree, UpdateList>(updateTree, updateList);
+       }
+       
        protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException;
        protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException {
                return new UpdateList(changes, changes.getModifications());
        }
        
+
+       protected void postProcess(UpdateTree updateTree, UpdateList updateList) throws DatabaseException{
+           
+       }
+       
        public Resource getOldModel() {
                return oldModel;
        }
@@ -296,13 +311,19 @@ public abstract class ModelUpdate {
        }
        
        public UpdateTree getUpdateTree3() throws DatabaseException{
-               if (updateTree3 == null && changes3 != null)
-                       updateTree3 = getUpdateTree(changes3);
+               if (updateTree3 == null && changes3 != null) {
+                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3);
+            updateTree3 = chg3.first;
+            updateList3 = chg3.second;
+               }
                return updateTree3;
        }
        public UpdateList getUpdateList3() throws DatabaseException {
-               if (updateList3 == null && changes3 != null)
-                       updateList3 = getUpdateList(changes3);
+               if (updateList3 == null && changes3 != null) {
+                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3);
+            updateTree3 = chg3.first;
+            updateList3 = chg3.second;
+               }
                return updateList3;
        }
        
index 81a342a7ef079429d9d3c7afdcb76fb1171644d1..07a3dc38e35cd98334a4238bc095d6e0154ded72 100644 (file)
@@ -15,7 +15,7 @@ public class PropertyChange {
        protected boolean applied = false;
        protected boolean selected = false;
        protected boolean visible = true;
-       
+       protected boolean enabled = true;
        
        public PropertyChange(GraphChanges changes, Resource left, Statement first, Resource right, Statement second) {
                if (first == null && second == null)
@@ -103,22 +103,40 @@ public class PropertyChange {
                
        }
        
+       /**
+        * Sets selected state. 
+        * @param select
+        * @return true if selection state was changed
+        */
        public boolean select(boolean select) {
+           if (!enabled)
+               return false;
                if (applied)
                        return false;
                this.selected = select;
                return true;
        }
        
-       
+       /**
+        * Is change selected.
+        * @return
+        */
        public boolean selected() {
                return selected;
        }
        
+       /**
+        * Has change been applied
+        * @return
+        */
        public boolean applied() {
                return applied;
        }
        
+       /**
+        * Is change visible
+        * @return
+        */
        public boolean isVisible() {
                return visible;
        }
@@ -127,13 +145,33 @@ public class PropertyChange {
                this.visible = visible;
        }
        
+       /**
+        * IS change enabled. Disabled changes do not allow changing selected state.
+        * @return
+        */
+       public boolean isEnabled() {
+        return enabled;
+    }
+       
+       public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+       
        @Override
        public String toString() {
                String s = "PropertyChange";
                if (pair.first != null)
-                       s += " (" + (leftSubject) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
+                       s += " L(" + (leftSubject) + " , " + pair.first.getPredicate() + " , " + pair.first.getObject() + ")";
                if (pair.second != null)
-                       s += " (" + (rightSubject) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")";
+                       s += " R(" + (rightSubject) + " , " + pair.second.getPredicate() + " , " + pair.second.getObject() + ")";
+               if (selected)
+                   s += " selected";
+               if (enabled)
+                   s += " enabled";
+               if (visible)
+            s += " visible";
+               if (applied)
+                   s += " applied";
                return s;
        }