Search in sources :

Example 51 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener 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 52 with TreeSelectionListener

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

Example 53 with TreeSelectionListener

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

the class ScopeChooserConfigurable method initTree.

@Override
protected void initTree() {
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            final TreePath path = e.getOldLeadSelectionPath();
            if (path != null) {
                final MyNode node = (MyNode) path.getLastPathComponent();
                final NamedConfigurable namedConfigurable = node.getConfigurable();
                if (namedConfigurable instanceof ScopeConfigurable) {
                    ((ScopeConfigurable) namedConfigurable).cancelCurrentProgress();
                }
            }
        }
    });
    super.initTree();
    myTree.setShowsRootHandles(false);
    new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {

        @Override
        public String convert(final TreePath treePath) {
            return ((MyNode) treePath.getLastPathComponent()).getDisplayName();
        }
    }, true);
    myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}
Also used : TreePath(javax.swing.tree.TreePath) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 54 with TreeSelectionListener

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

the class IntentionSettingsTree method initTree.

private void initTree() {
    myTree = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer(true) {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (!(value instanceof CheckedTreeNode))
                return;
            CheckedTreeNode node = (CheckedTreeNode) value;
            SimpleTextAttributes attributes = node.getUserObject() instanceof IntentionActionMetaData ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
            final String text = getNodeText(node);
            final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
            UIUtil.changeBackGround(this, background);
            if (text != null) {
                SearchUtil.appendFragments(myFilter != null ? myFilter.getFilter() : null, text, attributes.getStyle(), attributes.getFgColor(), background, getTextRenderer());
            }
        }
    }, new CheckedTreeNode(null));
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getPath();
            Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
            selectionChanged(userObject);
        }
    });
    myFilter = new MyFilterComponent();
    myComponent = new JPanel(new BorderLayout());
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    myNorthPanel = new JPanel(new BorderLayout());
    myNorthPanel.add(myFilter, BorderLayout.CENTER);
    final DefaultActionGroup group = new DefaultActionGroup();
    final CommonActionsManager actionManager = CommonActionsManager.getInstance();
    final DefaultTreeExpander treeExpander = new DefaultTreeExpander(myTree);
    group.add(actionManager.createExpandAllAction(treeExpander, myTree));
    group.add(actionManager.createCollapseAllAction(treeExpander, myTree));
    myNorthPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.WEST);
    myComponent.add(myNorthPanel, BorderLayout.NORTH);
    myComponent.add(scrollPane, BorderLayout.CENTER);
    myFilter.reset();
}
Also used : TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) TreePath(javax.swing.tree.TreePath) CommonActionsManager(com.intellij.ide.CommonActionsManager) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 55 with TreeSelectionListener

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

the class TreeFileChooserDialog method createCenterPanel.

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

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

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

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

        @Override
        public Object[] getChildElements(final Object element) {
            return filterFiles(super.getChildElements(element));
        }

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

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

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

        @Override
        public List<TreeStructureProvider> getProviders() {
            return myDisableStructureProviders ? null : super.getProviders();
        }
    };
    myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
    myTree.setRootVisible(false);
    myTree.expandRow(0);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setCellRenderer(new NodeRenderer());
    UIUtil.setLineStyleAngled(myTree);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    myTree.addKeyListener(new KeyAdapter() {

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

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

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            handleSelectionChanged();
        }
    });
    new TreeSpeedSearch(myTree);
    myTabbedPane = new TabbedPaneWrapper(getDisposable());
    final JPanel dummyPanel = new JPanel(new BorderLayout());
    String name = null;
    if (myInitialFile != null) {
        name = myInitialFile.getName();
    }
    PsiElement context = myInitialFile == null ? null : myInitialFile;
    myGotoByNamePanel = new ChooseByNamePanel(myProject, new MyGotoFileModel(), name, true, context) {

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

        @Override
        protected void initUI(final ChooseByNamePopupComponent.Callback callback, final ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
            //IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()).requestFocus();
            if (mySelectSearchByNameTab) {
                myTabbedPane.setSelectedIndex(1);
            }
        }

        @Override
        protected void showTextFieldPanel() {
        }

        @Override
        protected void chosenElementMightChange() {
            handleSelectionChanged();
        }
    };
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
    SwingUtilities.invokeLater(() -> myGotoByNamePanel.invoke(new MyCallback(), ModalityState.stateForComponent(getRootPane()), false));
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            handleSelectionChanged();
        }
    });
    return myTabbedPane.getComponent();
}
Also used : 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) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) 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) PsiElement(com.intellij.psi.PsiElement) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChooseByNamePanel(com.intellij.ide.util.gotoByName.ChooseByNamePanel) 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) ChooseByNamePopupComponent(com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent)

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