Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1077] Fix explorer in case of non-sysml domain #1071

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions backend/views/syson-tree-explorer-view/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- removes mockito warning: must align version of byte-buddy-agent with the version indirectly required by spring-boot-starter-test -->
<argLine>
-javaagent:"${settings.localRepository}/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar"
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public boolean hasChildren(Object self, IEditingContext editingContext, List<Str
List<Object> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IRepresentationImageProvider> representationImageProviders = new ArrayList<>();
IExplorerServices explorerServices = new ExplorerServices(objectService, urlParser, representationImageProviders, representationMetadataSearchService);

ISysONExplorerFilterService filterService = new SysONExplorerFilterService();

sysONDefaultExplorerServices = new SysONDefaultExplorerServices(identityService, contentService, representationMetadataSearchService, explorerServices, filterService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading