From c71da9ee63485299cc6ca876d0dfbc8bb2098f70 Mon Sep 17 00:00:00 2001 From: Didier Vojtisek Date: Sat, 1 Mar 2025 23:22:09 +0100 Subject: [PATCH] [1077] Fix explorer in case of non-sysml domain Fix behavior of hasChildren management of syson explorer when handling model elements from non-sysml domains. It now falls back to SiriusWeb implementation when necessary. Bug: https://github.com/eclipse-syson/syson/issues/1077 Signed-off-by: Didier Vojtisek --- CHANGELOG.adoc | 2 + .../views/syson-tree-explorer-view/pom.xml | 10 ++ .../SysONDefaultExplorerServices.java | 2 + .../SysONDefaultExplorerServicesTest.java | 108 ++++++++++++++++++ .../pages/release-notes/2025.4.0.adoc | 2 + 5 files changed, 124 insertions(+) create mode 100644 backend/views/syson-tree-explorer-view/src/test/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServicesTest.java diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e536c600b..7922c5286 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,6 +17,8 @@ === Bug fixes +- https://github.com/eclipse-syson/syson/issues/1077[#1077] [explorer] Fix navigation in case of project containing both sysml and non-sysml model elements + === Improvements - https://github.com/eclipse-syson/syson/issues/1061[#1061] [general-view] Add ellipsis on `Packages` label, to provide visual feedback on name overflow. diff --git a/backend/views/syson-tree-explorer-view/pom.xml b/backend/views/syson-tree-explorer-view/pom.xml index 976c6381e..d01003743 100644 --- a/backend/views/syson-tree-explorer-view/pom.xml +++ b/backend/views/syson-tree-explorer-view/pom.xml @@ -132,6 +132,16 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + + -javaagent:"${settings.localRepository}/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar" + + + org.apache.maven.plugins maven-source-plugin diff --git a/backend/views/syson-tree-explorer-view/src/main/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServices.java b/backend/views/syson-tree-explorer-view/src/main/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServices.java index d9cda2cea..7356e1cc7 100644 --- a/backend/views/syson-tree-explorer-view/src/main/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServices.java +++ b/backend/views/syson-tree-explorer-view/src/main/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServices.java @@ -133,6 +133,8 @@ public boolean hasChildren(Object self, IEditingContext editingContext, List contents = this.filterService.applyFilters(this.contentService.getContents(self), activeFilterIds); hasChildren = !contents.isEmpty() && contents.stream().anyMatch(e -> !(e instanceof EAnnotation)) || this.hasRepresentation(element, editingContext); + } else { + hasChildren = explorerServices.hasChildren(self, editingContext); } return hasChildren; } diff --git a/backend/views/syson-tree-explorer-view/src/test/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServicesTest.java b/backend/views/syson-tree-explorer-view/src/test/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServicesTest.java new file mode 100644 index 000000000..2631f9e7e --- /dev/null +++ b/backend/views/syson-tree-explorer-view/src/test/java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServicesTest.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2024, 2025 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ + +package org.eclipse.syson.tree.explorer.view.services; + +import org.eclipse.emf.common.command.BasicCommandStack; +import org.eclipse.emf.ecore.*; +import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; +import org.eclipse.emf.ecore.util.EcoreAdapterFactory; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; +import org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider; +import org.eclipse.sirius.components.core.api.IContentService; +import org.eclipse.sirius.components.core.api.IIdentityService; +import org.eclipse.sirius.components.core.api.IObjectService; +import org.eclipse.sirius.components.core.api.IURLParser; +import org.eclipse.sirius.web.application.editingcontext.EditingContext; +import org.eclipse.sirius.web.application.views.explorer.services.ExplorerServices; +import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerServices; +import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationMetadataSearchService; +import org.eclipse.syson.tree.explorer.view.services.api.ISysONExplorerFilterService; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +public class SysONDefaultExplorerServicesTest { + + private static EditingContext editingContext; + + private SysONDefaultExplorerServices sysONDefaultExplorerServices; + + @BeforeAll + static void createEditingContext() { + ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(); + composedAdapterFactory.addAdapterFactory(new EcoreAdapterFactory()); + composedAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); + + EPackage.Registry ePackageRegistry = new EPackageRegistryImpl(); + ePackageRegistry.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE); + + AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(composedAdapterFactory, new BasicCommandStack()); + ResourceSet resourceSet = editingDomain.getResourceSet(); + resourceSet.setPackageRegistry(ePackageRegistry); + resourceSet.eAdapters().add(new ECrossReferenceAdapter()); + editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain, Map.of(), List.of()); + } + + @Test + @DisplayName("hasChildren method can handle non sysml content") + public void hasChildrenCanHandleNonSysmlContent() { + this.createMockServicesForHasChildren(); + + EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); + ePackage.setName("somePackage"); + EClass c1 = EcoreFactory.eINSTANCE.createEClass(); + ePackage.getEClassifiers().add(c1); + EClass c2 = EcoreFactory.eINSTANCE.createEClass(); + ePackage.getEClassifiers().add(c2); + EAttribute c1_a1 = EcoreFactory.eINSTANCE.createEAttribute(); + c1.getEStructuralFeatures().add(c1_a1); + EAttribute c1_a2 = EcoreFactory.eINSTANCE.createEAttribute(); + c1.getEStructuralFeatures().add(c1_a2); + + assertThat(sysONDefaultExplorerServices.hasChildren(ePackage, editingContext, List.of(), List.of())).isTrue(); + assertThat(sysONDefaultExplorerServices.hasChildren(c1, editingContext, List.of(), List.of())).isTrue(); + assertThat(sysONDefaultExplorerServices.hasChildren(c1_a1, editingContext, List.of(), List.of())).isFalse(); + } + + /** + * Create instances of services required to test hasChildren + * Use mock instances for non required services + */ + private void createMockServicesForHasChildren() { + + IIdentityService identityService = mock(IIdentityService.class); + IContentService contentService = mock(IContentService.class); + IRepresentationMetadataSearchService representationMetadataSearchService = mock(IRepresentationMetadataSearchService.class); + + IObjectService objectService = mock(IObjectService.class); + IURLParser urlParser = mock(IURLParser.class); + List representationImageProviders = new ArrayList<>(); + IExplorerServices explorerServices = new ExplorerServices(objectService, urlParser, representationImageProviders, representationMetadataSearchService); + + ISysONExplorerFilterService filterService = new SysONExplorerFilterService(); + + sysONDefaultExplorerServices = new SysONDefaultExplorerServices(identityService, contentService, representationMetadataSearchService, explorerServices, filterService); + } +} diff --git a/doc/content/modules/user-manual/pages/release-notes/2025.4.0.adoc b/doc/content/modules/user-manual/pages/release-notes/2025.4.0.adoc index 8f67a7bb0..49f0d5bf2 100644 --- a/doc/content/modules/user-manual/pages/release-notes/2025.4.0.adoc +++ b/doc/content/modules/user-manual/pages/release-notes/2025.4.0.adoc @@ -8,6 +8,8 @@ In such cases, delete the `SuccessionUsage` graphical node and recreate it graph == Bug fixes +- In `Explorer View`, the fold/unfold arrow is now also available for non-sysml model elements. + == New features == Improvements