Search in sources :

Example 26 with DefaultTreeModel

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

the class TodoCheckinHandler method showTodo.

private void showTodo(TodoCheckinHandlerWorker worker) {
    String title = "For commit (" + DateFormatUtil.formatDateTime(System.currentTimeMillis()) + ")";
    ServiceManager.getService(myProject, TodoView.class).addCustomTodoView(new TodoTreeBuilderFactory() {

        @Override
        public TodoTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, Project project) {
            return new CustomChangelistTodosTreeBuilder(tree, treeModel, myProject, title, worker.inOneList());
        }
    }, title, new TodoPanelSettings(myConfiguration.myTodoPanelSettings));
    ApplicationManager.getApplication().invokeLater(() -> {
        ToolWindowManager manager = ToolWindowManager.getInstance(myProject);
        if (manager != null) {
            ToolWindow window = manager.getToolWindow("TODO");
            if (window != null) {
                window.show(() -> {
                    ContentManager cm = window.getContentManager();
                    Content[] contents = cm.getContents();
                    if (contents.length > 0) {
                        cm.setSelectedContent(contents[contents.length - 1], true);
                    }
                });
            }
        }
    }, ModalityState.NON_MODAL, myProject.getDisposed());
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ContentManager(com.intellij.ui.content.ContentManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Project(com.intellij.openapi.project.Project) ToolWindow(com.intellij.openapi.wm.ToolWindow) Content(com.intellij.ui.content.Content)

Example 27 with DefaultTreeModel

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

the class ChooseLibrariesDialogBase method createCenterPanel.

@Override
@Nullable
protected JComponent createCenterPanel() {
    myBuilder = new SimpleTreeBuilder(myTree, new DefaultTreeModel(new DefaultMutableTreeNode()), new MyStructure(getProject()), WeightBasedComparator.FULL_INSTANCE);
    myBuilder.initRootNode();
    myTree.setDragEnabled(false);
    myTree.setShowsRootHandles(true);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setRootVisible(false);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            updateOKAction();
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (isOKActionEnabled()) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
    myTree.getActionMap().put("ENTER", getOKAction());
    final JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
    pane.setPreferredSize(JBUI.size(500, 400));
    return pane;
}
Also used : SimpleTreeBuilder(com.intellij.ui.treeStructure.SimpleTreeBuilder) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with DefaultTreeModel

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

the class PackageChooserDialog method createNewPackage.

private void createNewPackage() {
    final PsiPackage selectedPackage = getTreeSelection();
    if (selectedPackage == null)
        return;
    final String newPackageName = Messages.showInputDialog(myProject, IdeBundle.message("prompt.enter.a.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", new InputValidator() {

        public boolean checkInput(final String inputString) {
            return inputString != null && inputString.length() > 0;
        }

        public boolean canClose(final String inputString) {
            return checkInput(inputString);
        }
    });
    if (newPackageName == null)
        return;
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        final Runnable action = () -> {
            try {
                String newQualifiedName = selectedPackage.getQualifiedName();
                if (!Comparing.strEqual(newQualifiedName, ""))
                    newQualifiedName += ".";
                newQualifiedName += newPackageName;
                final PsiDirectory dir = PackageUtil.findOrCreateDirectoryForPackage(myProject, newQualifiedName, null, false);
                if (dir == null)
                    return;
                final PsiPackage newPackage = JavaDirectoryService.getInstance().getPackage(dir);
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) myTree.getSelectionPath().getLastPathComponent();
                final DefaultMutableTreeNode newChild = new DefaultMutableTreeNode();
                newChild.setUserObject(newPackage);
                node.add(newChild);
                final DefaultTreeModel model = (DefaultTreeModel) myTree.getModel();
                model.nodeStructureChanged(node);
                final TreePath selectionPath = myTree.getSelectionPath();
                TreePath path;
                if (selectionPath == null) {
                    path = new TreePath(newChild.getPath());
                } else {
                    path = selectionPath.pathByAddingChild(newChild);
                }
                myTree.setSelectionPath(path);
                myTree.scrollPathToVisible(path);
                myTree.expandPath(path);
            } catch (IncorrectOperationException e) {
                Messages.showMessageDialog(getContentPane(), StringUtil.getMessage(e), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                if (LOG.isDebugEnabled()) {
                    LOG.debug(e);
                }
            }
        };
        ApplicationManager.getApplication().runReadAction(action);
    }, IdeBundle.message("command.create.new.package"), null);
}
Also used : InputValidator(com.intellij.openapi.ui.InputValidator) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 29 with DefaultTreeModel

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

the class ToDoTreeStructureTest method testToDo.

//todo kirillk
public void testToDo() throws Exception {
    AllTodosTreeBuilder all = new AllTodosTreeBuilder(new Tree(), new DefaultTreeModel(new DefaultMutableTreeNode()), myProject);
    all.init();
    AbstractTreeStructure structure = all.getTreeStructure();
    ProjectViewTestUtil.assertStructureEqual(structure, "Root\n" + " Summary\n" + "  toDo\n" + "   xmlFile.xml\n" + "    Item: (12,16)\n" + "  package1 toDoFileCount=2,toDoItemCount=4\n" + "   package2 toDoFileCount=1,toDoItemCount=2\n" + "    JavaClass.java\n" + "     Item: (62,78)\n" + "     Item: (145,162)\n" + "   JavaClass.java\n" + "    Item: (52,68)\n" + "    Item: (134,151)\n" + "  package3 toDoFileCount=1,toDoItemCount=2\n" + "   JavaClass.java\n" + "    Item: (53,69)\n" + "    Item: (136,153)\n", myPrintInfo);
    checkOccurrences(all, new String[] { "Item: (12,16)", "Item: (62,78)", "Item: (145,162)", "Item: (52,68)", "Item: (134,151)", "Item: (53,69)", "Item: (136,153)" });
    final DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    final JTree currentFileTree = new Tree(treeModel);
    CurrentFileTodosTreeBuilder builder = new CurrentFileTodosTreeBuilder(currentFileTree, treeModel, myProject);
    builder.init();
    builder.setFile(getSrcDirectory().findSubdirectory("package1").findFile("JavaClass.java"));
    builder.updateFromRoot();
    ProjectViewTestUtil.assertStructureEqual(builder.getTreeStructure(), "JavaClass.java\n" + " JavaClass.java\n" + "  Item: (52,68)\n" + "  Item: (134,151)\n", myPrintInfo);
    Disposer.dispose(builder);
    Disposer.dispose(all);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AllTodosTreeBuilder(com.intellij.ide.todo.AllTodosTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) CurrentFileTodosTreeBuilder(com.intellij.ide.todo.CurrentFileTodosTreeBuilder)

Example 30 with DefaultTreeModel

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

the class CommittedChangesTreeBrowser method buildTreeModel.

private TreeModel buildTreeModel(final List<CommittedChangeList> filteredChangeLists) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultTreeModel model = new DefaultTreeModel(root);
    Collections.sort(filteredChangeLists, myGroupingStrategy.getComparator());
    myGroupingStrategy.beforeStart();
    DefaultMutableTreeNode lastGroupNode = null;
    String lastGroupName = null;
    for (CommittedChangeList list : filteredChangeLists) {
        String groupName = StringUtil.notNullize(myGroupingStrategy.getGroupName(list));
        if (!Comparing.equal(groupName, lastGroupName)) {
            lastGroupName = groupName;
            lastGroupNode = new DefaultMutableTreeNode(lastGroupName);
            root.add(lastGroupNode);
        }
        assert lastGroupNode != null;
        lastGroupNode.add(new DefaultMutableTreeNode(list));
    }
    return model;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

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