Search in sources :

Example 1 with TreeItemComparator

use of org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator in project pentaho-platform by pentaho.

the class SolutionTree method buildSolutionTree.

private void buildSolutionTree(FileTreeItem parentTreeItem, RepositoryFileTree repositoryFileTree) {
    List<RepositoryFileTree> children = repositoryFileTree.getChildren();
    // BISERVER-9599 - Custom Sort
    Collections.sort(children, new Comparator<RepositoryFileTree>() {

        @Override
        public int compare(RepositoryFileTree repositoryFileTree, RepositoryFileTree repositoryFileTree2) {
            return (new TreeItemComparator()).compare(repositoryFileTree.getFile().getTitle(), repositoryFileTree2.getFile().getTitle());
        }
    });
    for (RepositoryFileTree treeItem : children) {
        RepositoryFile file = treeItem.getFile();
        boolean isDirectory = file.isFolder();
        String fileName = file.getName();
        if ((!file.isHidden() || isShowHiddenFiles()) && !StringUtils.isEmpty(fileName)) {
            // TODO Mapping Title to LocalizedName
            String localizedName = file.getTitle();
            String description = file.getDescription();
            FileTreeItem childTreeItem = new FileTreeItem();
            childTreeItem.setStylePrimaryName("leaf-widget");
            // $NON-NLS-1$
            childTreeItem.getElement().setAttribute("id", file.getPath());
            childTreeItem.setUserObject(treeItem);
            childTreeItem.setRepositoryFile(file);
            if (file.isHidden() && file.isFolder()) {
                childTreeItem.addStyleDependentName("hidden");
            }
            if (treeItem != null && treeItem.getChildren() != null) {
                for (RepositoryFileTree childItem : treeItem.getChildren()) {
                    if (childItem.getFile().isFolder()) {
                        childTreeItem.addStyleName("parent-widget");
                        break;
                    }
                }
            }
            ElementUtils.killAllTextSelection(childTreeItem.getElement());
            childTreeItem.setURL(fileName);
            if (showLocalizedFileNames) {
                childTreeItem.setText(localizedName);
                if (isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) {
                    childTreeItem.setTitle(description);
                } else {
                    childTreeItem.setTitle(fileName);
                }
            } else {
                childTreeItem.setText(fileName);
                if (isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) {
                    childTreeItem.setTitle(description);
                } else {
                    childTreeItem.setTitle(localizedName);
                }
            }
            childTreeItem.setFileName(fileName);
            if (parentTreeItem == null && isDirectory) {
                addItem(childTreeItem);
            } else if (parentTreeItem != null) {
                parentTreeItem.addItem(childTreeItem);
            }
            FileTreeItem tmpParent = childTreeItem;
            String pathToChild = tmpParent.getFileName();
            while (tmpParent.getParentItem() != null) {
                tmpParent = (FileTreeItem) tmpParent.getParentItem();
                // $NON-NLS-1$
                pathToChild = tmpParent.getFileName() + "/" + pathToChild;
            }
            /*
         * TODO Not sure what to do here if (parentTreeItem != null) { ArrayList<FileChooserRepositoryFile> files =
         * (ArrayList<FileChooserRepositoryFile>) parentTreeItem.getUserObject(); if (files == null) { files = new
         * ArrayList<FileChooserRepositoryFile>(); parentTreeItem.setUserObject(files); } files.add(file); }
         */
            if (isDirectory) {
                buildSolutionTree(childTreeItem, treeItem);
            } else {
                if (parentTreeItem != null) {
                    parentTreeItem.removeItem(childTreeItem);
                }
            }
        }
    }
}
Also used : TreeItemComparator(org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

Example 2 with TreeItemComparator

use of org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator in project pentaho-platform by pentaho.

the class SolutionTree method onFetchRepositoryFileTree.

public void onFetchRepositoryFileTree(RepositoryFileTree fileTree, List<RepositoryFile> repositoryTrashItems) {
    if (fileTree == null) {
        WaitPopup.getInstance().setVisible(false);
        return;
    }
    repositoryFileTree = fileTree;
    trashItems = repositoryTrashItems;
    // remember selectedItem, so we can reselect it after the tree is loaded
    clear();
    // get document root item
    RepositoryFile rootRepositoryFile = repositoryFileTree.getFile();
    if (!rootRepositoryFile.isHidden() || isShowHiddenFiles()) {
        FileTreeItem rootItem = null;
        if (createRootNode) {
            rootItem = new FileTreeItem();
            rootItem.setText(rootRepositoryFile.getPath());
            rootItem.setTitle(rootRepositoryFile.getPath());
            rootItem.getElement().setId(rootRepositoryFile.getPath());
            // added so we can traverse the true names
            // $NON-NLS-1$
            rootItem.setFileName("/");
            rootItem.setRepositoryFile(rootRepositoryFile);
            addItem(rootItem);
            buildSolutionTree(rootItem, repositoryFileTree);
        } else {
            buildSolutionTree(null, repositoryFileTree);
            // sort the root elements
            ArrayList<TreeItem> roots = new ArrayList<TreeItem>();
            for (int i = 0; i < getItemCount(); i++) {
                roots.add(getItem(i));
            }
            // BISERVER-9599 - Custom Sort
            Collections.sort(roots, new TreeItemComparator());
            clear();
            for (TreeItem myRootItem : roots) {
                addItem(myRootItem);
            }
        }
    }
    fixLeafNodes();
    if (selectedPath != null) {
        select(selectedPath);
    } else if (selectedItem != null) {
        ArrayList<TreeItem> parents = new ArrayList<TreeItem>();
        while (selectedItem != null) {
            parents.add(selectedItem);
            selectedItem = selectedItem.getParentItem();
        }
        Collections.reverse(parents);
        selectFromList(parents);
    } else {
        for (int i = 0; i < getItemCount(); i++) {
            getItem(i).setState(true);
        }
    }
    WaitPopup.getInstance().setVisible(false);
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.gwt.widgets.client.filechooser.RepositoryFile) TreeItemComparator(org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator)

Aggregations

RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)2 TreeItemComparator (org.pentaho.gwt.widgets.client.filechooser.TreeItemComparator)2 TreeItem (com.google.gwt.user.client.ui.TreeItem)1 ArrayList (java.util.ArrayList)1 RepositoryFileTree (org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)1