Search in sources :

Example 41 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.

the class TodoView method initToolWindow.

public void initToolWindow(@NotNull ToolWindow toolWindow) {
    // Create panels
    ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
    Content allTodosContent = contentFactory.createContent(null, IdeBundle.message("title.project"), false);
    myAllTodos = new TodoPanel(myProject, state.all, false, allTodosContent) {

        @Override
        protected TodoTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
            AllTodosTreeBuilder builder = createAllTodoBuilder(tree, treeModel, project);
            builder.init();
            return builder;
        }
    };
    allTodosContent.setComponent(myAllTodos);
    Disposer.register(this, myAllTodos);
    Content currentFileTodosContent = contentFactory.createContent(null, IdeBundle.message("title.todo.current.file"), false);
    CurrentFileTodosPanel currentFileTodos = new CurrentFileTodosPanel(myProject, state.current, currentFileTodosContent) {

        @Override
        protected TodoTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
            CurrentFileTodosTreeBuilder builder = new CurrentFileTodosTreeBuilder(tree, treeModel, project);
            builder.init();
            return builder;
        }
    };
    Disposer.register(this, currentFileTodos);
    currentFileTodosContent.setComponent(currentFileTodos);
    myChangeListTodosContent = contentFactory.createContent(null, IdeBundle.message("changelist.todo.title", ChangeListManager.getInstance(myProject).getDefaultChangeList().getName()), false);
    ChangeListTodosPanel changeListTodos = new ChangeListTodosPanel(myProject, state.current, myChangeListTodosContent) {

        @Override
        protected TodoTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
            ChangeListTodosTreeBuilder builder = new ChangeListTodosTreeBuilder(tree, treeModel, project);
            builder.init();
            return builder;
        }
    };
    Disposer.register(this, changeListTodos);
    myChangeListTodosContent.setComponent(changeListTodos);
    Content scopeBasedTodoContent = contentFactory.createContent(null, "Scope Based", false);
    ScopeBasedTodosPanel scopeBasedTodos = new ScopeBasedTodosPanel(myProject, state.current, scopeBasedTodoContent);
    Disposer.register(this, scopeBasedTodos);
    scopeBasedTodoContent.setComponent(scopeBasedTodos);
    myContentManager = toolWindow.getContentManager();
    myContentManager.addContent(allTodosContent);
    myContentManager.addContent(currentFileTodosContent);
    myContentManager.addContent(scopeBasedTodoContent);
    if (ProjectLevelVcsManager.getInstance(myProject).hasActiveVcss()) {
        myVcsListener.myIsVisible = true;
        myContentManager.addContent(myChangeListTodosContent);
    }
    for (Content content : myNotAddedContent) {
        myContentManager.addContent(content);
    }
    myChangeListTodosContent.setCloseable(false);
    allTodosContent.setCloseable(false);
    currentFileTodosContent.setCloseable(false);
    scopeBasedTodoContent.setCloseable(false);
    Content content = myContentManager.getContent(state.selectedIndex);
    myContentManager.setSelectedContent(content == null ? allTodosContent : content);
    myPanels.add(myAllTodos);
    myPanels.add(changeListTodos);
    myPanels.add(currentFileTodos);
    myPanels.add(scopeBasedTodos);
}
Also used : DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ContentFactory(com.intellij.ui.content.ContentFactory) Project(com.intellij.openapi.project.Project) Content(com.intellij.ui.content.Content)

Example 42 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.

the class TodoView method addCustomTodoView.

public void addCustomTodoView(final TodoTreeBuilderFactory factory, final String title, final TodoPanelSettings settings) {
    Content content = ContentFactory.SERVICE.getInstance().createContent(null, title, true);
    final ChangeListTodosPanel panel = new ChangeListTodosPanel(myProject, settings, content) {

        @Override
        protected TodoTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
            TodoTreeBuilder todoTreeBuilder = factory.createTreeBuilder(tree, treeModel, project);
            todoTreeBuilder.init();
            return todoTreeBuilder;
        }
    };
    content.setComponent(panel);
    Disposer.register(this, panel);
    if (myContentManager == null) {
        myNotAddedContent.add(content);
    } else {
        myContentManager.addContent(content);
    }
    myPanels.add(panel);
    content.setCloseable(true);
    content.setDisposer(new Disposable() {

        @Override
        public void dispose() {
            myPanels.remove(panel);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) Content(com.intellij.ui.content.Content) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 43 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.

the class TreeBuilderUtil method restorePaths.

public static void restorePaths(AbstractTreeBuilder treeBuilder, List<Object> pathsToExpand, List<Object> selectionPaths, boolean elementsOnly) {
    JTree tree = treeBuilder.getTree();
    if (!elementsOnly) {
        for (Object path : pathsToExpand) {
            tree.expandPath((TreePath) path);
        }
        tree.addSelectionPaths(selectionPaths.toArray(new TreePath[selectionPaths.size()]));
    } else {
        for (Object element : pathsToExpand) {
            treeBuilder.buildNodeForElement(element);
            DefaultMutableTreeNode node = treeBuilder.getNodeForElement(element);
            if (node != null) {
                tree.expandPath(new TreePath(node.getPath()));
            }
        }
        for (Object element : selectionPaths) {
            DefaultMutableTreeNode node = treeBuilder.getNodeForElement(element);
            if (node != null) {
                DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
                tree.addSelectionPath(new TreePath(treeModel.getPathToRoot(node)));
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 44 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.

the class ExternalProjectDataSelectorDialog method reloadTree.

private void reloadTree() {
    final DefaultTreeModel treeModel = (DefaultTreeModel) myTree.getModel();
    final Object root = treeModel.getRoot();
    if (!(root instanceof CheckedTreeNode))
        return;
    final CheckedTreeNode rootNode = (CheckedTreeNode) root;
    final Couple<CheckedTreeNode> rootAndPreselectedNode = createRoot();
    final CheckedTreeNode rootCopy = rootAndPreselectedNode.first;
    List<TreeNode> nodes = TreeUtil.listChildren(rootCopy);
    rootNode.removeAllChildren();
    TreeUtil.addChildrenTo(rootNode, nodes);
    treeModel.reload();
}
Also used : TreeNode(javax.swing.tree.TreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 45 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project intellij-community by JetBrains.

the class LiveTemplateSettingsEditor method createPopupContextPanel.

static JPanel createPopupContextPanel(final Runnable onChange, final TemplateContext context) {
    JPanel panel = new JPanel(new BorderLayout());
    MultiMap<TemplateContextType, TemplateContextType> hierarchy = MultiMap.createLinked();
    for (TemplateContextType type : TemplateManagerImpl.getAllContextTypes()) {
        hierarchy.putValue(type.getBaseContextType(), type);
    }
    final CheckedTreeNode root = new CheckedTreeNode(Pair.create(null, "Hi"));
    final CheckboxTree checkboxTree = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            final Object o = ((DefaultMutableTreeNode) value).getUserObject();
            if (o instanceof Pair) {
                getTextRenderer().append((String) ((Pair) o).second);
            }
        }
    }, root) {

        @Override
        protected void onNodeStateChanged(CheckedTreeNode node) {
            final TemplateContextType type = (TemplateContextType) ((Pair) node.getUserObject()).first;
            if (type != null) {
                context.setEnabled(type, node.isChecked());
            }
            onChange.run();
        }
    };
    for (TemplateContextType type : hierarchy.get(null)) {
        addContextNode(hierarchy, root, type, context);
    }
    ((DefaultTreeModel) checkboxTree.getModel()).nodeStructureChanged(root);
    TreeUtil.traverse(root, _node -> {
        final CheckedTreeNode node = (CheckedTreeNode) _node;
        if (node.isChecked()) {
            final TreeNode[] path = node.getPath();
            if (path != null) {
                checkboxTree.expandPath(new TreePath(path).getParentPath());
            }
        }
        return true;
    });
    panel.add(ScrollPaneFactory.createScrollPane(checkboxTree));
    final Dimension size = checkboxTree.getPreferredSize();
    panel.setPreferredSize(new Dimension(size.width + 30, Math.min(size.height + 10, 500)));
    return panel;
}
Also used : DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RelativePoint(com.intellij.ui.awt.RelativePoint) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TemplateContextType(com.intellij.codeInsight.template.TemplateContextType) Pair(com.intellij.openapi.util.Pair)

Aggregations

DefaultTreeModel (javax.swing.tree.DefaultTreeModel)362 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)204 TreePath (javax.swing.tree.TreePath)99 JTree (javax.swing.JTree)30 JScrollPane (javax.swing.JScrollPane)25 Test (org.junit.Test)24 Tree (com.intellij.ui.treeStructure.Tree)23 TreeNode (javax.swing.tree.TreeNode)22 ArrayList (java.util.ArrayList)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)20 TreeSelectionListener (javax.swing.event.TreeSelectionListener)18 MockTreeModelListener (com.facebook.buck.intellij.ideabuck.test.util.MockTreeModelListener)16 MouseEvent (java.awt.event.MouseEvent)16 List (java.util.List)16 JPanel (javax.swing.JPanel)16 BorderLayout (java.awt.BorderLayout)14 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)14 IOException (java.io.IOException)12 Dimension (java.awt.Dimension)11 ActionEvent (java.awt.event.ActionEvent)11