Skip to content

Commit

Permalink
[3763] Allow displaying the Selection Dialog candidates in a tree viewer
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 Jul 11, 2024
1 parent 46095ef commit cee31cb
Show file tree
Hide file tree
Showing 37 changed files with 772 additions and 81 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ More existing APIs will be migrated to this new common pattern.
* The `SelectionDescription` type has been renamed into `SelectionDialogDescription` and inherit from `DialogDescription`.
* The `InvokeSingleClickOnDiagramElementToolInput#selectedObjectId` has been replaced by a `variables: [ToolVariable!]!` to make it possible to provide any kind of variable to the backend context.



```
input InvokeSingleClickOnDiagramElementToolInput {
id: ID!
Expand All @@ -54,6 +56,12 @@ More existing APIs will be migrated to this new common pattern.

* The `String` attribute `org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput#selectedObjectId` has been replaced by the attribute `variables` of type `List<ToolVariable>`

- https://github.com/eclipse-sirius/sirius-web/issues/3763[#3695] [selection] Selection Dialog: Make it possible to display semantic candidates in a tree viewer

* `org.eclipse.sirius.components.core.api.IContentService#getParent(Object object)` has been added to allow retrieving the parent element of an object.
* `org.eclipse.sirius.components.core.api.IObjectService#getParent(Object object)` has been added to allow retrieving the parent element of an object.
* `org.eclipse.sirius.components.view.emf.ViewConverter` requires a new service of type `IURLParser`.

=== Dependency update

- https://github.com/eclipse-sirius/sirius-web/issues/3510[#3510] [releng] Switch to Spring Boot 3.2.5
Expand Down Expand Up @@ -125,6 +133,7 @@ image:doc/screenshots/diagramFilterView.png[Diagram Filter View, 70%]
- https://github.com/eclipse-sirius/sirius-web/issues/3591[#3591] [sirius-web] Add EditProject subtitle extension point
- https://github.com/eclipse-sirius/sirius-web/issues/3662[#3662] [sirius-web] Add an extension point to contribute props to ReactFlow diagram renderer, contributed props must be memoized
- https://github.com/eclipse-sirius/sirius-web/issues/3695[#3695] [form] Add an extension point to contribute widget labels decorators
- https://github.com/eclipse-sirius/sirius-web/issues/3763[#3695] [selection] Selection Dialog: Make it possible to display semantic candidates in a tree viewer

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public interface IContentService {
List<Object> getContents(Object object);

Object getParent(Object object);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand All @@ -33,5 +35,10 @@ class NoOp implements IContentService {
public List<Object> getContents(Object object) {
return List.of();
}

@Override
public Object getParent(Object object) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
public interface IContentServiceDelegate {

boolean canHandle(Object object);

List<Object> getContents(Object object);

Object getParent(Object object);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand All @@ -38,6 +41,10 @@ public boolean canHandle(Object object) {
public List<Object> getContents(Object object) {
return List.of();
}
@Override
public Object getParent(Object object) {
return null;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public interface IDefaultContentService {
List<Object> getContents(Object object);

Object getParent(Object object);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand All @@ -34,5 +36,10 @@ public List<Object> getContents(Object object) {
return List.of();
}

@Override
public Object getParent(Object object) {
return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public interface IObjectService {

Optional<Object> getObject(IEditingContext editingContext, String objectId);

Object getParent(Object object);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand Down Expand Up @@ -91,6 +93,11 @@ public String getKind(Object object) {
public Optional<Object> getObject(IEditingContext editingContext, String objectId) {
return Optional.empty();
}

@Override
public Object getParent(Object object) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.components.core.services;

import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.core.api.IContentService;
import org.eclipse.sirius.components.core.api.IContentServiceDelegate;
import org.eclipse.sirius.components.core.api.IDefaultContentService;
import org.eclipse.sirius.components.core.api.IIdentityService;

import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;

/**
* Implementation of {@link IIdentityService} which delegates to {@link IContentServiceDelegate} or fallback to
Expand Down Expand Up @@ -50,4 +49,15 @@ public List<Object> getContents(Object object) {
}
return this.defaultContentService.getContents(object);
}

@Override
public Object getParent(Object object) {
var optionalDelegate = this.contentServiceDelegate.stream()
.filter(delegate -> delegate.canHandle(object))
.findFirst();
if (optionalDelegate.isPresent()) {
return optionalDelegate.get().getParent(object);
}
return this.defaultContentService.getParent(object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ public Optional<Object> getObject(IEditingContext editingContext, String objectI
return this.objectSearchService.getObject(editingContext, objectId);
}

@Override
public Object getParent(Object object) {
return this.contentService.getParent(object);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
*******************************************************************************/
package org.eclipse.sirius.components.emf.services;

import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.sirius.components.core.api.IDefaultContentService;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;

/**
* Default implementation of {@link IDefaultContentService}.
Expand Down Expand Up @@ -50,4 +49,17 @@ public List<Object> getContents(Object object) {
}
return contents;
}
@Override
public Object getParent(Object object) {
Object parent = null;
if (object instanceof EObject eObject) {
Adapter adapter = this.composedAdapterFactory.adapt(eObject, IEditingDomainItemProvider.class);
if (adapter instanceof IEditingDomainItemProvider contentProvider) {
parent = contentProvider.getParent(eObject);
} else {
parent = eObject.eContainer();
}
}
return parent;
}
}
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 @@ -138,6 +152,9 @@ public List<String> getImagePath(Object object) {
.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.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private Selection refreshSelection() {
variableManager.put(IEditingContext.EDITING_CONTEXT, this.editingContext);
variableManager.put(GetOrCreateRandomIdProvider.PREVIOUS_REPRESENTATION_ID, this.id);

Selection selection = new SelectionRenderer(variableManager, this.selectionDescription).render();
Selection selection = new SelectionRenderer(variableManager, this.selectionDescription, this.objectService).render();

this.logger.trace("Selection refreshed: {}", selection.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ type Selection implements Representation {
targetObjectId: String!
message: String
objects: [SelectionObject!]!
displayedAsTree: Boolean!
expendedAtOpening: Boolean!
}

type SelectionObject {
id: ID!
label: String!
iconURL: [String!]!
parentId: String
isSelectable: Boolean!
}

type SelectionDescription implements RepresentationDescription {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>sirius-components-representations</artifactId>
<version>2024.5.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-core</artifactId>
<version>2024.5.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-tests</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public final class Selection implements IRepresentation {

private List<SelectionObject> objects;

private boolean displayedAsTree;

private boolean expendedAtOpening;

private Selection() {
// Prevent instantiation
}
Expand Down Expand Up @@ -80,6 +84,14 @@ public String getMessage() {
return this.message;
}

public boolean isDisplayedAsTree() {
return this.displayedAsTree;
}

public boolean isExpendedAtOpening() {
return this.expendedAtOpening;
}

public List<SelectionObject> getObjects() {
return this.objects;
}
Expand Down Expand Up @@ -115,6 +127,10 @@ public static final class Builder {

private List<SelectionObject> objects;

private boolean displayedAsTree;

private boolean expendedAtOpening;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand Down Expand Up @@ -144,6 +160,16 @@ public Builder objects(List<SelectionObject> objects) {
return this;
}

public Builder displayedAsTree(boolean displayedAsTree) {
this.displayedAsTree = displayedAsTree;
return this;
}

public Builder expendedAtOpening(boolean expendedAtOpening) {
this.expendedAtOpening = expendedAtOpening;
return this;
}

public Selection build() {
Selection selection = new Selection();
selection.id = Objects.requireNonNull(this.id);
Expand All @@ -153,6 +179,8 @@ public Selection build() {
selection.targetObjectId = Objects.requireNonNull(this.targetObjectId);
selection.message = this.message;
selection.objects = Objects.requireNonNull(this.objects);
selection.displayedAsTree = this.displayedAsTree;
selection.expendedAtOpening = this.expendedAtOpening;
return selection;
}
}
Expand Down
Loading

0 comments on commit cee31cb

Please sign in to comment.