]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Small changes to synchronization base impl to allow extending it 39/3139/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 21 Aug 2019 12:32:52 +0000 (15:32 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 21 Aug 2019 12:32:52 +0000 (15:32 +0300)
gitlab #356

Change-Id: I66327777c16645c582573df0f485d2c5452e088e

bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/ModuleUpdateContext.java
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/MappingBase.java

index a4dea1ab25ad9ce600e7b4edae7897acde3c50e8..246b6936029d3821d52aa54ebb6081ee0555838d 100644 (file)
@@ -66,11 +66,20 @@ public class ModuleUpdateContext<T extends ComponentBase<T>> {
     public int getModuleId() {
         return component.getModuleId();
     }
-    
+
+    public ModuleUpdaterBase<T> getUpdater() {
+        return updater;
+    }
+
     public SynchronizationEventHandlerBase<T> getHandler() {
         return handler;
     }
 
+    @SuppressWarnings("unchecked")
+    public <E extends SynchronizationEventHandlerBase<?>> E getConcreteHandler() {
+        return (E) handler;
+    }
+
     public void setModuleId(int moduleId) {
         component.setModuleId(moduleId);
     }
index a6efeefb2534bc402c25cfc671705ccbb6ad0cbb..67b120b6462cc10b3e36364c70e884f91f8c9d9c 100644 (file)
@@ -248,7 +248,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     if(oldChildMap != null)
                         for(T component : oldChildMap.values()) {
                             component.clearParent();
-                            mapping.addPendingRemoval(component);
+                            addPendingRemoval(component);
                         }
                 }
                 // Alternative implementation when uids are not available.
@@ -275,7 +275,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     if(oldChildMap != null)
                         for(T component : oldChildMap.values()) {
                             component.clearParent();
-                            mapping.addPendingRemoval(component);
+                            addPendingRemoval(component);
                         }
                 }
 
@@ -334,6 +334,12 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
         }
     }
 
+    protected void addPendingRemoval(T component) {
+        if (TRACE_EVENTS)
+            System.out.println("addPendingRemoval(" + component.componentId + " : " + component.solverComponentName + ")");
+        mapping.addPendingRemoval(component);
+    }
+
     private String getSubprocessName(String name,
             Collection<SerializedVariable> properties) {
         for(SerializedVariable property : properties)
index 3c96a3feff3a8405938032973f457e25e34ada7e..423e5a1256b5b54921a4f2537bb84a566173bb2f 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.structural.synchronization.utils;
 
-import java.io.PrintWriter;
-
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.procedure.TObjectObjectProcedure;
 import gnu.trove.procedure.TObjectProcedure;
 import gnu.trove.set.hash.THashSet;
 
+import java.io.PrintWriter;
+import java.util.function.Consumer;
+
 /**
  * The entry point to the mapping structure between Simantics database and a
  * designated solver. It is used to synchronize changes from Simantics to the
@@ -219,4 +220,11 @@ abstract public class MappingBase<T extends ComponentBase<T>> {
         return !pendingRemoval.isEmpty();
     }
 
+    public void forEachPendingRemoval(Consumer<T> consumer) {
+        pendingRemoval.forEach(c -> {
+            consumer.accept(c);
+            return true;
+        });
+    }
+
 }