Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2013-08-09 14:14:07 +0000
committerrschnekenbu2013-08-09 14:22:53 +0000
commit39c673175d0a64cd56944d4e9eb9915d1e7330df (patch)
tree58b3b3131f49cec6801471f8df6895407023401b /sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource
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
Diffstat (limited to 'sandbox/ExternalResourceStereotypeApplication/org.eclipse.papyrus.uml.profile.externalresource')
-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
3 files changed, 91 insertions, 3 deletions
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