From 4dff83585552fbbed4fb1433e694a3006fd8cca1 Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Tue, 2 Aug 2016 16:26:02 +0200 Subject: Bug 499007: [Property][Table] NPE when deleting an element displayed in a table with AbstractStereotypedElementUMLSynchronizedOnFeatureAxisManager https://bugs.eclipse.org/bugs/show_bug.cgi?id=499007 Save the resource listened in the case of removed element before its dispose. Change-Id: I84aa3f29174e38536c4680c0bff4ea2bcd5dc7b5 Signed-off-by: Nicolas FAUVERGUE --- ...ElementUMLSynchronizedOnFeatureAxisManager.java | 16 +++++++-- .../papyrus/uml/nattable/utils/UMLTableUtils.java | 40 ++++++++++++---------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/AbstractStereotypedElementUMLSynchronizedOnFeatureAxisManager.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/AbstractStereotypedElementUMLSynchronizedOnFeatureAxisManager.java index 98e92c34f1c..90aa7d2de67 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/AbstractStereotypedElementUMLSynchronizedOnFeatureAxisManager.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/axis/AbstractStereotypedElementUMLSynchronizedOnFeatureAxisManager.java @@ -9,7 +9,7 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 439501 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 439501, 499007 * *****************************************************************************/ package org.eclipse.papyrus.uml.nattable.manager.axis; @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -56,6 +57,11 @@ public abstract class AbstractStereotypedElementUMLSynchronizedOnFeatureAxisMana * the map between the stereotypes applications and the base_element */ protected Map stereotypedElementsMap; + + /** + * The list of resources listened. + */ + protected Collection listenedResources; /** @@ -109,7 +115,11 @@ public abstract class AbstractStereotypedElementUMLSynchronizedOnFeatureAxisMana * @return */ protected Collection getResourceToListen() { - return Collections.singleton(getTableContext().eResource()); + if(null == this.listenedResources){ + this.listenedResources = new HashSet(); + this.listenedResources.add(getTableContext().eResource()); + } + return this.listenedResources; } /** @@ -385,6 +395,8 @@ public abstract class AbstractStereotypedElementUMLSynchronizedOnFeatureAxisMana @Override public void dispose() { super.dispose(); + this.listenedResources.clear(); + this.listenedResources = null; this.listenerMap.clear(); this.stereotypedElementsMap.clear(); } 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 4323ef05494..b18dd0ce960 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 @@ -102,28 +102,30 @@ public class UMLTableUtils { // 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 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 stereotypesIterator = StereotypeUtil.getAllStereotypes(appliedProfile).iterator(); - while(stereotypesIterator.hasNext() && null == result){ - final Stereotype ownedStereotype = stereotypesIterator.next(); - final Iterator propertiesIterator = ownedStereotype.getAllAttributes().iterator(); - while(propertiesIterator.hasNext() && null == result){ - final Property property = propertiesIterator.next(); - if(property.getQualifiedName().equals(propertyQN)){ - result = property; + if (null != element.getNearestPackage()){ + final Iterator 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 stereotypesIterator = StereotypeUtil.getAllStereotypes(appliedProfile).iterator(); + while(stereotypesIterator.hasNext() && null == result){ + final Stereotype ownedStereotype = stereotypesIterator.next(); + final Iterator 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); + + // 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; -- cgit v1.2.3