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=56d61c86845b3a4941e8da58b088f786aac9dcb6;hb=873afce76b92cb7cf9094fe60e407278f220e5ed;hpb=65cf12eb906873cf56c10bd1f8d04ec8645e6cbd 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 56d61c868..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 @@ -545,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); @@ -553,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. *