Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2013-08-27 10:33:32 -0400
committerrschnekenbu2013-08-27 10:33:32 -0400
commitd85107d2963cc148f43c9101372556893749bec7 (patch)
tree3ff34e854708f861a27d705088e9cd72cac766c0
parente64645c55d4c35527c7acfd96d6a3e66b75df02d (diff)
downloadorg.eclipse.papyrus-d85107d2963cc148f43c9101372556893749bec7.tar.gz
org.eclipse.papyrus-d85107d2963cc148f43c9101372556893749bec7.tar.xz
org.eclipse.papyrus-d85107d2963cc148f43c9101372556893749bec7.zip
Add a command to change kind of profile application location strategy
Add a test to go from one resource per profile to one Resource only
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/META-INF/MANIFEST.MF3
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java46
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java90
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF3
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java94
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java7
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java8
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java19
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java8
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java8
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/UpdateStereotypeApplicationsLocationCommand.java56
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java20
12 files changed, 318 insertions, 44 deletions
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/META-INF/MANIFEST.MF b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/META-INF/MANIFEST.MF
index 84be7bf01b3..457c392258b 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/META-INF/MANIFEST.MF
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/META-INF/MANIFEST.MF
@@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.uml.tools;bundle-version="0.10.1",
org.eclipse.pde;bundle-version="3.8.100",
org.eclipse.pde.ui;bundle-version="3.8.0",
- org.eclipse.papyrus.uml.profile.externalresource;bundle-version="0.10.1"
+ org.eclipse.papyrus.uml.profile.externalresource;bundle-version="0.10.1",
+ org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.7.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.uml.profile.externalresource.tests,
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
index 365c4feecaa..2fb073fe466 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
@@ -23,10 +23,13 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ModelsReader;
+import org.eclipse.papyrus.infra.core.resource.TransactionalEditingDomainManager;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServiceMultiException;
import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
@@ -66,17 +69,22 @@ public abstract class AbstractExternalResourcesTest {
public static String editorID = "org.eclipse.papyrus.infra.core.papyrusEditor";
-
public static final String EXTERNAL_RESOURCES_TEST_PROFILE = "ExternalResourcesTestProfile";
- public static final String EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE = EXTERNAL_RESOURCES_TEST_PROFILE+NamedElement.SEPARATOR+"SubProfile";
+
+ public static final String EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE = EXTERNAL_RESOURCES_TEST_PROFILE + NamedElement.SEPARATOR + "SubProfile";
+
public static final String MODEL_CLASS1 = "Class1";
+
public static final String CLASS_STEREOTYPE_NAME = "ClassStereotype";
- public static final String CLASS_STEREOTYPE_QN = EXTERNAL_RESOURCES_TEST_PROFILE+"::"+CLASS_STEREOTYPE_NAME;
+
+ public static final String CLASS_STEREOTYPE_QN = EXTERNAL_RESOURCES_TEST_PROFILE + "::" + CLASS_STEREOTYPE_NAME;
public static final String MODEL_CLASS2 = "Class2";
+
public static final String ELEMENT_STEREOTYPE_NAME = "ElementStereotype";
- public static final String ELEMENT_STEREOTYPE_QN = EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE+NamedElement.SEPARATOR+ELEMENT_STEREOTYPE_NAME;
-
+
+ public static final String ELEMENT_STEREOTYPE_QN = EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE + NamedElement.SEPARATOR + ELEMENT_STEREOTYPE_NAME;
+
@Before
public void initializeRegistry() {
// first of all, delete existing model
@@ -84,22 +92,22 @@ public abstract class AbstractExternalResourcesTest {
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject(Activator.PLUGIN_ID);
//at this point, no resources have been created
- if(project.exists()) {
- try {
- project.delete(true, true, new NullProgressMonitor());
- } catch (CoreException e) {
- Assert.fail(e.getMessage());
- }
+ if(project.exists()) {
+ try {
+ project.delete(true, true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Assert.fail(e.getMessage());
}
-
+ }
// import model files.
- PluginImportOperation operation = new PluginImportOperation(new IPluginModelBase[] {PDECore.getDefault().getModelManager().findModel(Activator.PLUGIN_ID)} , PluginImportOperation.IMPORT_WITH_SOURCE, false);
+ PluginImportOperation operation = new PluginImportOperation(new IPluginModelBase[]{ PDECore.getDefault().getModelManager().findModel(Activator.PLUGIN_ID) }, PluginImportOperation.IMPORT_WITH_SOURCE, false);
IStatus status = operation.run(new NullProgressMonitor());
if(IStatus.ERROR == status.getSeverity()) {
Assert.fail(status.getMessage());
}
servicesRegistry = getServicesRegistry();
- modelSet = getModelSet();
+ modelSet = getModelSet(getURI());
+ Assert.assertNotNull("Model set should not be null", modelSet);
}
@After
@@ -180,7 +188,7 @@ public abstract class AbstractExternalResourcesTest {
return null;
}
- public ModelSet getModelSet() {
+ public ModelSet getModelSet(URI uri) {
//If null, try to find one or create one
if(modelSet == null) {
try {
@@ -188,10 +196,14 @@ public abstract class AbstractExternalResourcesTest {
} catch (ServiceException e) {
//Create one
try {
- modelSet = createModelSet(getURI());
+ modelSet = createModelSet(uri);
getServicesRegistry().add(ModelSet.class, 10, modelSet);
getServicesRegistry().add(ServiceUtilsForResourceInitializerService.class, 10, new ServiceUtilsForResourceInitializerService());
getServicesRegistry().startServicesByClassKeys(ModelSet.class, ServiceUtilsForResourceInitializerService.class);
+ TransactionalEditingDomain domain = TransactionalEditingDomainManager.createTransactionalEditingDomain(modelSet);
+ getServicesRegistry().add(TransactionalEditingDomain.class, 10, domain);
+ getServicesRegistry().add(EditingDomain.class, 10, domain);
+
} catch (ModelMultiException modelMultiException) {
Activator.log.error(modelMultiException);
} catch (ServiceMultiException e1) {
@@ -207,5 +219,5 @@ public abstract class AbstractExternalResourcesTest {
/**
* @return the uri
*/
- public abstract URI getURI();
+ public abstract URI getURI();
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java
index f84e8b1f46b..b70e135ec42 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java
@@ -14,9 +14,22 @@ package org.eclipse.papyrus.uml.profile.externalresource.tests.resourceperprofil
import static org.junit.Assert.fail;
+import java.io.IOException;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.uml.profile.externalresource.helper.ExternalResourceProfileUtils;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.OneResourceOnlyStrategy;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.PapyrusStereotypeApplicationHelper;
+import org.eclipse.papyrus.uml.profile.externalresource.helper.StrategyRegistry;
import org.eclipse.papyrus.uml.profile.externalresource.tests.AbstractExternalResourcesTest;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.uml2.uml.Class;
@@ -24,13 +37,12 @@ import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Assert;
import org.junit.Test;
-import org.junit.rules.ExternalResource;
/**
* Test class for load/unload
*/
public class LoadUnloadOutsideEditorTests extends AbstractExternalResourcesTest {
-
+
@Test
public void testLoadModelOutsidePapyrusEditor() {
UmlModel umlModel = null;
@@ -43,28 +55,90 @@ public class LoadUnloadOutsideEditorTests extends AbstractExternalResourcesTest
Model rootModel = (Model)umlModel.getResource().getContents().get(0);
Assert.assertNotNull("Root model impossible to find", rootModel);
// test applied profiles
+ checkModel(rootModel);
+ }
+
+ /**
+ * @param rootModel
+ */
+ protected void checkModel(Model rootModel) {
Assert.assertEquals("Some profiles are missing", 2, rootModel.getAllAppliedProfiles().size());
Assert.assertNotNull("ExternalResourcesTestProfile is missing", rootModel.getAppliedProfile(EXTERNAL_RESOURCES_TEST_PROFILE));
Assert.assertNotNull("ExternalResourcesTestProfile::SubProfile is missing", rootModel.getAppliedProfile(EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE));
-
// test some stereotype applications
// Model::class1 should have <<classStereotype>> Applied (verify root level stererotype)
Class class1_ = (Class)rootModel.getPackagedElement(MODEL_CLASS1, true, UMLPackage.eINSTANCE.getClass_(), false);
Assert.assertNotNull(MODEL_CLASS1 + " should not be null", class1_);
Assert.assertNotNull(MODEL_CLASS1 + " should have stereotype " + CLASS_STEREOTYPE_NAME, class1_.getAppliedStereotype(CLASS_STEREOTYPE_QN));
-
// Model::class1 should have <<classStereotype>> Applied (verify stereotype in subprofile)
Class class2_ = (Class)rootModel.getPackagedElement(MODEL_CLASS2, true, UMLPackage.eINSTANCE.getClass_(), false);
Assert.assertNotNull(MODEL_CLASS2 + " should not be null", class2_);
- Assert.assertNotNull(MODEL_CLASS2 + " should have stereotype " + ELEMENT_STEREOTYPE_NAME+", but has only: "+class2_.getAppliedStereotypes(), class2_.getAppliedStereotype(ELEMENT_STEREOTYPE_QN));
+ Assert.assertNotNull(MODEL_CLASS2 + " should have stereotype " + ELEMENT_STEREOTYPE_NAME + ", but has only: " + class2_.getAppliedStereotypes(), class2_.getAppliedStereotype(ELEMENT_STEREOTYPE_QN));
}
@Test
public void moveStereotypeApplicationOutsidePapyrusEditor() {
- //ExternalResourceProfileUtils.updateStereotypeApplicationsLocation(profileApplication, oldStrategy, newStrategy);
+ UmlModel umlModel = null;
+ // get The model. try to see applied stereotypes
+ try {
+ umlModel = (UmlModel)modelSet.getModelChecked(UmlModel.MODEL_ID);
+ } catch (NotFoundException e) {
+ fail(e.getMessage());
+ }
+ Model rootModel = (Model)umlModel.getResource().getContents().get(0);
+ Assert.assertNotNull("Root model impossible to find", rootModel);
+
+ ICommand command = ExternalResourceProfileUtils.createUpdateStereotypeApplicationsLocationCommand(rootModel, PapyrusStereotypeApplicationHelper.getCurrentLocationStrategy(rootModel), StrategyRegistry.getInstance().getStrategy(OneResourceOnlyStrategy.ID));
+ Assert.assertNotNull("Impossible to create update command", command);
+ Assert.assertTrue("Command should be executable", command.canExecute());
+ IStatus status = null;
+ try {
+ status = OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
+ } catch (ExecutionException e1) {
+ fail(e1.getMessage());
+ }
+
+ if(!status.isOK()) {
+ fail(status.getMessage());
+ }
+
+ URI tmpURI = URI.createPlatformResourceURI("/org.eclipse.papyrus.uml.profile.externalresource.tests/resources/OneResourcePerProfile/tmp.di", true);
+ try {
+ getModelSet(getURI()).saveAs(tmpURI);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ checkModel(rootModel);
+ // check current model still have right stereotypes/values
+ tearDownRegistry();
+ // try to load and read profiles in the tmp file
+ ModelSet tmpModelSet = getModelSet(tmpURI);
+ Assert.assertNotNull("TMP Model set should not be null", tmpModelSet);
+ UmlModel tmpUmlModel = null;
+ // get The tmp model. try to see applied stereotypes
+ try {
+ tmpUmlModel = (UmlModel)tmpModelSet.getModelChecked(UmlModel.MODEL_ID);
+ } catch (NotFoundException e) {
+ fail(e.getMessage());
+ }
+ Assert.assertNotNull(tmpUmlModel);
+ Resource tmpResource = tmpUmlModel.getResource();
+ Assert.assertNotNull(tmpResource);
+ Model tmpRootModel = (Model)tmpResource.getContents().get(0);
+ Assert.assertNotNull(tmpRootModel);
+ checkModel(tmpRootModel);
+ // additionnal checks : strategy, location of the stereotype application, etc.
+ // test some stereotype applications
+ // Model::class1 should have <<classStereotype>> Applied (verify root level stererotype)
+ Class class1_ = (Class)tmpRootModel.getPackagedElement(MODEL_CLASS1, true, UMLPackage.eINSTANCE.getClass_(), false);
+ EObject application = class1_.getStereotypeApplication(class1_.getAppliedStereotype(CLASS_STEREOTYPE_QN));
+ Assert.assertNotNull("No stereotype applied on "+ MODEL_CLASS1, application);
+ Assert.assertNotNull(application.eResource());
+ URI stereotypeApplicationURI = application.eResource().getURI();
+ Assert.assertEquals("Stereotype is not in expected resource", tmpURI.trimFileExtension().appendFileExtension(OneResourceOnlyStrategy.PROFILE_DEFAULT_EXTENSION), stereotypeApplicationURI);
+ // check undo, check redo...
}
-
-
+
/**
* {@inheritDoc}
*/
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF
index 09d1db80751..177e7f343cc 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.uml.tools.utils;bundle-version="0.10.1",
org.eclipse.papyrus.uml.tools;bundle-version="0.10.1",
org.eclipse.emf.transaction;bundle-version="1.4.0",
- com.google.guava;bundle-version="10.0.1"
+ com.google.guava;bundle-version="10.0.1",
+ org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.7.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.uml.profile.externalresource,
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
index eb1b706357f..b5408dab312 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
@@ -17,13 +17,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.uml.profile.externalresource.Activator;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.ProfileApplication;
import org.eclipse.uml2.uml.util.UMLUtil;
@@ -35,35 +41,39 @@ public class ExternalResourceProfileUtils {
/**
* @param profileApplication
*/
- public static void updateStereotypeApplicationsLocation(ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
+ public static IStatus updateStereotypeApplicationsLocation(ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
// 1. retrieve all stereotype applications concerned by the given profile application
// 2. move the stereotype application in their new containment list
Resource modelResource = profileApplication.eResource();
if(modelResource == null) {
- return;
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Impossible to find model resource");
}
ModelSet modelSet = null;
- if(modelResource.getResourceSet() instanceof ModelSet) {
- return;
+ if(!(modelResource.getResourceSet() instanceof ModelSet)) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Trying to modify the stereotype application outside a Papyrus Model Set");
} else {
modelSet = (ModelSet)modelResource.getResourceSet();
}
Map<EClass, List<EObject>> allStereotypeApplications = new HashMap<EClass, List<EObject>>();
// For all resources, retrieve the containment list that should hold the stereotype application for the given profile, for all UML elements at the root of the resource (should test for all elements, but would be really slow)
// for all elements in the containment list that corresponds to the profile application, store in a new list
- for(final EClassifier classifier : profileApplication.getAppliedDefinition().getEClassifiers()) {
+ List<EClassifier> classifiers = profileApplication.getAppliedDefinition().getEClassifiers();
+ for(final EClassifier classifier : classifiers) {
if(classifier instanceof EClass) {
final EClass definition = (EClass)classifier;
List<EObject> stereotypeApplications = new ArrayList<EObject>();
for(Resource resource : modelSet.getResources()) {
- for(EObject object : resource.getContents()) {
- if(object instanceof Element) {
- // retrieve the containment list for this element and all the stereotype applications of the applied profile
- Element element = ((Element)object);
- EList<EObject> fullList = oldStrategy.getContainmentList(element, definition);
- for(EObject possibleStereotypeApplication : fullList) {
- if(definition.equals(possibleStereotypeApplication.eClass())) {
- stereotypeApplications.add(possibleStereotypeApplication);
+ // if resource = read only (model import, etc.), nothing should be done
+ if(!modelSet.getTransactionalEditingDomain().isReadOnly(resource)) {
+ for(EObject object : resource.getContents()) {
+ if(object instanceof Element) {
+ // retrieve the containment list for this element and all the stereotype applications of the applied profile
+ Element element = ((Element)object);
+ EList<EObject> fullList = oldStrategy.getContainmentList(element, definition);
+ for(EObject possibleStereotypeApplication : fullList) {
+ if(definition.equals(possibleStereotypeApplication.eClass())) {
+ stereotypeApplications.add(possibleStereotypeApplication);
+ }
}
}
}
@@ -84,5 +94,63 @@ public class ExternalResourceProfileUtils {
};
}
}
+
+ // update Eannotation that stores the new strategy
+ PapyrusStereotypeApplicationHelper.setCurrentLocationStrategy(profileApplication, newStrategy);
+
+ return Status.OK_STATUS;
+ }
+
+ public static ICommand createUpdateStereotypeApplicationsLocationCommand( ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
+ if(profileApplication ==null) {
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+ // create a command based on #updateStereotypeApplicationsLocation()
+ return new UpdateStereotypeApplicationsLocationCommand(profileApplication, oldStrategy, newStrategy);
+ }
+
+
+ public static ICommand createUpdateStereotypeApplicationsLocationCommand( Element element, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
+ if(element ==null) {
+ return null;
+ }
+ // retrieve all stereotype applications from the element (should be for each root => subpackages and over), all stereotype applications
+ EObject root = EcoreUtil.getRootContainer(element, true);
+ if(root instanceof Package) {
+ List<ProfileApplication> profileApplications = new ArrayList<ProfileApplication>();
+ computeAllProfileApplications((Package)root, true, profileApplications);
+ return createUpdateStereotypeApplicationsLocationCommand(profileApplications, oldStrategy, newStrategy);
+ }
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * @param element
+ * @param recursive <code>true</code> if profile applications should be searched in nested packages
+ * @return
+ */
+ protected static void computeAllProfileApplications(Package package_, boolean recursive, List<ProfileApplication> profileApplications) {
+ List<ProfileApplication> thisPackageProfileApplications = package_.getProfileApplications();
+ if(thisPackageProfileApplications != null && thisPackageProfileApplications.size() > 0) {
+ profileApplications.addAll(thisPackageProfileApplications);
+ }
+
+ if(recursive) {
+ for(Package ownedPackage : package_.getNestedPackages()) {
+ computeAllProfileApplications(ownedPackage, recursive, profileApplications);
+ }
+ }
+ }
+
+ public static ICommand createUpdateStereotypeApplicationsLocationCommand(List<ProfileApplication> profileApplications, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
+ if(profileApplications == null || profileApplications.size() < 1) {
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ }
+ ICommand resultCommand = null;
+ for(ProfileApplication profileApplication : profileApplications) {
+ resultCommand = new UpdateStereotypeApplicationsLocationCommand(profileApplication, oldStrategy, newStrategy).compose(resultCommand);
+ }
+ return resultCommand;
}
+
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java
index 2f880b9db54..0dc998c92b0 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/IStereotypeApplicationLocationStrategy.java
@@ -41,4 +41,11 @@ public interface IStereotypeApplicationLocationStrategy {
*/
public Set<URI> getProfileApplicationResourceURIs(EObject root);
+
+ /**
+ * Returns the identifier of this strategy
+ * @return the identifier of this strategy, should never be <code>null</code>.
+ */
+ public String getIdentifier();
+
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java
index 1ea97abe14a..77def9cb776 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/OneResourceOnlyStrategy.java
@@ -101,4 +101,12 @@ public class OneResourceOnlyStrategy extends AbstractStereotypeApplicationLocati
return Collections.emptySet();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getIdentifier() {
+ return ID;
+ }
+
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java
index 33ef3494db9..a8aa71cadfc 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java
@@ -89,4 +89,23 @@ public class PapyrusStereotypeApplicationHelper extends StereotypeApplicationHel
return null;
}
+ /**
+ * Sets the specific location strategy to use for the given model element
+ * Warning: this method modifies the model, it should be executed in a command.
+ * @param element the stereotyped element
+ * @return the location strategy or <code>null</code> if none was found
+ */
+ public static void setCurrentLocationStrategy(EObject element, IStereotypeApplicationLocationStrategy newStrategy) {
+ EObject container = EcoreUtil.getRootContainer(element, true);
+ if(container instanceof Element) {
+ EAnnotation annotation = ((Element)container).getEAnnotation(PAPYRUS_EXTERNAL_RESOURCE_EANNOTATION_SOURCE);
+ if(annotation == null) {
+ // create a new one
+ annotation = ((Element)container).createEAnnotation(PAPYRUS_EXTERNAL_RESOURCE_EANNOTATION_SOURCE);
+ }
+ // update or create
+ annotation.getDetails().put(LOCATION_STRATEGY_KEY, newStrategy.getIdentifier());
+ }
+ }
+
}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java
index 6fb861b60f7..df2d511cb29 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ResourcePerProfileStrategy.java
@@ -64,6 +64,14 @@ public class ResourcePerProfileStrategy implements IStereotypeApplicationLocatio
}
return instance;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getIdentifier() {
+ return ID;
+ }
/**
* Returns the resource where the stereotype application should be added for the given couple element/stereotype
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java
index 1d75eaba828..d0e4de7274a 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/StandardApplicationLocationStrategy.java
@@ -37,6 +37,14 @@ public class StandardApplicationLocationStrategy implements IStereotypeApplicati
* {@inheritDoc}
*/
@Override
+ public String getIdentifier() {
+ return ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public EList<EObject> getContainmentList(Element element, EClass definition) {
if(element.eResource() !=null) {
return element.eResource().getContents();
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/UpdateStereotypeApplicationsLocationCommand.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/UpdateStereotypeApplicationsLocationCommand.java
new file mode 100644
index 00000000000..b45fa8fc07a
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/UpdateStereotypeApplicationsLocationCommand.java
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.externalresource.helper;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.uml2.uml.ProfileApplication;
+
+/**
+ * Command to update stereotype application locations when strategy is changed
+ */
+public class UpdateStereotypeApplicationsLocationCommand extends AbstractTransactionalCommand {
+
+ protected ProfileApplication profileApplication;
+ protected IStereotypeApplicationLocationStrategy oldStrategy;
+ protected IStereotypeApplicationLocationStrategy newStrategy;
+
+ /**
+ * Default Constructor
+ * @param profileApplication the profile application for which stereotype applications should be moved
+ * @param oldStrategy old strategy currently used to store stereotype applications
+ * @param newStrategy new strategy to use for stereotype application management
+ */
+ public UpdateStereotypeApplicationsLocationCommand(ProfileApplication profileApplication, IStereotypeApplicationLocationStrategy oldStrategy, IStereotypeApplicationLocationStrategy newStrategy) {
+ super(TransactionUtil.getEditingDomain(profileApplication), "Update Stereotype Applications Location", getWorkspaceFiles(profileApplication));
+ this.profileApplication = profileApplication;
+ this.oldStrategy = oldStrategy;
+ this.newStrategy = newStrategy;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ IStatus status = ExternalResourceProfileUtils.updateStereotypeApplicationsLocation(profileApplication, oldStrategy, newStrategy);
+ return new CommandResult(status);
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java
index 60a2f0b5ecb..ccd39aff4cd 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/model/StereotypeApplicationExternalResourceModel.java
@@ -46,7 +46,10 @@ public class StereotypeApplicationExternalResourceModel extends AbstractModel im
public static final String ID = "ExternalStereotypeApplicationModel";
/** list of resources for stereotype applications */
- List<Resource> profileApplicationResources = new ArrayList<Resource>();
+ protected List<Resource> profileApplicationResources = new ArrayList<Resource>();
+
+ /** stores the root URI that was used to load all the manage resources */
+ protected URI rootURI;
/**
* {@inheritDoc}
@@ -61,7 +64,7 @@ public class StereotypeApplicationExternalResourceModel extends AbstractModel im
*/
@Override
public void createModel(IPath fullPath) {
- throw new UnsupportedOperationException("CreateModel_IPath is not supported for " + getClass().getCanonicalName());
+ // throw new UnsupportedOperationException("CreateModel_IPath is not supported for " + getClass().getCanonicalName());
}
/**
@@ -69,7 +72,7 @@ public class StereotypeApplicationExternalResourceModel extends AbstractModel im
*/
@Override
public void createModel(URI uri) {
- throw new UnsupportedOperationException("CreateModel_URI is not supported for " + getClass().getCanonicalName());
+ // throw new UnsupportedOperationException("CreateModel_URI is not supported for " + getClass().getCanonicalName());
}
/**
@@ -96,6 +99,7 @@ public class StereotypeApplicationExternalResourceModel extends AbstractModel im
*/
@Override
public void loadModel(URI uri) {
+ rootURI = uri;
List<Resource> resources = getResources(true);
for(Resource resource : resources) {
try {
@@ -204,7 +208,15 @@ public class StereotypeApplicationExternalResourceModel extends AbstractModel im
*/
@Override
public void setModelURI(URI uri) {
- throw new UnsupportedOperationException("setModelURI is not supported for " + getClass().getCanonicalName());
+ List<Resource> resources = getResources(true);
+ for(Resource resource : resources) {
+ if(!ModelUtils.resourceFailedOnLoad(resource)) {
+ String fileExtension = resource.getURI().fileExtension();
+ URI newURI = uri.appendFileExtension(fileExtension);
+ resource.setURI(newURI);
+ }
+ }
+ rootURI = uri;
}
/**

Back to the top