diff options
| author | Maxime Porhel | 2019-12-06 18:19:36 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2019-12-09 20:37:52 +0000 |
| commit | 93e9a6422e5a6dca1c5ff7be1167e8559e5ec076 (patch) | |
| tree | 220620f91f02e7d64c1219f465234ad6259b1817 | |
| parent | 150812c4573ed203fa0f94b9853a234fa8b539df (diff) | |
| download | org.eclipse.sirius-93e9a6422e5a6dca1c5ff7be1167e8559e5ec076.tar.gz org.eclipse.sirius-93e9a6422e5a6dca1c5ff7be1167e8559e5ec076.tar.xz org.eclipse.sirius-93e9a6422e5a6dca1c5ff7be1167e8559e5ec076.zip | |
[558026] Make DeleteFromModel also delete DRepresentationDescriptor.
- Make consistent the deletion of DRepresentation in deleteFromModel:
also delete the descriptor when TaskHelper decides to delete the parent
DSemanticDecorator.
- Complete the Junit test.
Bug: 558026
Cherry-picked-from: 552839
Change-Id: I33bccb3b1d07d702113f24be5bb6db21777688e3
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
2 files changed, 37 insertions, 6 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/DeleteFromModelActionTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/DeleteFromModelActionTests.java index dcdd984a6c..e6417b2814 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/DeleteFromModelActionTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/action/DeleteFromModelActionTests.java @@ -26,6 +26,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.sirius.business.api.dialect.DialectManager; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DEdge; import org.eclipse.sirius.diagram.DSemanticDiagram; @@ -105,6 +106,7 @@ public class DeleteFromModelActionTests extends SiriusDiagramTestCase implements }); DDiagram rep1 = (DDiagram) createRepresentation("Entities", leafPack[0]); + DRepresentationDescriptor rep1Descriptor = new DRepresentationQuery(rep1, session).getRepresentationDescriptor(); DDiagramEditor rep1Editor = (DDiagramEditor) DialectUIManager.INSTANCE.openEditor(session, rep1, defaultProgress); TestsUtil.synchronizationWithUIThread(); @@ -127,7 +129,18 @@ public class DeleteFromModelActionTests extends SiriusDiagramTestCase implements assertEquals(2, DialectManager.INSTANCE.getAllRepresentations(session).size()); Collection<DRepresentationDescriptor> allRepresentationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); - assertEquals(3, allRepresentationDescriptors.size()); + assertEquals(2, allRepresentationDescriptors.size()); + for (DRepresentationDescriptor desc : allRepresentationDescriptors) { + assertNotNull(desc.getRepresentation()); + } + + // See DeletionCommandBuilder, DeleteEObjectTask and TaskHelper.getDElementToClearFromSemanticElements(); + // which are responsible for the deletion of rep1 as: + // - deleteFromModel is called on in Rep1 on ePackage + // - ePackage is an ancestor of rep1.getTarget(). + assertNull(rep1.eResource()); + assertNull(rep1Descriptor.eContainer()); + assertNull(rep1Descriptor.eResource()); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/helper/task/DeleteEObjectTask.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/helper/task/DeleteEObjectTask.java index 2a68c73d08..363918f26b 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/helper/task/DeleteEObjectTask.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/helper/task/DeleteEObjectTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2019 THALES GLOBAL SERVICES. * 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 @@ -15,6 +15,7 @@ package org.eclipse.sirius.business.api.helper.task; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.business.internal.session.danalysis.DanglingRefRemovalTrigger; @@ -22,12 +23,14 @@ import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; import org.eclipse.sirius.ecore.extender.business.api.accessor.exception.FeatureNotFoundException; import org.eclipse.sirius.ecore.extender.business.api.accessor.exception.MetaClassNotFoundException; import org.eclipse.sirius.ext.emf.EReferencePredicate; +import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.Messages; /** - * A task allowing to delete any DRepresentationElement or any EObject. - * Typically uesd in Command factories to build delete commands. + * A task allowing to delete any DRepresentationElement or any EObject. Typically uesd in Command factories to build + * delete commands. * * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a> * @@ -62,8 +65,7 @@ public class DeleteEObjectTask extends AbstractCommandTask { * @param accessor * the {@link ModelAccessor} to use to perform the deletion * @param eReferencesToIgnores - * a predicate to tell which {@link EReference} to ignore in the - * dangling references deletion + * a predicate to tell which {@link EReference} to ignore in the dangling references deletion */ public DeleteEObjectTask(EObject objectToDelete, ModelAccessor accessor, final EReferencePredicate eReferencesToIgnores) { this.objectToDelete = objectToDelete; @@ -108,8 +110,24 @@ public class DeleteEObjectTask extends AbstractCommandTask { if (session != null) { semanticCrossReferencer = session.getSemanticCrossReferencer(); } + + DRepresentationDescriptor dRepresentationDescriptorToDelete = null; + if (objectToDelete instanceof DRepresentation) { + // The expected way to delete representation is to call DeleteRepresentationCommand which will take the + // DRepresentationDescriptor as entry point but in some cases like DeleteFromModel (see + // DeletionCOmmandBuilder), Sirius might retrieve a Representation to delete (see + // org.eclipse.sirius.business.api.helper.task.TaskHelper.getDElementToClearFromSemanticElements(EObject, + // Set<EObject>). For example, this can occur when a user deletes a DDiagramElement whose target is A on a + // DDiagram whose target is a descendant of A. + dRepresentationDescriptorToDelete = new DRepresentationQuery((DRepresentation) objectToDelete, session).getRepresentationDescriptor(); + } + accessor.eDelete(objectToDelete, semanticCrossReferencer, danglingEReferencesToIgnores); + // Delete the DRepresentationDescriptor after the deletion of the DRepresentation. + if (dRepresentationDescriptorToDelete != null) { + accessor.eDelete(dRepresentationDescriptorToDelete, semanticCrossReferencer, danglingEReferencesToIgnores); + } } /** |
