From 049f646eb8f8c5e00fe75ceca59063d4a9722e67 Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Mon, 25 Mar 2024 13:59:28 +0100 Subject: [PATCH] [333] Add migration participant to remove useless StringValueStyle The representations created before the previous commit, that fixes the unexpected creation of StringValueStyle, can contain some kind of "empty StringValueStyle". The goal of this commit is to remove them. This commit also adds tests to check migration effect. Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/333 --- .../META-INF/MANIFEST.MF | 4 +- .../org.eclipse.sirius.diagram.elk/plugin.xml | 4 + ...sStringValueStyleMigrationParticipant.java | 122 ++++++++++++++++++ .../doc/Release_Notes.html | 25 ++-- .../doc/Release_Notes.textile | 7 +- .../diagram/layout/SimpleELKLayoutTest.java | 36 +++++- 6 files changed, 182 insertions(+), 16 deletions(-) create mode 100644 plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/migration/EmptyJunctionPointsStringValueStyleMigrationParticipant.java diff --git a/plugins/org.eclipse.sirius.diagram.elk/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.diagram.elk/META-INF/MANIFEST.MF index 46fb1d2759..c63de7b8d5 100644 --- a/plugins/org.eclipse.sirius.diagram.elk/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.diagram.elk/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.emf.common.ui, org.eclipse.elk.alg.layered;bundle-version="0.9.0", org.eclipse.sirius.ext.base;bundle-version="7.4.3", - org.eclipse.elk.alg.rectpacking;bundle-version="0.9.0" + org.eclipse.elk.alg.rectpacking;bundle-version="0.9.0", + org.eclipse.sirius.ecore.extender;bundle-version="7.4.3" Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy Import-Package: com.google.common.collect;version="27.0.0", @@ -27,4 +28,5 @@ Import-Package: com.google.common.collect;version="27.0.0", Bundle-Vendor: %providerName Automatic-Module-Name: org.eclipse.sirius.diagram.elk Export-Package: org.eclipse.sirius.diagram.elk, + org.eclipse.sirius.diagram.elk.migration, org.eclipse.sirius.diagram.elk.migration.description diff --git a/plugins/org.eclipse.sirius.diagram.elk/plugin.xml b/plugins/org.eclipse.sirius.diagram.elk/plugin.xml index f562a7b36e..d4a9f08554 100644 --- a/plugins/org.eclipse.sirius.diagram.elk/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.elk/plugin.xml @@ -29,5 +29,9 @@ class="org.eclipse.sirius.diagram.elk.migration.description.ELK090MigrationParticipant" kind="VSM"> + + diff --git a/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/migration/EmptyJunctionPointsStringValueStyleMigrationParticipant.java b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/migration/EmptyJunctionPointsStringValueStyleMigrationParticipant.java new file mode 100644 index 0000000000..8204500752 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/migration/EmptyJunctionPointsStringValueStyleMigrationParticipant.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2024 Obeo + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.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.diagram.elk.migration; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.StringValueStyle; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.business.api.migration.AbstractRepresentationsFileMigrationParticipant; +import org.eclipse.sirius.business.api.query.DViewQuery; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.elk.GmfLayoutCommand; +import org.eclipse.sirius.diagram.ui.business.api.query.DDiagramGraphicalQuery; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.DView; +import org.osgi.framework.Version; + +/** + * + * This migration participant fixes the GMF edges that contain an empty "junctionPoints" StringValueStyle. These empty + * "junctionPoints" StringValueStyle were created due to a bug in ELK./Sirius integration. This migration participant + * simply removes the empty "junctionPoints" StringValueStyle. + * + * @author Laurent Redor + * + */ +public class EmptyJunctionPointsStringValueStyleMigrationParticipant extends AbstractRepresentationsFileMigrationParticipant { + + /** + * Migration version. + */ + public static final Version MIGRATION_VERSION = new Version("15.4.3.202406261640"); //$NON-NLS-1$ + + @Override + public Version getMigrationVersion() { + return MIGRATION_VERSION; + } + + /** + * Update the styles of this edge if it contains empty "junctionPoints" StringValueStyle. In this case, + * this style is removed. + * + * @param edge + * the GMF edge + */ + private void updateEdge(View edge) { + StringValueStyle stringValueStyle = (StringValueStyle) edge.getStyle(NotationPackage.Literals.STRING_VALUE_STYLE); + if (stringValueStyle != null && GmfLayoutCommand.JUNCTION_POINTS_STYLE_NAME.equals(stringValueStyle.getName()) && "()".equals(stringValueStyle.getStringValue())) { //$NON-NLS-1$ + edge.getStyles().remove(stringValueStyle); + } + } + + /** + * Update the GMF diagram to migrate all invalid edges. + * + * @param diagram + * the GMF diagram + */ + private void migrateDiagram(Diagram diagram) { + List edges = diagram.getEdges(); + edges.stream().forEach(edge -> updateEdge(edge)); + } + + /** + * This method returns the associated GMF diagram of a Sirius diagram. + * + * @param dDiagram + * the Sirius diagram + * @return the associated GMF diagram if present + */ + private Optional getGMFDiagram(DDiagram dDiagram) { + DDiagramGraphicalQuery query = new DDiagramGraphicalQuery(dDiagram); + return Optional.ofNullable(query.getAssociatedGMFDiagram().get()); + } + + /** + * This method returns all representations descriptors of a view. + * + * @param dView + * the Sirius viewpoint. + * @return java stream of all representation descriptors of the dView. + */ + private Stream getRepresentationsDescriptors(DView dView) { + return new DViewQuery(dView).getLoadedRepresentationsDescriptors().stream(); + } + + /** + * This method is overridden to fix file with inconsistent GMF edges, ie having an empty "junctionPoints" + * StringValueStyle. + */ + @Override + protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) { + if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) { // loadedVersion < MIGRATION_VERSION + // for each diagrams of each viewpoints + dAnalysis.getOwnedViews().stream() // + .flatMap(this::getRepresentationsDescriptors) // + .map(descriptor -> descriptor.getRepresentation()) // + .filter(representation -> representation instanceof DDiagram) // + .map(representation -> (DDiagram) representation) // + .map(this::getGMFDiagram) // + .flatMap(Optional::stream) // + .forEach(this::migrateDiagram); + } + } +} diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index cecdd74b02..eca03c53a4 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -218,6 +218,12 @@

Specifier-Visible Changes

Developer-Visible Changes

+

Migrations

+
    +
  • Added A migration participant, EmptyJunctionPointsStringValueStyleMigrationParticipant, has been added to fix the GMF edges that contain an empty “junctionPoints” StringValueStyle. These empty “junctionPoints” StringValueStyle were created due to a bug in ELK./Sirius integration. This migration participant simply removes the empty “junctionPoints” StringValueStyle. As reminder, this migration participant has been introduced in Sirius 7.4.3. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is + 15.4.3.202406261640. +
  • +

Changes in Sirius Desktop 7.4.2

User-Visible Changes

    @@ -227,10 +233,7 @@

    User-Visible Changes

Specifier-Visible Changes

Developer-Visible Changes

-

Migrations

-

- None. -

+

Migrations

Changes in Sirius Desktop 7.4.1

User-Visible Changes

    @@ -249,7 +252,7 @@

    Changes in Map<String, RGB> collectVsmAndDefaultColors(Session session).

-

Migrations

+

Migrations

  • Added The migration participant WorkspaceImageGMFBoundsMigrationParticipant has been updated to handle the missed case of the image style of nodes contained in a container (and not directly in diagram). As reminder, this migration participant has been introduced in Sirius 7.0.0. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is 15.4.1.202403191723. @@ -428,7 +431,7 @@

    Changes in

-

Migrations

+

Migrations

  • Added A migration participant has been added to migrate ELK options used in VSM. Some have been renamed and some others have been removed. You should carefully read the information logged during this migration and the ELK release notes to check if any manual adjustments need to be made. The corresponding version, stored in attribute version of description:Group of the odesign file, is @@ -677,7 +680,7 @@

    Changes in org.eclipse.sirius.properties.core.api.SiriusInputDescriptor.getOriginalSelections().

-

Migrations

+

Migrations

-

Migrations

+

Migrations

-

Migrations

+

Migrations

  • Added A migration participant has been added to set a changeId value for each DRepresentationDescriptor that did not have one. Some old models were missing the changeId attribute, which could lead to technical problems. The migration participant org.eclipse.sirius.diagram.ui.business.internal.migration.SetChangeIdMigrationParticipant sets a random changeId if it didn’t already exist. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is @@ -1158,7 +1161,7 @@

    Migrations

Changes in Sirius 6.5.1

Developer-Visible Changes

-

Migrations

+

Migrations

  • Modified The migration participant org.eclipse.sirius.diagram.ui.business.internal.migration.NoteShapeDefaultLabelAlignmentMigrationParticipant has been updated to repair Notes with a potential wrong vertical label alignment. This problem can occur since Sirius 6.3.2 used in a collaborative environment, Obeo Designer Team Edition or Team For Capella for example. The corresponding version, stored in the attribute version of viewpoint:DAnalysis of the aird file, is @@ -1298,7 +1301,7 @@

    Changes in org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper.getAbsoluteBoundsWithoutLabelsIn100Percent(GraphicalEditPart) has been added to get the rectangle bounds without taking labels into account. This is used, in particular, to compute the bendpoints of an edge when the source or the target of the edge is an edge.

-

Migrations

+

Migrations

  • Added A migration participant has been added to repair rectilinear edges containing only one bendpoint. Bracket edges are not relevant. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is 14.5.0.202104070943. diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index e0d3740ceb..3e0e58008e 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -14,6 +14,10 @@ h3. Specifier-Visible Changes h3. Developer-Visible Changes +h4. Migrations + +* Added A migration participant, EmptyJunctionPointsStringValueStyleMigrationParticipant, has been added to fix the GMF edges that contain an empty "junctionPoints" StringValueStyle. These empty "junctionPoints" StringValueStyle were created due to a bug in ELK./Sirius integration. This migration participant simply removes the empty "junctionPoints" StringValueStyle. As reminder, this migration participant has been introduced in Sirius 7.4.3. The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is _15.4.3.202406261640_. + h2(#sirius7.4.2). Changes in Sirius Desktop 7.4.2 h3. User-Visible Changes @@ -26,9 +30,6 @@ h3. Developer-Visible Changes h4. Migrations -_None_. - - h2(#sirius7.4.1). Changes in Sirius Desktop 7.4.1 h3. User-Visible Changes diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java index 54b5f5ec64..8457775646 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/layout/SimpleELKLayoutTest.java @@ -28,6 +28,7 @@ import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; @@ -62,12 +63,14 @@ import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.AnimatableScrollPane; import org.eclipse.gmf.runtime.notation.Bounds; import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.FontStyle; import org.eclipse.gmf.runtime.notation.LayoutConstraint; import org.eclipse.gmf.runtime.notation.Location; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.Routing; +import org.eclipse.gmf.runtime.notation.StringValueStyle; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.sirius.diagram.DDiagram; @@ -89,6 +92,8 @@ import org.eclipse.sirius.diagram.description.EnumLayoutOption; import org.eclipse.sirius.diagram.description.EnumLayoutValue; import org.eclipse.sirius.diagram.description.LayoutOptionTarget; +import org.eclipse.sirius.diagram.elk.GmfLayoutCommand; +import org.eclipse.sirius.diagram.elk.migration.EmptyJunctionPointsStringValueStyleMigrationParticipant; import org.eclipse.sirius.diagram.tools.api.preferences.SiriusDiagramPreferencesKeys; import org.eclipse.sirius.diagram.tools.internal.commands.PinElementsCommand; import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery; @@ -121,6 +126,7 @@ import org.eclipse.sirius.viewpoint.description.Group; import org.eclipse.sirius.viewpoint.description.RepresentationDescription; import org.eclipse.ui.IEditorPart; +import org.osgi.framework.Version; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -1888,6 +1894,18 @@ private void testArrangeAllResultForEdgesRoutingStyle(String diagramName, String checkRoutingStyle(edgeEditPartWithoutRightAngle, WRONG_ROUTING_AFTER_LAYOUT_MESSAGE, secondEdgeNameToCheck, afterLayoutExpectedEdgeRouting); } + /** + * Test that the data were not migrated on the repository. It allows to check the effect of the migration of + * EmptyJunctionPointsStringValueStyleMigrationParticipant in other tests. + */ + public void testMigrationIsNeededOnData() { + Version migrationVersion = new EmptyJunctionPointsStringValueStyleMigrationParticipant().getMigrationVersion(); + + // Check that the migration of the session resource is needed. + Version loadedVersion = checkRepresentationFileMigrationStatus(URI.createPlatformPluginURI("/" + TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_RESOURCE_NAME, true), true); + assertTrue("The migration must be required on test data.", migrationVersion.compareTo(loadedVersion) > 0); //$NON-NLS-1$ + } + private void checkRoutingStyle(AbstractDiagramEdgeEditPart edgeEditPart, String message, String edgeName, int expectedRoutingStyle) { String fullMessage = MessageFormat.format(message, edgeName); View notationView = edgeEditPart.getNotationView(); @@ -1915,8 +1933,24 @@ protected void openDiagram(String diagramName) { diagram = (DDiagram) getRepresentationsByName(diagramName).toArray()[0]; editorPart = (IDiagramWorkbenchPart) DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor()); TestsUtil.synchronizationWithUIThread(); + checkStringValueStyle(); + } + + protected void checkStringValueStyle() { + Diagram gmfDiag = getGmfDiagram(diagram); + if (gmfDiag != null) { + TreeIterator childIterator = gmfDiag.eAllContents(); + while (childIterator.hasNext()) { + EObject eObject = childIterator.next(); + if (eObject instanceof Edge edge) { + StringValueStyle stringValueStyle = (StringValueStyle) edge.getStyle(NotationPackage.Literals.STRING_VALUE_STYLE); + if (stringValueStyle != null && GmfLayoutCommand.JUNCTION_POINTS_STYLE_NAME.equals(stringValueStyle.getName()) && "()".equals(stringValueStyle.getStringValue())) { + fail("At least one edge contains an empty junctionPoints StringValueStyle."); + } + } + } + } } - /** * Check that the Note is moved or not moved with an arrange using ELK, according to the value of the preference * "Move unlinked notes during layout".