Skip to content

Commit

Permalink
[3763] Implements the Selection Dialog TreeView
Browse files Browse the repository at this point in the history
Bug: #3763
Signed-off-by: Florian Barbin <[email protected]>
  • Loading branch information
florianbarbin committed Aug 23, 2024
1 parent 251994c commit 92bc756
Show file tree
Hide file tree
Showing 44 changed files with 1,141 additions and 1,503 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3776[#3776] [trees] Remove unwanted dependency from the reference widget in the explorer
- https://github.com/eclipse-sirius/sirius-web/issues/3777[#3777] [sirius-web] Add support for any kind of object as semantic element in the tree representation
- 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/3763[#3763] [diagram] Selection Dialog: Make it possible to display semantic candidates in a tree viewer

== v2024.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@
*******************************************************************************/
package org.eclipse.sirius.components.compatibility.diagrams;

import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.compatibility.api.IAQLInterpreterFactory;
import org.eclipse.sirius.components.compatibility.api.IIdentifierProvider;
import org.eclipse.sirius.components.compatibility.services.selection.api.ISelectModelElementVariableConverter;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.interpreter.AQLInterpreter;
import org.eclipse.sirius.components.interpreter.Result;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.selection.Selection;
import org.eclipse.sirius.components.selection.description.SelectionDescription;
import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable;
import org.springframework.stereotype.Service;
Expand All @@ -41,36 +36,25 @@ public class SelectModelElementVariableConverter implements ISelectModelElementV

private final IIdentifierProvider identifierProvider;

private final IAQLInterpreterFactory interpreterFactory;

public SelectModelElementVariableConverter(IObjectService objectService, IIdentifierProvider identifierProvider, IAQLInterpreterFactory interpreterFactory) {
public SelectModelElementVariableConverter(IObjectService objectService, IIdentifierProvider identifierProvider) {
this.objectService = Objects.requireNonNull(objectService);
this.identifierProvider = Objects.requireNonNull(identifierProvider);
this.interpreterFactory = Objects.requireNonNull(interpreterFactory);
}

@Override
public SelectionDescription convert(SelectModelElementVariable selectModelElementVariable, org.eclipse.sirius.diagram.description.DiagramDescription diagramDescription) {
AQLInterpreter interpreter = this.interpreterFactory.create(diagramDescription);
return SelectionDescription.newSelectionDescription(this.identifierProvider.getIdentifier(selectModelElementVariable))
.objectsProvider(variableManager -> {
Result result = interpreter.evaluateExpression(variableManager.getVariables(), selectModelElementVariable.getCandidatesExpression());
return result.asObjects().orElse(List.of()).stream()
.filter(Objects::nonNull)
.toList();
})
.messageProvider(variableManager -> {
String message = selectModelElementVariable.getMessage();
if (message == null) {
message = "";
}
return message;
})
.idProvider(variableManager -> Selection.PREFIX)
.idProvider(variableManager -> "selection://")
.labelProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getLabel).orElse(null))
.iconURLProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getImagePath).orElse(List.of()))
.targetObjectIdProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null))
.selectionObjectsIdProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null))
.label("Selection Description")
.canCreatePredicate(variableManager -> false)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public String getId(Object object) {
id = representation.getId();
} else if (object instanceof IEditingContext editingContext) {
id = editingContext.getId();
} else if (object instanceof Resource resource) {
id = resource.getURI().path().substring(1);
}
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedImage;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.ReflectiveItemProvider;
import org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider;
import org.eclipse.sirius.components.core.api.IDefaultLabelService;
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -66,10 +68,20 @@ public String getLabel(Object object) {
.orElse("");
} else if (object instanceof IRepresentation representation) {
label = representation.getLabel();
} else if (object instanceof Resource resource) {
label = this.getResourceLabel(resource);
}
return label;
}

private String getResourceLabel(Resource resource) {
return resource.eAdapters().stream()
.filter(ResourceMetadataAdapter.class::isInstance)
.map(ResourceMetadataAdapter.class::cast).findFirst()
.map(ResourceMetadataAdapter::getName)
.orElse(resource.getURI().lastSegment());
}

@Override
public String getFullLabel(Object object) {
String fullLabel = "";
Expand All @@ -81,6 +93,8 @@ public String getFullLabel(Object object) {
}
} else if (object instanceof IRepresentation representation) {
fullLabel = representation.getLabel();
} else if (object instanceof Resource resource) {
fullLabel = this.getResourceLabel(resource);
} else {
fullLabel = this.getLabel(object);
}
Expand Down Expand Up @@ -137,6 +151,8 @@ public List<String> getImagePath(Object object) {
.map(provider -> provider.getImageURL(representation.getKind()))
.flatMap(Optional::stream)
.toList();
} else if (object instanceof Resource) {
result = List.of("/icons/Resource.svg");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Service
public class EMFImagePathService implements IImagePathService {

private static final List<String> IMAGES_PATHS = List.of("/icons/full/obj16", "/icons/full/ovr16");
private static final List<String> IMAGES_PATHS = List.of("/icons/full/obj16", "/icons/full/ovr16", "/icons");

@Override
public List<String> getPaths() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading

0 comments on commit 92bc756

Please sign in to comment.