Fixed ComponentCopyAdvisor to account for L0.TypeWithIdentifier properly 03/1803/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 24 May 2018 22:29:31 +0000 (01:29 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 25 May 2018 05:50:11 +0000 (05:50 +0000)
The previous fix done for the same problem in Simantics redmine issue
7842 and commits
c912edf13bf5a91b2f6dc855f54d8728aa0a64f5,
803c42fd316859809eaeb3dc6a88b22cbf86b4b6 and
0cfc6a9b8b186ba432bc6758c089726b1471fd1f was simply wrong. Using
ModelingUtils.needsIdentifier is the most proper way to fix this.

gitlab #10

Change-Id: Id7cdc32a6596588154913fced742d751ce6ba864
(cherry picked from commit 290c3cfc8bf5a7b2cc6e8532f124512e0bf10517)

bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentCopyAdvisor.java

index b7ed06795788877bbdd440ec20dc8c211543d35e..3e6e9c1b9527096cfa1835a50e43f6b2dfb97c7f 100644 (file)
@@ -12,7 +12,6 @@
 package org.simantics.modeling.mapping;
 
 import java.util.Map;
-import java.util.Set;
 
 import org.simantics.Simantics;
 import org.simantics.databoard.Bindings;
@@ -29,6 +28,7 @@ import org.simantics.diagram.synchronization.graph.GraphCopyAdvisor;
 import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ComponentUtils;
+import org.simantics.modeling.ModelingUtils;
 import org.simantics.modeling.services.ComponentNamingUtil;
 import org.simantics.modeling.services.NamingException;
 import org.simantics.project.IProject;
@@ -59,23 +59,13 @@ public class ComponentCopyAdvisor extends GraphCopyAdvisor {
     public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer,
             Resource targetContainer, Map<Object, Object> map) throws DatabaseException {
         StructuralResource2 STR = StructuralResource2.getInstance(graph);
-        Resource copy = null;
-        Set<Resource> types = graph.getTypes(source);
-        if (types.contains(STR.Connection)) {
-            // Configuration connections are not named, can't use TG copy for
-            // them at the moment.
-            copy = CopyAdvisorUtil.copy2(graph, source, null, map);
-        } else {
-//            Resource model = graph.syncRequest(new PossibleModel(targetContainer));
-//            copy = CopyAdvisorUtil.copy4(graph, source, model);
-            copy = CopyAdvisorUtil.copy2(graph, source, null, map);
-        }
+        Resource copy = CopyAdvisorUtil.copy2(graph, source, null, map);
 
         Layer0 L0 = Layer0.getInstance(graph);
         if (graph.hasStatement(sourceContainer, L0.ConsistsOf, source))
             graph.claim(targetContainer, L0.ConsistsOf, copy);
 
-        if (types.contains(L0.TypeWithIdentifier))
+        if (ModelingUtils.needsIdentifier(graph, source))
             Layer0Utils.claimNewIdentifier(graph, copy, false);
         if (context.get(SynchronizationHints.NO_RENAME) == null)
             renameComponent(context, graph, source, copy, sourceContainer, targetContainer);