diff options
| author | Pierre-Charles David | 2016-08-17 10:20:27 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-10-18 08:00:17 +0000 |
| commit | 940c50853dc647e899406ebf122b83c323771fde (patch) | |
| tree | 7ccfdee42b111a57a516a66403eaaebb49ee4d74 | |
| parent | c78cdc76e44d58692bb1636e0a2dacb42386aa58 (diff) | |
| download | org.eclipse.sirius-940c50853dc647e899406ebf122b83c323771fde.tar.gz org.eclipse.sirius-940c50853dc647e899406ebf122b83c323771fde.tar.xz org.eclipse.sirius-940c50853dc647e899406ebf122b83c323771fde.zip | |
[481433] Pre-compute new tree item indices
Compute new indices only once per item, and store the result in a map
for fast access during the actual sorting.
Bug: 481433
Change-Id: Id8120ad0b58eed44cacd874ce2d1fc9243e77643
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/TreeItemContainerChildSupport.java | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeItemContainerChildSupport.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeItemContainerChildSupport.java index fa7d04ec64..3dc52647ec 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeItemContainerChildSupport.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeItemContainerChildSupport.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2015, 2016 THALES GLOBAL SERVICES 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.sirius.tree.business.internal.dialect.common.tree; +import java.util.Comparator; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -28,11 +29,9 @@ import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.Global import org.eclipse.sirius.tree.description.TreeItemMapping; import org.eclipse.sirius.viewpoint.RGBValues; -import com.google.common.base.Function; import com.google.common.collect.LinkedHashMultiset; import com.google.common.collect.Maps; import com.google.common.collect.Multiset; -import com.google.common.collect.Ordering; /** * A {@link ChildCreationSupport}. @@ -88,29 +87,33 @@ class TreeItemContainerChildSupport implements ChildCreationSupport { startIndex += subMappings.count(itemMapping); } - Function<DTreeItem, Integer> getNewIndex = new Function<DTreeItem, Integer>() { + // 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); + } - @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); - } - - 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)); + } + }); } } |
