Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-07-05 15:37:16 +0000
committerGerrit Code Review @ Eclipse.org2016-08-08 08:01:03 +0000
commitef5fb6f168553366f49e17b26e4516206556f803 (patch)
tree32d0fb2567da7692ec58e515a1a4387fbe73f950 /plugins/uml/nattable
parentef15ff64d8681bd86cd70f7d3d5fd5a3c8a3736b (diff)
downloadorg.eclipse.papyrus-ef5fb6f168553366f49e17b26e4516206556f803.tar.gz
org.eclipse.papyrus-ef5fb6f168553366f49e17b26e4516206556f803.tar.xz
org.eclipse.papyrus-ef5fb6f168553366f49e17b26e4516206556f803.zip
Bug 497301: [Table] Paste with stereotype property of profile into
package does not work https://bugs.eclipse.org/bugs/show_bug.cgi?id=497301 The sub packages of the profile was not checked to retrieve the stereotype property. + Same problem with stereotype search in the post actions. Add JUnit tests for the UMLTableUtils#getRealStereotypeProperty function. Change-Id: I9687bc2f50d29d8de9f0cdd70af5a470075908a1 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/uml/nattable')
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/paste/ApplyStereotypePastePostAction.java71
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java81
2 files changed, 74 insertions, 78 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/paste/ApplyStereotypePastePostAction.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/paste/ApplyStereotypePastePostAction.java
index 930d21411d4..01fbf2734e9 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/paste/ApplyStereotypePastePostAction.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/paste/ApplyStereotypePastePostAction.java
@@ -35,6 +35,7 @@ import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLPackage;
@@ -108,39 +109,49 @@ public class ApplyStereotypePastePostAction implements IPastePostAction {
final String stereotypeQN = postAction.replace(Constants.POST_ACTION_APPLY_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
alreadyApplied = elementToStereotype.eResource() != null && elementToStereotype.getAppliedStereotype(stereotypeQN) != null;
if (!alreadyApplied) {
- final String profileQN = NamedElementUtil.getParentQualifiedName(stereotypeQN);
- final String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQN);
- final Package nearestPackage = tableContext.getNearestPackage().getAppliedProfile(profileQN, true);
- if (nearestPackage != null) {
- final Stereotype ste = (Stereotype) nearestPackage.getMember(stereotypeName, false, UMLPackage.eINSTANCE.getStereotype());
-
- if (ste != null) {
- final EObject stereotypeApplication = CustomElementOperations.applyStereotype(tableContext.getNearestPackage(), elementToStereotype, ste);
- final Collection<EObject> steAppList;
- if (sharedMap.containsKey(STEREOTYPES_APPLICATIONS_TO_ADD_TO_RESOURCE)) {
- steAppList = (Collection<EObject>) sharedMap.get(STEREOTYPES_APPLICATIONS_TO_ADD_TO_RESOURCE);
- } else {
- steAppList = new ArrayList<EObject>();
- sharedMap.put(STEREOTYPES_APPLICATIONS_TO_ADD_TO_RESOURCE, steAppList);
- }
- steAppList.add(stereotypeApplication);
-
- // build the mapping between the stereotype and its emf instanciation
- Map<Property, EStructuralFeature> mapping = getMapping(ste, stereotypeApplication);
- final List<StereotypeApplicationStructure> struct;
- if (sharedMap.containsKey(elementToStereotype)) {
- struct = (List<StereotypeApplicationStructure>) sharedMap.get(elementToStereotype);
- } else {
- struct = new ArrayList<StereotypeApplicationStructure>();
- sharedMap.put(elementToStereotype, struct);
- }
- // create the structure used to store this mapping
- for (final Entry<Property, EStructuralFeature> current : mapping.entrySet()) {
- final StereotypeApplicationStructure structure = new StereotypeApplicationStructure(ste, stereotypeApplication, current.getKey(), current.getValue());
- struct.add(structure);
+ Stereotype findStereotype = null;
+
+ // Search the stereotype corresponding to the stereotype qualified name
+ final Iterator<Profile> appliedProfilesIterator = tableContext.getNearestPackage().getAllAppliedProfiles().iterator();
+ while(appliedProfilesIterator.hasNext() && null == findStereotype){
+ final Profile existingAppliedProfile = appliedProfilesIterator.next();
+
+ // Bug 488082 : Loop on all stereotypes (check in sub packages)
+ final Iterator<Stereotype> stereotypesIterator = StereotypeUtil.getAllStereotypes(existingAppliedProfile).iterator();
+ while(stereotypesIterator.hasNext() && null == findStereotype){
+ final Stereotype ownedStereotype = stereotypesIterator.next();
+ if(ownedStereotype.getQualifiedName().equals(stereotypeQN)){
+ findStereotype = ownedStereotype;
}
}
}
+
+ if (findStereotype != null) {
+ final EObject stereotypeApplication = CustomElementOperations.applyStereotype(tableContext.getNearestPackage(), elementToStereotype, findStereotype);
+ final Collection<EObject> steAppList;
+ if (sharedMap.containsKey(STEREOTYPES_APPLICATIONS_TO_ADD_TO_RESOURCE)) {
+ steAppList = (Collection<EObject>) sharedMap.get(STEREOTYPES_APPLICATIONS_TO_ADD_TO_RESOURCE);
+ } else {
+ steAppList = new ArrayList<EObject>();
+ sharedMap.put(STEREOTYPES_APPLICATIONS_TO_ADD_TO_RESOURCE, steAppList);
+ }
+ steAppList.add(stereotypeApplication);
+
+ // build the mapping between the stereotype and its emf instanciation
+ Map<Property, EStructuralFeature> mapping = getMapping(findStereotype, stereotypeApplication);
+ final List<StereotypeApplicationStructure> struct;
+ if (sharedMap.containsKey(elementToStereotype)) {
+ struct = (List<StereotypeApplicationStructure>) sharedMap.get(elementToStereotype);
+ } else {
+ struct = new ArrayList<StereotypeApplicationStructure>();
+ sharedMap.put(elementToStereotype, struct);
+ }
+ // create the structure used to store this mapping
+ for (final Entry<Property, EStructuralFeature> current : mapping.entrySet()) {
+ final StereotypeApplicationStructure structure = new StereotypeApplicationStructure(findStereotype, stereotypeApplication, current.getKey(), current.getValue());
+ struct.add(structure);
+ }
+ }
}
}
}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java
index b18dd0ce960..a31292d74f1 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java
@@ -93,42 +93,7 @@ public class UMLTableUtils {
* the UML::Property or <code>null</code> if we can't resolve it (the required profile is not applied)
*/
public static Property getRealStereotypeProperty(final EObject eobject, final String id) {
- Property result = null;
-
- Assert.isTrue(id.startsWith(PROPERTY_OF_STEREOTYPE_PREFIX));
- if (eobject instanceof Element) {
- final Element element = (Element) eobject;
- final String propertyQN = id.replace(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
-
- // Bug 435417 : Search the properties by their qualified name instead of search by its stereotypes first
- // This allows to manage the inherit properties and the stereotypes in packages
- if (null != element.getNearestPackage()){
- final Iterator<Profile> appliedProfilesIterator = element.getNearestPackage().getAllAppliedProfiles().iterator();
- while(appliedProfilesIterator.hasNext() && null == result){
- final Profile appliedProfile = appliedProfilesIterator.next();
-
- // Bug 488082 : Loop on all stereotypes (check in sub packages)
- final Iterator<Stereotype> stereotypesIterator = StereotypeUtil.getAllStereotypes(appliedProfile).iterator();
- while(stereotypesIterator.hasNext() && null == result){
- final Stereotype ownedStereotype = stereotypesIterator.next();
- final Iterator<Property> propertiesIterator = ownedStereotype.getAllAttributes().iterator();
- while(propertiesIterator.hasNext() && null == result){
- final Property property = propertiesIterator.next();
- if(property.getQualifiedName().equals(propertyQN)){
- result = property;
- }
- }
- }
- }
-
- // 2. if not, the profile could be applied on a sub-package of the nearest package
- /* the table can show element which are not children of its context, so the profile could not be available in its context */
- if(null == result){
- result = getProperty(element.getNearestPackage().getNestedPackages(), propertyQN);
- }
- }
- }
- return result;
+ return getRealStereotypeProperty(eobject, id, null);
}
/**
@@ -213,31 +178,51 @@ public class UMLTableUtils {
* the UML::Property or <code>null</code> if we can't resolve it (the required profile is not applied)
*/
public static Property getRealStereotypeProperty(final EObject eobject, final String id, final Map<?, ?> sharedMap) {
+ Property result = null;
+
Assert.isTrue(id.startsWith(PROPERTY_OF_STEREOTYPE_PREFIX));
if (eobject instanceof Element) {
final Element element = (Element) eobject;
final String propertyQN = id.replace(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
- final String propertyName = NamedElementUtil.getNameFromQualifiedName(propertyQN);
- final String stereotypeQN = NamedElementUtil.getParentQualifiedName(propertyQN);
- final String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQN);
- final String profileQN = NamedElementUtil.getParentQualifiedName(stereotypeQN);
- final Package nearestPackage;
- if (sharedMap != null) {
+
+ Package nearestPackage = null;
+ if (null != sharedMap) {
final Element context = (Element) sharedMap.get(Constants.PASTED_ELEMENT_CONTAINER_KEY);
nearestPackage = context.getNearestPackage();
} else {
nearestPackage = element.getNearestPackage();
}
- if (nearestPackage != null) {
- final Profile profile = nearestPackage.getAppliedProfile(profileQN, true);
- if (profile != null) {
- final Stereotype ste = profile.getOwnedStereotype(stereotypeName);
- return (Property) ste.getMember(propertyName);
+
+ if (null != nearestPackage) {
+ // Bug 435417 : Search the properties by their qualified name instead of search by its stereotypes first
+ // This allows to manage the inherit properties and the stereotypes in packages
+ final Iterator<Profile> appliedProfilesIterator = nearestPackage.getAllAppliedProfiles().iterator();
+ while(appliedProfilesIterator.hasNext() && null == result){
+ final Profile appliedProfile = appliedProfilesIterator.next();
+
+ // Bug 488082 : Loop on all stereotypes (check in sub packages)
+ final Iterator<Stereotype> stereotypesIterator = StereotypeUtil.getAllStereotypes(appliedProfile).iterator();
+ while(stereotypesIterator.hasNext() && null == result){
+ final Stereotype ownedStereotype = stereotypesIterator.next();
+ final Iterator<Property> propertiesIterator = ownedStereotype.getAllAttributes().iterator();
+ while(propertiesIterator.hasNext() && null == result){
+ final Property property = propertiesIterator.next();
+ if(property.getQualifiedName().equals(propertyQN)){
+ result = property;
+ }
+ }
+ }
+ }
+
+ // 2. if not, the profile could be applied on a sub-package of the nearest package
+ /* the table can show element which are not children of its context, so the profile could not be available in its context */
+ if(null == result){
+ result = getProperty(element.getNearestPackage().getNestedPackages(), propertyQN);
}
}
}
- return null;
+ return result;
}
/**

Back to the top