Skip to content

Commit

Permalink
[3763] Split the SelectionDialogDescription to prepare the Tree support
Browse files Browse the repository at this point in the history
The SelectionDialogDescription will now just hold the message
information
The SelectionDialogDescription will now have a
selectionDialogTreeDescription to make it possible for the specifier to
display the selectable elements as a tree.
The selectionDialogTreeDescription will be relatively simple at first
time.

Bug: #3763
Signed-off-by: Florian Barbin <[email protected]>
  • Loading branch information
florianbarbin committed Aug 20, 2024
1 parent dd9b41e commit dd123a8
Show file tree
Hide file tree
Showing 29 changed files with 2,080 additions and 622 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3557[#3550] [sirius-web] Add an extension point to contribute setting pages
- 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/3763[#3763] [diagram] Split the SelectionDialogDescription to prepare the Tree support


== v2024.7.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2024 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.web.application.editingcontext.migration.participants;

import com.google.gson.JsonObject;

import java.util.Optional;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.components.emf.migration.api.IMigrationParticipant;
import org.eclipse.sirius.components.view.builder.generated.SelectionDialogTreeDescriptionBuilder;
import org.eclipse.sirius.components.view.diagram.SelectionDialogDescription;
import org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription;
import org.springframework.stereotype.Service;

/**
* MigrationParticipant that create a new SelectionDialogTreeDescription in the SelectionDialogDescription to replace the former SelectionDialogDescription#selectionCandidatesExpression.
* SelectionDialogDescription#selectionCandidatesExpression value is moved toward SelectionDialogDescription#selectionDialogTreeDescription#elementsExpression
*
* @author fbarbin
*/
@Service
public class SelectionDialogDescriptionSelectionCandidatesExpressionMigrationParticipant implements IMigrationParticipant {

private static final String PARTICIPANT_VERSION = "2024.9.0-202408121400";

@Override
public String getVersion() {
return PARTICIPANT_VERSION;
}

@Override
public void postObjectLoading(EObject eObject, JsonObject jsonObject) {
if (eObject instanceof SelectionDialogDescription selectionDialogDescription) {
var optionalSelectionDialogDescriptionData = Optional.ofNullable(jsonObject.getAsJsonObject("data"));
optionalSelectionDialogDescriptionData.ifPresent(selectionDialogDescriptionData -> {
var optionalSelectionCandidatesExpression = Optional.ofNullable(selectionDialogDescriptionData.get("selectionCandidatesExpression"));
optionalSelectionCandidatesExpression.ifPresent(selectionCandidatesExpression -> {
SelectionDialogTreeDescription selectionDialogTreeDescription = new SelectionDialogTreeDescriptionBuilder()
.elementsExpression(selectionCandidatesExpression.getAsString())
.build();
selectionDialogDescription.setSelectionDialogTreeDescription(selectionDialogTreeDescription);
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public final class MigrationIdentifiers {

public static final String MIGRATION_NODE_LABEL_STYLE_SHOW_ICON_STUDIO_DIAGRAM = "NodeLabelStyle#showIcon migration";

public static final UUID MIGRATION_SELECTION_DIALOG_DESCRIPTION_SELECTION_CANDIDATES_EXPRESSION_STUDIO = UUID.fromString("19d73d38-3de2-4d03-a8f1-ce36c2ed36db");

public static final String MIGRATION_SELECTION_DIALOG_DESCRIPTION_SELECTION_CANDIDATES_EXPRESSION_STUDIO_DIAGRAM = "SelectionDialogDescription#selectionCandidatesExpression migration";



private MigrationIdentifiers() {
// Prevent instantiation
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.sirius.components.emf.services.IDAdapter;
import org.eclipse.sirius.components.emf.services.JSONResourceFactory;
import org.eclipse.sirius.components.view.View;
import org.eclipse.sirius.components.view.builder.generated.SelectionDialogTreeDescriptionBuilder;
import org.eclipse.sirius.components.view.builder.generated.diagram.DiagramDescriptionBuilder;
import org.eclipse.sirius.components.view.builder.generated.diagram.DiagramPaletteBuilder;
import org.eclipse.sirius.components.view.builder.generated.diagram.InsideLabelDescriptionBuilder;
Expand All @@ -37,6 +38,7 @@
import org.eclipse.sirius.components.view.diagram.DiagramFactory;
import org.eclipse.sirius.components.view.diagram.InsideLabelPosition;
import org.eclipse.sirius.components.view.diagram.NodeTool;
import org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription;
import org.eclipse.sirius.components.view.diagram.SynchronizationPolicy;
import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider;
import org.eclipse.sirius.emfjson.resource.JsonResource;
Expand Down Expand Up @@ -193,9 +195,13 @@ private void createCreateNodeTool() {
}

private void createRenameElementNodeTool() {

SelectionDialogTreeDescription selectionDialogTreeDescription = new SelectionDialogTreeDescriptionBuilder()
.elementsExpression("aql:self.eResource().eAllContents()")
.build();
var selectionDialog = new SelectionDialogDescriptionBuilder()
.selectionCandidatesExpression("aql:self.eResource().eAllContents()")
.selectionMessage("Select a new element")
.selectionDialogTreeDescription(selectionDialogTreeDescription)
.build();

var setSelectedComponentName = new ViewBuilders().newSetValue()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2024 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.web.services.migration;

import static org.assertj.core.api.Assertions.assertThat;

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IEditingContextSearchService;
import org.eclipse.sirius.components.view.diagram.DiagramDescription;
import org.eclipse.sirius.components.view.diagram.SelectionDialogDescription;
import org.eclipse.sirius.web.AbstractIntegrationTests;
import org.eclipse.sirius.web.application.editingcontext.EditingContext;
import org.eclipse.sirius.web.data.MigrationIdentifiers;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.transaction.annotation.Transactional;

/**
* Integration tests of SelectionDialogDescriptionSelectionCandidatesExpressionMigrationParticipant.
*
* @author fbarbin
*/
@Transactional
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SelectionDialogDescriptionSelectionCandidatesExpressionMigrationParticipantTests extends AbstractIntegrationTests {

@Autowired
private IEditingContextSearchService editingContextSearchService;

@Test
@DisplayName("Given a project with an old model, SelectionDialogDescriptionSelectionCandidatesExpressionMigrationParticipant migrates the model correctly")
@Sql(scripts = { "/scripts/migration.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void givenAnOldModelMigrationParticipantCanBeContributedToUpdateTheModel() {
var optionalEditingContext = this.editingContextSearchService.findById(MigrationIdentifiers.MIGRATION_SELECTION_DIALOG_DESCRIPTION_SELECTION_CANDIDATES_EXPRESSION_STUDIO.toString());
assertThat(optionalEditingContext).isPresent();
this.testIsMigrationSuccessful(optionalEditingContext.get());
}

private void testIsMigrationSuccessful(IEditingContext editingContext) {
if (editingContext instanceof EditingContext siriusWebEditingContext) {
var optionalDiagramDescription = siriusWebEditingContext.getViews().stream().flatMap(view -> view.getDescriptions().stream()).filter(
representationDescription -> representationDescription.getName().equals(MigrationIdentifiers.MIGRATION_SELECTION_DIALOG_DESCRIPTION_SELECTION_CANDIDATES_EXPRESSION_STUDIO_DIAGRAM))
.findFirst();
assertThat(optionalDiagramDescription).isPresent();
assertThat(optionalDiagramDescription.get()).isInstanceOf(DiagramDescription.class);
optionalDiagramDescription.ifPresent(representationDescription -> {
if (representationDescription instanceof DiagramDescription diagramDescription) {
assertThat(diagramDescription.getPalette()).isNotNull();
var palette = diagramDescription.getPalette();
assertThat(palette.getNodeTools()).hasSize(1);
var nodeTool = palette.getNodeTools().get(0);
var dialogDescription = nodeTool.getDialogDescription();
assertThat(dialogDescription).isNotNull();
assertThat(dialogDescription).isInstanceOf(SelectionDialogDescription.class);
if (dialogDescription instanceof SelectionDialogDescription selectionDialogDescription) {
var selectionDialogTreeDescription = selectionDialogDescription.getSelectionDialogTreeDescription();
assertThat(selectionDialogTreeDescription).isNotNull();
assertThat(selectionDialogTreeDescription.getElementsExpression()).isEqualTo("aql:self.eContents()");
}
}
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,108 @@ INSERT INTO document (
'2024-07-18 15:00:0.000',
'2024-07-18 15:00:0.000'
);


INSERT INTO project (
id,
name,
created_on,
last_modified_on
) VALUES (
'19d73d38-3de2-4d03-a8f1-ce36c2ed36db',
'Migration SelectionDialogDescription#selectionCandidatesExpression Studio',
'2024-07-18 15:00:0.000',
'2024-07-18 15:00:0.000'
);
INSERT INTO nature (
project_id,
name
) VALUES (
'19d73d38-3de2-4d03-a8f1-ce36c2ed36db',
'siriusComponents://nature?kind=studio'
);
INSERT INTO semantic_data (
id,
project_id,
created_on,
last_modified_on
) VALUES (
'06d828d9-c2c6-46d0-a9c4-7fabd588755b',
'19d73d38-3de2-4d03-a8f1-ce36c2ed36db',
'2024-07-01 15:00:0.000',
'2024-07-01 15:00:0.000'
);
INSERT INTO semantic_data_domain (
semantic_data_id,
uri
) VALUES (
'06d828d9-c2c6-46d0-a9c4-7fabd588755b',
'http://www.eclipse.org/sirius-web/view'
);
INSERT INTO semantic_data_domain (
semantic_data_id,
uri
) VALUES (
'06d828d9-c2c6-46d0-a9c4-7fabd588755b',
'http://www.eclipse.org/sirius-web/diagram'
);
INSERT INTO document (
id,
semantic_data_id,
name,
content,
created_on,
last_modified_on
) VALUES (
'8652ae06-6754-4c46-aa4c-2c8db2c3b602',
'06d828d9-c2c6-46d0-a9c4-7fabd588755b',
'SelectionDialogDescription#selectionCandidatesExpression migration',
'{
"json": { "version": "1.0", "encoding": "utf-8" },
"ns": { "diagram": "http://www.eclipse.org/sirius-web/diagram", "view": "http://www.eclipse.org/sirius-web/view" },
"content": [
{
"id": "00deb638-5c32-4d94-983d-1d00517ac82f",
"eClass": "view:View",
"data": {
"descriptions": [
{
"id": "683b678c-6263-4d21-b25a-502661859198",
"eClass": "diagram:DiagramDescription",
"data": {
"name": "SelectionDialogDescription#selectionCandidatesExpression migration",
"domainType": "wilson::Root",
"titleExpression": "wilson diagram",
"palette": {
"id": "3e54cf6c-a1d0-4eaa-bfca-48fbb9a25695",
"eClass": "diagram:DiagramPalette",
"data": {
"nodeTools": [
{
"id": "b5b0dfc1-566c-48ae-9907-00f50a553dae",
"eClass": "diagram:NodeTool",
"data": {
"name": "Selection Tool",
"dialogDescription": {
"id": "6a4e7200-2040-46fb-89c3-9060f321ecf4",
"eClass": "diagram:SelectionDialogDescription",
"data": {
"selectionCandidatesExpression": "aql:self.eContents()",
"selectionMessage": "Select an element"
}
}
}
}
]
}
}
}
}
]
}
}
]
}',
'2024-07-18 15:00:0.000',
'2024-07-18 15:00:0.000'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 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.view.builder.generated;

/**
* Builder for SelectionDialogTreeDescriptionBuilder.
*
* @author BuilderGenerator
* @generated
*/
public class SelectionDialogTreeDescriptionBuilder {

/**
* Create instance org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription.
* @generated
*/
private org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription selectionDialogTreeDescription = org.eclipse.sirius.components.view.diagram.DiagramFactory.eINSTANCE.createSelectionDialogTreeDescription();

/**
* Return instance org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription.
* @generated
*/
protected org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription getSelectionDialogTreeDescription() {
return this.selectionDialogTreeDescription;
}

/**
* Return instance org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription.
* @generated
*/
public org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription build() {
return this.getSelectionDialogTreeDescription();
}

/**
* Setter for ElementsExpression.
*
* @generated
*/
public SelectionDialogTreeDescriptionBuilder elementsExpression(java.lang.String value) {
this.getSelectionDialogTreeDescription().setElementsExpression(value);
return this;
}

/**
* Setter for ChildrenExpression.
*
* @generated
*/
public SelectionDialogTreeDescriptionBuilder childrenExpression(java.lang.String value) {
this.getSelectionDialogTreeDescription().setChildrenExpression(value);
return this;
}

/**
* Setter for IsSelectableExpression.
*
* @generated
*/
public SelectionDialogTreeDescriptionBuilder isSelectableExpression(java.lang.String value) {
this.getSelectionDialogTreeDescription().setIsSelectableExpression(value);
return this;
}

}

Loading

0 comments on commit dd123a8

Please sign in to comment.