aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-03-26 15:55:06 (EDT)
committerOleg Besedin2012-03-26 15:55:06 (EDT)
commit4d10c1a37a911bb20f12b49088e20d72ed1eb9ea (patch)
tree1d1253950b4f87b1fb9bc35937bdf4b9ca144ee8
parentd260d1bea8f977b396660fad7a4acb81075054bc (diff)
downloadeclipse.platform.ui-4d10c1a37a911bb20f12b49088e20d72ed1eb9ea.zip
eclipse.platform.ui-4d10c1a37a911bb20f12b49088e20d72ed1eb9ea.tar.gz
eclipse.platform.ui-4d10c1a37a911bb20f12b49088e20d72ed1eb9ea.tar.bz2
Bug 375269 - Menus items from fragments multiply after restart (MCommand
persistence is wrong)
-rw-r--r--bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java37
1 files changed, 35 insertions, 2 deletions
diff --git a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java
index 93f0afc..2e1e6ce 100644
--- a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java
+++ b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.e4.ui.model.internal;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -115,13 +117,13 @@ public class ModelUtils {
if( index >= 0 && list.size() > index ) {
flag = false;
- list.addAll(index, elements);
+ mergeList(list, elements, index);
}
}
// If there was no match append it to the list
if( flag ) {
- list.addAll(elements);
+ mergeList(list, elements, -1);
}
return copy;
@@ -139,6 +141,37 @@ public class ModelUtils {
return Collections.emptyList();
}
+
+ private static void mergeList(List list, List<MApplicationElement> elements, int index) {
+ MApplicationElement[] tmp = new MApplicationElement[elements.size()];
+ elements.toArray(tmp);
+ for(MApplicationElement element : tmp) {
+ String elementID = element.getElementId();
+ boolean found = false;
+ if ((elementID != null) && (!elementID.isEmpty())) {
+ for(Object existingObject : list) {
+ if (!(existingObject instanceof MApplicationElement))
+ continue;
+ MApplicationElement existingEObject = (MApplicationElement) existingObject;
+ if (!elementID.equals(existingEObject.getElementId()))
+ continue;
+ if (EcoreUtil.equals((EObject)existingEObject, (EObject)element)) {
+ found = true; // skip
+ break;
+ } else { // replace
+ EcoreUtil.replace((EObject)existingEObject, (EObject)element);
+ found = true;
+ }
+ }
+ }
+ if (!found) {
+ if (index == -1)
+ list.add(element);
+ else
+ list.add(index, element);
+ }
+ }
+ }
public static IEclipseContext getContainingContext(MApplicationElement element) {
MApplicationElement curParent = null;