X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FModuleUpdaterBase.java;fp=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FModuleUpdaterBase.java;h=0000000000000000000000000000000000000000;hb=e4007b17057ff4acc2e900c5c811743b74f71f41;hp=45ea7400fbbf8682d0da92ce463cc008fdbe62d1;hpb=3fe6778c21d6437e90d08987de6dae7bca89bc6d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java deleted file mode 100644 index 45ea7400f..000000000 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.simantics.structural.synchronization.base; - -import gnu.trove.map.hash.THashMap; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.structural.synchronization.protocol.Connection; -import org.simantics.structural.synchronization.protocol.SerializedVariable; -import org.simantics.structural.synchronization.utils.ComponentBase; - -abstract public class ModuleUpdaterBase> { - - public String moduleType; - public THashMap> propertyUpdateRules = - new THashMap>(); - public THashMap> connectionUpdateRules = - new THashMap>(); - public boolean isUserComponent; - public boolean isComposite; - public String subprocessType; - - public ModuleUpdaterBase(String moduleType) { - this.moduleType = moduleType; - } - - public void addPropertyUpdateRule(PropertyUpdateRule rule) { - propertyUpdateRules.put(rule.getPropertyName(), rule); - } - - public void addConnectionUpdateRule(ConnectionUpdateRule rule) { - connectionUpdateRules.put(rule.getConnectionPointName(), rule); - } - - public void create(ModuleUpdateContext context, Collection properties, Collection connections) { - context.command = createAddCommandBuilder(context.getModuleName()); - applyRules(context, true, properties, connections); - } - - abstract public CommandBuilder createAddCommandBuilder(String name); - - public void update(ModuleUpdateContext context, Collection properties, Collection connections) { - // Check that the module type matches - int moduleTypeId = context.getSolver().getModuleType(context.getModuleId()); - String moduleTypeName = context.getSolver().getName(moduleTypeId); - if(!moduleTypeName.equals(moduleType)) { - context.getSolver().remove(context.getModuleId()); - context.component.componentId = -1; - context.setModuleId(-1); - create(context, properties, connections); - } - - // Update - else { - context.command = createUpdateCommandBuilder(context.getModuleName()); - applyRules(context, false, properties, connections); - } - } - - abstract public CommandBuilder createUpdateCommandBuilder(String name); - - private void applyRules(ModuleUpdateContext context, boolean inCreate, - Collection properties, Collection connections) { - THashMap propertyMap = new THashMap(properties.size()); - Map> connectionMap = connections.isEmpty() - ? Collections.>emptyMap() - : new THashMap>(connections.size()); - for(SerializedVariable property : properties) - propertyMap.put(property.name, property.value); - for(Connection connection : connections) - connectionMap.put(connection.relation, connection.connectionPoints); - - context.incPendingCount(); // To prevent premature execution of the command - for(SerializedVariable property : properties) { - PropertyUpdateRule rule = propertyUpdateRules.get(property.name); - if(rule != null) - rule.apply(context, inCreate, propertyMap, connectionMap, property.value); - else if(property.name.equals("IsAttached")) - ; - else - if(SynchronizationEventHandlerBase.TRACE_EVENTS) - System.out.println(" skipped property " + property.name + " " + property.toString()); - } - if(inCreate) { - for(Connection connection : connections) { - ConnectionUpdateRule rule = connectionUpdateRules.get(connection.relation); - if(rule != null) - rule.apply(context, propertyMap, connection.connectionPoints); - else - if(SynchronizationEventHandlerBase.TRACE_EVENTS) - System.out.println(" skipped connection " + connection.relation + " " + connection.connectionPoints); - } - } - else { - THashMap> unusedConnectionUpdateRules = - new THashMap>(connectionUpdateRules); - for(Connection connection : connections) { - ConnectionUpdateRule rule = unusedConnectionUpdateRules.remove(connection.relation); - if(rule != null) - rule.apply(context, propertyMap, connection.connectionPoints); - else - if(SynchronizationEventHandlerBase.TRACE_EVENTS) - System.out.println(" skipped connection " + connection.relation + " " + connection.connectionPoints); - } - for(ConnectionUpdateRule rule : unusedConnectionUpdateRules.values()) - rule.apply(context, propertyMap, Collections.emptyList()); - } - context.decPendingCount(); - } - -}