diff options
author | vlorenzo | 2012-09-10 15:03:07 +0000 |
---|---|---|
committer | vlorenzo | 2012-09-10 15:03:07 +0000 |
commit | fb0cc901644cfb96db3feb6fce5e1b0dc5e2e6a8 (patch) | |
tree | 78717f2c25fb6e62c20044a9bb94eeaa5d019592 /plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src | |
parent | 575e7dd1065b51c79a9c1caa718af2ad5b41bfc5 (diff) | |
download | org.eclipse.papyrus-fb0cc901644cfb96db3feb6fce5e1b0dc5e2e6a8.tar.gz org.eclipse.papyrus-fb0cc901644cfb96db3feb6fce5e1b0dc5e2e6a8.tar.xz org.eclipse.papyrus-fb0cc901644cfb96db3feb6fce5e1b0dc5e2e6a8.zip |
387704: [Control Mode] Controlling a package leaves the stereotypes applied to the package in the parent files
https://bugs.eclipse.org/bugs/show_bug.cgi?id=387704
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src')
-rw-r--r-- | plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/helpers/ProfileApplicationHelper.java | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/helpers/ProfileApplicationHelper.java b/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/helpers/ProfileApplicationHelper.java index 55e814524d4..b033fcc8d55 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/helpers/ProfileApplicationHelper.java +++ b/plugins/uml/org.eclipse.papyrus.uml.controlmode.profile/src/org/eclipse/papyrus/uml/controlmode/profile/helpers/ProfileApplicationHelper.java @@ -9,7 +9,7 @@ *
* Contributors:
* Atos Origin - Initial API and implementation
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.controlmode.profile.helpers;
@@ -109,26 +109,45 @@ public class ProfileApplicationHelper { /**
* Relocate stereotype applications for the nested elements of the selection in the controlled resource
*
- * @param pack
- * the package for which stereotype application must be relocated
+ * @param root
+ * the root element for which stereotype applications must be relocated
* @param target
* the target controlled resource
*/
- public static void relocateStereotypeApplications(Package pack, Resource target) {
- for(Iterator<EObject> i = EcoreUtil.getAllProperContents(pack, false); i.hasNext();) {
+ public static void relocateStereotypeApplications(Element root, Resource target) {
+ // Relocate stereotype applications of the root element itself.
+ for(EObject stereotypeApplication : root.getStereotypeApplications()) {
+ relocateStereotypeApplication(root, stereotypeApplication);
+ }
+ // Relocate stereotype applications of the root's child elements.
+ for(Iterator<EObject> i = EcoreUtil.getAllProperContents(root, false); i.hasNext();) {
EObject current = i.next();
if(current instanceof Element) {
Element element = (Element)current;
- EList<EObject> stereotypeApplications = element.getStereotypeApplications();
- if(!stereotypeApplications.isEmpty()) {
- for(EObject e : stereotypeApplications) {
- int size = target.getContents().size();
- target.getContents().add(size, e);
- }
+ for(EObject stereotypeApplication : element.getStereotypeApplications()) {
+ relocateStereotypeApplication(element, stereotypeApplication);
}
}
}
}
+
+ /**
+ * Relocate one stereotype application of the given element.
+ *
+ * @param element
+ * the element holding the stereotype application to be relocated
+ * @param stereotypeApplication
+ * the stereotype application to be relocated
+ */
+ public static void relocateStereotypeApplication(Element element, EObject stereotypeApplication) {
+ // Too bad that StereotypeApplicationHelper.getContainmentList is not public, it would have allowed a completely generic heuristic.
+ EList<EObject> containmentList; // = StereotypeApplicationHelper.INSTANCE.getContainmentList(element, stereotypeApplication.eClass());
+ Resource resource = element.eResource();
+ containmentList = resource != null ? resource.getContents() : null; // Default heuristic of StereotypeApplicationHelper.
+ if (containmentList != null) {
+ containmentList.add(stereotypeApplication);
+ }
+ }
/**
* Check if the profile application is a duplicated one
|