Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2013-08-09 10:14:07 -0400
committerrschnekenbu2013-08-09 10:22:53 -0400
commit39c673175d0a64cd56944d4e9eb9915d1e7330df (patch)
tree58b3b3131f49cec6801471f8df6895407023401b
parent97aac38470f7ab344bf31301181b861d8699f7cc (diff)
downloadorg.eclipse.papyrus-39c673175d0a64cd56944d4e9eb9915d1e7330df.tar.gz
org.eclipse.papyrus-39c673175d0a64cd56944d4e9eb9915d1e7330df.tar.xz
org.eclipse.papyrus-39c673175d0a64cd56944d4e9eb9915d1e7330df.zip
- Create a method to update from one save strategy to another one.
- Create a first test on model loading
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/META-INF/MANIFEST.MF10
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/org.eclipse.papyrus.uml.profile.externalresource.tests.launch2
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java210
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/Activator.java20
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AllTests.java4
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java72
-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.java88
-rw-r--r--sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/PapyrusStereotypeApplicationHelper.java3
9 files changed, 398 insertions, 14 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 5f2a1b82ef1..114db58284b 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
@@ -8,7 +8,15 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.junit,
org.eclipse.papyrus.uml.extensionpoints,
- org.eclipse.emf.ecore
+ org.eclipse.emf.ecore,
+ org.eclipse.papyrus.infra.core;bundle-version="0.10.1",
+ org.eclipse.core.resources;bundle-version="3.8.100",
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
+ org.eclipse.ui.ide;bundle-version="3.9.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.10.1",
+ 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"
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/org.eclipse.papyrus.uml.profile.externalresource.tests.launch b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/org.eclipse.papyrus.uml.profile.externalresource.tests.launch
index 7c572e9f2e6..d5620191059 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/org.eclipse.papyrus.uml.profile.externalresource.tests.launch
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/org.eclipse.papyrus.uml.profile.externalresource.tests.launch
@@ -28,7 +28,7 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.uml.profile.externalresource.tests"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -Xms768m -Xmx1200m -XX:PermSize=256M -XX:MaxPermSize=512M -Dorg.eclipse.uml2.uml.util.UMLUtil$StereotypeApplicationHelper.INSTANCE=org.eclipse.papyrus.uml.profile.externalresource.helper.PapyrusStereotypeApplicationHelper"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -Xms768m -Xmx1200m -XX:PermSize=256M -XX:MaxPermSize=512M -Dorg.eclipse.uml2.uml.util.UMLUtil$StereotypeApplicationHelper.INSTANCE=org.eclipse.papyrus.uml.profile.externalresource:org.eclipse.papyrus.uml.profile.externalresource.helper.PapyrusStereotypeApplicationHelper"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.platform.ide"/>
<booleanAttribute key="run_in_ui_thread" value="false"/>
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
new file mode 100644
index 00000000000..d7ee1a4a927
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AbstractExternalResourcesTest.java
@@ -0,0 +1,210 @@
+/*****************************************************************************
+ * 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.tests;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+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.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.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServiceMultiException;
+import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceInitializerService;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.internal.core.PDECore;
+import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.NamedElement;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+
+/**
+ * Abstract class for all tests in this plugin
+ */
+public abstract class AbstractExternalResourcesTest {
+
+ /** services registry for the model under test */
+ protected ServicesRegistry servicesRegistry;
+
+ /** model set that contains the model under test */
+ protected ModelSet modelSet;
+
+ /** The papyrus editor. */
+ protected IMultiDiagramEditor papyrusEditor;
+
+ public static boolean isInitialized = false;
+
+ public static IEditorPart editor = null;
+
+ public static String editorID = "org.eclipse.papyrus.infra.core.papyrusEditor";
+
+ public static final String EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE = "ExternalResourcesTestProfile::SubProfile";
+ public static final String EXTERNAL_RESOURCES_TEST_PROFILE = "ExternalResourcesTestProfile";
+ 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 MODEL_CLASS2 = "Class2";
+ public static final String ELEMENT_STEREOTYPE_NAME = "ElementStereotype";
+ public static final String ELEMENT_STEREOTYPE_QN = EXTERNAL_RESOURCES_TEST_PROFILE+NamedElement.SEPARATOR+EXTERNAL_RESOURCES_TEST_PROFILE_SUB_PROFILE+NamedElement.SEPARATOR+ELEMENT_STEREOTYPE_NAME;
+
+ @Before
+ public void initializeRegistry() {
+ // first of all, delete existing model
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ 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());
+ }
+ }
+
+ // import model files.
+ 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();
+ }
+
+ @After
+ public void tearDownRegistry() {
+ if(modelSet != null) {
+ modelSet.unload();
+ modelSet = null;
+ }
+ if(servicesRegistry != null) {
+ try {
+ servicesRegistry.disposeRegistry();
+ servicesRegistry = null;
+ } catch (ServiceMultiException e) {
+ Activator.log.error(e);
+ org.junit.Assert.fail(e.getMessage());
+ }
+ }
+ }
+
+ public ModelSet createModelSet(URI uri) throws ModelMultiException {
+ ModelSet modelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(modelSet);
+ modelSet.loadModels(uri);
+ return modelSet;
+ }
+
+ protected ServicesRegistry getUpdatedServiceRegistry() {
+ if(papyrusEditor != null) {
+ ServicesRegistry registry = (ServicesRegistry)papyrusEditor.getAdapter(ServicesRegistry.class);
+ return registry;
+ }
+ return servicesRegistry;
+ }
+
+ protected Collection<IEditorPart> getEditors() {
+ Collection<IEditorPart> results = new HashSet<IEditorPart>();
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for(IWorkbenchWindow iWorkbenchWindow : windows) {
+ IWorkbenchPage[] pages = iWorkbenchWindow.getPages();
+ for(IWorkbenchPage iWorkbenchPage : pages) {
+ IEditorReference[] references = iWorkbenchPage.getEditorReferences();
+ for(IEditorReference ref : references) {
+ IEditorPart editor = ref.getEditor(true);
+ results.add(editor);
+ }
+ }
+ }
+ return results;
+ }
+
+ public ServicesRegistry getServicesRegistry() {
+ if(servicesRegistry == null) {
+ //Try to find existing
+ ServicesRegistry registry = getUpdatedServiceRegistry();
+ if(registry != null) {
+ servicesRegistry = registry;
+ } else {
+ servicesRegistry = createServicesRegistry();
+ }
+ }
+ return servicesRegistry;
+ }
+
+ /**
+ * Starts a new Service registry
+ *
+ * @return
+ */
+ protected ServicesRegistry createServicesRegistry() {
+ try {
+ ServicesRegistry serviceRegistry = new ServicesRegistry();
+ serviceRegistry.startRegistry();
+ return serviceRegistry;
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return null;
+ }
+
+ public ModelSet getModelSet() {
+ //If null, try to find one or create one
+ if(modelSet == null) {
+ try {
+ modelSet = ServiceUtils.getInstance().getModelSet(getServicesRegistry());
+ } catch (ServiceException e) {
+ //Create one
+ try {
+ modelSet = createModelSet(getURI());
+ getServicesRegistry().add(ModelSet.class, 10, modelSet);
+ getServicesRegistry().add(ServiceUtilsForResourceInitializerService.class, 10, new ServiceUtilsForResourceInitializerService());
+ getServicesRegistry().startServicesByClassKeys(ModelSet.class, ServiceUtilsForResourceInitializerService.class);
+ } catch (ModelMultiException modelMultiException) {
+ Activator.log.error(modelMultiException);
+ } catch (ServiceMultiException e1) {
+ Activator.log.error(e1);
+ } catch (ServiceNotFoundException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
+ return modelSet;
+ }
+
+ /**
+ * @return the uri
+ */
+ public abstract URI getURI();
+}
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/Activator.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/Activator.java
index 6e3ffab829f..5272fa70ce6 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/Activator.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/Activator.java
@@ -12,6 +12,7 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.profile.externalresource.tests;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -26,30 +27,35 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
+ /** logger helper */
+ public static LogHelper log;
+
/**
* The constructor
*/
public Activator() {
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ /**
+ * {@inheritDoc}
*/
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ log = new LogHelper(this);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ /**
+ * {@inheritDoc}
*/
+ @Override
public void stop(BundleContext context) throws Exception {
plugin = null;
+ log = null;
super.stop(context);
}
-
+
/**
* Returns the shared instance
*
diff --git a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AllTests.java b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AllTests.java
index 06a4b841610..566623f0766 100644
--- a/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AllTests.java
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/AllTests.java
@@ -12,7 +12,7 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.profile.externalresource.tests;
-import org.eclipse.papyrus.uml.profile.externalresource.tests.resourceloading.ResourceLoading;
+import org.eclipse.papyrus.uml.profile.externalresource.tests.resourceperprofile.LoadUnloadOutsideEditorTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -23,7 +23,7 @@ import org.junit.runners.Suite.SuiteClasses;
*/
@RunWith(Suite.class)
@SuiteClasses({
- ResourceLoading.class
+ LoadUnloadOutsideEditorTests.class
})
public class AllTests {
}
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
new file mode 100644
index 00000000000..189b0a33178
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource.tests/src/org/eclipse/papyrus/uml/profile/externalresource/tests/resourceperprofile/LoadUnloadOutsideEditorTests.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * 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.tests.resourceperprofile;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.uml.profile.externalresource.tests.AbstractExternalResourcesTest;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test class for load/unload
+ */
+public class LoadUnloadOutsideEditorTests extends AbstractExternalResourcesTest {
+ @Test
+ public void testLoadModelOutsidePapyrusEditor() {
+ 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);
+ // test applied profiles
+ 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, class2_.getAppliedStereotype(ELEMENT_STEREOTYPE_QN));
+ }
+
+ @Test
+ public void testStereotypeApplicationOutsidePapyrusEditor() {
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public URI getURI() {
+ return URI.createPlatformResourceURI("/org.eclipse.papyrus.uml.profile.externalresource.tests/resources/OneResourcePerProfile/oneProfileApplied.di", true);
+ }
+}
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 bda54b83e1d..534dec7f3c0 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
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.core;bundle-version="0.10.0",
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"
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ com.google.guava;bundle-version="10.0.1"
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
new file mode 100644
index 00000000000..0e3a2e1e7d0
--- /dev/null
+++ b/sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource/src/org/eclipse/papyrus/uml/profile/externalresource/helper/ExternalResourceProfileUtils.java
@@ -0,0 +1,88 @@
+/*****************************************************************************
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * Utility class for stereotype application management in external resources
+ */
+public class ExternalResourceProfileUtils {
+
+ /**
+ * @param profileApplication
+ */
+ public void 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;
+ }
+ ModelSet modelSet = null;
+ if(modelResource.getResourceSet() instanceof ModelSet) {
+ return;
+ } 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()) {
+ 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);
+ }
+ }
+ }
+ }
+ }
+ allStereotypeApplications.put(definition, stereotypeApplications);
+ }
+ }
+
+ // now have a map of all definitions of stereotypes contained in the profile applied, now they should be moved according to the new strategy
+ for(EClass definition : allStereotypeApplications.keySet()) {
+ for(EObject stereotypeApplication : allStereotypeApplications.get(definition)) {
+ // move the EObject in the new containment list
+ Element baseElement = UMLUtil.getBaseElement(stereotypeApplication);
+ List<EObject> containmentList =newStrategy.getContainmentList(baseElement, definition);
+ if(!containmentList.contains(stereotypeApplication)) { // move the stereotype application only if it was not already there (to avoid useless moves)
+ containmentList.add(stereotypeApplication); // move stereotype at the right place
+ };
+ }
+ }
+ }
+}
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 f1398a885fe..33ef3494db9 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
@@ -64,9 +64,8 @@ public class PapyrusStereotypeApplicationHelper extends StereotypeApplicationHel
}
/**
- * Returns the location strategy to use for the given couple element/definition
+ * Returns the specific location strategy to use for the given model element
* @param element the stereotyped element
- * @param definition the definition of the stereotype to be applied
* @return the location strategy or <code>null</code> if none was found
*/
public static IStereotypeApplicationLocationStrategy getCurrentLocationStrategy(EObject element) {

Back to the top