diff options
| author | Laurent Fasani | 2015-02-26 11:06:00 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2015-03-19 16:35:12 +0000 |
| commit | f26c2739fdad4a6a3a9d2cf718328972b9643f27 (patch) | |
| tree | 2f7ebdd4286272bfed378960d9ede7aa55167df8 | |
| parent | 637da94b5e0cbc404ee480d2a3f88aa8199ca025 (diff) | |
| download | org.eclipse.sirius-f26c2739fdad4a6a3a9d2cf718328972b9643f27.tar.gz org.eclipse.sirius-f26c2739fdad4a6a3a9d2cf718328972b9643f27.tar.xz org.eclipse.sirius-f26c2739fdad4a6a3a9d2cf718328972b9643f27.zip | |
[462213] Differentiate behavior between delete notif or remove model cmd
When receiving a delete resource notification, only the concerned
resource is removed from session (DASI.removeSemanticResource) and no
more all impacted resources.
API breaks:
* RemoveSemanticResource default constructor. removeReferencingResources
has been added and removeFromControlledResources removed because
controlled resources are managed internally in DASI
* Session.removeSemanticResource. removeReferencingResources has been
added
Bug: 462213
Change-Id: Icef919a3cb877359022d178095c68228e5b54c71
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
11 files changed, 58 insertions, 47 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html index 32e5dac0ec..3f42155ba9 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html @@ -130,6 +130,21 @@ <code>getAllRepresentations()</code> can simply use <code>getOwnedRepresentations()</code> instead. </li> + <li>The default constructor has been changed in + <code>org.eclipse.sirius.tools.api.command.semantic.RemoveSemanticResourceCommand</code>. + <ul> + <li>The boolean value + <code>removeReferencingResources</code> has been added to indicate if the referencing resources are also to remove. + </li> + <li>The boolean value + <code>removeFromControlledResources</code> has been removed because controlled resources are managed internally. + </li> + </ul> + </li> + <li>The boolean value + <code>removeReferencingResources</code> has been added in + <code>org.eclipse.sirius.business.api.session.Session.removeSemanticResource</code> method to indicate if the referencing resources are also to remove. + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.ui">Changes in <code>org.eclipse.sirius.ui</code> @@ -2427,4 +2442,4 @@ void removeSelectedView(DView view); <li>The ability to print table representations has been disabled for the 0.9 release due to an external dependency issue (see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=422223" target="_blank">bug #422223</a>: for the details). It should be re-introduced in 1.0.</li> </ul> </body> -</html>
\ No newline at end of file +</html> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile index 469416c449..4545ca10ab 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile @@ -38,6 +38,10 @@ h4. Changes in @org.eclipse.sirius@ * @org.eclipse.sirius.business.api.session.SessionListener.SEMANTIC_CHANGE@ is no more send to @SessionListener@ and @SessionManagerListener@ listeners on save when a semantic resource is saved. Use a @ResourceSyncClient@ listener on @ResourceSetSync@ to have know if a semantic resource is saved. * The @ExtendedPackage@ @EDataType@ which was defined in the @http://www.eclipse.org/sirius/1.1.0@ package was not actually used anywhere and has been removed. * The @DView@ methods @getAllRepresentations()@, @getReferencedRepresentations()@ and @getHiddenRepresentations()@ have been removed: @getReferencedRepresentations()@ and @getHiddenRepresentations()@ were never actually used, making @getAllRepresentations()@ strictly equivalent to @getOwnedRepresentations()@. Code that used @getAllRepresentations()@ can simply use @getOwnedRepresentations()@ instead. +* The default constructor has been changed in @org.eclipse.sirius.tools.api.command.semantic.RemoveSemanticResourceCommand@. +** The boolean value @removeReferencingResources@ has been added to indicate if the referencing resources are also to remove. +** The boolean value @removeFromControlledResources@ has been removed because controlled resources are managed internally. +* The boolean value @removeReferencingResources@ has been added in @org.eclipse.sirius.business.api.session.Session.removeSemanticResource@ method to indicate if the referencing resources are also to remove. h4. Changes in @org.eclipse.sirius.ui@ diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/semantic/XSDSemanticResourceTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/semantic/XSDSemanticResourceTests.java index d4fa9b5751..8301a610f7 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/semantic/XSDSemanticResourceTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/semantic/XSDSemanticResourceTests.java @@ -199,7 +199,7 @@ public class XSDSemanticResourceTests extends SiriusDiagramTestCase { private void removeSemanticResource() { TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); Resource addedSemanticResource = session.getSemanticResources().iterator().next(); - Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, addedSemanticResource, true, new NullProgressMonitor()); + Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, addedSemanticResource, new NullProgressMonitor(), true); domain.getCommandStack().execute(removeSemanticResourceCmd); } diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/DAnalysisSessionTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/DAnalysisSessionTests.java index 7bed839a43..daff8a523a 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/DAnalysisSessionTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/DAnalysisSessionTests.java @@ -416,7 +416,7 @@ public class DAnalysisSessionTests extends SiriusDiagramTestCase { @Override protected void doExecute() { session.addSemanticResource(resource.getURI(), new NullProgressMonitor()); - session.removeSemanticResource(resource, new NullProgressMonitor()); + session.removeSemanticResource(resource, new NullProgressMonitor(), true); } }); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionManagerListener2Tests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionManagerListener2Tests.java index dcc4cb0718..555b8f153e 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionManagerListener2Tests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionManagerListener2Tests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 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 @@ -300,7 +300,7 @@ public class SessionManagerListener2Tests extends SiriusDiagramTestCase implemen private void removeSemanticResource() { session.getTransactionalEditingDomain().getCommandStack() - .execute(new RemoveSemanticResourceCommand(session, session.getSemanticResources().iterator().next(), true, new NullProgressMonitor())); + .execute(new RemoveSemanticResourceCommand(session, session.getSemanticResources().iterator().next(), new NullProgressMonitor(), true)); } /** diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionSemanticResourceTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionSemanticResourceTests.java index f962be9564..11d5bd74fc 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionSemanticResourceTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/session/SessionSemanticResourceTests.java @@ -170,7 +170,7 @@ public class SessionSemanticResourceTests extends SiriusDiagramTestCase { Resource addedSemanticResource = session.getSemanticResources().iterator().next(); TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); - Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, addedSemanticResource, true, new NullProgressMonitor()); + Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, addedSemanticResource, new NullProgressMonitor(), true); domain.getCommandStack().execute(removeSemanticResourceCmd); assertEquals("The session shouldn't have semantic resource now", 0, session.getSemanticResources().size()); @@ -188,7 +188,7 @@ public class SessionSemanticResourceTests extends SiriusDiagramTestCase { Resource semanticResource3 = getSemanticResourceFromSession(semanticResource3URI); TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); - Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource3, true, new NullProgressMonitor()); + Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource3, new NullProgressMonitor(), true); domain.getCommandStack().execute(removeSemanticResourceCmd); assertEquals("The session should have now only 2 semantic resources", 2, session.getSemanticResources().size()); @@ -208,7 +208,7 @@ public class SessionSemanticResourceTests extends SiriusDiagramTestCase { Resource semanticResource5 = getSemanticResourceFromSession(semanticResource5URI); TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); - Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource5, true, new NullProgressMonitor()); + Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource5, new NullProgressMonitor(), true); domain.getCommandStack().execute(removeSemanticResourceCmd); assertEquals("The session shouldn't have semantic resource now", 0, session.getSemanticResources().size()); @@ -236,7 +236,7 @@ public class SessionSemanticResourceTests extends SiriusDiagramTestCase { // Test the removal of r5.ecore URI semanticResource5URI = URI.createPlatformResourceURI("/" + TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_RESOURCE_5_NAME, true); Resource semanticResource5 = getSemanticResourceFromSession(semanticResource5URI); - Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource5, true, new NullProgressMonitor()); + Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource5, new NullProgressMonitor(), true); domain.getCommandStack().execute(removeSemanticResourceCmd); assertEquals("The session should have only 1 semantic resource now", 1, session.getSemanticResources().size()); @@ -267,7 +267,7 @@ public class SessionSemanticResourceTests extends SiriusDiagramTestCase { domain.getCommandStack().execute(addR2DependencyToR4Cmd); // Test the removal of r4.ecore - Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource4, true, new NullProgressMonitor()); + Command removeSemanticResourceCmd = new RemoveSemanticResourceCommand(session, semanticResource4, new NullProgressMonitor(), true); domain.getCommandStack().execute(removeSemanticResourceCmd); assertEquals("The session shouldn't have semantic resource now", 0, session.getSemanticResources().size()); diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java index dcb1d5f256..d899913736 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 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 @@ -81,7 +81,7 @@ public class RemoveSemanticResourceAction extends Action { final TransactionalEditingDomain transDomain = session.getTransactionalEditingDomain(); CompoundCommand compoundCommand = new CompoundCommand(); for (Resource semanticResourceToRemove : toRemove) { - compoundCommand.append(new RemoveSemanticResourceCommand(session, semanticResourceToRemove, false, new NullProgressMonitor())); + compoundCommand.append(new RemoveSemanticResourceCommand(session, semanticResourceToRemove, new NullProgressMonitor(), true)); } transDomain.getCommandStack().execute(compoundCommand); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/Session.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/Session.java index c6da52f510..ae02fb34e0 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/Session.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/Session.java @@ -142,8 +142,10 @@ public interface Session { * @param monitor * a {@link IProgressMonitor} to show progression of semantic * resource removal + * @param removeReferencingResources + * indicates if the referencing resources are also to remove */ - void removeSemanticResource(final Resource semanticResource, IProgressMonitor monitor); + void removeSemanticResource(final Resource semanticResource, IProgressMonitor monitor, boolean removeReferencingResources); /** * Save the session data. diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java index 1c826e3f68..393e2a13d6 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java @@ -419,6 +419,12 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements return analysisAndReferenced; } + Collection<Resource> getAllSemanticResources() { + Collection<Resource> semanticResources = new LinkedHashSet<Resource>(this.getSemanticResources()); + semanticResources.addAll(this.getControlledResources()); + return semanticResources; + } + private void addAllReferencedAnalyses(final Collection<DAnalysis> analysisAndReferenced, final DAnalysis analysis) { for (DAnalysis referenced : Sets.newLinkedHashSet(analysis.getReferencedAnalysis())) { if (!analysisAndReferenced.contains(referenced) && referenced.eResource() != null) { @@ -689,10 +695,12 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements } @Override - public void removeSemanticResource(Resource semanticResource, IProgressMonitor monitor) { + public void removeSemanticResource(Resource semanticResource, IProgressMonitor monitor, boolean removeReferencingResources) { ResourceSet resourceSet = transactionalEditingDomain.getResourceSet(); - for (final Resource res : collectAllReferencingResources(semanticResource)) { - doRemoveSemanticResource(res, resourceSet); + if (removeReferencingResources) { + for (final Resource res : collectAllReferencingResources(semanticResource)) { + doRemoveSemanticResource(res, resourceSet); + } } doRemoveSemanticResource(semanticResource, resourceSet); } @@ -706,6 +714,8 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements * the resourceset from which to remove it. */ protected void doRemoveSemanticResource(final Resource res, final ResourceSet set) { + set.getResources().remove(res); + if (res.getContents().size() > 0) { final EObject root = findSemanticRoot(res); for (final DAnalysis analysis : this.allAnalyses()) { @@ -718,7 +728,6 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements res.unload(); enableCrossReferencerResolve(res); } - set.getResources().remove(res); } void discoverAutomaticallyLoadedSemanticResources(List<Resource> allResources) { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java index d4d5bd0fe7..1ce3c1f67a 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionResourcesSynchronizer.java @@ -233,8 +233,8 @@ public class SessionResourcesSynchronizer implements ResourceSyncClient { * The resource to remove */ private void removeResourceFromSession(Resource resource, IProgressMonitor pm) { - if (session.getSemanticResources().contains(resource)) { - session.getTransactionalEditingDomain().getCommandStack().execute(new RemoveSemanticResourceCommand(session, resource, false, new NullProgressMonitor())); + if (session.getAllSemanticResources().contains(resource)) { + session.getTransactionalEditingDomain().getCommandStack().execute(new RemoveSemanticResourceCommand(session, resource, new NullProgressMonitor(), false)); } else if (session.getAllSessionResources().contains(resource)) { session.removeAnalysis(resource); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/semantic/RemoveSemanticResourceCommand.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/semantic/RemoveSemanticResourceCommand.java index e41e8372b3..379a2a4136 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/semantic/RemoveSemanticResourceCommand.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/semantic/RemoveSemanticResourceCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 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 @@ -12,14 +12,9 @@ package org.eclipse.sirius.tools.api.command.semantic; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; -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.RecordingCommand; import org.eclipse.sirius.business.api.session.Session; -import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject; - -import com.google.common.collect.Lists; /** * Specific command do remove semantic resources from the given session. @@ -41,14 +36,9 @@ public class RemoveSemanticResourceCommand extends RecordingCommand { protected Resource semanticResource; /** - * Indicates whether cross referenced resources should be removed or not. - */ - protected boolean removeCrossReferencedResources; - - /** - * Indicates if the resource should be removed from controlled resources. + * Indicates if the referencing resources are also to remove. */ - protected boolean removeFromControlledResources; + private boolean removeReferencingResources; private IProgressMonitor monitor; @@ -58,20 +48,19 @@ public class RemoveSemanticResourceCommand extends RecordingCommand { * @param session * contextual {@link Session} * @param semanticResource - * Resource - * @param removeFromControlledResources - * true if the given resource will removed from controlled - * resources + * resource to remove * @param monitor * a {@link IProgressMonitor} to show progression of semantic * resource removal + * @param removeReferencingResources + * indicates if the referencing resources are also to remove */ - public RemoveSemanticResourceCommand(Session session, Resource semanticResource, boolean removeFromControlledResources, IProgressMonitor monitor) { + public RemoveSemanticResourceCommand(Session session, Resource semanticResource, IProgressMonitor monitor, boolean removeReferencingResources) { super(session.getTransactionalEditingDomain(), "Remove model"); this.semanticResource = semanticResource; this.session = session; - this.removeFromControlledResources = removeFromControlledResources; this.monitor = monitor; + this.removeReferencingResources = removeReferencingResources; } /** @@ -82,15 +71,7 @@ public class RemoveSemanticResourceCommand extends RecordingCommand { if (monitor == null) { monitor = new NullProgressMonitor(); } - if (semanticResource != null && session != null && session.getSemanticResources().contains(semanticResource)) { - session.removeSemanticResource(semanticResource, monitor); - } - if (removeFromControlledResources && session instanceof DAnalysisSessionEObject && ((DAnalysisSessionEObject) session).getControlledResources().contains(semanticResource)) { - for (final EObject root : Lists.newArrayList(semanticResource.getContents())) { - EcoreUtil.remove(root); - } - ((DAnalysisSessionEObject) session).getControlledResources().remove(semanticResource); - } + session.removeSemanticResource(semanticResource, monitor, removeReferencingResources); } } |
