Skip to content

Commit

Permalink
[3794] Change showIcon by showIconExpression in Diagram View DSL
Browse files Browse the repository at this point in the history
Bug: #3794
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD authored and sbegaudeau committed Jul 19, 2024
1 parent 21e9f7a commit 790fec7
Show file tree
Hide file tree
Showing 27 changed files with 582 additions and 273 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The new implementation still uses URIs, but URIs now have the following pattern:
- https://github.com/eclipse-sirius/sirius-web/issues/3778[#3778] [diagram] Export `EdgeData` in `sirius-components-diagrams/src/index.ts`
- https://github.com/eclipse-sirius/sirius-web/issues/3755[#3755] [sirius-web] Move code related to Sirius Web form based views out of Sirius Components.
Thanks to this change, the various form based representations (details, related elements, representations, etc) can now have dedicated features such as specific inputs or additional payloads for their subscriptions.
- https://github.com/eclipse-sirius/sirius-web/issues/3794[#3794] [view] In diagram view DSL, _NodeLabelStyle#showIcon_ has been change to _NodeLabelStyle#showIconExpression_, allowing to dynamically change this style option depending on a condition evaluated at runtime.
A migration participant has been added to automatically keep compatible all diagram descriptions created before 2024.9.0.


== v2024.7.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* 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.diagram.NodeLabelStyle;
import org.springframework.stereotype.Service;

/**
* MigrationParticipant that update the showIcon (to ShowIconExpression) of NodeLabelStyle.
*
* @author arichard
*/
@Service
public class NodeLabelStyleShowIconMigrationParticipant implements IMigrationParticipant {

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

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

@Override
public void postObjectLoading(EObject eObject, JsonObject jsonObject) {
if (eObject instanceof NodeLabelStyle nodeLabelStyle) {
var optionalNodeLabelStyle = Optional.ofNullable(jsonObject.getAsJsonObject("data"));
optionalNodeLabelStyle.ifPresent(nodeLabelStyleData -> {
var optionalShowIcon = Optional.ofNullable(nodeLabelStyleData.get("showIcon"));
optionalShowIcon.ifPresent(showIcon -> {
nodeLabelStyle.setShowIconExpression("aql:" + showIcon);
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private InsideLabelDescription entityNodeLabelDescription() {
var insideLabelStyle = new DiagramBuilders()
.newInsideLabelStyle()
.labelColor(this.colorProvider.getColor(DomainDiagramDescriptionProvider.BLACK_COLOR))
.showIcon(true)
.showIconExpression("aql:true")
.withHeader(true)
.displayHeaderSeparator(true)
.borderSize(0)
Expand All @@ -306,7 +306,7 @@ private InsideLabelDescription entityNodeLabelDescription() {
var abstractEntityLabelStyle = new DiagramBuilders()
.newInsideLabelStyle()
.labelColor(this.colorProvider.getColor(DomainDiagramDescriptionProvider.BLACK_COLOR))
.showIcon(true)
.showIconExpression("aql:true")
.withHeader(true)
.displayHeaderSeparator(true)
.italic(true)
Expand Down Expand Up @@ -360,15 +360,15 @@ private InsideLabelDescription attributeNodeLabelDescription() {
.newInsideLabelStyle()
.fontSize(12)
.labelColor(this.colorProvider.getColor(DomainDiagramDescriptionProvider.GREY_COLOR))
.showIcon(true)
.showIconExpression("aql:true")
.borderSize(0)
.build();

var requiredAttributeLabelStyle = new DiagramBuilders()
.newInsideLabelStyle()
.fontSize(12)
.labelColor(this.colorProvider.getColor(DomainDiagramDescriptionProvider.GREY_COLOR))
.showIcon(true)
.showIconExpression("aql:true")
.bold(true)
.borderSize(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ClassNodeDescriptionProvider(IColorProvider colorProvider) {
@Override
public NodeDescription create() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.displayHeaderSeparator(true)
.withHeader(true)
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
Expand Down Expand Up @@ -137,7 +137,7 @@ private NodeDescription constructorsNodeDescription() {

private NodeDescription constructorNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down Expand Up @@ -167,7 +167,7 @@ private NodeDescription constructorNodeDescription() {

private NodeDescription attributesNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(false)
.showIconExpression("aql:false")
.withHeader(true)
.displayHeaderSeparator(false)
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
Expand Down Expand Up @@ -208,7 +208,8 @@ private NodeDescription attributesNodeDescription() {

private NodeDescription attributeNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")

.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down Expand Up @@ -238,7 +239,7 @@ private NodeDescription attributeNodeDescription() {

private NodeDescription operationsNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(false)
.showIconExpression("aql:false")
.withHeader(true)
.displayHeaderSeparator(false)
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
Expand Down Expand Up @@ -279,7 +280,7 @@ private NodeDescription operationsNodeDescription() {

private NodeDescription operationNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public EnumNodeDescriptionProvider(IColorProvider colorProvider) {
@Override
public NodeDescription create() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.displayHeaderSeparator(true)
.withHeader(true)
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
Expand Down Expand Up @@ -84,7 +84,7 @@ public NodeDescription create() {

private NodeDescription enumLiteralNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public InterfaceNodeDescriptionProvider(IColorProvider colorProvider) {
@Override
public NodeDescription create() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.displayHeaderSeparator(true)
.withHeader(true)
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
Expand Down Expand Up @@ -87,7 +87,7 @@ public NodeDescription create() {

private NodeDescription operationNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RecordNodeDescriptionProvider(IColorProvider colorProvider) {
@Override
public NodeDescription create() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.displayHeaderSeparator(true)
.withHeader(true)
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
Expand Down Expand Up @@ -84,7 +84,7 @@ public NodeDescription create() {

private NodeDescription recordComponentNodeDescription() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ComponentNodeDescriptionProvider(IColorProvider colorProvider) {
@Override
public NodeDescription create() {
var insideLabelStyle = new DiagramBuilders().newInsideLabelStyle()
.showIcon(true)
.showIconExpression("aql:true")
.labelColor(this.colorProvider.getColor(PapayaColorPaletteProvider.PALETTE_TEXT_PRIMARY))
.borderSize(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public final class MigrationIdentifiers {

public static final String MIGRATION_DIAGRAM_LABEL_STYLE_BORDER_SIZE_STUDIO_DIAGRAM = "DiagramLabelStyle#borderSize migration";

public static final UUID MIGRATION_NODE_LABEL_STYLE_SHOW_ICON_STUDIO = UUID.fromString("8e4dc281-b458-4354-b2c8-a03b426b6966");

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

private MigrationIdentifiers() {
// Prevent instantiation
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* 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.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 NodeLabelStyleShowIconMigrationParticipant.
*
* @author arichard
*/
@Transactional
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class NodeLabelStyleShowIconMigrationParticipantTests extends AbstractIntegrationTests {

@Autowired
private IEditingContextSearchService editingContextSearchService;

@Test
@DisplayName("Given a project with an old model, NodeLabelStyleShowIconMigrationParticipant 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_NODE_LABEL_STYLE_SHOW_ICON_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_NODE_LABEL_STYLE_SHOW_ICON_STUDIO_DIAGRAM)).findFirst();
assertThat(optionalDiagramDescription).isPresent();
assertThat(optionalDiagramDescription.get()).isInstanceOf(DiagramDescription.class);
optionalDiagramDescription.ifPresent(representationDescription -> {
if (representationDescription instanceof DiagramDescription diagramDescription) {
assertThat(diagramDescription.getNodeDescriptions()).hasSize(2);
var nodeDescriptionShowIconTrue = diagramDescription.getNodeDescriptions().get(0);
assertThat(nodeDescriptionShowIconTrue.getInsideLabel().getStyle().getShowIconExpression()).isEqualTo("aql:true");
var nodeDescriptionShowIconNoValue = diagramDescription.getNodeDescriptions().get(1);
assertThat(nodeDescriptionShowIconNoValue.getInsideLabel().getStyle().getShowIconExpression()).isEqualTo(null);
}
});
}
}

}
Loading

0 comments on commit 790fec7

Please sign in to comment.