From: jsimomaa Date: Fri, 31 Jan 2020 09:58:48 +0000 (+0200) Subject: Fix DNElementRemover to remove the actual component first if possible X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F52%2F3752%2F1;p=simantics%2Fdistrict.git Fix DNElementRemover to remove the actual component first if possible gitlab #77 Change-Id: If3f627eff8a0bda7567a313446dff4f2cfd5b634 (cherry picked from commit ba7c2c670c6c2d2c358664474607461f1bbc2d6c) --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java index 06b31031..a32d5359 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java @@ -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); } } }