diff options
| author | Florian Barbin | 2015-09-17 08:40:50 +0000 |
|---|---|---|
| committer | Florian Barbin | 2015-09-22 11:51:32 +0000 |
| commit | 9d04caf38d968cb3c0b742c717277344bc44b041 (patch) | |
| tree | 2832066de8908ee57d53bd51abd060dc48b85708 | |
| parent | e42e4f67bfb5842ebb8931827009a81a74a78473 (diff) | |
| download | org.eclipse.sirius-9d04caf38d968cb3c0b742c717277344bc44b041.tar.gz org.eclipse.sirius-9d04caf38d968cb3c0b742c717277344bc44b041.tar.xz org.eclipse.sirius-9d04caf38d968cb3c0b742c717277344bc44b041.zip | |
[477191] Adds a migration participant the retrieve the GMF font format.
* Since bug 424422, all the font format are set in the Sirius model. But
existing underline and strike-through properties that was in the GMF
model are not set in the Sirius model after the migration. The end user
don't see those properties anymore. This commit adds a new migration to
perform this task.
Bug: 477191
Change-Id: Idb9d09f8db6389827c96c6f0c3c2f0aaebc1d51c
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
4 files changed, 135 insertions, 5 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/plugin.xml b/plugins/org.eclipse.sirius.diagram/plugin.xml index 554ddd7579..78bde40ee5 100644 --- a/plugins/org.eclipse.sirius.diagram/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram/plugin.xml @@ -724,6 +724,10 @@ class="org.eclipse.sirius.diagram.business.internal.migration.ComputedStyleDescriptionCachePackingFileMigrationParticipant" kind="RepresentationsFile"> </participant> + <participant + class="org.eclipse.sirius.diagram.business.internal.migration.GMFLabelStyleMigrationParticipant" + kind="RepresentationsFile"> + </participant> </extension> <extension point="org.eclipse.sirius.mmdescriptor"> diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/GMFLabelStyleMigrationParticipant.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/GMFLabelStyleMigrationParticipant.java new file mode 100644 index 0000000000..9499a9ae64 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/migration/GMFLabelStyleMigrationParticipant.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2015 THALES GLOBAL SERVICES. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.business.internal.migration; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.FontStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.Style; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.business.api.metamodel.helper.FontFormatHelper; +import org.eclipse.sirius.business.api.migration.AbstractRepresentationsFileMigrationParticipant; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.business.api.refresh.DiagramCreationUtil; +import org.eclipse.sirius.viewpoint.BasicLabelStyle; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.DView; +import org.eclipse.sirius.viewpoint.FontFormat; +import org.eclipse.sirius.viewpoint.ViewpointPackage; +import org.osgi.framework.Version; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; +import com.google.common.collect.UnmodifiableIterator; + +/** + * A migration participant following the bug #477191.<br /> + * This migration participant copies the GMF underline and strike-through + * properties toward the Sirius style. + * + * @author Florian Barbin + * + */ +public class GMFLabelStyleMigrationParticipant extends AbstractRepresentationsFileMigrationParticipant { + private static final Version MIGRATION_VERSION = new Version("10.1.0.201509162000"); //$NON-NLS-1$ + + @Override + public Version getMigrationVersion() { + return MIGRATION_VERSION; + } + + @Override + protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) { + if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) { + for (DView dView : dAnalysis.getOwnedViews()) { + for (DDiagram dDiagram : Iterables.filter(dView.getOwnedRepresentations(), DDiagram.class)) { + DiagramCreationUtil diagramCreationUtil = new DiagramCreationUtil(dDiagram); + if (diagramCreationUtil.findAssociatedGMFDiagram()) { + Diagram gmfDiagram = diagramCreationUtil.getAssociatedGMFDiagram(); + addFontFormatsFromGMFStyle(gmfDiagram); + } + } + } + super.postLoad(dAnalysis, loadedVersion); + } + } + + private void addFontFormatsFromGMFStyle(Diagram gmfDiagram) { + UnmodifiableIterator<View> iterator = Iterators.filter(gmfDiagram.eAllContents(), View.class); + while (iterator.hasNext()) { + View view = iterator.next(); + EObject element = view.getElement(); + if (element instanceof DDiagramElement) { + org.eclipse.sirius.viewpoint.Style siriusStyle = ((DDiagramElement) element).getStyle(); + Style style = view.getStyle(NotationPackage.eINSTANCE.getFontStyle()); + if (style instanceof FontStyle && siriusStyle instanceof BasicLabelStyle) { + Set<FontFormat> fontFormatToSet = new HashSet<FontFormat>(((BasicLabelStyle) siriusStyle).getLabelFormat()); + int initialSize = fontFormatToSet.size(); + if (((FontStyle) style).isStrikeThrough()) { + fontFormatToSet.add(FontFormat.STRIKE_THROUGH_LITERAL); + } + if (((FontStyle) style).isUnderline()) { + fontFormatToSet.add(FontFormat.UNDERLINE_LITERAL); + } + if (initialSize != fontFormatToSet.size()) { + FontFormatHelper.setFontFormat(((BasicLabelStyle) siriusStyle).getLabelFormat(), fontFormatToSet); + + // If the GMF underline and/or strike-through were set + // to true, that means the user customized those + // features. That was not set in the customFeatures list + // since it was not handled by Sirius. + String labelFormatFeatureName = ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT.getName(); + if (!((BasicLabelStyle) siriusStyle).getCustomFeatures().contains(labelFormatFeatureName)) { + ((BasicLabelStyle) siriusStyle).getCustomFeatures().add(labelFormatFeatureName); + } + } + } + } + } + } +} diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/repair/customizations/VP-3643.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/repair/customizations/VP-3643.aird index a7c195587a..a3dc3d0caf 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/unit/repair/customizations/VP-3643.aird +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/repair/customizations/VP-3643.aird @@ -11,7 +11,7 @@ <styles xmi:type="notation:SortingStyle" xmi:id="_72pFkSzdEeKO1tOqDmd78A"/> <styles xmi:type="notation:FilteringStyle" xmi:id="_72pFkizdEeKO1tOqDmd78A"/> </children> - <styles xmi:type="notation:ShapeStyle" xmi:id="_72k0ISzdEeKO1tOqDmd78A" fontName="Ubuntu" fontHeight="8" bold="true" italic="true" fillColor="10011046"/> + <styles xmi:type="notation:ShapeStyle" xmi:id="_72k0ISzdEeKO1tOqDmd78A" fontColor="15053796" fontName="Ubuntu" fontHeight="8" bold="true" italic="true" underline="true" strikeThrough="true" fillColor="10011046"/> <layoutConstraint xmi:type="notation:Bounds" xmi:id="_72k0IizdEeKO1tOqDmd78A" x="35" y="130"/> </children> <children xmi:type="notation:Node" xmi:id="_u9FxcC2nEeKG1qVh92N5RA" type="2002" element="_ukjVoC2nEeKG1qVh92N5RA"> @@ -23,7 +23,7 @@ <styles xmi:type="notation:SortingStyle" xmi:id="_1-taES2nEeKG1qVh92N5RA"/> <styles xmi:type="notation:FilteringStyle" xmi:id="_1-taEi2nEeKG1qVh92N5RA"/> </children> - <styles xmi:type="notation:ShapeStyle" xmi:id="_1-nTcS2nEeKG1qVh92N5RA" fontName="Ubuntu" fontHeight="8"/> + <styles xmi:type="notation:ShapeStyle" xmi:id="_1-nTcS2nEeKG1qVh92N5RA" fontName="Ubuntu" fontHeight="8" underline="true" strikeThrough="true"/> <layoutConstraint xmi:type="notation:Bounds" xmi:id="_1-nTci2nEeKG1qVh92N5RA" x="62" y="35"/> </children> <styles xmi:type="notation:SortingStyle" xmi:id="_u9YFUS2nEeKG1qVh92N5RA"/> @@ -66,7 +66,8 @@ <arrangeConstraints>KEEP_RATIO</arrangeConstraints> <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_70l3ICzdEeKO1tOqDmd78A" labelFormat="bold_italic" backgroundStyle="GradientTopToBottom"> <customFeatures>labelFormat</customFeatures> - <labelColor xmi:type="viewpoint:RGBValues" xmi:id="_70l3ISzdEeKO1tOqDmd78A"/> + <customFeatures>labelColor</customFeatures> + <labelColor xmi:type="viewpoint:RGBValues" xmi:id="_70l3ISzdEeKO1tOqDmd78A" red="228" green="179" blue="229"/> <description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@style"/> <borderColor xmi:type="viewpoint:RGBValues" xmi:id="_70l3IizdEeKO1tOqDmd78A"/> <foregroundColor xmi:type="viewpoint:RGBValues" xmi:id="_3Qxe4C2nEeKG1qVh92N5RA" red="166" green="193" blue="152"/> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepairOnStyleCustomizationsTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepairOnStyleCustomizationsTest.java index aac1472f60..6c527114f0 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepairOnStyleCustomizationsTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepairOnStyleCustomizationsTest.java @@ -40,6 +40,10 @@ import org.eclipse.sirius.viewpoint.RGBValues; import org.eclipse.sirius.viewpoint.ViewpointPackage; import org.eclipse.sirius.viewpoint.description.SystemColor; import org.eclipse.ui.IEditorPart; +import org.osgi.framework.Version; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; /** * Test that the repair process restore only customizations and leave the @@ -91,6 +95,9 @@ public class RepairOnStyleCustomizationsTest extends AbstractRepairMigrateTest { @SuppressWarnings("unchecked") private void testRepairOnStyleCustomizations(boolean unsynchronized) throws Exception { + // Check that the representation file migration is needed. + Version loadedVersion = checkRepresentationFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + "/" + PATH + REPRESENTATIONS_RESOURCE_NAME, true), true); + assertTrue("The test case has been migrated but should be in 8.0.0 version", Version.parseVersion("8.0.0").compareTo(loadedVersion) == 0); URI representationsResourceURI = URI.createPlatformResourceURI("/" + TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_RESOURCE_NAME, true); if (unsynchronized) { @@ -109,16 +116,19 @@ public class RepairOnStyleCustomizationsTest extends AbstractRepairMigrateTest { DDiagramElement dDiagramElementOfEPackage = getDiagramElementsFromLabel(dDiagram, "newPackage1").get(0); DDiagramElement dDiagramElementOfEPackageWithWorkspaceImage = getDiagramElementsFromLabel(dDiagram, "newPackage2").get(0); DDiagramElement dDiagramElementOfEClass = getDiagramElementsFromLabel(dDiagram, "NewEClass1").get(0); + DDiagramElement dDiagramElementOfEClass2 = getDiagramElementsFromLabel(dDiagram, "NewEClass2").get(0); DDiagramElement dDiagramElementOfEReference = getDiagramElementsFromLabel(dDiagram, "[0..1] newEReference1").get(0); assertTrue(dDiagramElementOfEPackage instanceof DNodeContainer); assertTrue(dDiagramElementOfEPackageWithWorkspaceImage instanceof DNodeContainer); assertTrue(dDiagramElementOfEClass instanceof DNodeList); + assertTrue(dDiagramElementOfEClass2 instanceof DNodeList); assertTrue(dDiagramElementOfEReference instanceof DEdge); DNodeContainer dNodeContainerOfEPackage = (DNodeContainer) dDiagramElementOfEPackage; DNodeContainer dNodeContainerOfEPackageWithWorkspaceImage = (DNodeContainer) dDiagramElementOfEPackageWithWorkspaceImage; DNodeList dNodeListOfEClass = (DNodeList) dDiagramElementOfEClass; + DNodeList dNodeListOfEClass2 = (DNodeList) dDiagramElementOfEClass2; DEdge dEdgeOfEReference = (DEdge) dDiagramElementOfEReference; RGBValuesProvider rgbValuesProvider = new RGBValuesProvider(); @@ -142,15 +152,27 @@ public class RepairOnStyleCustomizationsTest extends AbstractRepairMigrateTest { assertEquals(assertMessage, foregroundColorRGBValuesFromDescriptionForEPackage.getGreen(), ((FlatContainerStyle) dNodeContainerOfEPackage.getStyle()).getForegroundColor().getGreen()); assertEquals(assertMessage, foregroundColorRGBValuesFromDescriptionForEPackage.getBlue(), ((FlatContainerStyle) dNodeContainerOfEPackage.getStyle()).getForegroundColor().getBlue()); - assertMessage = "After a repair the Style.customFeatures should be unchanged"; + assertMessage = "After a migration and a repair the Style.customFeatures should be unchanged"; EAttribute labelFormatFeature = ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT; assertEquals(assertMessage, Collections.emptyList(), dEdgeOfEReference.getOwnedStyle().getCustomFeatures()); assertEquals(assertMessage, Collections.singletonList(labelFormatFeature.getName()), dEdgeOfEReference.getOwnedStyle().getCenterLabelStyle().getCustomFeatures()); assertEquals(assertMessage, FontFormat.BOLD_LITERAL, ((List<FontFormat>) dEdgeOfEReference.getOwnedStyle().getCenterLabelStyle().eGet(labelFormatFeature)).get(1)); assertEquals(assertMessage, FontFormat.ITALIC_LITERAL, ((List<FontFormat>) dEdgeOfEReference.getOwnedStyle().getCenterLabelStyle().eGet(labelFormatFeature)).get(0)); - assertEquals(assertMessage, Collections.singletonList(labelFormatFeature.getName()), dNodeListOfEClass.getStyle().getCustomFeatures()); + List<String> expectedDnodeListCustomFeatures = Lists.newArrayList(); + expectedDnodeListCustomFeatures.add(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_COLOR.getName()); + expectedDnodeListCustomFeatures.add(labelFormatFeature.getName()); + assertEquals(assertMessage, Sets.newHashSet(expectedDnodeListCustomFeatures), Sets.newHashSet(dNodeListOfEClass.getStyle().getCustomFeatures())); + assertEquals(assertMessage, 4, ((List<FontFormat>) dNodeListOfEClass.getStyle().eGet(labelFormatFeature)).size()); + assertEquals(assertMessage, FontFormat.STRIKE_THROUGH_LITERAL, ((List<FontFormat>) dNodeListOfEClass.getStyle().eGet(labelFormatFeature)).get(3)); + assertEquals(assertMessage, FontFormat.UNDERLINE_LITERAL, ((List<FontFormat>) dNodeListOfEClass.getStyle().eGet(labelFormatFeature)).get(2)); assertEquals(assertMessage, FontFormat.BOLD_LITERAL, ((List<FontFormat>) dNodeListOfEClass.getStyle().eGet(labelFormatFeature)).get(1)); assertEquals(assertMessage, FontFormat.ITALIC_LITERAL, ((List<FontFormat>) dNodeListOfEClass.getStyle().eGet(labelFormatFeature)).get(0)); + assertEquals(assertMessage, RGBValues.create(228, 179, 229), dNodeListOfEClass.getStyle().eGet(ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_COLOR)); + + assertEquals(assertMessage, Collections.singletonList(labelFormatFeature.getName()), dNodeListOfEClass2.getStyle().getCustomFeatures()); + assertEquals(assertMessage, FontFormat.UNDERLINE_LITERAL, ((List<FontFormat>) dNodeListOfEClass2.getStyle().eGet(labelFormatFeature)).get(0)); + assertEquals(assertMessage, FontFormat.STRIKE_THROUGH_LITERAL, ((List<FontFormat>) dNodeListOfEClass2.getStyle().eGet(labelFormatFeature)).get(1)); + assertEquals(assertMessage, Collections.singletonList(labelFormatFeature.getName()), dNodeContainerOfEPackage.getStyle().getCustomFeatures()); assertEquals(assertMessage, FontFormat.BOLD_LITERAL, ((List<FontFormat>) dNodeContainerOfEPackage.getStyle().eGet(labelFormatFeature)).get(1)); assertEquals(assertMessage, FontFormat.ITALIC_LITERAL, ((List<FontFormat>) dNodeContainerOfEPackage.getStyle().eGet(labelFormatFeature)).get(0)); |
