Skip to content

Commit

Permalink
[2080] Add an inital label value when editing tree items label
Browse files Browse the repository at this point in the history
Bug: #2080
Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
  • Loading branch information
mcharfadi committed Jun 20, 2023
1 parent 3bbe4bc commit 714359e
Show file tree
Hide file tree
Showing 26 changed files with 641 additions and 188 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Expand Up @@ -14,6 +14,10 @@

=== Breaking changes

- https://github.com/eclipse-sirius/sirius-components/issues/2080[#2080] [tree] EditingContextRepresentationDataFetcher will filter on IRepresentation unstead of ISemanticRepresentation to be able to support TreeDescription.
+
As such targetObjectId is removed from RepresentationMetadata.

=== Dependency update

- [releng] Switch to Jacoco 0.8.10
Expand All @@ -28,6 +32,7 @@
=== New Features

- https://github.com/eclipse-sirius/sirius-components/issues/2039[#2039] [project] A new "Blank Studio" project template is available to create a project with the "studio" nature but no initial content
- https://github.com/eclipse-sirius/sirius-components/issues/2080[#2080] [tree] Add an inital label value when editing tree items label.

=== Improvements

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 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
Expand Down Expand Up @@ -62,9 +62,9 @@ public class NavigationOperationHandlerTests {
private final IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp() {
@Override
public List<RepresentationMetadata> findAllByTargetObjectId(IEditingContext editingContext, String targetObjectId) {
var firstRepresentationMetadata = new RepresentationMetadata(FIRST_DIAGRAM_ID, Diagram.KIND, FIRST_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID, targetObjectId);
var secondRepresentationMetadata = new RepresentationMetadata(SECOND_DIAGRAM_ID, Diagram.KIND, SECOND_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID, targetObjectId);
var thirdRepresentationMetadata = new RepresentationMetadata(THIRD_DIAGRAM_ID, Diagram.KIND, THIRD_DIAGRAM_LABEL, SECOND_DIAGRAM_DESCRIPTION_ID, targetObjectId);
var firstRepresentationMetadata = new RepresentationMetadata(FIRST_DIAGRAM_ID, Diagram.KIND, FIRST_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID);
var secondRepresentationMetadata = new RepresentationMetadata(SECOND_DIAGRAM_ID, Diagram.KIND, SECOND_DIAGRAM_LABEL, FIRST_DIAGRAM_DESCRIPTION_ID);
var thirdRepresentationMetadata = new RepresentationMetadata(THIRD_DIAGRAM_ID, Diagram.KIND, THIRD_DIAGRAM_LABEL, SECOND_DIAGRAM_DESCRIPTION_ID);
return List.of(firstRepresentationMetadata, secondRepresentationMetadata, thirdRepresentationMetadata);
}
};
Expand Down
Expand Up @@ -20,8 +20,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import jakarta.annotation.PreDestroy;

import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorFactory;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
Expand All @@ -34,6 +32,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import jakarta.annotation.PreDestroy;
import reactor.core.Disposable;
import reactor.core.publisher.Mono;

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 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
Expand Down Expand Up @@ -29,14 +29,11 @@ public class RepresentationMetadata {

private final String descriptionId;

private final String targetObjectId;

public RepresentationMetadata(String id, String kind, String label, String descriptionId, String targetObjectId) {
public RepresentationMetadata(String id, String kind, String label, String descriptionId) {
this.id = Objects.requireNonNull(id);
this.kind = Objects.requireNonNull(kind);
this.label = Objects.requireNonNull(label);
this.descriptionId = Objects.requireNonNull(descriptionId);
this.targetObjectId = targetObjectId;
}

public String getId() {
Expand All @@ -55,13 +52,9 @@ public String getDescriptionId() {
return this.descriptionId;
}

public String getTargetObjectId() {
return this.targetObjectId;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, descriptionId: {4}, targetObjectId: {5}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.descriptionId, this.targetObjectId);
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, descriptionId: {4}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.descriptionId);
}
}
Expand Up @@ -15,16 +15,13 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.LocalContextConstants;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.eclipse.sirius.components.representations.ISemanticRepresentation;
import org.eclipse.sirius.web.services.api.representations.IRepresentationService;
import org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor;

Expand Down Expand Up @@ -66,22 +63,18 @@ public DataFetcherResult<RepresentationMetadata> get(DataFetchingEnvironment env

Map<String, Object> localContext = new HashMap<>(environment.getLocalContext());
localContext.put(LocalContextConstants.REPRESENTATION_ID, representationId);

// Search among the active representations first. They are already loaded in memory and include transient
// representations.
// @formatter:off
var representationMetadata = this.editingContextEventProcessorRegistry.getEditingContextEventProcessors().stream()
.flatMap(editingContextEventProcessor -> editingContextEventProcessor.getRepresentationEventProcessors().stream())
.filter(editingContextEventProcessor -> editingContextEventProcessor.getRepresentation().getId().equals(representationId))
.map(IRepresentationEventProcessor::getRepresentation)
.filter(ISemanticRepresentation.class::isInstance)
.map(ISemanticRepresentation.class::cast)
.map((ISemanticRepresentation representation) -> {
.map(representation -> {
return new RepresentationMetadata(representation.getId(),
representation.getKind(),
representation.getLabel(),
representation.getDescriptionId(),
representation.getTargetObjectId());
representation.getDescriptionId());
})
.findFirst();
// @formatter:on
Expand All @@ -90,7 +83,10 @@ public DataFetcherResult<RepresentationMetadata> get(DataFetchingEnvironment env
if (representationMetadata.isEmpty()) {
representationMetadata = this.representationService.getRepresentationDescriptorForProjectId(editingContextId, representationId)
.map(RepresentationDescriptor::getRepresentation)
.map(this::toRepresentationMetadata);
.map(representation -> new RepresentationMetadata(representation.getId(),
representation.getKind(),
representation.getLabel(),
representation.getDescriptionId()));
}

return DataFetcherResult.<RepresentationMetadata>newResult()
Expand All @@ -99,16 +95,4 @@ public DataFetcherResult<RepresentationMetadata> get(DataFetchingEnvironment env
.build();
// @formatter:on
}

private RepresentationMetadata toRepresentationMetadata(IRepresentation representation) {
// @formatter:off
String targetObjectId = Optional.of(representation)
.filter(ISemanticRepresentation.class::isInstance)
.map(ISemanticRepresentation.class::cast)
.map(ISemanticRepresentation::getTargetObjectId)
.orElse(null);
// @formatter:on
return new RepresentationMetadata(representation.getId(), representation.getKind(), representation.getLabel(), representation.getDescriptionId(), targetObjectId);
}

}
Expand Up @@ -15,13 +15,11 @@
import java.util.Base64;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.eclipse.sirius.components.representations.ISemanticRepresentation;
import org.eclipse.sirius.web.services.api.representations.IRepresentationService;
import org.eclipse.sirius.web.services.api.representations.RepresentationDescriptor;

Expand Down Expand Up @@ -90,14 +88,7 @@ public Connection<RepresentationMetadata> get(DataFetchingEnvironment environmen
}

private RepresentationMetadata toRepresentationMetadata(IRepresentation representation) {
// @formatter:off
String targetObjectId = Optional.of(representation)
.filter(ISemanticRepresentation.class::isInstance)
.map(ISemanticRepresentation.class::cast)
.map(ISemanticRepresentation::getTargetObjectId)
.orElse(null);
// @formatter:on
return new RepresentationMetadata(representation.getId(), representation.getKind(), representation.getLabel(), representation.getDescriptionId(), targetObjectId);
return new RepresentationMetadata(representation.getId(), representation.getKind(), representation.getLabel(), representation.getDescriptionId());
}

}
Expand Up @@ -24,12 +24,15 @@
import org.eclipse.sirius.components.collaborative.dto.GetRepresentationDescriptionInput;
import org.eclipse.sirius.components.collaborative.dto.GetRepresentationDescriptionPayload;
import org.eclipse.sirius.components.collaborative.forms.PropertiesEventProcessorFactory;
import org.eclipse.sirius.components.collaborative.trees.TreeEventProcessorFactory;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.forms.description.FormDescription;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.LocalContextConstants;
import org.eclipse.sirius.components.representations.Failure;
import org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
import org.eclipse.sirius.components.trees.description.TreeDescription;

import graphql.schema.DataFetchingEnvironment;
import reactor.core.publisher.Mono;
Expand All @@ -53,8 +56,28 @@ public class RepresentationMetadataDescriptionDataFetcher implements IDataFetche
.build();
// @formatter:on

// @formatter:off
private static final IRepresentationDescription FAKE_DETAILS_TREE = TreeDescription.newTreeDescription(TreeEventProcessorFactory.TREE_ID)
.label("Explorer")
.idProvider(new GetOrCreateRandomIdProvider())
.treeItemIdProvider(variableManager -> TreeEventProcessorFactory.TREE_ID)
.kindProvider(variableManager -> TreeEventProcessorFactory.TREE_ID)
.labelProvider(variableManager -> TreeEventProcessorFactory.TREE_ID)
.imageURLProvider(variableManager -> TreeEventProcessorFactory.TREE_ID)
.editableProvider(variableManager -> null)
.deletableProvider(variableManager -> null)
.elementsProvider(variableManager -> null)
.hasChildrenProvider(variableManager -> null)
.childrenProvider(variableManager -> null)
.canCreatePredicate(variableManager -> true)
.deleteHandler(variableManager -> null)
.renameHandler((variableManager, newValue) -> new Failure(""))
.build();
// @formatter:on

private final IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry;


public RepresentationMetadataDescriptionDataFetcher(IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry) {
this.editingContextEventProcessorRegistry = Objects.requireNonNull(editingContextEventProcessorRegistry);
}
Expand All @@ -64,23 +87,27 @@ public CompletableFuture<IRepresentationDescription> get(DataFetchingEnvironment
CompletableFuture<IRepresentationDescription> result = Mono.<IRepresentationDescription>empty().toFuture();

RepresentationMetadata representationMetadata = environment.getSource();
if (Objects.equals(PropertiesEventProcessorFactory.DETAILS_VIEW_ID, representationMetadata.getDescriptionId())) {
if (Objects.equals(PropertiesEventProcessorFactory.DETAILS_VIEW_ID, representationMetadata.getDescriptionId()) || (Objects.equals(TreeEventProcessorFactory.TREE_ID, representationMetadata.getDescriptionId()))) {
/*
* The FormDescription used for the details view can not be found by
* IRepresentationDescriptionSearchService, but we can get away by returning a fake one with the same id as
* no GraphQL query actually needs to see its content. We need to return *something* with the correct id
* The FormDescription used for the details view and the TreeDescription used for the explorer can not be found by
* IRepresentationDescriptionSearchService. We can get away by returning fake ones with the same ids as
* no GraphQL query actually needs to see their content. We need to return *something* with the correct ids
* only to allow GraphQL resolution to continue on queries like "completionProposals" defined on
* FormDescription.
*/
result = Mono.just(FAKE_DETAILS_DESCRIPTION).toFuture();
if (Objects.equals(PropertiesEventProcessorFactory.DETAILS_VIEW_ID, representationMetadata.getDescriptionId())) {
result = Mono.just(FAKE_DETAILS_DESCRIPTION).toFuture();
}
if (Objects.equals(TreeEventProcessorFactory.TREE_ID, representationMetadata.getDescriptionId())) {
result = Mono.just(FAKE_DETAILS_TREE).toFuture();
}
} else {
Map<String, Object> localContext = environment.getLocalContext();

String editingContextId = Optional.ofNullable(localContext.get(LocalContextConstants.EDITING_CONTEXT_ID)).map(Object::toString).orElse(null);
String representationId = Optional.ofNullable(localContext.get(LocalContextConstants.REPRESENTATION_ID)).map(Object::toString).orElse(null);
if (editingContextId != null && representationId != null) {
GetRepresentationDescriptionInput input = new GetRepresentationDescriptionInput(UUID.randomUUID(), editingContextId, representationId);

// @formatter:off
result = this.editingContextEventProcessorRegistry.dispatchEvent(input.editingContextId(), input)
.filter(GetRepresentationDescriptionPayload.class::isInstance)
Expand Down
Expand Up @@ -19,12 +19,14 @@
import fr.obeo.dsl.designer.sample.flow.FlowFactory;
import fr.obeo.dsl.designer.sample.flow.Processor;
import fr.obeo.dsl.designer.sample.flow.System;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService;
Expand Down Expand Up @@ -133,7 +135,7 @@ private Optional<RepresentationMetadata> initializeFlowProject(IEditingContext e
Diagram diagram = this.diagramCreationService.create(topographyDiagram.getLabel(), semanticTarget, topographyDiagram, editingContext);
this.representationPersistenceService.save(editingContext, diagram);

result = Optional.of(new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId(), diagram.getTargetObjectId()));
result = Optional.of(new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId()));
}
} catch (IOException exception) {
this.logger.warn(exception.getMessage(), exception);
Expand Down
Expand Up @@ -159,7 +159,7 @@ private Optional<RepresentationMetadata> initializeStudioProject(IEditingContext
Diagram diagram = this.diagramCreationService.create(topographyDiagram.getLabel(), semanticTarget, topographyDiagram, editingContext);
this.representationPersistenceService.save(editingContext, diagram);

result = Optional.of(new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId(), diagram.getTargetObjectId()));
result = Optional.of(new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId()));
}
} catch (IOException exception) {
this.logger.warn(exception.getMessage(), exception);
Expand Down
Expand Up @@ -133,7 +133,7 @@ private Optional<RepresentationMetadata> initializeStudioProject(IEditingContext
Diagram diagram = this.diagramCreationService.create(topographyDiagram.getLabel(), semanticTarget, topographyDiagram, editingContext);
this.representationPersistenceService.save(editingContext, diagram);

result = Optional.of(new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId(), diagram.getTargetObjectId()));
result = Optional.of(new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId()));
}
} catch (IOException exception) {
this.logger.warn(exception.getMessage(), exception);
Expand Down

0 comments on commit 714359e

Please sign in to comment.