Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-09-03 09:14:52 +0000
committerChristian W. Damus2014-09-04 19:07:19 +0000
commit9b4b201ff635d6a7fa66ce865fd0ce29dcbaa339 (patch)
treee9dd09755d047b1883a98e544ec8dc3501f6e973 /plugins/infra
parenta52600de7d6fef0605a1b9bf60a3b569d1d9868c (diff)
downloadorg.eclipse.papyrus-9b4b201ff635d6a7fa66ce865fd0ce29dcbaa339.tar.gz
org.eclipse.papyrus-9b4b201ff635d6a7fa66ce865fd0ce29dcbaa339.tar.xz
org.eclipse.papyrus-9b4b201ff635d6a7fa66ce865fd0ce29dcbaa339.zip
Bug 440443 - [Refactoring] Workspace-private sash model not copied when
a model copied and pasted - keep sash while renaming model (use the fact that modelset.loadmodels create the missing sash see SashModel.loadModel) - keep sash while copy/paste model Change-Id: Iff07764fe8009ea6fb92dd6bd9975059961d543b Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java4
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/action/PapyrusCopyFilesAndFoldersOperation.java55
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/RenameModelChange.java23
3 files changed, 68 insertions, 14 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
index fb3f6a1edbc..3ef7414db4c 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
@@ -689,7 +689,7 @@ public class ModelSet extends ResourceSetImpl {
* Create models that are not already created or loaded.
*/
public void createMissingModels() throws ModelException {
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO
}
@@ -697,7 +697,7 @@ public class ModelSet extends ResourceSetImpl {
* Load models that are not already created or loaded.
*/
public void loadMissingModels() throws ModelException {
- throw new UnsupportedOperationException("Not yet implemented");
+ throw new UnsupportedOperationException("Not yet implemented"); // TODO
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/action/PapyrusCopyFilesAndFoldersOperation.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/action/PapyrusCopyFilesAndFoldersOperation.java
index 79985ec5cad..691de191cdb 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/action/PapyrusCopyFilesAndFoldersOperation.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/action/PapyrusCopyFilesAndFoldersOperation.java
@@ -15,7 +15,9 @@
package org.eclipse.papyrus.infra.onefile.action;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -29,8 +31,11 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
import org.eclipse.papyrus.infra.emf.resource.DependencyManagementHelper;
import org.eclipse.papyrus.infra.emf.resource.MoveFileURIReplacementStrategy;
@@ -61,7 +66,7 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.onefile.action.CopyFilesAndFoldersOperation#performCopyWithAutoRename(org.eclipse.core.resources.IResource[],
* org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor)
*/
@@ -109,7 +114,7 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.onefile.action.CopyFilesAndFoldersOperation#performCopy(org.eclipse.core.resources.IResource[],
* org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor)
*/
@@ -129,7 +134,7 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.onefile.action.CopyFilesAndFoldersOperation#copyResources(org.eclipse.core.resources.IResource[],
* org.eclipse.core.resources.IContainer)
*/
@@ -138,11 +143,13 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
public IResource[] copyResources(IResource[] resources, IContainer destination) {
IResource[] copyResources = super.copyResources(resources, destination);
try {
- ModelSet modelSet = initModelSet(copyResources);
+ List<ModelSet> modelSetList = initModelSet(copyResources);
Map<URI, URI> constructInternalMapping = constructInternalMapping(copyResources);
for (int i = 0; i < resources.length; i++) {
- if (checkResource(modelSet, resources[i])) {
- restoreAllLink(modelSet, constructInternalMapping, copyResources[i], destinationPaths[i]);
+ for (ModelSet modelSet : modelSetList) {
+ if (checkResource(modelSet, resources[i])) {
+ restoreAllLink(modelSet, constructInternalMapping, copyResources[i], destinationPaths[i]);
+ }
}
}
} catch (IOException e) {
@@ -157,17 +164,23 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
* @param resources
* @return
*/
- protected ModelSet initModelSet(IResource[] resources) {
- ModelSet modelSet = new DiResourceSet();
+ protected List<ModelSet> initModelSet(IResource[] resources) {
+ List<ModelSet> modelSetList = new ArrayList<ModelSet>();
for (IResource iResource : resources) {
IPath fullPath = iResource.getFullPath();
if (DiModel.MODEL_FILE_EXTENSION.equals(fullPath.getFileExtension())) {
if (iResource instanceof IFile) {
- modelSet.createsModels((IFile) iResource);
+ try {
+ ModelSet modelSet = new DiResourceSet();
+ modelSet.loadModels((IFile) iResource);
+ modelSetList.add(modelSet);
+ } catch (ModelMultiException e) {
+ Activator.log.error("It was not possible to load models", e); //$NON-NLS-1$
+ }
}
}
}
- return modelSet;
+ return modelSetList;
}
/**
@@ -210,8 +223,27 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
DependencyManagementHelper.updateDependencies(oneInternalCopyMapping.getKey(), oneInternalCopyMapping.getValue(), resource);
}
resource.save(ResourceUtils.getSaveOptions());
- }
+ IPath fullPath = copyResources.getFullPath();
+ Resource sashResource = null;
+ // restore links for sash
+ if (DiModel.MODEL_FILE_EXTENSION.equals(fullPath.getFileExtension())) {
+ SashModel sashModel = SashModelUtils.getSashModel(modelSet);
+ if (sashModel != null && !constructInternalMapping.containsKey(sashModel.getURI())) { // Kepler and earlier stored the sash model in the DI
+ sashResource = sashModel.getResource();
+ for (Entry<URI, URI> oneInternalCopyMapping : constructInternalMapping.entrySet()) {
+ DependencyManagementHelper.updateDependencies(oneInternalCopyMapping.getKey(), oneInternalCopyMapping.getValue(), sashResource);
+ }
+ }
+ if (sashResource != null) { // save new sash model
+ ModelSet tempModelSet = new DiResourceSet();
+ tempModelSet.createModels(uri);
+ URI newsashModelURI = SashModelUtils.getSashModel(tempModelSet).getURI();
+ sashResource.setURI(newsashModelURI);
+ sashResource.save(ResourceUtils.getSaveOptions());
+ }
+ }
+ }
/**
* Construct an URI mapping from source to target
@@ -230,5 +262,4 @@ public class PapyrusCopyFilesAndFoldersOperation extends CopyFilesAndFoldersOper
}
return internalCopyMapping;
}
-
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/RenameModelChange.java b/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/RenameModelChange.java
index 7163d8a32b2..f4f3ed6ae18 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/RenameModelChange.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.ui.resources/src/org/eclipse/papyrus/infra/ui/resources/refactoring/RenameModelChange.java
@@ -60,6 +60,8 @@ import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ModelsReader;
import org.eclipse.papyrus.infra.core.resource.ReadOnlyAxis;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.emf.readonly.ReadOnlyManager;
@@ -282,6 +284,27 @@ public class RenameModelChange extends Change {
}
pm.worked(5);
+
+ try {
+ SashModel oldSash = SashModelUtils.getSashModel(resourceSet);
+ URI oldSashURI = oldSash.getResourceURI();
+ Resource resource = oldSash.getResource();
+ resourceSet.loadModels(newFile);
+ SashModel sashModel = SashModelUtils.getSashModel(resourceSet);
+ URI stashNewFile = sashModel.getResourceURI();
+ resource.setURI(stashNewFile);
+ resource.save(ResourceUtils.getSaveOptions());
+ if(oldSash != null) { // delete old stash
+ try {
+ resourceSet.getURIConverter().delete(oldSashURI, null);
+ } catch (IOException e) {
+ log.error(Messages.bind(Messages.RenameModelChange_ErrorLoading, oldSashURI), e);
+ }
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
// Do not forget to unload all the resources to avoid memory leak
pm.subTask(Messages.RenameModelChange_Unloading);
resourceSet.unload();

Back to the top