Search in sources :

Example 46 with DefaultTreeModel

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

the class ShelvedChangesViewManager method buildChangesModel.

private TreeModel buildChangesModel() {
    // not null for TreeState matching to work
    myRoot = new DefaultMutableTreeNode(ROOT_NODE_VALUE);
    DefaultTreeModel model = new DefaultTreeModel(myRoot);
    final List<ShelvedChangeList> changeLists = new ArrayList<>(myShelveChangesManager.getShelvedChangeLists());
    Collections.sort(changeLists, ChangelistComparator.getInstance());
    if (myShelveChangesManager.isShowRecycled()) {
        ArrayList<ShelvedChangeList> recycled = new ArrayList<>(myShelveChangesManager.getRecycledShelvedChangeLists());
        changeLists.addAll(recycled);
        Collections.sort(changeLists, ChangelistComparator.getInstance());
    }
    myMoveRenameInfo.clear();
    for (ShelvedChangeList changeList : changeLists) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(changeList);
        model.insertNodeInto(node, myRoot, myRoot.getChildCount());
        final List<Object> shelvedFilesNodes = new ArrayList<>();
        List<ShelvedChange> changes = changeList.getChanges(myProject);
        for (ShelvedChange change : changes) {
            putMovedMessage(change.getBeforePath(), change.getAfterPath());
            shelvedFilesNodes.add(change);
        }
        List<ShelvedBinaryFile> binaryFiles = changeList.getBinaryFiles();
        for (ShelvedBinaryFile file : binaryFiles) {
            putMovedMessage(file.BEFORE_PATH, file.AFTER_PATH);
            shelvedFilesNodes.add(file);
        }
        Collections.sort(shelvedFilesNodes, ShelvedFilePatchComparator.getInstance());
        for (int i = 0; i < shelvedFilesNodes.size(); i++) {
            final Object filesNode = shelvedFilesNodes.get(i);
            final DefaultMutableTreeNode pathNode = new DefaultMutableTreeNode(filesNode);
            model.insertNodeInto(pathNode, node, i);
        }
    }
    return model;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 47 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 48 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 49 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 50 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)

Aggregations

DefaultTreeModel (javax.swing.tree.DefaultTreeModel)196 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)99 TreePath (javax.swing.tree.TreePath)50 Tree (com.intellij.ui.treeStructure.Tree)22 Test (org.junit.Test)21 JTree (javax.swing.JTree)17 MockTreeModelListener (com.facebook.buck.intellij.ideabuck.test.util.MockTreeModelListener)16 JScrollPane (javax.swing.JScrollPane)16 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)15 TreeSelectionListener (javax.swing.event.TreeSelectionListener)14 ArrayList (java.util.ArrayList)10 TreeNode (javax.swing.tree.TreeNode)10 NotNull (org.jetbrains.annotations.NotNull)10 Module (com.intellij.openapi.module.Module)9 MouseEvent (java.awt.event.MouseEvent)9 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)9 Project (com.intellij.openapi.project.Project)7 javax.swing (javax.swing)7 JPanel (javax.swing.JPanel)7 ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)6