Search in sources :

Example 6 with TreePath

use of javax.swing.tree.TreePath in project darkFunction-Editor by darkFunction.

the class AddDirNodeCommand method insertNewNode.

public void insertNewNode(CustomNode parentNode, DefaultMutableTreeNode aNewNode) {
    int insertIndex = parentNode.getChildCount();
    while (insertIndex > 0) {
        if (parentNode.getChildAt(insertIndex - 1).isLeaf())
            insertIndex--;
        else
            break;
    }
    ((DefaultTreeModel) nameTree.getModel()).insertNodeInto(newNode, parentNode, insertIndex);
    TreePath newPath = new TreePath(newNode.getPath());
    nameTree.scrollPathToVisible(newPath);
    nameTree.setSelectionPath(newPath);
    nameTree.startEditingAtPath(newPath);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 7 with TreePath

use of javax.swing.tree.TreePath in project darkFunction-Editor by darkFunction.

the class AddLeafNodeCommand method insertNewNode.

public void insertNewNode(CustomNode parentNode, DefaultMutableTreeNode newNode) {
    ((DefaultTreeModel) nameTree.getModel()).insertNodeInto(newNode, parentNode, parentNode.getChildCount());
    TreePath newPath = new TreePath(newNode.getPath());
    nameTree.scrollPathToVisible(newPath);
    nameTree.setSelectionPath(newPath);
    nameTree.startEditingAtPath(newPath);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 8 with TreePath

use of javax.swing.tree.TreePath in project darkFunction-Editor by darkFunction.

the class AddNodeCommand method execute.

public boolean execute() {
    if (parentNode != null) {
        DefaultMutableTreeNode selectedNode = null;
        TreePath treePath = nameTree.getSelectionPath();
        if (treePath != null)
            selectedNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (selectedNode != null)
            this.prevSelectedPath = new TreePath(selectedNode.getPath());
        else
            this.prevSelectedPath = null;
        insertNewNode(parentNode, newNode);
        return true;
    }
    return false;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 9 with TreePath

use of javax.swing.tree.TreePath in project intellij-leiningen-plugin by derkork.

the class LeiningenProjectStructure method getSelectedNodes.

private static List<SimpleNode> getSelectedNodes(SimpleTree tree) {
    List<SimpleNode> nodes = new ArrayList<SimpleNode>();
    TreePath[] treePaths = tree.getSelectionPaths();
    if (treePaths != null) {
        for (TreePath treePath : treePaths) {
            nodes.add(tree.getNodeFor(treePath));
        }
    }
    return nodes;
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) SimpleNode(com.intellij.ui.treeStructure.SimpleNode)

Example 10 with TreePath

use of javax.swing.tree.TreePath in project buck by facebook.

the class BuckToolWindowFactory method createBuildInfoPanel.

private JComponent createBuildInfoPanel(Project project) {
    Tree result = new Tree(BuckUIManager.getInstance(project).getTreeModel());
    result.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            Tree tree = (Tree) e.getComponent();
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
            if (selRow != -1 && e.getClickCount() == 2) {
                TreeNode node = (TreeNode) selPath.getLastPathComponent();
                if (node.isLeaf()) {
                    BuckTreeNodeDetail buckNode = (BuckTreeNodeDetail) node;
                    if (buckNode instanceof BuckTreeNodeDetailError) {
                        BuckToolWindowFactory.this.handleClickOnError((BuckTreeNodeDetailError) buckNode);
                    }
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    result.setCellRenderer(new BuckTreeCellRenderer());
    result.setShowsRootHandles(false);
    result.setRowHeight(0);
    JBScrollPane treeView = new JBScrollPane(result);
    return treeView;
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) Tree(com.intellij.ui.treeStructure.Tree) BuckTreeNodeDetailError(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeDetailError) BuckTreeCellRenderer(com.facebook.buck.intellij.ideabuck.ui.tree.renderers.BuckTreeCellRenderer) JBScrollPane(com.intellij.ui.components.JBScrollPane) BuckTreeNodeDetail(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeDetail)

Aggregations

TreePath (javax.swing.tree.TreePath)539 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)177 ArrayList (java.util.ArrayList)58 TreeNode (javax.swing.tree.TreeNode)56 Nullable (org.jetbrains.annotations.Nullable)49 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)46 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 MouseEvent (java.awt.event.MouseEvent)18 Point (java.awt.Point)17 ActionEvent (java.awt.event.ActionEvent)15 KeyEvent (java.awt.event.KeyEvent)12 EVTask (net.sourceforge.processdash.ev.EVTask)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 KeyAdapter (java.awt.event.KeyAdapter)11 List (java.util.List)11