private void createTreeModel() {
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    final FileIndex fileIndex =
        myModule != null
            ? ModuleRootManager.getInstance(myModule).getFileIndex()
            : ProjectRootManager.getInstance(myProject).getFileIndex();
    fileIndex.iterateContent(
        new ContentIterator() {
          public boolean processFile(VirtualFile fileOrDir) {
            if (fileOrDir.isDirectory() && fileIndex.isInSourceContent(fileOrDir)) {
              final PsiDirectory psiDirectory = psiManager.findDirectory(fileOrDir);
              LOG.assertTrue(psiDirectory != null);
              PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
              if (aPackage != null) {
                addPackage(aPackage);
              }
            }
            return true;
          }
        });

    TreeUtil.sort(
        myModel,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            DefaultMutableTreeNode n1 = (DefaultMutableTreeNode) o1;
            DefaultMutableTreeNode n2 = (DefaultMutableTreeNode) o2;
            PsiNamedElement element1 = (PsiNamedElement) n1.getUserObject();
            PsiNamedElement element2 = (PsiNamedElement) n2.getUserObject();
            return element1.getName().compareToIgnoreCase(element2.getName());
          }
        });
  }
Example #2
0
 public static void sort(final DefaultMutableTreeNode node, final Comparator comparator) {
   final List<TreeNode> children = childrenToArray(node);
   Collections.sort(children, comparator);
   node.removeAllChildren();
   addChildrenTo(node, children);
   for (int i = 0; i < node.getChildCount(); i++) {
     sort((DefaultMutableTreeNode) node.getChildAt(i), comparator);
   }
 }
 protected void sortDescendants(MyNode root) {
   TreeUtil.sort(root, getNodeComparator());
   ((DefaultTreeModel) myTree.getModel()).reload(root);
 }
Example #4
0
 public static void sort(final DefaultTreeModel model, final Comparator comparator) {
   sort((DefaultMutableTreeNode) model.getRoot(), comparator);
 }