Search in sources :

Example 46 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.

the class ModulesDependenciesPanel method installLeftTreeListeners.

private void installLeftTreeListeners() {
    myLeftTree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            DefaultMutableTreeNode expandedNode = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
            for (int i = 0; i < expandedNode.getChildCount(); i++) {
                DefaultMutableTreeNode child = (DefaultMutableTreeNode) expandedNode.getChildAt(i);
                if (child.getChildCount() == 0 && !isLooped(event.getPath(), child)) {
                    Module module = ((MyUserObject) child.getUserObject()).myModule;
                    for (Module dependency : getModuleDependencies(module)) {
                        child.add(new DefaultMutableTreeNode(new MyUserObject(isInCycle(dependency), dependency)));
                    }
                    TreeUtil.sortRecursively(child, NODE_COMPARATOR);
                }
            }
        }

        private boolean isLooped(TreePath path, DefaultMutableTreeNode child) {
            for (Object o : path.getPath()) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
                if (node != child && Comparing.equal(node.getUserObject(), child.getUserObject())) {
                    return true;
                }
            }
            return false;
        }
    });
    myLeftTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath selectionPath = myLeftTree.getSelectionPath();
            if (selectionPath != null) {
                myPathField.setText(StringUtil.join(selectionPath.getPath(), o -> {
                    Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
                    return userObject instanceof MyUserObject ? ((MyUserObject) userObject).myModule.getName() : "";
                }, " : "));
                DefaultMutableTreeNode selection = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
                if (selection != null) {
                    updateRightTree(((MyUserObject) selection.getUserObject()).myModule);
                }
            }
        }
    });
}
Also used : TreeExpansionListener(javax.swing.event.TreeExpansionListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 47 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.

the class SMTestRunnerResultsForm method addEventsListener.

public void addEventsListener(final EventsListener listener) {
    myEventListeners.add(listener);
    addTestsTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(final TreeSelectionEvent e) {
            //We should fire event only if it was generated by this component,
            //e.g. it is focused. Otherwise it is side effect of selecting proxy in
            //try by other component
            //if (myTreeView.isFocusOwner()) {
            @Nullable final SMTestProxy selectedProxy = (SMTestProxy) getTreeView().getSelectedTest();
            listener.onSelected(selectedProxy, SMTestRunnerResultsForm.this, SMTestRunnerResultsForm.this);
        //}
        }
    });
}
Also used : TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 48 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.

the class UpdateInfoTree method createTree.

private void createTree() {
    SmartExpander.installOn(myTree);
    SelectionSaver.installOn(myTree);
    createTreeModel();
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            AbstractTreeNode treeNode = (AbstractTreeNode) e.getPath().getLastPathComponent();
            VirtualFilePointer pointer = null;
            if (treeNode instanceof FileTreeNode) {
                pointer = ((FileTreeNode) treeNode).getFilePointer();
            }
            if (pointer != null) {
                mySelectedUrl = pointer.getUrl();
                mySelectedFile = pointer.getFile();
            } else {
                mySelectedUrl = null;
                mySelectedFile = null;
            }
        }
    });
    myTree.setCellRenderer(new UpdateTreeCellRenderer());
    TreeUtil.installActions(myTree);
    new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {

        public String convert(TreePath path) {
            Object last = path.getLastPathComponent();
            if (last instanceof AbstractTreeNode) {
                return ((AbstractTreeNode) last).getText();
            }
            return TreeSpeedSearch.NODE_DESCRIPTOR_TOSTRING.convert(path);
        }
    }, true);
    myTree.addMouseListener(new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            final DefaultActionGroup group = (DefaultActionGroup) ActionManager.getInstance().getAction("UpdateActionGroup");
            if (group != null) {
                //if no UpdateActionGroup was configured
                ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UPDATE_POPUP, group);
                popupMenu.getComponent().show(comp, x, y);
            }
        }
    });
    EditSourceOnDoubleClickHandler.install(myTree);
    EditSourceOnEnterKeyHandler.install(myTree);
    myTree.setSelectionRow(0);
}
Also used : TreeSelectionListener(javax.swing.event.TreeSelectionListener) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 49 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.

the class TargetChooserDialog method initTree.

private Tree initTree() {
    @NonNls final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    final Tree tree = new Tree(root);
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
                final Object userObject = node.getUserObject();
                if (userObject instanceof AntTargetNodeDescriptor) {
                    final AntTargetNodeDescriptor antBuildTarget = (AntTargetNodeDescriptor) userObject;
                    mySelectedTarget = antBuildTarget.getAntTarget();
                } else {
                    mySelectedTarget = null;
                }
            }
        }
    });
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setLineStyleAngled();
    TreeUtil.installActions(tree);
    new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {

        public String convert(final TreePath path) {
            final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
            if (userObject instanceof AntTargetNodeDescriptor) {
                final AntBuildTarget target = ((AntTargetNodeDescriptor) userObject).getAntTarget();
                return target.getDisplayName();
            }
            return null;
        }
    });
    DefaultMutableTreeNode selectedNode = null;
    final AntConfiguration antConfiguration = AntConfigurationImpl.getInstance(myProject);
    for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
        final DefaultMutableTreeNode buildFileNode = new DefaultMutableTreeNode(buildFile);
        DefaultMutableTreeNode selection = processFileTargets(antConfiguration.getMetaTargets(buildFile), buildFile, buildFileNode);
        if (selection != null) {
            selectedNode = selection;
        }
        selection = processFileTargets(antConfiguration.getModel(buildFile).getTargets(), buildFile, buildFileNode);
        if (selection != null) {
            selectedNode = selection;
        }
        root.add(buildFileNode);
    }
    TreeUtil.expandAll(tree);
    TreeUtil.selectInTree(selectedNode, true, tree);
    return tree;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) AntBuildTarget(com.intellij.lang.ant.config.AntBuildTarget)

Example 50 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.

the class CallerChooserBase method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    Splitter splitter = new Splitter(false, (float) 0.6);
    JPanel result = new JPanel(new BorderLayout());
    if (myTree == null) {
        myTree = createTree();
    } else {
        final CheckedTreeNode root = (CheckedTreeNode) myTree.getModel().getRoot();
        myRoot = (MethodNodeBase) root.getFirstChild();
    }
    myTreeSelectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            final TreePath path = e.getPath();
            if (path != null) {
                final MethodNodeBase<M> node = (MethodNodeBase) path.getLastPathComponent();
                myAlarm.cancelAllRequests();
                myAlarm.addRequest(() -> updateEditorTexts(node), 300);
            }
        }
    };
    myTree.getSelectionModel().addTreeSelectionListener(myTreeSelectionListener);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    splitter.setFirstComponent(scrollPane);
    final JComponent callSitesViewer = createCallSitesViewer();
    TreePath selectionPath = myTree.getSelectionPath();
    if (selectionPath == null) {
        selectionPath = new TreePath(myRoot.getPath());
        myTree.getSelectionModel().addSelectionPath(selectionPath);
    }
    final MethodNodeBase<M> node = (MethodNodeBase) selectionPath.getLastPathComponent();
    updateEditorTexts(node);
    splitter.setSecondComponent(callSitesViewer);
    result.add(splitter);
    return result;
}
Also used : Splitter(com.intellij.openapi.ui.Splitter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

TreeSelectionListener (javax.swing.event.TreeSelectionListener)87 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)36 TreePath (javax.swing.tree.TreePath)33 JTree (javax.swing.JTree)27 JScrollPane (javax.swing.JScrollPane)25 ActionEvent (java.awt.event.ActionEvent)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 MouseEvent (java.awt.event.MouseEvent)16 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)16 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)14 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)12 JButton (javax.swing.JButton)11 Tree (com.intellij.ui.treeStructure.Tree)10 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9