diff options
| author | Arthur Daussy | 2019-11-08 15:33:12 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2019-12-09 10:17:55 +0000 |
| commit | 8ec1596af6caca26d68bd7e5430c311c11e6d735 (patch) | |
| tree | b4eca305e6679b9acc36a328cf2fb2ae12967006 | |
| parent | 6bb7ae1a943ec829eacd28573eb6627bf3b3497c (diff) | |
| download | org.eclipse.sirius-8ec1596af6caca26d68bd7e5430c311c11e6d735.tar.gz org.eclipse.sirius-8ec1596af6caca26d68bd7e5430c311c11e6d735.tar.xz org.eclipse.sirius-8ec1596af6caca26d68bd7e5430c311c11e6d735.zip | |
[552839] Provide JUnit and complete DialectEditorCloserFilter
- Complete the Junit test
- Add additional matching cases in DialectEditorCloserFilter.
Bug: 552839
Change-Id: Iad8c4bc5c498aa7517e83d118eabcf56bc839e84
Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
2 files changed, 92 insertions, 2 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 acf30eafd8..dcdd984a6c 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 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 @@ -12,27 +12,35 @@ *******************************************************************************/ package org.eclipse.sirius.tests.unit.diagram.action; +import java.util.Collection; import java.util.List; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EcoreFactory; import org.eclipse.emf.ecore.impl.EClassImpl; +import org.eclipse.emf.transaction.RecordingCommand; +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.diagram.DDiagram; import org.eclipse.sirius.diagram.DEdge; +import org.eclipse.sirius.diagram.DSemanticDiagram; import org.eclipse.sirius.diagram.business.api.query.IEdgeMappingQuery; import org.eclipse.sirius.diagram.description.IEdgeMapping; import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramEdgeEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeNameEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListNameEditPart; import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; +import org.eclipse.sirius.tests.support.api.DummyDialectEditorDialogFactory; import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; import org.eclipse.sirius.tests.support.api.TestsUtil; import org.eclipse.sirius.tests.unit.diagram.modeler.ecore.EcoreModeler; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; @@ -64,6 +72,65 @@ public class DeleteFromModelActionTests extends SiriusDiagramTestCase implements TestsUtil.synchronizationWithUIThread(); } + public void testDeleteContainerOfSemanticTarget() { + assertEquals(ePackage, ((DSemanticDiagram) editor.getRepresentation()).getTarget()); + assertEquals(2, DialectManager.INSTANCE.getAllRepresentations(session).size()); + assertEquals(2, DialectManager.INSTANCE.getAllRepresentationDescriptors(session).size()); + + TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain(); + + final EPackage[] leafPack = new EPackage[1]; + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) { + + @Override + protected void doExecute() { + EPackage pack1 = createEPackage("P1"); + ePackage.getESubpackages().add(pack1); + + EPackage pack1_1 = createEPackage("P1_1"); + pack1.getESubpackages().add(pack1_1); + + EPackage pack1_1_1 = createEPackage("P1_1_1"); + pack1_1.getESubpackages().add(pack1_1_1); + + leafPack[0] = pack1_1_1; + + } + + private EPackage createEPackage(String name) { + EPackage pack = EcoreFactory.eINSTANCE.createEPackage(); + pack.setName(name); + return pack; + } + }); + + DDiagram rep1 = (DDiagram) createRepresentation("Entities", leafPack[0]); + DDiagramEditor rep1Editor = (DDiagramEditor) DialectUIManager.INSTANCE.openEditor(session, rep1, defaultProgress); + TestsUtil.synchronizationWithUIThread(); + + assertEquals(3, DialectManager.INSTANCE.getAllRepresentations(session).size()); + assertEquals(3, DialectManager.INSTANCE.getAllRepresentationDescriptors(session).size()); + + dropSemantic(ePackage, rep1, null); + TestsUtil.synchronizationWithUIThread(); + + DummyDialectEditorDialogFactory editorCloserPopupDetector = new DummyDialectEditorDialogFactory(); + rep1Editor.setDialogFactory(editorCloserPopupDetector); + editor.setDialogFactory(editorCloserPopupDetector); + + delete(getEditPart(getFirstDiagramElement(rep1, ePackage))); + TestsUtil.synchronizationWithUIThread(); + + assertEquals("Diagram target deletion or diagram deletion has not been correctly detected, check the DialectEditorCloserFilter.", 2, + editorCloserPopupDetector.getNbEditorWillBeClosedInformationDialogCalls()); + TestsUtil.synchronizationWithUIThread(); + + assertEquals(2, DialectManager.INSTANCE.getAllRepresentations(session).size()); + Collection<DRepresentationDescriptor> allRepresentationDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session); + assertEquals(3, allRepresentationDescriptors.size()); + + } + public void testDeleteContainerEditPart() throws Exception { applyNodeCreationTool(TOOL_CREATION_CLASS_NAME, diagram, diagram); final EClass eClass = (EClass) ePackage.getEClassifiers().get(0); diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/editor/DialectEditorCloserFilter.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/editor/DialectEditorCloserFilter.java index 69a9d3486a..5f301b6793 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/editor/DialectEditorCloserFilter.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/dialect/editor/DialectEditorCloserFilter.java @@ -18,9 +18,12 @@ import java.util.Optional; import org.eclipse.core.runtime.Assert; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.NotificationFilter; +import org.eclipse.sirius.business.api.resource.ResourceDescriptor; import org.eclipse.sirius.business.internal.session.danalysis.DanglingRefRemovalTrigger; +import org.eclipse.sirius.business.internal.session.danalysis.SessionLazyCrossReferencer; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DSemanticDecorator; @@ -50,7 +53,19 @@ public class DialectEditorCloserFilter extends NotificationFilter.Custom { @Override public boolean matches(Notification notification) { - return !notification.isTouch() && (isTargetUnset(notification) || isRepresentationDeletion(notification) || isTargetDetachment(notification)); + if (notification.isTouch()) { + // DRepresentationDescriptor#representation is volatile, when setRepresentation(null) is called, the + // oldValue access is an attempt to compute the previous representation which might already be null or + // impossible to access. + // For example when a DRepresentation is deleted, we will get a touch notification for the + // DRepresentationDescriptor.setRepresentation(null). + // We need to inspect touch notification whose notifier is the current DRepresentationDescriptor. + boolean currentDRepDescriptorTarget = notification.getNotifier() == dRepDescriptor && notification.getFeature() == ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR__TARGET; + return currentDRepDescriptorTarget && notification.getEventType() == Notification.SET && notification.getNewValue() == null; + } else { + // !notification.isTouch() case + return isTargetUnset(notification) || isRepresentationDeletion(notification) || isTargetDetachment(notification); + } } /** @@ -96,6 +111,14 @@ public class DialectEditorCloserFilter extends NotificationFilter.Custom { representationDeleted = dRepDescriptor.eContainer() == null || !(dRepDescriptor.eContainer() != null && dRepDescriptor.eContainer().eContainer() instanceof DView); } else if (notification.getFeature() == ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR__REPRESENTATION) { representationDeleted = notification.getNewValue() == null && notification.getOldValue() != null && notification.getNotifier() == dRepDescriptor; + } else if (SessionLazyCrossReferencer.isTopLevelRepresentationRemoval(notification) && notification.getOldValue() instanceof DRepresentation + && notification.getNotifier() instanceof Resource) { + // A representation has been deleted, retrieve is repPath and compare it to the one of the current + // DRepresentationDescriptor. + DRepresentation rep = (DRepresentation) notification.getOldValue(); + Resource res = (Resource) notification.getNotifier(); + ResourceDescriptor repPathBeforeDeletion = new ResourceDescriptor(res.getURI().appendFragment(rep.getUid())); + representationDeleted = repPathBeforeDeletion.equals(dRepDescriptor.getRepPath()); } return representationDeleted; } |
