Skip to content

Commit

Permalink
[1068] Add support for displaying details on arbitrary element kinds
Browse files Browse the repository at this point in the history
Bug: #1068
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Feb 17, 2022
1 parent 8f1d242 commit 8635ad2
Show file tree
Hide file tree
Showing 20 changed files with 249 additions and 164 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
- https://github.com/eclipse-sirius/sirius-components/issues/1019[#1019] [core] Services now have access to the context of the request triggering their execution. Consumer of Sirius Components will have to provide the `RequestAttributes`` in the `RequestContextHolder`` to make the `EditingContextEventProcessor`` work. It should be very easy for those in a Spring environment, but it is not automatic for those outside of a Spring environment
- https://github.com/eclipse-sirius/sirius-components/issues/699[#699] [core] The `IRepresentationImageProvider` will now use the `kind` of the representation instead of the instance to compute the image. It will allow users to ask for the image of a representation with either its instance or its metadata
- https://github.com/eclipse-sirius/sirius-components/issues/699[#699] [core] Add the `targetObjectId` to the `RepresentationMetadata`
- https://github.com/eclipse-sirius/sirius-components/issues/1045[#1045] [core] Providers will now return List<?> instead of List<Object>. This makes it possible for applications to reuse existing services to implement providers without making useless copies of lists.
- https://github.com/eclipse-sirius/sirius-components/issues/1045[#1045] [core] Providers will now return List<?> instead of List<Object>. This makes it possible for applications to reuse existing services to implement providers without making useless copies of lists
- https://github.com/eclipse-sirius/sirius-components/issues/1068[#1068] [form] The form representation is now supporting multiple elements as an input. As a result, the variable `self` of the `idProvider`, `targetIdProvider` and `labelProvider` will be a list of objects. The GraphQL schema and the Java class used for the input of the properties subscription have been updated to support multiple inputs. This will allow the details view to display the properties of the whole selection at once. This will break existing form descriptions which may still expect a single object. The behavior of the for renderer has been updated and any page supporting any of the objects in the `self` variable will be used. As such, it there are two objects in the input and if a page is available for each of them, both pages will be displayed
- https://github.com/eclipse-sirius/sirius-components/issues/1068[#1068] [workbench] The integration of the details view in the workbench is not limited to semantic objects with a kind starting with `siriusComponents://semantic`. Any object can be used as the input of the details view and we will now provide the identifier of all the objects in the selection. This may include graphical elements such as nodes, edges, representations or anything selected in the explorer for example

=== Dependency update

Expand All @@ -46,6 +48,7 @@
- https://github.com/eclipse-sirius/sirius-components/issues/1025[#1025] [diagram] Add a new API to perform tests of our layout algorithm
- https://github.com/eclipse-sirius/sirius-components/issues/699[#699] [core] Provide the `IEditingContext` to find all the `RepresentationMetadata` for a specific object
- https://github.com/eclipse-sirius/sirius-components/issues/1054[#1054] [diagram] Add missing variables to compute the label of an edge
- https://github.com/eclipse-sirius/sirius-components/issues/1068[#1068] [form] Add support for displaying details on arbitrary element kinds

=== New features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2022 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
Expand Down Expand Up @@ -33,34 +33,39 @@
*/
public class FormDescriptionAggregator {

public Optional<FormDescription> aggregate(List<FormDescription> formDescriptions, Object object, IObjectService objectService) {
public Optional<FormDescription> aggregate(List<FormDescription> formDescriptions, List<Object> objects, IObjectService objectService) {
VariableManager pageVariableManager = new VariableManager();
pageVariableManager.put(VariableManager.SELF, object);
pageVariableManager.put(VariableManager.SELF, objects);

// @formatter:off
List<PageDescription> pageDescriptions = formDescriptions.stream()
.flatMap(formDescription -> formDescription.getPageDescriptions().stream())
.filter(pageDescription -> pageDescription.getCanCreatePredicate().test(pageVariableManager))
.collect(Collectors.toList());
// @formatter:on

if (pageDescriptions.isEmpty()) {
return Optional.empty();
}

List<GroupDescription> groupDescriptions = pageDescriptions.stream()
.flatMap(pageDescription -> pageDescription.getGroupDescriptions().stream())
.collect(Collectors.toUnmodifiableList());

List<GroupDescription> groupDescriptions = pageDescriptions.stream().flatMap(pageDescription -> pageDescription.getGroupDescriptions().stream()).collect(Collectors.toUnmodifiableList());

Function<VariableManager, String> labelProvider = variableManager -> {
return Optional.ofNullable(variableManager.getVariables().get(VariableManager.SELF))
.map(objectService::getFullLabel)
.orElse("Properties"); //$NON-NLS-1$
};
// @formatter:off
Function<VariableManager, String> labelProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.map(objectService::getFullLabel)
.orElse("Properties"); //$NON-NLS-1$
// @formatter:on

Function<VariableManager, String> targetObjectIdProvider = variableManager -> {
return Optional.ofNullable(object).map(objectService::getId).orElse(null);
};
// @formatter:off
Function<VariableManager, String> targetObjectIdProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.map(objectService::getId)
.orElse(null);

return Optional.of(FormDescription.newFormDescription(UUID.randomUUID())
.label("Aggregated form description") //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private IRepresentationRefreshPolicy getDefaultRefreshPolicy() {

private Form refreshForm() {
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, this.formCreationParameters.getObject());
variableManager.put(VariableManager.SELF, this.formCreationParameters.getObjects());
variableManager.put(GetOrCreateRandomIdProvider.PREVIOUS_REPRESENTATION_ID, this.formCreationParameters.getId());
variableManager.put(IEditingContext.EDITING_CONTEXT, this.formCreationParameters.getEditingContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio
FormCreationParameters formCreationParameters = FormCreationParameters.newFormCreationParameters(formConfiguration.getId())
.editingContext(editingContext)
.formDescription(formDescription)
.object(object)
.objects(List.of(object))
.build();
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
Expand Down Expand Up @@ -79,20 +80,24 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio
PropertiesConfiguration propertiesConfiguration = (PropertiesConfiguration) configuration;

List<FormDescription> formDescriptions = this.propertiesDescriptionService.getPropertiesDescriptions();
Optional<Object> optionalObject = this.objectService.getObject(editingContext, propertiesConfiguration.getObjectId());
if (optionalObject.isPresent()) {
Object object = optionalObject.get();
// @formatter:off
var objects = propertiesConfiguration.getObjectIds().stream()
.map(objectId -> this.objectService.getObject(editingContext, objectId))
.flatMap(Optional::stream)
.collect(Collectors.toList());
// @formatter:on
if (!objects.isEmpty()) {
Optional<FormDescription> optionalFormDescription = Optional.empty();
if (!formDescriptions.isEmpty()) {
optionalFormDescription = new FormDescriptionAggregator().aggregate(formDescriptions, object, this.objectService);
optionalFormDescription = new FormDescriptionAggregator().aggregate(formDescriptions, objects, this.objectService);
}
FormDescription formDescription = optionalFormDescription.orElse(this.propertiesDefaultDescriptionProvider.getFormDescription());

// @formatter:off
FormCreationParameters formCreationParameters = FormCreationParameters.newFormCreationParameters(propertiesConfiguration.getId())
.editingContext(editingContext)
.formDescription(formDescription)
.object(object)
.objects(objects)
.build();
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio
FormCreationParameters formCreationParameters = FormCreationParameters.newFormCreationParameters(representationsConfiguration.getId())
.editingContext(editingContext)
.formDescription(formDescription)
.object(object)
.objects(List.of(object))
.build();
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.sirius.components.collaborative.forms.api;

import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.annotations.Immutable;
Expand All @@ -32,7 +33,7 @@ public final class FormCreationParameters {

private String id;

private Object object;
private List<Object> objects;

private FormDescription formDescription;

Expand All @@ -46,8 +47,8 @@ public String getId() {
return this.id;
}

public Object getObject() {
return this.object;
public List<Object> getObjects() {
return this.objects;
}

public FormDescription getFormDescription() {
Expand All @@ -67,7 +68,7 @@ public static Builder newFormCreationParameters(FormCreationParameters formCreat
return new Builder(formCreationParameters.getId())
.formDescription(formCreationParameters.getFormDescription())
.editingContext(formCreationParameters.getEditingContext())
.object(formCreationParameters.getObject());
.objects(formCreationParameters.getObjects());
// @formatter:on
}

Expand All @@ -86,7 +87,7 @@ public String toString() {
public static final class Builder {
private String id;

private Object object;
private List<Object> objects;

private FormDescription formDescription;

Expand All @@ -96,8 +97,8 @@ private Builder(String id) {
this.id = id;
}

public Builder object(Object object) {
this.object = Objects.requireNonNull(object);
public Builder objects(List<Object> objects) {
this.objects = Objects.requireNonNull(objects);
return this;
}

Expand All @@ -114,7 +115,7 @@ public Builder editingContext(IEditingContext editingContext) {
public FormCreationParameters build() {
FormCreationParameters formCreationParameters = new FormCreationParameters();
formCreationParameters.id = this.id;
formCreationParameters.object = Objects.requireNonNull(this.object);
formCreationParameters.objects = Objects.requireNonNull(this.objects);
formCreationParameters.formDescription = Objects.requireNonNull(this.formDescription);
formCreationParameters.editingContext = Objects.requireNonNull(this.editingContext);
return formCreationParameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2022 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
Expand All @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.forms.api;

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

Expand All @@ -28,19 +29,19 @@ public class PropertiesConfiguration implements IRepresentationConfiguration {

private final String formId;

private final String objectId;
private final List<String> objectIds;

public PropertiesConfiguration(String objectId) {
this.objectId = Objects.requireNonNull(objectId);
this.formId = UUID.nameUUIDFromBytes((PROPERTIES_PREFIX + objectId).getBytes()).toString();
public PropertiesConfiguration(List<String> objectIds) {
this.objectIds = Objects.requireNonNull(objectIds);
this.formId = UUID.nameUUIDFromBytes((PROPERTIES_PREFIX + objectIds).getBytes()).toString();
}

@Override
public String getId() {
return this.formId;
}

public String getObjectId() {
return this.objectId;
public List<String> getObjectIds() {
return this.objectIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.sirius.components.collaborative.forms.dto;

import java.text.MessageFormat;
import java.util.List;
import java.util.UUID;

import org.eclipse.sirius.components.core.api.IInput;
Expand All @@ -27,7 +28,7 @@ public final class PropertiesEventInput implements IInput {

private String editingContextId;

private String objectId;
private List<String> objectIds;

@Override
public UUID getId() {
Expand All @@ -38,13 +39,13 @@ public String getEditingContextId() {
return this.editingContextId;
}

public String getObjectId() {
return this.objectId;
public List<String> getObjectIds() {
return this.objectIds;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, editingContextId: {2}, objectId: {3}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.editingContextId, this.objectId);
String pattern = "{0} '{'id: {1}, editingContextId: {2}, objectIds: {3}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.editingContextId, this.objectIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ input FormEventInput {
input PropertiesEventInput {
id: ID!
editingContextId: ID!
objectId: ID!
objectIds: [ID!]!
}

input RepresentationsEventInput {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2021 Obeo.
* Copyright (c) 2019, 2022 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
Expand All @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -87,11 +86,17 @@ public FormDescription convert(ViewExtensionDescription viewExtensionDescription
.map(pageDescription -> pageDescriptionConverter.convert(pageDescription, siriusGroup2SiriusWebGroup))
.collect(Collectors.toList());

Function<VariableManager, String> labelProvider = variableManager -> Optional.ofNullable(variableManager.getVariables().get(VariableManager.SELF))
.map(this.objectService::getLabel)
Function<VariableManager, String> labelProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.map(this.objectService::getFullLabel)
.orElse("Properties"); //$NON-NLS-1$

Function<VariableManager, String> targetObjectIdProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.map(this.objectService::getId)
.orElse(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ public FormDescription getFormDescription() {
pageDescriptions.add(firstPageDescription);

// @formatter:off
Function<VariableManager, String> labelProvider = variableManager -> {
return Optional.ofNullable(variableManager.getVariables().get(VariableManager.SELF))
.map(this.objectService::getFullLabel)
.orElse("Properties"); //$NON-NLS-1$
};
Function<VariableManager, String> labelProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.map(this.objectService::getFullLabel)
.orElse("Properties"); //$NON-NLS-1$
// @formatter:on

// @formatter:off
Function<VariableManager, String> targetObjectIdProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.map(this.objectService::getId)
.orElse(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ public Optional<Object> getObject(IEditingContext editingContext, String objectI
// If not found in the resources of the ResourceSet, we search in the PackageRegistry resources
if (!optionalEObject.isPresent()) {
URI uri = URI.createURI(objectId);
EObject eObject = resourceSet.getEObject(uri, false);
optionalEObject = Optional.ofNullable(eObject);
if (uri.hasFragment()) {
EObject eObject = resourceSet.getEObject(uri, false);
optionalEObject = Optional.ofNullable(eObject);
}
}
return optionalEObject;
});
Expand Down
Loading

0 comments on commit 8635ad2

Please sign in to comment.