Search in sources :

Example 46 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent 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 47 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent 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 48 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent 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)

Example 49 with TreeSelectionEvent

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

the class BreakpointItemsTreeController method setTreeView.

public void setTreeView(JTree treeView) {
    myTreeView = treeView;
    myTreeView.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent event) {
            selectionChanged();
        }
    });
    if (treeView instanceof BreakpointsCheckboxTree) {
        ((BreakpointsCheckboxTree) treeView).setDelegate(this);
    }
    myTreeView.setShowsRootHandles(!myGroupingRules.isEmpty());
}
Also used : TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 50 with TreeSelectionEvent

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

the class FileStructurePopup method show.

public void show() {
    //final long time = System.currentTimeMillis();
    JComponent panel = createCenterPanel();
    MnemonicHelper.init(panel);
    myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null).setTitle(myTitle).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true).setMovable(true).setBelongsToGlobalPopupStack(true).setCancelKeyEnabled(false).setDimensionServiceKey(null, getDimensionServiceKey(), true).setCancelCallback(() -> myCanClose).createPopup();
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (myPopup.isVisible()) {
                final PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class);
                if (updateProcessor != null) {
                    final AbstractTreeNode node = getSelectedNode();
                    updateProcessor.updatePopup(node);
                }
            }
        }
    });
    Disposer.register(myPopup, this);
    Disposer.register(myPopup, new Disposable() {

        @Override
        public void dispose() {
            if (!myTreeHasBuilt.isDone()) {
                myTreeHasBuilt.setRejected();
            }
        }
    });
    myTree.getEmptyText().setText("Loading...");
    myPopup.showCenteredInCurrentWindow(myProject);
    ((AbstractPopup) myPopup).setShowHints(true);
    IdeFocusManager.getInstance(myProject).requestFocus(myTree, true);
    Window window = SwingUtilities.windowForComponent(myPopup.getContent());
    WindowFocusListener windowFocusListener = new WindowFocusListener() {

        @Override
        public void windowGainedFocus(WindowEvent e) {
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            myPopup.cancel();
        }
    };
    window.addWindowFocusListener(windowFocusListener);
    Disposer.register(myPopup, () -> window.removeWindowFocusListener(windowFocusListener));
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        ApplicationManager.getApplication().runReadAction(() -> myFilteringStructure.rebuild());
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> {
            myAbstractTreeBuilder.queueUpdate().doWhenDone(() -> {
                myTreeHasBuilt.setDone();
                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(() -> {
                    if (myAbstractTreeBuilder.isDisposed())
                        return;
                    if (selectPsiElement(myInitialPsiElement) == null) {
                        TreeUtil.ensureSelection(myAbstractTreeBuilder.getTree());
                        myAbstractTreeBuilder.revalidateTree();
                    }
                });
            });
            installUpdater();
        });
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) AbstractPopup(com.intellij.ui.popup.AbstractPopup) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) PopupUpdateProcessor(com.intellij.ui.popup.PopupUpdateProcessor)

Aggregations

TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)85 TreeSelectionListener (javax.swing.event.TreeSelectionListener)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)34 TreePath (javax.swing.tree.TreePath)32 JTree (javax.swing.JTree)27 ActionEvent (java.awt.event.ActionEvent)23 JScrollPane (javax.swing.JScrollPane)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)18 MouseEvent (java.awt.event.MouseEvent)15 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)13 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)9 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9