Skip to content

Commit

Permalink
[3856] Add tree expandAll fallback handler
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#3856
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo committed Sep 13, 2024
1 parent bf55ab7 commit 2b15bd3
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.sirius.components.collaborative.trees.dto.ExpandAllTreePathInput;
import org.eclipse.sirius.components.collaborative.trees.dto.ExpandAllTreePathSuccessPayload;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePath;
import org.eclipse.sirius.components.collaborative.trees.services.api.ITreeNavigationService;
import org.eclipse.sirius.components.core.api.IContentService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IIdentityService;
Expand All @@ -30,7 +31,6 @@
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.description.TreeDescription;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerNavigationService;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationDataSearchService;
import org.springframework.stereotype.Service;

Expand All @@ -46,16 +46,16 @@ public class ExpandAllTreePathProvider implements IExpandAllTreePathProvider {

private final IContentService contentService;

private final IExplorerNavigationService explorerNavigationService;
private final ITreeNavigationService treeNavigationService;

private final IRepresentationDataSearchService representationDataSearchService;

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

public ExpandAllTreePathProvider(IIdentityService identityService, IContentService contentService, IExplorerNavigationService explorerNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationDataSearchService representationDataSearchService) {
public ExpandAllTreePathProvider(IIdentityService identityService, IContentService contentService, ITreeNavigationService treeNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationDataSearchService representationDataSearchService) {
this.identityService = Objects.requireNonNull(identityService);
this.contentService = Objects.requireNonNull(contentService);
this.explorerNavigationService = Objects.requireNonNull(explorerNavigationService);
this.treeNavigationService = Objects.requireNonNull(treeNavigationService);
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.representationDataSearchService = Objects.requireNonNull(representationDataSearchService);
}
Expand All @@ -74,7 +74,7 @@ public IPayload handle(IEditingContext editingContext, Tree tree, ExpandAllTreeP
var object = this.getTreeItemObject(editingContext, tree, treeItemId);
if (object instanceof EObject) {
// We need to get the current depth of the tree item
var itemAncestors = this.explorerNavigationService.getAncestors(editingContext, tree, treeItemId);
var itemAncestors = this.treeNavigationService.getAncestors(editingContext, tree, treeItemId);
maxDepth = itemAncestors.size();
maxDepth = this.addAllContents(editingContext, treeItemId, maxDepth, treeItemIdsToExpand, tree);
} else if (object instanceof Resource resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.eclipse.sirius.components.collaborative.trees.dto.TreePath;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload;
import org.eclipse.sirius.components.collaborative.trees.services.api.ITreeNavigationService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerNavigationService;
import org.springframework.stereotype.Service;

/**
Expand All @@ -35,10 +35,10 @@
@Service
public class ExplorerTreePathProvider implements ITreePathProvider {

private final IExplorerNavigationService explorerNavigationService;
private final ITreeNavigationService treeNavigationService;

public ExplorerTreePathProvider(IExplorerNavigationService explorerNavigationService) {
this.explorerNavigationService = Objects.requireNonNull(explorerNavigationService);
public ExplorerTreePathProvider(ITreeNavigationService treeNavigationService) {
this.treeNavigationService = Objects.requireNonNull(treeNavigationService);
}

@Override
Expand All @@ -51,7 +51,7 @@ public IPayload handle(IEditingContext editingContext, Tree tree, TreePathInput
int maxDepth = 0;
Set<String> allAncestors = new LinkedHashSet<>();
for (String selectionEntryId : input.selectionEntryIds()) {
List<String> itemAncestors = this.explorerNavigationService.getAncestors(editingContext, tree, selectionEntryId);
List<String> itemAncestors = this.treeNavigationService.getAncestors(editingContext, tree, selectionEntryId);
allAncestors.addAll(itemAncestors);
maxDepth = Math.max(maxDepth, itemAncestors.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.sirius.components.collaborative.trees.dto.ExpandAllTreePathInput;
import org.eclipse.sirius.components.collaborative.trees.dto.ExpandAllTreePathSuccessPayload;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePath;
import org.eclipse.sirius.components.collaborative.trees.services.api.ITreeNavigationService;
import org.eclipse.sirius.components.core.api.IContentService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IIdentityService;
Expand All @@ -31,7 +32,6 @@
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.description.TreeDescription;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerNavigationService;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationDataSearchService;
import org.springframework.stereotype.Service;

Expand All @@ -47,15 +47,15 @@ public class DomainExpandAllTreePathProvider implements IExpandAllTreePathProvid

private final IContentService contentService;

private final IExplorerNavigationService explorerNavigationService;
private final ITreeNavigationService treeNavigationService;

private final IRepresentationDataSearchService representationDataSearchService;

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;
public DomainExpandAllTreePathProvider(IIdentityService identityService, IContentService contentService, IExplorerNavigationService explorerNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationDataSearchService representationDataSearchService) {
public DomainExpandAllTreePathProvider(IIdentityService identityService, IContentService contentService, ITreeNavigationService treeNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationDataSearchService representationDataSearchService) {
this.identityService = Objects.requireNonNull(identityService);
this.contentService = Objects.requireNonNull(contentService);
this.explorerNavigationService = Objects.requireNonNull(explorerNavigationService);
this.treeNavigationService = Objects.requireNonNull(treeNavigationService);
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.representationDataSearchService = Objects.requireNonNull(representationDataSearchService);
}
Expand All @@ -74,7 +74,7 @@ public IPayload handle(IEditingContext editingContext, Tree tree, ExpandAllTreeP
var object = this.getTreeItemObject(editingContext, tree, treeItemId);
if (object instanceof EObject || treeItemId.startsWith(DomainTreeRepresentationDescriptionProvider.SETTING)) {
// We need to get the current depth of the tree item
var itemAncestors = this.explorerNavigationService.getAncestors(editingContext, tree, treeItemId);
var itemAncestors = this.treeNavigationService.getAncestors(editingContext, tree, treeItemId);
maxDepth = itemAncestors.size();
maxDepth = this.addAllContents(editingContext, treeItemId, maxDepth, treeItemIdsToExpand, tree);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.eclipse.sirius.components.collaborative.trees.dto.TreePath;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePathInput;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePathSuccessPayload;
import org.eclipse.sirius.components.collaborative.trees.services.api.ITreeNavigationService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerNavigationService;
import org.springframework.stereotype.Service;

/**
Expand All @@ -35,10 +35,10 @@
@Service
public class DomainTreePathProvider implements ITreePathProvider {

private final IExplorerNavigationService explorerNavigationService;
private final ITreeNavigationService treeNavigationService;

public DomainTreePathProvider(IExplorerNavigationService explorerNavigationService) {
this.explorerNavigationService = Objects.requireNonNull(explorerNavigationService);
public DomainTreePathProvider(ITreeNavigationService treeNavigationService) {
this.treeNavigationService = Objects.requireNonNull(treeNavigationService);
}

@Override
Expand All @@ -52,7 +52,7 @@ public IPayload handle(IEditingContext editingContext, Tree tree, TreePathInput
int maxDepth = 0;
Set<String> allAncestors = new LinkedHashSet<>();
for (String selectionEntryId : input.selectionEntryIds()) {
List<String> itemAncestors = this.explorerNavigationService.getAncestors(editingContext, tree, selectionEntryId);
List<String> itemAncestors = this.treeNavigationService.getAncestors(editingContext, tree, selectionEntryId);
allAncestors.addAll(itemAncestors);
maxDepth = Math.max(maxDepth, itemAncestors.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,50 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.studio.services.representations;
package org.eclipse.sirius.components.collaborative.trees.handlers;

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

import org.eclipse.sirius.components.collaborative.trees.api.IExpandAllTreePathProvider;
import org.eclipse.sirius.components.collaborative.trees.dto.ExpandAllTreePathInput;
import org.eclipse.sirius.components.collaborative.trees.dto.ExpandAllTreePathSuccessPayload;
import org.eclipse.sirius.components.collaborative.trees.dto.TreePath;
import org.eclipse.sirius.components.core.URLParser;
import org.eclipse.sirius.components.collaborative.trees.services.api.ITreeNavigationService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.description.TreeDescription;
import org.eclipse.sirius.components.trees.renderer.TreeRenderer;
import org.eclipse.sirius.components.view.emf.IViewRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.view.emf.tree.ITreeIdProvider;
import org.eclipse.sirius.web.application.views.explorer.services.ExplorerDescriptionProvider;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerNavigationService;
import org.springframework.stereotype.Service;

/**
* Used to handle the Expand All action on the Domain explorer.
* This class is used as a fallback to handle an ExpandAllTreePath event that no handlers can handle.
*
* @author Jerome Gout
*/
@Service
public class DomainExplorerExpandAllTreePathProvider implements IExpandAllTreePathProvider {

private final IExplorerNavigationService explorerNavigationService;
public class DefaultExpandAllTreePathHandler {
private final ITreeNavigationService treeNavigationService;

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

private final IViewRepresentationDescriptionSearchService viewRepresentationDescriptionSearchService;

public DomainExplorerExpandAllTreePathProvider(IExplorerNavigationService explorerNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService,
IViewRepresentationDescriptionSearchService viewRepresentationDescriptionSearchService) {
this.explorerNavigationService = Objects.requireNonNull(explorerNavigationService);
public DefaultExpandAllTreePathHandler(ITreeNavigationService treeNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService) {
this.treeNavigationService = Objects.requireNonNull(treeNavigationService);
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.viewRepresentationDescriptionSearchService = viewRepresentationDescriptionSearchService;
}

@Override
public boolean canHandle(Tree tree) {
return tree.getDescriptionId().startsWith(ITreeIdProvider.TREE_DESCRIPTION_KIND);
}

@Override
public IPayload handle(IEditingContext editingContext, Tree tree, ExpandAllTreePathInput input) {
var parameterValues = new URLParser().getParameterValues(tree.getId());
var treeDescriptionId = parameterValues.get(ExplorerDescriptionProvider.TREE_DESCRIPTION_ID_PARAMETER).get(0);
var optionalViewTreeDescription = this.viewRepresentationDescriptionSearchService.findById(editingContext, treeDescriptionId);
if (optionalViewTreeDescription.isPresent()) {
if (optionalViewTreeDescription.get().getName().equals(DomainViewTreeDescriptionProvider.DOMAIN_EXPLORER_DESCRIPTION_NAME)) {
return this.doHandle(editingContext, tree, input);
}
}
return new ExpandAllTreePathSuccessPayload(input.id(), new TreePath(List.of(), 0));
}

public IPayload doHandle(IEditingContext editingContext, Tree tree, ExpandAllTreePathInput input) {
int maxDepth = 0;
String treeItemId = input.treeItemId();

Set<String> treeItemIdsToExpand = new LinkedHashSet<>();
// We need to get the current depth of the tree item
var itemAncestors = this.explorerNavigationService.getAncestors(editingContext, tree, treeItemId);
var itemAncestors = this.treeNavigationService.getAncestors(editingContext, tree, treeItemId);
maxDepth = itemAncestors.size();
maxDepth = this.addAllContents(editingContext, treeItemId, maxDepth, treeItemIdsToExpand, tree);
return new ExpandAllTreePathSuccessPayload(input.id(), new TreePath(treeItemIdsToExpand.stream().toList(), maxDepth));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public class ExpandAllTreePathEventHandler implements ITreeEventHandler {

private final List<IExpandAllTreePathProvider> expandAllTreePathsProviders;

public ExpandAllTreePathEventHandler(List<IExpandAllTreePathProvider> treePathProviders) {
private final DefaultExpandAllTreePathHandler defaultExpandAllTreePathHandler;

public ExpandAllTreePathEventHandler(List<IExpandAllTreePathProvider> treePathProviders, DefaultExpandAllTreePathHandler defaultExpandAllTreePathHandler) {
this.expandAllTreePathsProviders = Objects.requireNonNull(treePathProviders);
this.defaultExpandAllTreePathHandler = Objects.requireNonNull(defaultExpandAllTreePathHandler);
}

@Override
Expand All @@ -65,12 +68,12 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
if (treeInput instanceof ExpandAllTreePathInput input) {
Optional<IExpandAllTreePathProvider> optionalPathsProvider = this.expandAllTreePathsProviders.stream().filter(expandAllTreePathsProvider -> expandAllTreePathsProvider.canHandle(tree)).findFirst();
if (optionalPathsProvider.isPresent()) {
IPayload resultPayload = optionalPathsProvider.get().handle(editingContext, tree, input);
if (resultPayload instanceof ExpandAllTreePathSuccessPayload) {
payload = resultPayload;
} else if (resultPayload instanceof ErrorPayload errorPayload) {
this.logger.warn(errorPayload.message());
}
payload = optionalPathsProvider.get().handle(editingContext, tree, input);
} else {
payload = this.defaultExpandAllTreePathHandler.handle(editingContext, tree, input);
}
if (payload instanceof ErrorPayload errorPayload) {
this.logger.warn(errorPayload.message());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.views.explorer.services;
package org.eclipse.sirius.components.collaborative.trees.services;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.sirius.components.collaborative.trees.services.api.ITreeNavigationService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.description.TreeDescription;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerNavigationService;
import org.springframework.stereotype.Service;

/**
* Services for the navigation through the Sirius Web Explorer.
* Services for the tree navigation.
*
* @author arichard
*/
@Service
public class ExplorerNavigationService implements IExplorerNavigationService {
public class TreeNavigationService implements ITreeNavigationService {

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

public ExplorerNavigationService(IRepresentationDescriptionSearchService representationDescriptionSearchService) {
public TreeNavigationService(IRepresentationDescriptionSearchService representationDescriptionSearchService) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
}

Expand Down
Loading

0 comments on commit 2b15bd3

Please sign in to comment.