Skip to content

Commit

Permalink
[2460] Separates the management of element creation from the referenc…
Browse files Browse the repository at this point in the history
…e widget in specific services

Bug: #2460
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
frouene authored and pcdavid committed Oct 30, 2023
1 parent 7c51f40 commit 9dde437
Show file tree
Hide file tree
Showing 31 changed files with 540 additions and 237 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -31,6 +31,7 @@ For example, Diagram & Form domains are not root domains because `DiagramDescrip
- https://github.com/eclipse-sirius/sirius-web/issues/2456[#2456] [sirius-web] The GraphQL field `CreateChildSuccessPayload` now expects to have a list of messages.
- https://github.com/eclipse-sirius/sirius-web/issues/1982[#1982] [diagram] Change the diagram structure. The Node's 'label' attribute has been renamed into 'insideLabel' and its type changed from `Label` to `InsideLabel` (which is currently identical to `Label` except for the name).
- https://github.com/eclipse-sirius/sirius-web/issues/2388[#2388] [core] The `IObjectService.getImagePath` API changed and now must return a list containing all the image paths to compose/overlay.
- https://github.com/eclipse-sirius/sirius-web/issues/2460[#2460] [form] The reference widget no longer declares a `createElementHandlerProvider`, this feature is delegated to the new service `IReferenceWidgetCreateElementHandler`.

=== Dependency update

Expand Down
Expand Up @@ -17,7 +17,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;

import org.eclipse.emf.common.util.EList;
Expand All @@ -29,8 +28,6 @@
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.compatibility.emf.properties.api.IPropertiesValidationProvider;
import org.eclipse.sirius.components.compatibility.forms.WidgetIdProvider;
import org.eclipse.sirius.components.core.api.IEditService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IFeedbackMessageService;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.emf.services.api.IEMFKindService;
Expand Down Expand Up @@ -67,13 +64,11 @@ public class NonContainmentReferenceIfDescriptionProvider {

private final IFeedbackMessageService feedbackMessageService;

private final IEditService editService;

public NonContainmentReferenceIfDescriptionProvider(ComposedAdapterFactory composedAdapterFactory, IObjectService objectService, IEditService editService, IEMFKindService emfKindService,
public NonContainmentReferenceIfDescriptionProvider(ComposedAdapterFactory composedAdapterFactory, IObjectService objectService, IEMFKindService emfKindService,
IFeedbackMessageService feedbackMessageService, IPropertiesValidationProvider propertiesValidationProvider, Function<VariableManager, String> semanticTargetIdProvider) {
this.composedAdapterFactory = Objects.requireNonNull(composedAdapterFactory);
this.objectService = Objects.requireNonNull(objectService);
this.editService = Objects.requireNonNull(editService);
this.propertiesValidationProvider = Objects.requireNonNull(propertiesValidationProvider);
this.semanticTargetIdProvider = Objects.requireNonNull(semanticTargetIdProvider);
this.emfKindService = Objects.requireNonNull(emfKindService);
Expand Down Expand Up @@ -120,7 +115,6 @@ private ReferenceWidgetDescription getReferenceWidgetDescription() {
.itemRemoveHandlerProvider(this::handleRemoveValue)
.setHandlerProvider(this::handleSetReference)
.addHandlerProvider(this::handleAddReferenceValues)
.createElementHandlerProvider(this::handleCreateElement)
.moveHandlerProvider(this::handleMoveReferenceValue)
.build();
}
Expand Down Expand Up @@ -306,24 +300,6 @@ private IStatus handleAddReferenceValues(VariableManager variableManager) {
return result;
}

private Object handleCreateElement(VariableManager variableManager) {
Optional<Object> result = Optional.empty();
Optional<Boolean> optionalIsChild = variableManager.get(ReferenceWidgetComponent.IS_CHILD_CREATION_VARIABLE, Boolean.class);
var optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
String creationDescriptionId = variableManager.get(ReferenceWidgetComponent.CREATION_DESCRIPTION_ID_VARIABLE, String.class).orElse("");
if (optionalIsChild.isPresent() && optionalEditingContext.isPresent()) {
if (optionalIsChild.get()) {
EObject parent = variableManager.get(ReferenceWidgetComponent.PARENT_VARIABLE, EObject.class).orElse(null);
result = this.editService.createChild(optionalEditingContext.get(), parent, creationDescriptionId);
} else {
UUID documentId = variableManager.get(ReferenceWidgetComponent.DOCUMENT_ID_VARIABLE, UUID.class).orElse(UUID.randomUUID());
String domainId = variableManager.get(ReferenceWidgetComponent.DOMAIN_ID_VARIABLE, String.class).orElse("");
result = this.editService.createRootObject(optionalEditingContext.get(), documentId, domainId, creationDescriptionId);
}
}
return result.orElse(null);
}

private IStatus handleMoveReferenceValue(VariableManager variableManager) {
IStatus result = this.createErrorStatus("Something went wrong while reordering reference values.");
EObject referenceOwner = variableManager.get(VariableManager.SELF, EObject.class).orElse(null);
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.eclipse.sirius.components.collaborative.forms.PropertiesEventProcessorFactory;
import org.eclipse.sirius.components.collaborative.forms.api.IPropertiesDefaultDescriptionProvider;
import org.eclipse.sirius.components.compatibility.emf.properties.api.IPropertiesValidationProvider;
import org.eclipse.sirius.components.core.api.IEditService;
import org.eclipse.sirius.components.core.api.IFeedbackMessageService;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.emf.services.api.IEMFKindService;
Expand All @@ -55,8 +54,6 @@ public class PropertiesDefaultDescriptionProvider implements IPropertiesDefaultD

private final IObjectService objectService;

private final IEditService editService;

private final IEMFKindService emfKindService;

private final IFeedbackMessageService feedbackMessageService;
Expand All @@ -69,10 +66,9 @@ public class PropertiesDefaultDescriptionProvider implements IPropertiesDefaultD

private final Function<VariableManager, String> semanticTargetIdProvider;

public PropertiesDefaultDescriptionProvider(IObjectService objectService, IEditService editService, IEMFKindService emfKindService, IFeedbackMessageService feedbackMessageService, ComposedAdapterFactory composedAdapterFactory, IPropertiesValidationProvider propertiesValidationProvider,
public PropertiesDefaultDescriptionProvider(IObjectService objectService, IEMFKindService emfKindService, IFeedbackMessageService feedbackMessageService, ComposedAdapterFactory composedAdapterFactory, IPropertiesValidationProvider propertiesValidationProvider,
IEMFMessageService emfMessageService) {
this.objectService = Objects.requireNonNull(objectService);
this.editService = Objects.requireNonNull(editService);
this.emfKindService = Objects.requireNonNull(emfKindService);
this.feedbackMessageService = Objects.requireNonNull(feedbackMessageService);
this.composedAdapterFactory = Objects.requireNonNull(composedAdapterFactory);
Expand Down Expand Up @@ -173,7 +169,7 @@ private GroupDescription getGroupDescription() {
ifDescriptions.add(new EBooleanIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider, this.semanticTargetIdProvider).getIfDescription());
ifDescriptions.add(new EEnumIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider, this.semanticTargetIdProvider).getIfDescription());

ifDescriptions.add(new NonContainmentReferenceIfDescriptionProvider(this.composedAdapterFactory, this.objectService, this.editService, this.emfKindService, this.feedbackMessageService, this.propertiesValidationProvider, this.semanticTargetIdProvider).getIfDescription());
ifDescriptions.add(new NonContainmentReferenceIfDescriptionProvider(this.composedAdapterFactory, this.objectService, this.emfKindService, this.feedbackMessageService, this.propertiesValidationProvider, this.semanticTargetIdProvider).getIfDescription());

// @formatter:off
var numericDataTypes = List.of(
Expand Down
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2023 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.widget.reference;

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

import org.eclipse.sirius.components.core.api.ChildCreationDescription;
import org.eclipse.sirius.components.core.api.IEditService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.widget.reference.IReferenceWidgetCreateElementHandler;
import org.springframework.stereotype.Service;

/**
* * Default implementation of {@link IReferenceWidgetCreateElementHandler}.
* * This implementation use {@link IEditService}.
*
* @author frouene
*/
@Service
public class ReferenceWidgetDefaultCreateElementHandler implements IReferenceWidgetCreateElementHandler {

private final IEditService editService;

public ReferenceWidgetDefaultCreateElementHandler(IEditService editService) {
this.editService = Objects.requireNonNull(editService);
}

@Override
public boolean canHandle(String descriptionId) {
return false; // Default implementation, it'll be used if no other service can handle the descriptionId
}

@Override
public List<ChildCreationDescription> getRootCreationDescriptions(IEditingContext editingContext, String domainId, String referenceKind, String descriptionId) {
return this.editService.getRootCreationDescriptions(editingContext, domainId, false, referenceKind);
}

@Override
public List<ChildCreationDescription> getChildCreationDescriptions(IEditingContext editingContext, String kind, String referenceKind, String descriptionId) {
return this.editService.getChildCreationDescriptions(editingContext, kind, referenceKind);
}

@Override
public Optional<Object> createRootObject(IEditingContext editingContext, UUID documentId, String domainId, String rootObjectCreationDescriptionId, String descriptionId) {
return this.editService.createRootObject(editingContext, documentId, domainId, rootObjectCreationDescriptionId);
}

@Override
public Optional<Object> createChild(IEditingContext editingContext, Object object, String childCreationDescriptionId, String descriptionId) {
return this.editService.createChild(editingContext, object, childCreationDescriptionId);
}
}
Expand Up @@ -18,7 +18,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;

import org.eclipse.emf.common.notify.AdapterFactory;
Expand All @@ -36,7 +35,6 @@
import org.eclipse.sirius.components.compatibility.forms.WidgetIdProvider;
import org.eclipse.sirius.components.compatibility.utils.StringValueProvider;
import org.eclipse.sirius.components.core.api.IEditService;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IFeedbackMessageService;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.emf.services.api.IEMFKindService;
Expand Down Expand Up @@ -135,7 +133,6 @@ public AbstractWidgetDescription caseReferenceWidgetDescription(ReferenceWidgetD
.itemRemoveHandlerProvider(variableManager -> this.handleItemRemove(variableManager, referenceDescription))
.setHandlerProvider(variableManager -> this.handleSetReference(variableManager, referenceDescription))
.addHandlerProvider(variableManager -> this.handleAddReference(variableManager, referenceDescription))
.createElementHandlerProvider(variableManager -> this.handleCreateElement(variableManager, referenceDescription)).styleProvider(styleProvider)
.moveHandlerProvider(variableManager -> this.handleMoveReferenceValue(variableManager, referenceDescription));

if (referenceDescription.getHelpExpression() != null && !referenceDescription.getHelpExpression().isBlank()) {
Expand Down Expand Up @@ -357,24 +354,6 @@ private IStatus handleAddReference(VariableManager variableManager, ReferenceWid
return result;
}

private Object handleCreateElement(VariableManager variableManager, ReferenceWidgetDescription referenceDescription) {
Optional<Object> result = Optional.empty();
Optional<Boolean> optionalIsChild = variableManager.get(ReferenceWidgetComponent.IS_CHILD_CREATION_VARIABLE, Boolean.class);
var optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
String creationDescriptionId = variableManager.get(ReferenceWidgetComponent.CREATION_DESCRIPTION_ID_VARIABLE, String.class).orElse("");
if (optionalIsChild.isPresent() && optionalEditingContext.isPresent()) {
if (optionalIsChild.get()) {
EObject parent = variableManager.get(ReferenceWidgetComponent.PARENT_VARIABLE, EObject.class).orElse(null);
result = this.editService.createChild(optionalEditingContext.get(), parent, creationDescriptionId);
} else {
UUID documentId = variableManager.get(ReferenceWidgetComponent.DOCUMENT_ID_VARIABLE, UUID.class).orElse(UUID.randomUUID());
String domainId = variableManager.get(ReferenceWidgetComponent.DOMAIN_ID_VARIABLE, String.class).orElse("");
result = this.editService.createRootObject(optionalEditingContext.get(), documentId, domainId, creationDescriptionId);
}
}
return result.orElse(null);
}

private IStatus handleMoveReferenceValue(VariableManager variableManager, ReferenceWidgetDescription referenceDescription) {
IStatus result = this.createErrorStatus("Something went wrong while reordering reference values.");
EObject owner = this.getReferenceOwner(variableManager, referenceDescription.getReferenceOwnerExpression());
Expand Down
Expand Up @@ -50,8 +50,6 @@
import org.eclipse.sirius.components.trees.description.TreeDescription;
import org.eclipse.sirius.components.trees.renderer.TreeRenderer;
import org.eclipse.sirius.components.widget.reference.IReferenceWidgetRootCandidateSearchProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
Expand All @@ -70,8 +68,6 @@ public class ModelBrowsersDescriptionProvider implements IRepresentationDescript

public static final String TREE_KIND = "modelBrowser://";

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

private final IObjectService objectService;

private final IURLParser urlParser;
Expand All @@ -80,11 +76,14 @@ public class ModelBrowsersDescriptionProvider implements IRepresentationDescript

private final List<IReferenceWidgetRootCandidateSearchProvider> candidateProviders;

public ModelBrowsersDescriptionProvider(IObjectService objectService, IURLParser urlParser, IEMFKindService emfKindService, List<IReferenceWidgetRootCandidateSearchProvider> candidateProviders) {
private final ReferenceWidgetDefaultCandidateSearchProvider defaultCandidateProvider;

public ModelBrowsersDescriptionProvider(IObjectService objectService, IURLParser urlParser, IEMFKindService emfKindService, List<IReferenceWidgetRootCandidateSearchProvider> candidateProviders, ReferenceWidgetDefaultCandidateSearchProvider defaultCandidateProvider) {
this.objectService = Objects.requireNonNull(objectService);
this.urlParser = Objects.requireNonNull(urlParser);
this.emfKindService = Objects.requireNonNull(emfKindService);
this.candidateProviders = Objects.requireNonNull(candidateProviders);
this.defaultCandidateProvider = Objects.requireNonNull(defaultCandidateProvider);
}

@Override
Expand Down Expand Up @@ -297,12 +296,9 @@ private List<? extends Object> getSearchScopeElements(VariableManager variableMa

return this.candidateProviders.stream()
.filter(provider -> provider.canHandle(descriptionId))
.map(provider -> provider.getRootElementsForReference(semanticOwner, descriptionId, optionalEditingContext.get()))
.findFirst()
.orElseGet(() -> {
this.logger.warn("Unable to find a proper implementation of IReferenceWidgetRootCandidateSeachProvider for widget {}", descriptionId);
return List.of();
});
.orElse(this.defaultCandidateProvider)
.getRootElementsForReference(semanticOwner, descriptionId, optionalEditingContext.get());
}
return Collections.emptyList();
}
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.springframework.stereotype.Service;

/**
*
* Default implementation of {@link IReferenceWidgetRootCandidateSearchProvider}.
* This implementation returns all root resources from the current model.
*
Expand All @@ -36,7 +35,7 @@ public class ReferenceWidgetDefaultCandidateSearchProvider implements IReference

@Override
public boolean canHandle(String descriptionId) {
return true;
return false; // Default implementation, it'll be used if no other service can handle the descriptionId
}

@Override
Expand Down
Expand Up @@ -21,6 +21,7 @@
*
* @author Jerome Gout
*/
public record CreateElementInput(UUID id, String editingContextId, String representationId, String referenceWidgetId, String containerId, String domainId, String creationDescriptionId) implements IFormInput {
public record CreateElementInput(UUID id, String editingContextId, String representationId, String referenceWidgetId, String containerId, String domainId,
String creationDescriptionId, String descriptionId) implements IFormInput {

}
Expand Up @@ -10,17 +10,17 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.widget.reference.dto;
package org.eclipse.sirius.components.collaborative.widget.reference.dto;

import java.util.UUID;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.components.core.api.IInput;

/**
* Input object to pass inputs to the createElementInReferenceHandler field of ReferenceWidget.
* Input object for the query to retrieve the child creation descriptions.
*
* @author Jerome Gout
* @author frouene
*/
public record CreateElementInReferenceHandlerParameters(UUID documentId, String domainId, EObject parent, String creationDescriptionId) {
public record ReferenceWidgetChildCreationDescriptionsInput(UUID id, String editingContextId, String kind, String referenceKind, String descriptionId) implements IInput {

}

0 comments on commit 9dde437

Please sign in to comment.