-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3763] Fix expand issues with the SelectionDialog tree
Bug: #3763 Signed-off-by: Florian Barbin <[email protected]>
- Loading branch information
1 parent
a7208fd
commit 5459da1
Showing
10 changed files
with
708 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...components/collaborative/selection/services/SelectionDialogExpandAllTreePathProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.sirius.components.collaborative.selection.services; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.eclipse.sirius.components.collaborative.selection.services.api.ISelectionDialogNavigationService; | ||
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.api.IContentService; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
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.representations.VariableManager; | ||
import org.eclipse.sirius.components.trees.Tree; | ||
import org.eclipse.sirius.components.trees.description.TreeDescription; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Implementation of {@link IExpandAllTreePathProvider} for the Selection Dialog Tree. | ||
* | ||
* @author frouene | ||
* @author fbarbin | ||
*/ | ||
@Service | ||
public class SelectionDialogExpandAllTreePathProvider implements IExpandAllTreePathProvider { | ||
|
||
private final IIdentityService identityService; | ||
|
||
private final IContentService contentService; | ||
|
||
private final ISelectionDialogNavigationService selectionDialogNavigationService; | ||
|
||
private final IRepresentationDescriptionSearchService representationDescriptionSearchService; | ||
|
||
public SelectionDialogExpandAllTreePathProvider(IIdentityService identityService, IContentService contentService, ISelectionDialogNavigationService selectionDialogNavigationService, IRepresentationDescriptionSearchService representationDescriptionSearchService) { | ||
this.identityService = Objects.requireNonNull(identityService); | ||
this.contentService = Objects.requireNonNull(contentService); | ||
this.selectionDialogNavigationService = Objects.requireNonNull(selectionDialogNavigationService); | ||
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(Tree tree) { | ||
return tree.getDescriptionId().startsWith(ISelectionDialogNavigationService.SELECTION_DIALOG_TREE_DESCRIPTION_KIND); | ||
} | ||
|
||
@Override | ||
public IPayload handle(IEditingContext editingContext, Tree tree, ExpandAllTreePathInput input) { | ||
int maxDepth = 0; | ||
String treeItemId = input.treeItemId(); | ||
Set<String> treeItemIdsToExpand = new LinkedHashSet<>(); | ||
var object = this.getTreeItemObject(editingContext, treeItemId, tree); | ||
if (object != null) { | ||
// We need to get the current depth of the tree item | ||
var itemAncestors = this.selectionDialogNavigationService.getAncestors(editingContext, treeItemId, tree); | ||
maxDepth = itemAncestors.size(); | ||
maxDepth = this.addAllContents(editingContext, treeItemId, maxDepth, treeItemIdsToExpand, tree); | ||
} | ||
return new ExpandAllTreePathSuccessPayload(input.id(), new TreePath(treeItemIdsToExpand.stream().toList(), maxDepth)); | ||
} | ||
|
||
private int addAllContents(IEditingContext editingContext, String treeItemId, int depth, Set<String> treeItemIdsToExpand, Tree tree) { | ||
var depthConsidered = depth; | ||
var object = this.getTreeItemObject(editingContext, treeItemId, tree); | ||
if (object != null) { | ||
var contents = this.contentService.getContents(object); | ||
if (!contents.isEmpty()) { | ||
treeItemIdsToExpand.add(treeItemId); | ||
|
||
for (var child : contents) { | ||
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); | ||
} | ||
} | ||
} | ||
|
||
return depthConsidered; | ||
} | ||
|
||
private Object getTreeItemObject(IEditingContext editingContext, String treeItemId, Tree tree) { | ||
var optionalTreeDescription = this.representationDescriptionSearchService.findById(editingContext, tree.getDescriptionId()) | ||
.filter(TreeDescription.class::isInstance) | ||
.map(TreeDescription.class::cast); | ||
|
||
if (optionalTreeDescription.isPresent()) { | ||
var variableManager = new VariableManager(); | ||
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext); | ||
variableManager.put(TreeDescription.ID, treeItemId); | ||
return optionalTreeDescription.get().getTreeItemObjectProvider().apply(variableManager); | ||
} | ||
return null; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
.../sirius/components/collaborative/selection/services/SelectionDialogNavigationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.sirius.components.collaborative.selection.services; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.collaborative.selection.services.api.ISelectionDialogNavigationService; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
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.springframework.stereotype.Service; | ||
|
||
/** | ||
* Services for the navigation through the Selection Dialog Tree. | ||
* | ||
* @author frouene | ||
* @author fbarbin | ||
*/ | ||
@Service | ||
public class SelectionDialogNavigationService implements ISelectionDialogNavigationService { | ||
|
||
private final IObjectService objectService; | ||
|
||
private final IRepresentationDescriptionSearchService representationDescriptionSearchService; | ||
|
||
public SelectionDialogNavigationService(IObjectService objectService, IRepresentationDescriptionSearchService representationDescriptionSearchService) { | ||
this.objectService = Objects.requireNonNull(objectService); | ||
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService); | ||
} | ||
|
||
@Override | ||
public List<String> getAncestors(IEditingContext editingContext, String treeItemId, Tree tree) { | ||
List<String> ancestorsIds = new ArrayList<>(); | ||
|
||
Optional<Object> optionalObject = this.getParentSemanticObject(treeItemId, ancestorsIds, editingContext, tree); | ||
while (optionalObject.isPresent()) { | ||
String parentId = this.objectService.getId(optionalObject.get()); | ||
ancestorsIds.add(parentId); | ||
optionalObject = this.getParentSemanticObject(parentId, ancestorsIds, editingContext, tree); | ||
} | ||
return ancestorsIds; | ||
} | ||
|
||
private Optional<Object> getParentSemanticObject(String elementId, List<String> ancestorsIds, IEditingContext editingContext, Tree tree) { | ||
Optional<Object> result = Optional.empty(); | ||
|
||
var variableManager = new VariableManager(); | ||
var optionalSemanticObject = this.getTreeItemObject(editingContext, elementId, tree); | ||
var optionalTreeDescription = this.representationDescriptionSearchService.findById(editingContext, tree.getDescriptionId()) | ||
.filter(TreeDescription.class::isInstance) | ||
.map(TreeDescription.class::cast); | ||
|
||
if (optionalSemanticObject.isPresent() && optionalTreeDescription.isPresent()) { | ||
variableManager.put(VariableManager.SELF, optionalSemanticObject.get()); | ||
variableManager.put(TreeDescription.ID, elementId); | ||
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext); | ||
result = Optional.ofNullable(optionalTreeDescription.get().getParentObjectProvider().apply(variableManager)); | ||
} | ||
return result; | ||
} | ||
|
||
private Optional<Object> getTreeItemObject(IEditingContext editingContext, String id, Tree tree) { | ||
var optionalTreeDescription = this.representationDescriptionSearchService.findById(editingContext, tree.getDescriptionId()) | ||
.filter(TreeDescription.class::isInstance) | ||
.map(TreeDescription.class::cast); | ||
|
||
if (optionalTreeDescription.isPresent()) { | ||
var variableManager = new VariableManager(); | ||
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext); | ||
variableManager.put(TreeDescription.ID, id); | ||
return Optional.ofNullable(optionalTreeDescription.get().getTreeItemObjectProvider().apply(variableManager)); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...us/components/collaborative/selection/services/api/ISelectionDialogNavigationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.sirius.components.collaborative.selection.services.api; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.trees.Tree; | ||
|
||
/** | ||
* Interface of the service for the navigation through the Selection Dialog Tree. | ||
* | ||
* @author fbarbin | ||
*/ | ||
public interface ISelectionDialogNavigationService { | ||
|
||
String SELECTION_DIALOG_TREE_DESCRIPTION_KIND = "siriusComponents://selectionDialogTreeDescription"; | ||
|
||
List<String> getAncestors(IEditingContext editingContext, String treeItemId, Tree tree); | ||
|
||
/** | ||
* Implementation which does nothing, used for mocks in unit tests. | ||
* | ||
* @author fbarbin | ||
*/ | ||
class NoOp implements ISelectionDialogNavigationService { | ||
|
||
@Override | ||
public List<String> getAncestors(IEditingContext editingContext, String treeItemId, Tree tree) { | ||
return List.of(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.