Search in sources :

Example 1 with NameComparator

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);
}
Also used : NodePresentation(org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation) FileNode(org.eclipse.che.ide.resources.tree.FileNode) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) AbstractTreeNode(org.eclipse.che.ide.api.data.tree.AbstractTreeNode) ArrayList(java.util.ArrayList) Resource(org.eclipse.che.ide.api.resources.Resource) FileNode(org.eclipse.che.ide.resources.tree.FileNode) NameComparator(org.eclipse.che.ide.ui.smartTree.compare.NameComparator)

Example 2 with NameComparator

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);
}
Also used : Path(org.eclipse.che.ide.resource.Path) HashMap(java.util.HashMap) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList) NameComparator(org.eclipse.che.ide.ui.smartTree.compare.NameComparator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 NameComparator (org.eclipse.che.ide.ui.smartTree.compare.NameComparator)2 HashMap (java.util.HashMap)1 List (java.util.List)1 AbstractTreeNode (org.eclipse.che.ide.api.data.tree.AbstractTreeNode)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 Path (org.eclipse.che.ide.resource.Path)1 FileNode (org.eclipse.che.ide.resources.tree.FileNode)1 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)1 NodePresentation (org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation)1