Search in sources :

Example 36 with DefaultTreeModel

use of javax.swing.tree.DefaultTreeModel in project jackrabbit-oak by apache.

the class NodeStoreTree method refreshModel.

private void refreshModel() {
    index = backend.getTarReaderIndex();
    sizeCache = newHashMap();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new NamePathModel("/", "/", backend.getHead(), sizeCache, skipSizeCheck, backend), true);
    treeModel = new DefaultTreeModel(rootNode);
    addChildren(rootNode);
    tree.setModel(treeModel);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 37 with DefaultTreeModel

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

the class IntentionSettingsTree method reset.

private void reset(List<IntentionActionMetaData> intentionsToShow) {
    CheckedTreeNode root = new CheckedTreeNode(null);
    final DefaultTreeModel treeModel = (DefaultTreeModel) myTree.getModel();
    intentionsToShow = sort(intentionsToShow);
    for (final IntentionActionMetaData metaData : intentionsToShow) {
        String[] category = metaData.myCategory;
        CheckedTreeNode node = root;
        for (final String name : category) {
            CheckedTreeNode child = findChild(node, name);
            if (child == null) {
                CheckedTreeNode newChild = new CheckedTreeNode(name);
                treeModel.insertNodeInto(newChild, node, node.getChildCount());
                child = newChild;
            }
            node = child;
        }
        CheckedTreeNode newChild = new CheckedTreeNode(metaData);
        treeModel.insertNodeInto(newChild, node, node.getChildCount());
    }
    resetCheckMark(root);
    treeModel.setRoot(root);
    treeModel.nodeChanged(root);
    TreeUtil.expandAll(myTree);
    myTree.setSelectionRow(0);
}
Also used : DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 38 with DefaultTreeModel

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

the class DetectedFrameworksTree method rebuildTree.

public void rebuildTree(final List<? extends DetectedFrameworkDescription> frameworks) {
    final CheckedTreeNode root = getRoot();
    root.removeAllChildren();
    if (myGroupByOption == DetectedFrameworksComponent.GroupByOption.TYPE) {
        createNodesGroupedByType(root, frameworks);
    } else {
        createNodesGroupedByDirectory(root, frameworks);
    }
    ((DefaultTreeModel) getModel()).nodeStructureChanged(root);
    TreeUtil.expandAll(this);
    myDetectedFrameworks = frameworks;
}
Also used : CheckedTreeNode(com.intellij.ui.CheckedTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 39 with DefaultTreeModel

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

the class AbstractTreeClassChooserDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
    myTree = new Tree(model);
    ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {

        @Override
        public boolean isFlattenPackages() {
            return false;
        }

        @Override
        public boolean isShowMembers() {
            return myIsShowMembers;
        }

        @Override
        public boolean isHideEmptyMiddlePackages() {
            return true;
        }

        @Override
        public boolean isAbbreviatePackageNames() {
            return false;
        }

        @Override
        public boolean isShowLibraryContents() {
            return myIsShowLibraryContents;
        }

        @Override
        public boolean isShowModules() {
            return false;
        }
    };
    myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandRow(0);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setCellRenderer(new NodeRenderer());
    UIUtil.setLineStyleAngled(myTree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                doOKAction();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
            if (path != null && myTree.isPathSelected(path)) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            handleSelectionChanged();
        }
    });
    new TreeSpeedSearch(myTree);
    myTabbedPane = new TabbedPaneWrapper(getDisposable());
    final JPanel dummyPanel = new JPanel(new BorderLayout());
    String name = null;
    /*
    if (myInitialClass != null) {
      name = myInitialClass.getName();
    }
*/
    myGotoByNamePanel = new ChooseByNamePanel(myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) {

        @Override
        protected void showTextFieldPanel() {
        }

        @Override
        protected void close(boolean isOk) {
            super.close(isOk);
            if (isOk) {
                doOKAction();
            } else {
                doCancelAction();
            }
        }

        @NotNull
        @Override
        protected Set<Object> filter(@NotNull Set<Object> elements) {
            return doFilter(elements);
        }

        @Override
        protected void initUI(ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()), true);
            });
        }

        @Override
        protected void showList() {
            super.showList();
            if (myInitialClass != null && myList.getModel().getSize() > 0) {
                myList.setSelectedValue(myInitialClass, true);
                myInitialClass = null;
            }
        }

        @Override
        protected void chosenElementMightChange() {
            handleSelectionChanged();
        }
    };
    Disposer.register(myDisposable, myGotoByNamePanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
    myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false);
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            handleSelectionChanged();
        }
    });
    return myTabbedPane.getComponent();
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) NotNull(org.jetbrains.annotations.NotNull) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) KeyEvent(java.awt.event.KeyEvent) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) Tree(com.intellij.ui.treeStructure.Tree) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) ModalityState(com.intellij.openapi.application.ModalityState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 40 with DefaultTreeModel

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

the class ScopeTreeViewPanel method reload.

private void reload(@Nullable final DefaultMutableTreeNode rootToReload) {
    final DefaultTreeModel treeModel = (DefaultTreeModel) myTree.getModel();
    if (rootToReload != null && rootToReload != treeModel.getRoot()) {
        final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myTree, new TreePath(rootToReload.getPath()));
        final List<TreePath> selectionPaths = TreeUtil.collectSelectedPaths(myTree, new TreePath(rootToReload.getPath()));
        final TreePath path = new TreePath(rootToReload.getPath());
        final boolean wasCollapsed = myTree.isCollapsed(path);
        final Runnable runnable = () -> {
            if (!isTreeShowing() || rootToReload.getParent() == null)
                return;
            TreeUtil.sort(rootToReload, getNodeComparator());
            treeModel.reload(rootToReload);
            if (!wasCollapsed) {
                myTree.collapsePath(path);
                for (TreePath treePath : treePaths) {
                    myTree.expandPath(treePath);
                }
                for (TreePath selectionPath : selectionPaths) {
                    TreeUtil.selectPath(myTree, selectionPath);
                }
            }
        };
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            runnable.run();
        } else {
            SwingUtilities.invokeLater(runnable);
        }
    } else {
        TreeUtil.sort(treeModel, getNodeComparator());
        treeModel.reload();
    }
}
Also used : TreePath(javax.swing.tree.TreePath) 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