use of org.eclipse.che.ide.ui.smartTree.compare.NameComparator in project che by eclipse.
the class FindResultGroupNode method getChildrenImpl.
/** {@inheritDoc} */
@Override
protected Promise<List<Node>> getChildrenImpl() {
List<Node> fileNodes = new ArrayList<>();
for (Resource resource : findResults) {
if (resource.getResourceType() != FILE) {
continue;
}
FileNode node = nodeFactory.newFileNode((File) resource, null);
NodePresentation presentation = node.getPresentation(true);
presentation.setInfoText(resource.getLocation().toString());
presentation.setInfoTextWrapper(Pair.of("(", ")"));
presentation.setInfoTextCss("color:" + getEditorInfoTextColor() + ";font-size: 11px");
fileNodes.add(node);
}
//sort nodes by file name
Collections.sort(fileNodes, new NameComparator());
return Promises.resolve(fileNodes);
}
use of org.eclipse.che.ide.ui.smartTree.compare.NameComparator in project che by eclipse.
the class ChangedListViewImpl method getGroupedNodes.
private List<Node> getGroupedNodes(Map<String, Status> items) {
List<String> allFiles = new ArrayList<>(items.keySet());
List<String> allPaths = new ArrayList<>();
for (String file : allFiles) {
String path = file.substring(0, file.lastIndexOf("/"));
if (!allPaths.contains(path)) {
allPaths.add(path);
}
}
List<String> commonPaths = getCommonPaths(allPaths);
for (String commonPath : commonPaths) {
if (!allPaths.contains(commonPath)) {
allPaths.add(commonPath);
}
}
Map<String, Node> preparedNodes = new HashMap<>();
for (int i = getMaxNestedLevel(allFiles); i > 0; i--) {
//Collect child files of all folders of current nesting level
Map<String, List<Node>> currentChildNodes = new HashMap<>();
for (String file : allFiles) {
Path pathName = Path.valueOf(file);
if (pathName.segmentCount() != i) {
continue;
}
Node fileNode = new ChangedFileNode(file, items.get(file), nodesResources, delegate, true);
String filePath = pathName.removeLastSegments(1).toString();
if (currentChildNodes.keySet().contains(filePath)) {
currentChildNodes.get(filePath).add(fileNode);
} else {
List<Node> listFiles = new ArrayList<>();
listFiles.add(fileNode);
currentChildNodes.put(filePath, listFiles);
}
}
//Map child files to related folders of current nesting level or just create a common folder
for (String path : allPaths) {
if (!(Path.valueOf(path).segmentCount() == i - 1)) {
continue;
}
Node folder = new ChangedFolderNode(getTransitFolderName(allPaths, path), nodesResources);
if (currentChildNodes.keySet().contains(path)) {
folder.setChildren(currentChildNodes.get(path));
}
preparedNodes.put(path, folder);
}
//Take all child folders and nest them to related parent folders of current nesting level
List<String> currentPaths = new ArrayList<>(preparedNodes.keySet());
for (String parentPath : currentPaths) {
List<Node> nodesToNest = new ArrayList<>();
for (String nestedItem : currentPaths) {
if (!parentPath.equals(nestedItem) && (nestedItem.startsWith(parentPath + "/") || parentPath.isEmpty())) {
nodesToNest.add(preparedNodes.remove(nestedItem));
}
}
if (nodesToNest.isEmpty()) {
continue;
}
Collections.sort(nodesToNest, new NameComparator());
if (currentChildNodes.keySet().contains(parentPath)) {
nodesToNest.addAll(currentChildNodes.get(parentPath));
}
if (parentPath.isEmpty()) {
return nodesToNest;
} else {
preparedNodes.get(parentPath).setChildren(nodesToNest);
}
}
}
ArrayList<Node> nodes = new ArrayList<>(preparedNodes.values());
Collections.sort(nodes, new NameComparator());
return new ArrayList<>(nodes);
}
Aggregations