Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2017-04-27 12:35:45 -0400
committerChristian W. Damus2017-04-27 12:39:04 -0400
commit510aa9bc9580e39be4f820c0a2218e30e3d75b41 (patch)
treeb642d4125b81a15118f01e03d6a07b9696b33814 /plugins/facet
parentc68d86a9abeeb4b43160d99e0506a4e150ecd098 (diff)
downloadorg.eclipse.papyrus-510aa9bc9580e39be4f820c0a2218e30e3d75b41.tar.gz
org.eclipse.papyrus-510aa9bc9580e39be4f820c0a2218e30e3d75b41.tar.xz
org.eclipse.papyrus-510aa9bc9580e39be4f820c0a2218e30e3d75b41.zip
Bug 515913: [Model Explorer] Toggling advanced mode does not respect "rank" order
Implement a proper and complete delegating list in for customizations, at the very least one that doesn't cause IndexOutOfBoundsExceptions by reporting wrong results for size() and isEmpty(). When toggling advanced mode off by re-enabling the SimpleUML customization, insert in the list in something like the place where it belongs according to "rank" ordering. https://bugs.eclipse.org/bugs/show_bug.cgi?id=515913 Change-Id: Ife845cf766a0641b252e371492d2548d114b5672
Diffstat (limited to 'plugins/facet')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/CustomizationsDelegatingList.java194
1 files changed, 47 insertions, 147 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/CustomizationsDelegatingList.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/CustomizationsDelegatingList.java
index 0a807ecdbac..9df3c12b6bc 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/CustomizationsDelegatingList.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.core/src/org/eclipse/papyrus/emf/facet/custom/core/internal/CustomizationsDelegatingList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012, 2017 CEA LIST, Christian W. Damus, and others.
* 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
@@ -9,181 +9,81 @@
* Nicolas Bros (Mia-Software) - Bug 374758 - [Table] repair the table
* Gregoire Dupe (Mia-Software) - Bug 372626 - Aggregates
* Thomas Cicognani (Soft-Maint) - Bug 420192 - UnsupportedOperationException in a usefull method
+ * Christian W. Damus - bug 515913
*******************************************************************************/
package org.eclipse.papyrus.emf.facet.custom.core.internal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.Arrays;
import java.util.List;
-import java.util.ListIterator;
+import java.util.stream.Collectors;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
/** Represents a list of {@link Customization}s that exists as a subset of a delegate list of {@link FacetSet}s. */
-public class CustomizationsDelegatingList implements List<Customization> {
+public class CustomizationsDelegatingList extends BasicEList<Customization> {
+ private static final long serialVersionUID = 1L;
+
private final List<FacetSet> delegate;
public CustomizationsDelegatingList(final List<FacetSet> delegate) {
+ super(customizations(delegate));
this.delegate = delegate;
}
- public int size() {
- return this.delegate.size();
- }
-
- public boolean isEmpty() {
- return this.delegate.isEmpty();
- }
-
- public boolean contains(final Object element) {
- return element instanceof Customization && this.delegate.contains(element);
- }
-
- public Iterator<Customization> iterator() {
- ArrayList<Customization> tmp = new ArrayList<Customization>();
- for (Iterator<FacetSet> iterator = this.delegate.iterator(); iterator.hasNext();) {
- FacetSet facetSet = iterator.next();
- if (facetSet instanceof Customization) {
- tmp.add((Customization) facetSet);
- }
-
+ @Override
+ protected void didAdd(int index, Customization newObject) {
+ // Insert at the corresponding location in the delegate
+ if (index > 0) {
+ index = delegate.indexOf(get(index - 1)) + 1;
}
-
- return tmp.iterator();
+ delegate.add(index, newObject);
}
- public Object[] toArray() {
- ArrayList<Customization> tmp = new ArrayList<Customization>();
- for (Iterator<FacetSet> iterator = this.delegate.iterator(); iterator.hasNext();) {
- FacetSet facetSet = iterator.next();
- if (facetSet instanceof Customization) {
- tmp.add((Customization) facetSet);
- }
-
- }
-
-
- return tmp.toArray();
+ @Override
+ protected void didSet(int index, Customization newObject, Customization oldObject) {
+ index = delegate.indexOf(oldObject);
+ delegate.set(index, newObject);
}
- public <T> T[] toArray(final T[] a) {
- ArrayList<Customization> tmp = new ArrayList<Customization>();
- for (Iterator<FacetSet> iterator = this.delegate.iterator(); iterator.hasNext();) {
- FacetSet facetSet = iterator.next();
- if (facetSet instanceof Customization) {
- tmp.add((Customization) facetSet);
- }
-
- }
-
-
- return tmp.toArray(a);
- }
-
- public boolean add(final Customization o) {
- return this.delegate.add(o);
+ @Override
+ protected void didRemove(int index, Customization oldObject) {
+ delegate.remove(oldObject);
}
- public boolean remove(final Object element) {
- return this.delegate.remove(element);
+ @Override
+ protected void didClear(int size, Object[] oldObjects) {
+ delegate.removeAll(Arrays.asList(oldObjects));
}
- public boolean containsAll(final Collection<?> c) {
- ArrayList<Customization> tmp = new ArrayList<Customization>();
- for (Iterator<FacetSet> iterator = this.delegate.iterator(); iterator.hasNext();) {
- FacetSet facetSet = iterator.next();
- if (facetSet instanceof Customization) {
- tmp.add((Customization) facetSet);
- }
-
+ @Override
+ protected void didMove(int index, Customization movedObject, int oldIndex) {
+ // Move to the corresponding location in the delegate
+ if (index > 0) {
+ index = delegate.indexOf(get(index - 1)) + 1;
}
- return tmp.containsAll(c);
- }
-
- public boolean addAll(final Collection<? extends Customization> c) {
- return this.delegate.addAll(c);
- }
-
- public boolean addAll(final int index, final Collection<? extends Customization> c) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public boolean removeAll(final Collection<?> c) {
- return this.delegate.removeAll(c);
- }
-
- public boolean retainAll(final Collection<?> c) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public void clear() {
- final ListIterator<FacetSet> listIterator = this.delegate.listIterator();
- while (listIterator.hasNext()) {
- final FacetSet facetSet = listIterator.next();
- if (facetSet instanceof Customization) {
- listIterator.remove();
- }
- }
- }
-
- public Customization get(final int index) {
- ArrayList<Customization> tmp = new ArrayList<Customization>();
- for (Iterator<FacetSet> iterator = this.delegate.iterator(); iterator.hasNext();) {
- FacetSet facetSet = iterator.next();
- if (facetSet instanceof Customization) {
- tmp.add((Customization) facetSet);
- }
-
- }
- return tmp.get(index);
- }
-
- public Customization set(final int index, final Customization element) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public void add(final int index, final Customization element) {
- if (index == 0) {
- this.delegate.add(0, element);
+ if (delegate instanceof EList<?>) {
+ ((EList<FacetSet>) delegate).move(index, movedObject);
} else {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
+ // Do it the hard way
+ delegate.remove(movedObject);
+ delegate.add(index, movedObject);
}
}
- public Customization remove(final int index) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public int indexOf(final Object element) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public int lastIndexOf(final Object element) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public ListIterator<Customization> listIterator() {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public ListIterator<Customization> listIterator(final int index) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
- }
-
- public List<Customization> subList(final int fromIndex, final int toIndex) {
- // FIXME implement
- throw new UnsupportedOperationException("not implemented"); //$NON-NLS-1$
+ /**
+ * Obtains the subset of a list of facet-sets that are customizations.
+ *
+ * @param facetSets
+ * the superset
+ * @return the subset of customizations
+ */
+ protected static List<Customization> customizations(List<FacetSet> facetSets) {
+ return facetSets.stream()
+ .filter(Customization.class::isInstance).map(Customization.class::cast)
+ .collect(Collectors.toList());
}
}

Back to the top