Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2019-04-02 05:49:25 -0400
committerRemi Schnekenburger2019-04-02 05:49:25 -0400
commit3b45dadbfa72b9969f1ecb9cd7b46833b0e5d806 (patch)
treeb74b467c1e4cf194519511e954640e9907955f27 /plugins/uml
parent9d15ecca37f4e63defe5f2539ed65578ee8c46cd (diff)
downloadorg.eclipse.papyrus-3b45dadbfa72b9969f1ecb9cd7b46833b0e5d806.tar.gz
org.eclipse.papyrus-3b45dadbfa72b9969f1ecb9cd7b46833b0e5d806.tar.xz
org.eclipse.papyrus-3b45dadbfa72b9969f1ecb9cd7b46833b0e5d806.zip
Bug 546040 - [Table] Column Add/remove menu not available on top left
corner for some models - Add some null checks in the code. As a note, these issues are hard to detect, as the model explorer does not display the empty package imports. Change-Id: I30d67f67459253a0a90e1331a4fa47af47221198 Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java92
1 files changed, 51 insertions, 41 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java
index 6302cbacf9d..503811bf52d 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/provider/UMLStereotypeRestrictedPropertyContentProvider.java
@@ -32,6 +32,7 @@ import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageImport;
+import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.ProfileApplication;
import org.eclipse.uml2.uml.Stereotype;
@@ -84,7 +85,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
* inits the fields of the table
*/
protected void init() {
- setProfiles(new ArrayList<Profile>(getAllAvailableProfiles()));
+ setProfiles(new ArrayList<>(getAllAvailableProfiles()));
this.restrictedElements = calculusOfAllowedElements();
}
@@ -108,7 +109,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
return new Object[0];
} else {
List<Object> values = Arrays.asList(super.getElements());
- values = new ArrayList<Object>(values);
+ values = new ArrayList<>(values);
values.retainAll(restrictedElements);
return values.toArray();
}
@@ -120,12 +121,12 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
/**
*
* @return
- * the list of the allowed profiles and stereotypes
+ * the list of the allowed profiles and stereotypes
*/
protected Collection<Element> calculusOfAllowedElements() {
- final Collection<Element> restrictedElements = new HashSet<Element>();
+ final Collection<Element> restrictedElements = new HashSet<>();
// we are restricted so we show only the elements available for the current contents of the table
- final Set<Stereotype> restrictedStereotypes = new HashSet<Stereotype>();
+ final Set<Stereotype> restrictedStereotypes = new HashSet<>();
final boolean isColumnManager = umlStereotypePropertyManager.isUsedAsColumnManager();
final List<?> elementsList;
if (isColumnManager) {
@@ -140,7 +141,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
}
}
- final Collection<Namespace> stereotypesNamespace = new HashSet<Namespace>();
+ final Collection<Namespace> stereotypesNamespace = new HashSet<>();
stereotypesNamespace.addAll(restrictedStereotypes);
for (Stereotype stereotype : restrictedStereotypes) {
stereotypesNamespace.addAll(stereotype.allNamespaces());
@@ -169,10 +170,10 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
/**
*
* @return
- * the list of all the profiles applied somewhere in the model
+ * the list of all the profiles applied somewhere in the model
*/
protected Set<Profile> getAllAvailableProfiles() {
- final Set<Profile> coll = new HashSet<Profile>();
+ final Set<Profile> coll = new HashSet<>();
final EObject context = umlStereotypePropertyManager.getTableManager().getTableContext();
if (context instanceof Element) {
final EObject container = EcoreUtil.getRootContainer(context);
@@ -213,11 +214,11 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
* @param pack
* a package
* @return
- * a collection with all profiles applied in the package and its subpackage
+ * a collection with all profiles applied in the package and its subpackage
* //TODO : should be moved in an upper plugin
*/
private static final Collection<Profile> getAppliedProfilesInWholePackage(final Package pack) {
- final Collection<Profile> appliedProfiles = new HashSet<Profile>();
+ final Collection<Profile> appliedProfiles = new HashSet<>();
final List<ProfileApplication> result = getInstancesFilteredByType(pack, ProfileApplication.class, null);
for (ProfileApplication profileApplication : result) {
if (EcoreUtil.getRootContainer((profileApplication.getApplyingPackage())) == pack) {// restriction to avoid to find profile application from an imported model
@@ -249,7 +250,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
// Assert.isNotNull(topPackage,
// "Top package should not be null for element " + element);
Iterator<EObject> iter = topPackage.eAllContents();
- List<T> filteredElements = new ArrayList<T>();
+ List<T> filteredElements = new ArrayList<>();
while (iter.hasNext()) {
EObject currentElt = iter.next();
@@ -263,39 +264,45 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
/* package imports treatment */
else if (currentElt instanceof PackageImport) {
- Iterator<EObject> piIter = ((PackageImport) currentElt).getImportedPackage().eAllContents();
- while (piIter.hasNext()) {
- EObject piCurrentElt = piIter.next();
- if (piCurrentElt instanceof Element) {
- if (appliedStereotype != null) {
-
- Iterator<Stereotype> appStIter = ((Element) piCurrentElt).getAppliedStereotypes().iterator();
- while (appStIter.hasNext()) {
- Stereotype currentSt = appStIter.next();
+ Package imported = ((PackageImport) currentElt).getImportedPackage();
+ if (imported != null) {
+ Iterator<EObject> piIter = imported.eAllContents();
+ while (piIter.hasNext()) {
+ EObject piCurrentElt = piIter.next();
+ if (piCurrentElt instanceof Element) {
+ if (appliedStereotype != null) {
+
+ Iterator<Stereotype> appStIter = ((Element) piCurrentElt).getAppliedStereotypes().iterator();
+ while (appStIter.hasNext()) {
+ Stereotype currentSt = appStIter.next();
+
+ if (currentSt.conformsTo(appliedStereotype)) {
+ filteredElements.add((T) piCurrentElt);
+ }
+ }
- if (currentSt.conformsTo(appliedStereotype)) {
+ } else { // if (appliedStereotype == null)
+ if (metaType.isInstance(piCurrentElt)) {
filteredElements.add((T) piCurrentElt);
}
- }
- } else { // if (appliedStereotype == null)
- if (metaType.isInstance(piCurrentElt)) {
- filteredElements.add((T) piCurrentElt);
- }
-
- /** add imported meta elements */
- else if (piCurrentElt instanceof ElementImport) {
- Iterator<EObject> eIter = ((ElementImport) piCurrentElt).getImportedElement().eAllContents();
- while (eIter.hasNext()) {
- EObject currentEIelt = eIter.next();
- if (metaType.isInstance(currentEIelt)) {
- filteredElements.add((T) currentEIelt);
+ /** add imported meta elements */
+ else if (piCurrentElt instanceof ElementImport) {
+ PackageableElement importedElement = ((ElementImport) piCurrentElt).getImportedElement();
+ if (importedElement != null) {
+ Iterator<EObject> eIter = importedElement.eAllContents();
+ while (eIter.hasNext()) {
+ EObject currentEIelt = eIter.next();
+ if (metaType.isInstance(currentEIelt)) {
+ filteredElements.add((T) currentEIelt);
+ }
+ }
}
}
}
}
- }
+ }
}
}
@@ -320,11 +327,14 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
/** add imported meta elements */
else if (currentElt instanceof ElementImport) {
- Iterator<EObject> eIter = ((ElementImport) currentElt).getImportedElement().eAllContents();
- while (eIter.hasNext()) {
- EObject currentEIelt = eIter.next();
- if (metaType.isInstance(currentEIelt)) {
- filteredElements.add((T) currentEIelt);
+ PackageableElement importedElement = ((ElementImport) currentElt).getImportedElement();
+ if (importedElement != null) {
+ Iterator<EObject> eIter = importedElement.eAllContents();
+ while (eIter.hasNext()) {
+ EObject currentEIelt = eIter.next();
+ if (metaType.isInstance(currentEIelt)) {
+ filteredElements.add((T) currentEIelt);
+ }
}
}
}
@@ -365,7 +375,7 @@ public class UMLStereotypeRestrictedPropertyContentProvider extends UMLStereotyp
return children;
} else {
// we are restricted so we show only the elements available for the current contents of the table
- final Collection<Object> returnedValues = new ArrayList<Object>();
+ final Collection<Object> returnedValues = new ArrayList<>();
returnedValues.addAll(Arrays.asList(children));
returnedValues.retainAll(this.restrictedElements);
return returnedValues.toArray();

Back to the top