Source:
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(); outputToItem.put(createdElement, createdOutput); if (createdElement instanceof DTreeItem) { DTreeItem createdDTreeItem = (DTreeItem) createdElement; TreeItemMapping actualMapping = createdDTreeItem.getActualMapping(); subMappings.add(actualMapping); mappings.add(actualMapping); } } if (mappings.size() > 1) { int startIndex = 0; final Map<TreeItemMapping, Integer> startIndexes = Maps.newHashMap(); for (TreeItemMapping itemMapping : subMappings) { startIndexes.put(itemMapping, startIndex); startIndex += subMappings.count(itemMapping); } final Map<DTreeItem, Integer> newIndices = Maps.newHashMap(); for (DTreeItem from : container.getOwnedTreeItems()) { 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) { index = index + createdOutput.getNewIndex(); } else { index = -1; } newIndices.put(from, index); } ECollections.sort(container.getOwnedTreeItems(), new Comparator<DTreeItem>() { @Override public int compare(DTreeItem o1, DTreeItem o2) { return newIndices.get(o1).compareTo(newIndices.get(o2)); } }); } }

Target:
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(); outputToItem.put(createdElement, createdOutput); if (createdElement instanceof DTreeItem) { DTreeItem createdDTreeItem = (DTreeItem) createdElement; TreeItemMapping actualMapping = createdDTreeItem.getActualMapping(); subMappings.add(actualMapping); mappings.add(actualMapping); } } if (mappings.size() > 1) { int startIndex = 0; final Map<TreeItemMapping, Integer> startIndexes = Maps.newHashMap(); for (TreeItemMapping itemMapping : subMappings) { startIndexes.put(itemMapping, startIndex); startIndex += subMappings.count(itemMapping); } final Map<DTreeItem, Integer> newIndices = Maps.newHashMap(); for (DTreeItem treeItem : container.getOwnedTreeItems()) { int index = outputToItem.size(); TreeItemMapping itemMapping = treeItem.getActualMapping(); if (itemMapping != null && startIndexes.containsKey(itemMapping)) { index = startIndexes.get(itemMapping); } CreatedOutput createdOutput = outputToItem.get(treeItem); if (createdOutput != null) { index = index + createdOutput.getNewIndex(); } else { index = -1; } 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)); } }); } }