Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2017-06-22 14:38:59 +0000
committerLaurent Fasani2017-07-07 15:56:19 +0000
commit1fe812ff6c96c5ab1875c540dd836e1b474d9513 (patch)
treeac35ffb82960520eace33b4a5f77447ead570a92
parentb281e69bf082c6a18a48634c5bed027397669c29 (diff)
downloadorg.eclipse.sirius-1fe812ff6c96c5ab1875c540dd836e1b474d9513.tar.gz
org.eclipse.sirius-1fe812ff6c96c5ab1875c540dd836e1b474d9513.tar.xz
org.eclipse.sirius-1fe812ff6c96c5ab1875c540dd836e1b474d9513.zip
[516669] Fix representation deletion when it is in its own resource
* Delete the resource containing the representation if it is empty after the representation deletion. * Avoid loading the representation to close its corresponding editor as it is not necessary. * Remove explicit deletion of GMF diagram into the DDiagram. Only the DDiagram deletion is sufficient. * Modify SessionServiceGMFDiagramTest consequently to avoid testing explicit GMF diagram deletion. Bug: 516669 Change-Id: I07e6924f19518912eac4b30c356a39e48f4d7c01 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java16
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/session/SessionServiceGMFDiagramTest.java13
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java14
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java19
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java2
5 files changed, 26 insertions, 38 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java
index 3551b493f9..250be1a2fa 100644
--- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java
+++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java
@@ -31,7 +31,6 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressionQuery;
-import org.eclipse.sirius.business.api.helper.SiriusUtil;
import org.eclipse.sirius.business.api.helper.task.AbstractCommandTask;
import org.eclipse.sirius.business.api.query.DRepresentationElementQuery;
import org.eclipse.sirius.business.api.query.DViewQuery;
@@ -284,21 +283,6 @@ public class DiagramDialectServices extends AbstractRepresentationDialectService
}
@Override
- public boolean deleteRepresentation(final DRepresentationDescriptor representationDescriptor, final Session session) {
- DRepresentation representation = representationDescriptor.getRepresentation();
- if (representation instanceof DDiagram) {
- session.getServices().clearCustomData(CustomDataConstants.GMF_DIAGRAMS, representation);
- SiriusUtil.delete(representation, session);
- SiriusUtil.delete(representationDescriptor, session);
- return true;
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public RepresentationDescription getDescription(final DRepresentation representation) {
if (representation instanceof DDiagram) {
return ((DDiagram) representation).getDescription();
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/session/SessionServiceGMFDiagramTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/session/SessionServiceGMFDiagramTest.java
index f72ae0e751..9158f9e270 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/session/SessionServiceGMFDiagramTest.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/session/SessionServiceGMFDiagramTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2017 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
@@ -24,9 +24,7 @@ import org.eclipse.sirius.diagram.DDiagram;
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.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
-import org.eclipse.sirius.viewpoint.description.AnnotationEntry;
/**
* Test for {@link SessionService}.
@@ -68,7 +66,6 @@ public class SessionServiceGMFDiagramTest extends SiriusDiagramTestCase implemen
public void testClearGMFData() throws Exception {
final Collection<DRepresentationDescriptor> allRepDescriptors = DialectManager.INSTANCE.getAllRepresentationDescriptors(session);
- final Collection<DRepresentation> allRepresentations = DialectManager.INSTANCE.getAllRepresentations(session);
Command cmd = new RecordingCommand(session.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
@@ -86,13 +83,5 @@ public class SessionServiceGMFDiagramTest extends SiriusDiagramTestCase implemen
if (content instanceof Diagram)
fail();
}
-
- for (DRepresentation dRepresentation : allRepresentations) {
- for (AnnotationEntry annotation : dRepresentation.getOwnedAnnotationEntries()) {
- if (annotation.getSource().equals(CustomDataConstants.GMF_DIAGRAMS)) {
- fail();
- }
- }
- }
}
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java
index bc76fcf125..7eeb05a3a6 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2016 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2011, 2017 THALES GLOBAL SERVICES and others.
* 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
@@ -16,6 +16,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -101,14 +102,13 @@ public class DeleteRepresentationAction extends Action {
IEditingSession editingSession = SessionUIManager.INSTANCE.getUISession(session);
if (editingSession != null) {
for (DRepresentationDescriptor dRepDescriptor : dRepdescriptors) {
- DRepresentation representation = dRepDescriptor.getRepresentation();
- if (representation != null) {
- DialectEditor editor = editingSession.getEditor(representation);
+ Optional.of(dRepDescriptor).filter(DRepresentationDescriptor::isLoadedRepresentation).map(DRepresentationDescriptor::getRepresentation).ifPresent(rep -> {
+ DialectEditor editor = editingSession.getEditor(rep);
if (editor != null) {
DialectUIManager.INSTANCE.closeEditor(editor, false);
editingSession.detachEditor(editor);
}
- }
+ });
}
}
}
@@ -142,9 +142,7 @@ public class DeleteRepresentationAction extends Action {
};
PlatformUI.getWorkbench().getProgressService().run(true, false, representationsDeletionRunnable);
}
- } catch (final InvocationTargetException e) {
- SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
- } catch (final InterruptedException e) {
+ } catch (final InvocationTargetException | InterruptedException e) {
SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
}
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java
index 9c8976ad8c..e68826eeee 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java
@@ -10,11 +10,14 @@
*******************************************************************************/
package org.eclipse.sirius.business.api.dialect;
+import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
+import java.util.Optional;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -23,6 +26,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.business.api.helper.SiriusUtil;
import org.eclipse.sirius.business.api.helper.task.AbstractCommandTask;
@@ -44,6 +48,7 @@ import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.Messages;
+import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.sirius.viewpoint.ViewpointPackage;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
@@ -209,8 +214,20 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe
@Override
public boolean deleteRepresentation(DRepresentationDescriptor representationDescriptor, Session session) {
if (isSupported(representationDescriptor)) {
- SiriusUtil.delete(representationDescriptor.getRepresentation(), session);
+ Optional<Resource> resOpt = Optional.ofNullable(representationDescriptor.getRepresentation()).map(EObject::eResource);
+ if (representationDescriptor.getRepresentation() != null) {
+ SiriusUtil.delete(representationDescriptor.getRepresentation(), session);
+ }
SiriusUtil.delete(representationDescriptor, session);
+
+ // delete the resource if it is empty
+ resOpt.filter(res -> res.getContents().isEmpty()).ifPresent(res -> {
+ try {
+ res.delete(Collections.emptyMap());
+ } catch (IOException e) {
+ SiriusPlugin.getDefault().error(Messages.SiriusUncontrolCommand_resourceDeletionFailedMsg, e);
+ }
+ });
return true;
}
return false;
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java
index 43f87eb7c1..52e2c9e6b9 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/ResourceQuery.java
@@ -118,7 +118,7 @@ public class ResourceQuery {
*/
public boolean isSrmResource() {
EList<EObject> contents = resource.getContents();
- return Optional.ofNullable(contents.isEmpty() ? null : resource.getContents().get(0)).filter(DRepresentation.class::isInstance).isPresent();
+ return Optional.ofNullable(contents.isEmpty() ? null : contents.get(0)).filter(DRepresentation.class::isInstance).isPresent();
}
/**

Back to the top