]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Fix DNElementRemover to remove the actual component first if possible 27/3927/1
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 31 Jan 2020 09:58:48 +0000 (11:58 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 16 Mar 2020 22:26:46 +0000 (22:26 +0000)
gitlab #77

Change-Id: If3f627eff8a0bda7567a313446dff4f2cfd5b634
(cherry picked from commit ba7c2c670c6c2d2c358664474607461f1bbc2d6c)

org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java

index 06b31031f2efc794eca78c498aaaf5e0a1287e29..a32d5359ee10653e545761725e83baca179732e1 100644 (file)
@@ -10,6 +10,7 @@ import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;
+import org.simantics.modeling.ModelingResources;
 import org.simantics.modeling.adapters.ElementRemover;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -71,9 +72,15 @@ public class DNElementRemover extends ElementRemover {
         Boolean trackChangesEnabled = DistrictNetworkUtil.trackChangesEnabled(graph, graph.getPossibleObject(resource, Layer0.getInstance(graph).PartOf));
         if (trackChangesEnabled) {
             DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-            Resource mappedComponent = graph.getPossibleObject(resource, DN.MappedComponent);
-            if (mappedComponent != null) {
-                RemoverUtil.remove(graph, mappedComponent);
+            Resource element = graph.getPossibleObject(resource, DN.MappedComponent);
+            if (element != null) {
+                // get component
+                ModelingResources MOD = ModelingResources.getInstance(graph);
+                Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);
+                if (component != null)
+                    RemoverUtil.remove(graph, component);
+                else
+                    RemoverUtil.remove(graph, element);
             }
         }
     }