Skip to content

Commit

Permalink
[3882] Add a new tree event to support non explorer tree descriptions
Browse files Browse the repository at this point in the history
Bug: #3882
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo committed Aug 26, 2024
1 parent 69116ec commit b3da927
Show file tree
Hide file tree
Showing 28 changed files with 1,135 additions and 171 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3392[#3392] [diagram] Prevent edge from passing through another node
- https://github.com/eclipse-sirius/sirius-web/issues/3763[#3763] [diagram] Split the SelectionDialogDescription to prepare the Tree support
- https://github.com/eclipse-sirius/sirius-web/issues/3875[#3875] [sirius-web] Move explorer related code from components-trees to sirius-web-application
- https://github.com/eclipse-sirius/sirius-web/issues/3882[#3882] [sirius-web] Add a new tree event to handle tree description which are not explorer-related

== v2024.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public String getId() {
return this.treeId;
}

@Override
public List<String> getActiveFilterIds() {
return this.activeFilterIds;
}

@Override
public List<String> getExpanded() {
return this.expanded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicyRegistry;
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManagerFactory;
import org.eclipse.sirius.components.collaborative.trees.TreeEventProcessor;
import org.eclipse.sirius.components.collaborative.trees.api.ITreeConfiguration;
import org.eclipse.sirius.components.collaborative.trees.api.ITreeEventHandler;
import org.eclipse.sirius.components.collaborative.trees.api.ITreeService;
import org.eclipse.sirius.components.collaborative.trees.api.TreeCreationParameters;
Expand Down Expand Up @@ -91,9 +92,9 @@ public Optional<IRepresentationEventProcessor> createRepresentationEventProcesso
return Optional.empty();
}

private Optional<TreeDescription> findTreeDescription(IEditingContext editingContext, ExplorerConfiguration treeConfiguration) {
private Optional<TreeDescription> findTreeDescription(IEditingContext editingContext, ITreeConfiguration treeConfiguration) {
VariableManager variableManager = new VariableManager();
variableManager.put(ExplorerConfiguration.TREE_ID, treeConfiguration.getId());
variableManager.put(ITreeConfiguration.TREE_ID, treeConfiguration.getId());
return this.representationDescriptionSearchService
.findAll(editingContext).values().stream()
.filter(TreeDescription.class::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Objects;

import org.eclipse.sirius.components.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.components.collaborative.trees.api.ITreeConfiguration;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.IEventProcessorSubscriptionProvider;
Expand Down Expand Up @@ -56,7 +57,7 @@ public SubscriptionExplorerEventDataFetcher(ObjectMapper objectMapper, IExceptio
public Publisher<DataFetcherResult<IPayload>> get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, ExplorerEventInput.class);
var treeConfiguration = new ExplorerConfiguration(input.editingContextId(), input.treeId(), input.expanded(), input.activeFilterIds());
ITreeConfiguration treeConfiguration = new ExplorerConfiguration(input.editingContextId(), input.treeId(), input.expanded(), input.activeFilterIds());

Map<String, Object> localContext = new HashMap<>();
localContext.put(LocalContextConstants.EDITING_CONTEXT_ID, input.editingContextId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.sirius.components.core.api.IIdentityService;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.domain.Entity;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.description.TreeDescription;
Expand Down Expand Up @@ -99,17 +98,6 @@ private int addAllContents(IEditingContext editingContext, String treeItemId, in
var object = this.getTreeItemObject(editingContext, treeItemId, tree);

if (object instanceof EObject eObject) {
if (object instanceof Entity entity) {
// an Entity has a virtual node for its super types, this node should be a child of the Entity
var id = ExplorerDescriptionProvider.SETTING + this.identityService.getId(entity) + ExplorerDescriptionProvider.SETTING_ID_SEPARATOR + "superTypes";
treeItemIdsToExpand.add(id);
var superTypes = entity.getSuperTypes();
if (superTypes.size() > 0) {
depthConsidered = Math.max(depthConsidered, depth + 2);
} else {
depthConsidered = Math.max(depthConsidered, depth + 1);
}
}
var contents = this.contentService.getContents(eObject);
if (!contents.isEmpty()) {
treeItemIdsToExpand.add(treeItemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@
package org.eclipse.sirius.web.application.views.explorer.services;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService;
import org.eclipse.sirius.components.domain.Entity;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.trees.renderer.TreeRenderer;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerChildrenProvider;
Expand Down Expand Up @@ -71,15 +67,6 @@ public boolean hasChildren(VariableManager variableManager) {
String id = this.objectService.getId(eObject);
hasChildren = this.representationDataSearchService.existAnyRepresentationForTargetObjectId(id);
}

if (!hasChildren && self instanceof Entity) {
hasChildren = true;
}
} else if (self instanceof Setting setting) {
var value = setting.get(true);
if (value instanceof Collection<?> collection) {
hasChildren = !collection.isEmpty();
}
}
return hasChildren;
}
Expand Down Expand Up @@ -130,17 +117,8 @@ private List<Object> getDefaultChildren(VariableManager variableManager) {
representationMetadata.sort(Comparator.comparing(RepresentationMetadata::getLabel));
result.addAll(representationMetadata);
List<Object> contents = this.objectService.getContents(self);
if (self instanceof Entity entity) {
result.add(((InternalEObject) entity).eSetting(entity.eClass().getEStructuralFeature("superTypes")));
}
result.addAll(contents);
} else if (self instanceof Setting setting) {
var value = setting.get(true);
if (value instanceof Collection<?> collection) {
result.addAll(collection);
}
}

}
}
return result;
Expand All @@ -167,8 +145,6 @@ private String getTreeItemId(VariableManager variableManager) {
id = resource.getURI().path().substring(1);
} else if (self instanceof EObject) {
id = this.objectService.getId(self);
} else if (self instanceof Setting setting) {
id = ExplorerDescriptionProvider.SETTING + this.objectService.getId(setting.getEObject()) + ExplorerDescriptionProvider.SETTING_ID_SEPARATOR + setting.getEStructuralFeature().getName();
}
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider;
Expand Down Expand Up @@ -67,10 +65,6 @@ public class ExplorerDescriptionProvider implements IEditingContextRepresentatio

public static final String REPRESENTATION_NAME = "Explorer";

public static final String SETTING = "setting:";

public static final String SETTING_ID_SEPARATOR = "::";

private final IObjectService objectService;

private final IURLParser urlParser;
Expand Down Expand Up @@ -155,8 +149,6 @@ private String getTreeItemId(VariableManager variableManager) {
id = resource.getURI().path().substring(1);
} else if (self instanceof EObject) {
id = this.objectService.getId(self);
} else if (self instanceof Setting setting) {
id = SETTING + this.objectService.getId(setting.getEObject()) + SETTING_ID_SEPARATOR + setting.getEStructuralFeature().getName();
}
return id;
}
Expand All @@ -168,8 +160,6 @@ private String getKind(VariableManager variableManager) {
kind = representationMetadata.getKind();
} else if (self instanceof Resource) {
kind = DOCUMENT_KIND;
} else if (self instanceof Setting) {
kind = "setting";
} else {
kind = this.objectService.getKind(self);
}
Expand All @@ -192,8 +182,6 @@ private StyledString getLabel(VariableManager variableManager) {
var kind = this.objectService.getKind(self);
label = this.urlParser.getParameterValues(kind).get(SemanticKindConstants.ENTITY_ARGUMENT).get(0);
}
} else if (self instanceof Setting setting) {
label = setting.getEStructuralFeature().getName();
}
return StyledString.of(label);
}
Expand Down Expand Up @@ -297,36 +285,24 @@ private Object getTreeItemObject(VariableManager variableManager) {
if (optionalEditingContext.isPresent() && optionalTreeItemId.isPresent()) {
var treeItemId = optionalTreeItemId.get();
var editingContext = optionalEditingContext.get();

if (treeItemId.startsWith(SETTING)) {
// the tree item is a setting, get the object and then the structural feature associated
var objectId = treeItemId.substring(SETTING.length(), treeItemId.indexOf(SETTING_ID_SEPARATOR));
var featureName = treeItemId.substring(treeItemId.indexOf(SETTING_ID_SEPARATOR) + SETTING_ID_SEPARATOR.length());
var optObject = this.objectService.getObject(editingContext, objectId);
if (optObject.isPresent()) {
InternalEObject internalObject = (InternalEObject) optObject.get();
result = internalObject.eSetting(internalObject.eClass().getEStructuralFeature(featureName));
}
var optionalObject = this.objectService.getObject(editingContext, treeItemId);
if (optionalObject.isPresent()) {
result = optionalObject.get();
} else {
var optionalObject = this.objectService.getObject(editingContext, treeItemId);
if (optionalObject.isPresent()) {
result = optionalObject.get();
} else {
var optionalEditingDomain = Optional.of(editingContext)
.filter(IEMFEditingContext.class::isInstance)
.map(IEMFEditingContext.class::cast)
.map(IEMFEditingContext::getDomain);

if (optionalEditingDomain.isPresent()) {
var editingDomain = optionalEditingDomain.get();
ResourceSet resourceSet = editingDomain.getResourceSet();
URI uri = new JSONResourceFactory().createResourceURI(treeItemId);

result = resourceSet.getResources().stream()
.filter(resource -> resource.getURI().equals(uri))
.findFirst()
.orElse(null);
}
var optionalEditingDomain = Optional.of(editingContext)
.filter(IEMFEditingContext.class::isInstance)
.map(IEMFEditingContext.class::cast)
.map(IEMFEditingContext::getDomain);

if (optionalEditingDomain.isPresent()) {
var editingDomain = optionalEditingDomain.get();
ResourceSet resourceSet = editingDomain.getResourceSet();
URI uri = new JSONResourceFactory().createResourceURI(treeItemId);

result = resourceSet.getResources().stream()
.filter(resource -> resource.getURI().equals(uri))
.findFirst()
.orElse(null);
}
}
}
Expand Down
Loading

0 comments on commit b3da927

Please sign in to comment.