From a38763229ea4aca42a489a78beef57d7a42abc97 Mon Sep 17 00:00:00 2001 From: Alexander Diewald <diewald@fortiss.org> Date: Wed, 18 Dec 2019 19:55:17 +0100 Subject: [PATCH] DelegatingModelFactory: Do not duplicate contents and alike * Ensure to avoid duplicate entries in the Lists returned by the delegating model factory. * This avoids creating duplicate controllers and visuals for the same model elements. Issue-Ref: 3883 Issue-Url: https://af3-developer.fortiss.org/issues/3883 Signed-off-by: Alexander Diewald <diewald@fortiss.org> --- .../kernel/ui/extension/base/factory/.ratings | 2 +- .../base/factory/DelegatingModelFactory.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/.ratings index e394ca991..9f583729c 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/.ratings @@ -1,4 +1,4 @@ DelegatingControllerFactory.java ad214d83b5821b39862b7c382c91a13c3dfddbd0 GREEN DelegatingFactoryBase.java f421742267610f41bb6196346026d2f239d90ed0 GREEN -DelegatingModelFactory.java 87ad29bc457b6316392625fb63221039bbb7c616 GREEN +DelegatingModelFactory.java 717b706781879efe9efcb5ce4bf53723e39a3e1b YELLOW DelegatingVisualFactory.java 7e834acd12ae4d1c2b2b32a5456dc9f2b6d4e466 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/DelegatingModelFactory.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/DelegatingModelFactory.java index 87ad29bc4..717b70678 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/DelegatingModelFactory.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/factory/DelegatingModelFactory.java @@ -17,6 +17,7 @@ package org.fortiss.tooling.kernel.ui.extension.base.factory; import static java.util.stream.Collectors.toList; import static org.apache.commons.lang3.reflect.ConstructorUtils.getMatchingAccessibleConstructor; +import static org.conqat.lib.commons.collections.CollectionUtils.isNullOrEmpty; import static org.fortiss.tooling.kernel.utils.EcoreUtils.getInterfaceType; import static org.fortiss.tooling.kernel.utils.LoggingUtils.error; @@ -80,7 +81,8 @@ public class DelegatingModelFactory extends DelegatingFactoryBase<IModelFactory> @Override public List<?> getContentAnchorageModels(Object parent) { return getDelegateFactories().stream().map(f -> f.getContentAnchorageModels(parent)) - .filter(cc -> cc != null).findFirst().orElse(null); + .filter(lm -> !isNullOrEmpty(lm)).flatMap(Collection::stream).distinct() + .collect(toList()); } /** {@inheritDoc} */ @@ -114,21 +116,24 @@ public class DelegatingModelFactory extends DelegatingFactoryBase<IModelFactory> @Override public List<?> getContentModels() { return getDelegateFactories().stream().map(f -> f.getContentModels()) - .flatMap(Collection::stream).collect(toList()); + .filter(lm -> !isNullOrEmpty(lm)).flatMap(Collection::stream).distinct() + .collect(toList()); } /** {@inheritDoc} */ @Override public List<?> getDiagramAnchorageModels() { return getDelegateFactories().stream().map(f -> f.getDiagramAnchorageModels()) - .flatMap(Collection::stream).collect(toList()); + .filter(lm -> !isNullOrEmpty(lm)).flatMap(Collection::stream).distinct() + .collect(toList()); } /** {@inheritDoc} */ @Override public List<?> getLinkModels() { return getDelegateFactories().stream().map(f -> f.getLinkModels()) - .flatMap(Collection::stream).collect(toList()); + .filter(lm -> !isNullOrEmpty(lm)).flatMap(Collection::stream).distinct() + .collect(toList()); } /** {@inheritDoc} */ -- GitLab