Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2016-10-27 08:23:51 +0000
committerPierre-Charles David2016-10-27 08:26:37 +0000
commit3003c5b7b7ea0628ce2a01f94a63f28f49ab0962 (patch)
tree9f9a8a02acbfbbe03526ff0a712cbe0d114ded6d
parent7ced4bd44b5c036f7b1c7fed8627680efbe4d3d4 (diff)
downloadorg.eclipse.sirius-3.1.7.tar.gz
org.eclipse.sirius-3.1.7.tar.xz
org.eclipse.sirius-3.1.7.zip
[506125] Make sure tree items are always correctly sortedv3.1.7
Bug: 506125 Change-Id: I8d93ac0233e93ab6ac27c6c6b7487aa5ca542b29 Cherry-picks: 940c50853dc647e899406ebf122b83c323771fde Cherry-picks: 797d815f9237644e06caecad99feef202d2d9ec0 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/DTreeRefresh.java73
1 files changed, 34 insertions, 39 deletions
diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/DTreeRefresh.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/DTreeRefresh.java
index 0457b45246..7f2458ce9e 100644
--- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/DTreeRefresh.java
+++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/DTreeRefresh.java
@@ -12,11 +12,10 @@ package org.eclipse.sirius.tree.business.internal.dialect.common.tree;
import java.text.MessageFormat;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@@ -72,7 +71,6 @@ import com.google.common.collect.LinkedHashMultiset;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multiset;
-import com.google.common.collect.Ordering;
/**
* Update the {@link DTree} model according to the semantic model and the
@@ -449,7 +447,6 @@ class TreeItemContainerChildSupport implements ChildCreationSupport {
@Override
public void reorderChilds(Iterable<CreatedOutput> outDesc) {
final Multiset<TreeItemMapping> subMappings = LinkedHashMultiset.create();
- Set<TreeItemMapping> mappings = new HashSet<TreeItemMapping>();
final Map<EObject, CreatedOutput> outputToItem = Maps.newHashMap();
for (CreatedOutput createdOutput : outDesc) {
EObject createdElement = createdOutput.getCreatedElement();
@@ -458,48 +455,46 @@ class TreeItemContainerChildSupport implements ChildCreationSupport {
DTreeItem createdDTreeItem = (DTreeItem) createdElement;
TreeItemMapping actualMapping = createdDTreeItem.getActualMapping();
subMappings.add(actualMapping);
- mappings.add(actualMapping);
}
}
- // Does not need to sort DTreeItem according to their mapping if there
- // is only one mapping
- if (mappings.size() > 1) {
-
- // Counts subMappings to correctly sort tree items regarding mapping
- // order (items have been created regarding the semantic candidates
- // order)
- int startIndex = 0;
- final Map<TreeItemMapping, Integer> startIndexes = Maps.newHashMap();
- for (TreeItemMapping itemMapping : subMappings) {
- startIndexes.put(itemMapping, startIndex);
- startIndex += subMappings.count(itemMapping);
- }
+ // Counts subMappings to correctly sort tree items regarding mapping
+ // order (items have been created regarding the semantic candidates
+ // order)
+ int startIndex = 0;
+ final Map<TreeItemMapping, Integer> startIndexes = Maps.newHashMap();
+ for (TreeItemMapping itemMapping : subMappings) {
+ startIndexes.put(itemMapping, startIndex);
+ startIndex += subMappings.count(itemMapping);
+ }
- Function<DTreeItem, Integer> getNewIndex = new Function<DTreeItem, Integer>() {
-
- @Override
- public Integer apply(DTreeItem from) {
- // init with element count : elements with unknown mapping
- // will
- // be placed at
- // the end.
- int index = outputToItem.size();
- TreeItemMapping itemMapping = from.getActualMapping();
- if (itemMapping != null && startIndexes.containsKey(itemMapping)) {
- index = startIndexes.get(itemMapping);
- }
+ // Pre-compute the new indices
+ final Map<DTreeItem, Integer> newIndices = Maps.newHashMap();
+ for (DTreeItem treeItem : container.getOwnedTreeItems()) {
+ // init with element count : elements with unknown mapping
+ // will be placed at the end.
+ int index = outputToItem.size();
+ TreeItemMapping itemMapping = treeItem.getActualMapping();
+ if (itemMapping != null && startIndexes.containsKey(itemMapping)) {
+ index = startIndexes.get(itemMapping);
+ }
- CreatedOutput createdOutput = outputToItem.get(from);
- if (createdOutput != null) {
- return index + createdOutput.getNewIndex();
- }
- return -1;
- }
- };
+ CreatedOutput createdOutput = outputToItem.get(treeItem);
+ if (createdOutput != null) {
+ index = index + createdOutput.getNewIndex();
+ } else {
+ index = -1;
+ }
- ECollections.sort(container.getOwnedTreeItems(), Ordering.natural().onResultOf(getNewIndex));
+ newIndices.put(treeItem, index);
}
+
+ ECollections.sort(container.getOwnedTreeItems(), new Comparator<DTreeItem>() {
+ @Override
+ public int compare(DTreeItem o1, DTreeItem o2) {
+ return newIndices.get(o1).compareTo(newIndices.get(o2));
+ }
+ });
}
@Override

Back to the top