X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftypicals%2FSyncTypicalTemplatesToInstances.java;h=cd326051371169ad70b442b8b986300c336cbce2;hp=435d6447324e0497b55a7d46b1442412094f37e5;hb=873afce76b92cb7cf9094fe60e407278f220e5ed;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java index 435d64473..cd3260513 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java @@ -11,9 +11,6 @@ *******************************************************************************/ package org.simantics.modeling.typicals; -import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; - import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Collection; @@ -85,6 +82,9 @@ import org.simantics.utils.strings.AlphanumComparator; import org.simantics.utils.strings.EString; import org.simantics.utils.ui.ErrorLogger; +import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; + /** * A write request that synchronizes typical master templates and their * instances as specified. @@ -210,6 +210,26 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { private boolean writeLog; + /** + * For SCL API. + * + * @param graph + * @param selectedRules + * @param templates + * @param instances + * @throws DatabaseException + */ + public static void syncTypicals(WriteGraph graph, boolean log, List templates, List instances) throws DatabaseException { + graph.syncRequest( + new SyncTypicalTemplatesToInstances( + null, + templates.toArray(Resource.NONE), + instances.toArray(Resource.NONE), + ALL, + null) + .logging(log)); + } + /** * @param templates typical diagram templates to completely synchronize with * their instances @@ -437,7 +457,11 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { private boolean isSynchronizedConnector(ReadGraph graph, Resource templateConnection, Resource instanceConnector) throws DatabaseException { DiagramResource DIA = DiagramResource.getInstance(graph); Resource instanceConnection = graph.getPossibleObject(instanceConnector, DIA.IsConnectorOf); - return graph.hasStatement(instanceConnection, MOD.HasElementSource, templateConnection); + return graph.hasStatement(instanceConnection, MOD.HasElementSource, templateConnection) + // If the master connection has been removed, this is all that's left + // to identify a connection that at least was originally synchronized + // from the typical master to this instance. + || graph.hasStatement(instanceConnection, MOD.IsTemplatized); } /** @@ -541,6 +565,7 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { // Perform changes boolean changed = false; + changed |= synchronizeDiagramChanges(graph, info, template, instance); changed |= removeElements(graph, info, instanceElementsRemovedFromTemplate); changed |= addMissingElements(graph, info, template, instance, templateElementsAddedToTemplate); changed |= synchronizeChangedElements(graph, info, template, instance, changedTemplateElements, templateElementsAddedToTemplate, changedElementsByDiagram == ALL); @@ -549,6 +574,35 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { metadata.addTypical(instance); } + /** + * Synchronize any configurable aspects of the typical diagram instance itself. + * Every rule executed here comes from the ontology, nothing is fixed. + * + * @param graph + * @param typicalInfo + * @param template + * @param instance + * @return if any changes were made. + * @throws DatabaseException + */ + private boolean synchronizeDiagramChanges( + WriteGraph graph, + TypicalInfo typicalInfo, + Resource template, + Resource instance) + throws DatabaseException + { + boolean changed = false; + for (Resource rule : graph.getObjects(template, MOD.HasTypicalSynchronizationRule)) { + if (selectedRules != null && !selectedRules.contains(rule)) + continue; + ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class); + if (r != null) + changed |= r.synchronize(graph, template, instance, typicalInfo); + } + return changed; + } + /** * Add elements from template that do not yet exist in the instance. *