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 authored and sbegaudeau committed Sep 16, 2024
1 parent bcef547 commit b5ab3ca
Show file tree
Hide file tree
Showing 41 changed files with 1,010 additions and 1,510 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ As a result, the following maven modules have been deleted: `sirius-web-sample-a
- https://github.com/eclipse-sirius/sirius-web/issues/3437[#3437] [core] Migrate frontend to MUI 5, if you contributed React componenent that use MUI, you should upgrade them to use MUI 5.
- https://github.com/eclipse-sirius/sirius-web/issues/2204[#2204] [core] Added `getStyledLabel` in `IDefaultLabelService` and `IObjectService`, you must implement this method if you have custom implementation of these interface.
- https://github.com/eclipse-sirius/sirius-web/issues/3815[#3815] [core] Make child creation descriptions locale independent
- https://github.com/eclipse-sirius/sirius-web/issues/2204[#2204] [core, tree] Added `getStyledLabel` in `IDefaultLabelService` and `IObjectService`, you must implement this method if you have custom implementation of these interface.
- https://github.com/eclipse-sirius/sirius-web/issues/3763[#3763] [core] updates some services behavior:
** The `org.eclipse.sirius.components.emf.services.DefaultIdentityService#getId(Object object)` Can now provides the Id if the Object is of type `org.eclipse.emf.ecore.resource.Resource`. Before this change, it would have returned null.
** The `org.eclipse.sirius.components.emf.services.DefaultLabelService` Can now provides the label if the Object is of type `org.eclipse.emf.ecore.resource.Resource`. Before this change, it would have returned an empty string.


=== Dependency update

Expand Down Expand Up @@ -174,7 +179,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] Make it possible to display semantic candidates in the selection dialog using a tree
- https://github.com/eclipse-sirius/sirius-web/issues/3793[#3793] [sirius-web] Add mechanism to retrieve the parent object of an element in the tree representation
- https://github.com/eclipse-sirius/sirius-web/issues/3880[#3880] [sirius-web] Make some tests methods more generic
- https://github.com/eclipse-sirius/sirius-web/issues/3834[#3834] [deck] Add more variables for DeckDescription
Expand All @@ -186,6 +191,8 @@ 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 @@ -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,13 +24,15 @@
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.core.api.labels.StyledString;
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -45,23 +47,29 @@
public class DefaultLabelService implements IDefaultLabelService {

public static final String DEFAULT_ICON_PATH = "/icons/svg/Default.svg";

private static final String DEFAULT_LABEL_FEATURE = "name";

private final LabelFeatureProviderRegistry labelFeatureProviderRegistry;

private final ComposedAdapterFactory composedAdapterFactory;

private final List<IRepresentationImageProvider> representationImageProviders;

private final Logger logger = LoggerFactory.getLogger(LabelFeatureProviderRegistry.class);

public DefaultLabelService(LabelFeatureProviderRegistry labelFeatureProviderRegistry, ComposedAdapterFactory composedAdapterFactory, List<IRepresentationImageProvider> representationImageProviders) {
this.labelFeatureProviderRegistry = Objects.requireNonNull(labelFeatureProviderRegistry);
this.composedAdapterFactory = Objects.requireNonNull(composedAdapterFactory);
this.representationImageProviders = Objects.requireNonNull(representationImageProviders);
}

@Override
public String getLabel(Object object) {
return this.getStyledLabel(object).toString();
}

@Override
public StyledString getStyledLabel(Object object) {
String label = "";
if (object instanceof EObject eObject) {
Expand All @@ -71,11 +79,21 @@ public StyledString getStyledLabel(Object object) {
.orElse("");
} else if (object instanceof IRepresentation representation) {
label = representation.getLabel();
} else if (object instanceof Resource resource) {
label = this.getResourceLabel(resource);
}

return StyledString.of(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 @@ -87,6 +105,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 @@ -143,6 +163,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 b5ab3ca

Please sign in to comment.