]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java
Merge remote-tracking branch 'origin/svn'
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / typicals / SyncTypicalTemplatesToInstances.java
index 435d6447324e0497b55a7d46b1442412094f37e5..55f5aef3dabf1869b305b5376d14633abbcf9850 100644 (file)
@@ -437,7 +437,11 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest {
     private boolean isSynchronizedConnector(ReadGraph graph, Resource templateConnection, Resource instanceConnector) throws DatabaseException {\r
        DiagramResource DIA = DiagramResource.getInstance(graph);\r
        Resource instanceConnection = graph.getPossibleObject(instanceConnector, DIA.IsConnectorOf);\r
-       return graph.hasStatement(instanceConnection, MOD.HasElementSource, templateConnection);\r
+       return graph.hasStatement(instanceConnection, MOD.HasElementSource, templateConnection)\r
+                       // If the master connection has been removed, this is all that's left\r
+                       // to identify a connection that at least was originally synchronized\r
+                       // from the typical master to this instance.\r
+                       || graph.hasStatement(instanceConnection, MOD.IsTemplatized);\r
     }\r
 \r
     /**\r
@@ -541,6 +545,7 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest {
         \r
         // Perform changes\r
         boolean changed = false;\r
+        changed |= synchronizeDiagramChanges(graph, info, template, instance);\r
         changed |= removeElements(graph, info, instanceElementsRemovedFromTemplate);\r
         changed |= addMissingElements(graph, info, template, instance, templateElementsAddedToTemplate);\r
         changed |= synchronizeChangedElements(graph, info, template, instance, changedTemplateElements, templateElementsAddedToTemplate, changedElementsByDiagram == ALL);\r
@@ -549,6 +554,35 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest {
             metadata.addTypical(instance);\r
     }\r
 \r
+    /**\r
+     * Synchronize any configurable aspects of the typical diagram instance itself.\r
+     * Every rule executed here comes from the ontology, nothing is fixed. \r
+     * \r
+     * @param graph\r
+     * @param typicalInfo\r
+     * @param template\r
+     * @param instance\r
+     * @return if any changes were made. \r
+     * @throws DatabaseException\r
+     */\r
+    private boolean synchronizeDiagramChanges(\r
+            WriteGraph graph,\r
+            TypicalInfo typicalInfo,\r
+            Resource template,\r
+            Resource instance)\r
+                    throws DatabaseException\r
+    {\r
+        boolean changed = false;\r
+        for (Resource rule : graph.getObjects(template, MOD.HasTypicalSynchronizationRule)) {\r
+            if (selectedRules != null && !selectedRules.contains(rule))\r
+                continue;\r
+            ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class);\r
+            if (r != null)\r
+                changed |= r.synchronize(graph, template, instance, typicalInfo);\r
+        }\r
+        return changed;\r
+    }\r
+\r
     /**\r
      * Add elements from template that do not yet exist in the instance.\r
      * \r