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
+ an example of tree representation for Domain elements

Bug: #3882
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo committed Sep 23, 2024
1 parent 4be44b4 commit 8980df7
Show file tree
Hide file tree
Showing 28 changed files with 1,449 additions and 160 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ It is now possible to choose between three options:
never, always and if_children (to display the separator only if children exist).
- https://github.com/eclipse-sirius/sirius-web/issues/4021[#4021] [sirius-web] Disable the _Rename_ and _Delete_ project menu actions when project is read-only
- https://github.com/eclipse-sirius/sirius-web/issues/3677[#3677] [diagram] Remove backend layouting code from the time the backend was computing the layout.
- 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.9.0

Expand Down Expand Up @@ -212,7 +213,6 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3951[#3951] [sirius-web] Provide an error page to redirect users in case of error
- https://github.com/eclipse-sirius/sirius-web/issues/3974[#3974] [diagram] Add support for `<` and `>` to trigger direct edit


== v2024.7.0

=== Shapes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.sirius.web.application.views.explorer.services;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

Expand All @@ -28,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 @@ -74,7 +72,7 @@ public IPayload handle(IEditingContext editingContext, Tree tree, ExpandAllTreeP

Set<String> treeItemIdsToExpand = new LinkedHashSet<>();
var object = this.getTreeItemObject(editingContext, tree, treeItemId);
if (object instanceof EObject || treeItemId.startsWith(ExplorerDescriptionProvider.SETTING)) {
if (object instanceof EObject) {
// We need to get the current depth of the tree item
var itemAncestors = this.explorerNavigationService.getAncestors(editingContext, tree, treeItemId);
maxDepth = itemAncestors.size();
Expand All @@ -99,27 +97,7 @@ private int addAllContents(IEditingContext editingContext, String treeItemId, in
var depthConsidered = depth;
var object = this.getTreeItemObject(editingContext, tree, treeItemId);

if (treeItemId.startsWith(ExplorerDescriptionProvider.SETTING) && object instanceof List<?> list) {
treeItemIdsToExpand.add(treeItemId);
for (var child : list) {
String childId = this.identityService.getId(child);
treeItemIdsToExpand.add(childId);
var childTreePathMaxDepth = depth + 1;
childTreePathMaxDepth = this.addAllContents(editingContext, childId, childTreePathMaxDepth, treeItemIdsToExpand, tree);
depthConsidered = Math.max(depthConsidered, childTreePathMaxDepth);
}
} else 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);
}
}
if (object instanceof EObject eObject) {
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 @@ -20,8 +20,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 @@ -70,10 +68,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 @@ -160,8 +154,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 @@ -173,8 +165,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 @@ -197,8 +187,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 @@ -302,36 +290,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 All @@ -354,9 +330,6 @@ private Object getParentObject(VariableManager variableManager) {
semanticContainer = eObject.eResource();
}
result = semanticContainer;
} else if (self instanceof Setting setting) {
// the parent of the superTypes node is the object associated to this Setting
result = setting.getEObject();
}
return result;
}
Expand Down
Loading

0 comments on commit 8980df7

Please sign in to comment.