Search in sources :

Example 11 with TreeExpansionEvent

use of javax.swing.event.TreeExpansionEvent in project cayenne by apache.

the class DbImportTree method createTreeExpandListener.

private void createTreeExpandListener() {
    TreeExpansionListener treeExpansionListener = new TreeExpansionListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            Object lastPathComponent = path.getLastPathComponent();
            if (!(lastPathComponent instanceof TransferableNode)) {
                return;
            }
            DbImportTreeNode node = (DbImportTreeNode) lastPathComponent;
            if ((node.isIncludeTable() || node.isSchema() || node.isCatalog()) && !node.isLoaded()) {
                // reload tables and columns action.
                LoadDbSchemaAction action = Application.getInstance().getActionManager().getAction(LoadDbSchemaAction.class);
                action.performAction(null, path);
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }
    };
    this.addTreeExpansionListener(treeExpansionListener);
}
Also used : TreeExpansionListener(javax.swing.event.TreeExpansionListener) TreePath(javax.swing.tree.TreePath) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) LoadDbSchemaAction(org.apache.cayenne.modeler.action.LoadDbSchemaAction) TransferableNode(org.apache.cayenne.modeler.dialog.db.load.TransferableNode) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 12 with TreeExpansionEvent

use of javax.swing.event.TreeExpansionEvent in project omegat by omegat-org.

the class PreferencesWindowController method show.

@SuppressWarnings("serial")
public void show(Window parent, Class<? extends IPreferencesController> initialSelection) {
    dialog = new JDialog();
    dialog.setTitle(OStrings.getString("PREFERENCES_TITLE_NO_SELECTION"));
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.setModal(true);
    StaticUIUtils.setWindowIcon(dialog);
    outerPanel = new PreferencePanel();
    innerPanel = new PreferenceViewSelectorPanel();
    outerPanel.prefsViewPanel.add(innerPanel, BorderLayout.CENTER);
    dialog.getContentPane().add(outerPanel);
    overlay = new HighlightablePanel(dialog.getRootPane(), innerPanel.selectedPrefsScrollPane);
    // Prevent ugly white viewport background with GTK LAF
    innerPanel.selectedPrefsScrollPane.getViewport().setOpaque(false);
    innerPanel.selectedPrefsScrollPane.setBackground(innerPanel.getBackground());
    innerPanel.searchTextField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            SwingUtilities.invokeLater(PreferencesWindowController.this::searchAndFilterTree);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            SwingUtilities.invokeLater(PreferencesWindowController.this::searchAndFilterTree);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            SwingUtilities.invokeLater(PreferencesWindowController.this::searchAndFilterTree);
        }
    });
    innerPanel.searchTextField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
                innerPanel.availablePrefsTree.getActionForKeyStroke(KeyStroke.getKeyStrokeForEvent(e)).actionPerformed(new ActionEvent(innerPanel.availablePrefsTree, 0, null));
                innerPanel.availablePrefsTree.requestFocusInWindow();
                e.consume();
            }
        }
    });
    innerPanel.searchTextField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            innerPanel.searchTextField.selectAll();
            searchCurrentView();
            preloadGuis();
        }
    });
    innerPanel.clearButton.addActionListener(e -> {
        innerPanel.searchTextField.clear();
    });
    innerPanel.availablePrefsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    DefaultMutableTreeNode root = createNodeTree();
    walkTree(root, node -> {
        IPreferencesController view = (IPreferencesController) node.getUserObject();
        if (view != null) {
            view.addFurtherActionListener(this);
        }
    });
    innerPanel.availablePrefsTree.setModel(new DefaultTreeModel(root));
    innerPanel.availablePrefsTree.addTreeSelectionListener(e -> {
        handleViewSelection(e);
        updateTitle();
    });
    innerPanel.availablePrefsTree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            SwingUtilities.invokeLater(PreferencesWindowController.this::adjustTreeSize);
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }
    });
    innerPanel.selectedPrefsScrollPane.getViewport().setBackground(innerPanel.getBackground());
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) innerPanel.availablePrefsTree.getCellRenderer();
    renderer.setIcon(null);
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    renderer.setDisabledIcon(null);
    outerPanel.okButton.addActionListener(e -> {
        if (currentView == null || currentView.validate()) {
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    doSave();
                    return null;
                }

                @Override
                protected void done() {
                    if (getIsReloadRequired()) {
                        SwingUtilities.invokeLater(ProjectUICommands::promptReload);
                    }
                }
            }.execute();
            StaticUIUtils.closeWindowByEvent(dialog);
        }
    });
    outerPanel.cancelButton.addActionListener(e -> StaticUIUtils.closeWindowByEvent(dialog));
    // Hide undo, reset buttons on outer panel
    outerPanel.undoButton.setVisible(false);
    outerPanel.resetButton.setVisible(false);
    // Use ones on inner panel to indicate that actions are view-specific
    innerPanel.undoButton.addActionListener(e -> currentView.undoChanges());
    innerPanel.resetButton.addActionListener(e -> currentView.restoreDefaults());
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            walkTree(root, node -> {
                // Start with tree fully expanded
                if (node.getChildCount() > 0) {
                    innerPanel.availablePrefsTree.expandPath(new TreePath(node.getPath()));
                }
            });
            SwingUtilities.invokeLater(() -> {
                if (initialSelection != null) {
                    selectView(initialSelection);
                }
            });
        }
    });
    innerPanel.availablePrefsScrollPane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            SwingUtilities.invokeLater(PreferencesWindowController.this::adjustTreeSize);
        }
    });
    ActionMap actionMap = innerPanel.getActionMap();
    InputMap inputMap = innerPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    actionMap.put(ACTION_KEY_NEW_SEARCH, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            innerPanel.searchTextField.requestFocusInWindow();
            innerPanel.searchTextField.selectAll();
        }
    });
    KeyStroke searchKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, Java8Compat.getMenuShortcutKeyMaskEx());
    inputMap.put(searchKeyStroke, ACTION_KEY_NEW_SEARCH);
    actionMap.put(ACTION_KEY_CLEAR_OR_CLOSE, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!innerPanel.searchTextField.isEmpty()) {
                // Move focus away from search field
                innerPanel.availablePrefsTree.requestFocusInWindow();
                innerPanel.clearButton.doClick();
            } else {
                StaticUIUtils.closeWindowByEvent(dialog);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ACTION_KEY_CLEAR_OR_CLOSE);
    // Don't let Enter close the dialog
    innerPanel.searchTextField.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ACTION_KEY_DO_SEARCH);
    innerPanel.searchTextField.getActionMap().put(ACTION_KEY_DO_SEARCH, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            searchCurrentView();
        }
    });
    String searchKeyText = StaticUIUtils.getKeyStrokeText(searchKeyStroke);
    innerPanel.searchTextField.setHintText(OStrings.getString("PREFERENCES_SEARCH_HINT", searchKeyText));
    // Set initial state
    searchAndFilterTree();
    adjustTreeSize();
    dialog.getRootPane().setDefaultButton(outerPanel.okButton);
    dialog.setPreferredSize(new Dimension(800, 500));
    dialog.pack();
    // Prevent search field from getting initial focus
    innerPanel.availablePrefsTree.requestFocusInWindow();
    dialog.setLocationRelativeTo(parent);
    dialog.setVisible(true);
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) ExternalFinderPreferencesController(org.omegat.externalfinder.gui.ExternalFinderPreferencesController) Enumeration(java.util.Enumeration) StaticUIUtils(org.omegat.util.gui.StaticUIUtils) RepositoriesCredentialsController(org.omegat.core.team2.gui.RepositoriesCredentialsController) CustomColorSelectionController(org.omegat.gui.preferences.view.CustomColorSelectionController) StringUtil(org.omegat.util.StringUtil) MouseWheelEvent(java.awt.event.MouseWheelEvent) Map(java.util.Map) SwingWorker(javax.swing.SwingWorker) CharTableAutoCompleterOptionsController(org.omegat.gui.preferences.view.CharTableAutoCompleterOptionsController) KeyStroke(javax.swing.KeyStroke) TreePath(javax.swing.tree.TreePath) FiltersCustomizerController(org.omegat.gui.filters2.FiltersCustomizerController) UserPassController(org.omegat.gui.preferences.view.UserPassController) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) InvocationTargetException(java.lang.reflect.InvocationTargetException) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractAction(javax.swing.AbstractAction) FontSelectionController(org.omegat.gui.preferences.view.FontSelectionController) LanguageToolConfigurationController(org.omegat.gui.preferences.view.LanguageToolConfigurationController) AutotextAutoCompleterOptionsController(org.omegat.gui.preferences.view.AutotextAutoCompleterOptionsController) BasicStroke(java.awt.BasicStroke) SpellcheckerConfigurationController(org.omegat.gui.preferences.view.SpellcheckerConfigurationController) GlossaryPreferencesController(org.omegat.gui.preferences.view.GlossaryPreferencesController) TeamOptionsController(org.omegat.gui.preferences.view.TeamOptionsController) TreeExpansionListener(javax.swing.event.TreeExpansionListener) Preferences(org.omegat.util.Preferences) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) ProjectUICommands(org.omegat.gui.main.ProjectUICommands) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) MachineTranslationPreferencesController(org.omegat.gui.preferences.view.MachineTranslationPreferencesController) BiConsumer(java.util.function.BiConsumer) Container(java.awt.Container) DocumentEvent(javax.swing.event.DocumentEvent) TMMatchesPreferencesController(org.omegat.gui.preferences.view.TMMatchesPreferencesController) ActionMap(javax.swing.ActionMap) GeneralOptionsController(org.omegat.gui.preferences.view.GeneralOptionsController) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JRootPane(javax.swing.JRootPane) Window(java.awt.Window) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) MouseEvent(java.awt.event.MouseEvent) SaveOptionsController(org.omegat.gui.preferences.view.SaveOptionsController) Java8Compat(org.omegat.util.Java8Compat) JScrollBar(javax.swing.JScrollBar) JLayeredPane(javax.swing.JLayeredPane) AutoCompleterController(org.omegat.gui.preferences.view.AutoCompleterController) DocumentListener(javax.swing.event.DocumentListener) JDialog(javax.swing.JDialog) Area(java.awt.geom.Area) HistoryAutoCompleterOptionsController(org.omegat.gui.preferences.view.HistoryAutoCompleterOptionsController) Point(java.awt.Point) RenderingHints(java.awt.RenderingHints) SegmentationCustomizerController(org.omegat.gui.segmentation.SegmentationCustomizerController) ComponentListener(java.awt.event.ComponentListener) Core(org.omegat.core.Core) MouseAdapter(java.awt.event.MouseAdapter) BorderLayout(java.awt.BorderLayout) Method(java.lang.reflect.Method) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Shape(java.awt.Shape) Predicate(java.util.function.Predicate) ComponentEvent(java.awt.event.ComponentEvent) Logger(java.util.logging.Logger) WindowEvent(java.awt.event.WindowEvent) RoundRectangle2D(java.awt.geom.RoundRectangle2D) DictionaryPreferencesController(org.omegat.gui.preferences.view.DictionaryPreferencesController) Objects(java.util.Objects) Dimension(java.awt.Dimension) List(java.util.List) PluginsPreferencesController(org.omegat.gui.preferences.view.PluginsPreferencesController) Graphics(java.awt.Graphics) VersionCheckPreferencesController(org.omegat.gui.preferences.view.VersionCheckPreferencesController) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Rectangle(java.awt.Rectangle) TreeNode(javax.swing.tree.TreeNode) HashMap(java.util.HashMap) Function(java.util.function.Function) ViewOptionsController(org.omegat.gui.preferences.view.ViewOptionsController) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) SecureStoreController(org.omegat.gui.preferences.view.SecureStoreController) Level(java.util.logging.Level) FocusAdapter(java.awt.event.FocusAdapter) SwingUtilities(javax.swing.SwingUtilities) Graphics2D(java.awt.Graphics2D) FurtherActionListener(org.omegat.gui.preferences.IPreferencesController.FurtherActionListener) OStrings(org.omegat.util.OStrings) JComponent(javax.swing.JComponent) GlossaryAutoCompleterOptionsController(org.omegat.gui.preferences.view.GlossaryAutoCompleterOptionsController) ActionEvent(java.awt.event.ActionEvent) ComponentAdapter(java.awt.event.ComponentAdapter) Consumer(java.util.function.Consumer) FocusEvent(java.awt.event.FocusEvent) EditingBehaviorController(org.omegat.gui.preferences.view.EditingBehaviorController) TagProcessingOptionsController(org.omegat.gui.preferences.view.TagProcessingOptionsController) AppearanceController(org.omegat.gui.preferences.view.AppearanceController) InputMap(javax.swing.InputMap) DocumentListener(javax.swing.event.DocumentListener) FocusAdapter(java.awt.event.FocusAdapter) TreeExpansionListener(javax.swing.event.TreeExpansionListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) WindowAdapter(java.awt.event.WindowAdapter) FocusEvent(java.awt.event.FocusEvent) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) KeyEvent(java.awt.event.KeyEvent) AbstractAction(javax.swing.AbstractAction) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) ComponentAdapter(java.awt.event.ComponentAdapter) ActionMap(javax.swing.ActionMap) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException) TreePath(javax.swing.tree.TreePath) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent) JDialog(javax.swing.JDialog)

Example 13 with TreeExpansionEvent

use of javax.swing.event.TreeExpansionEvent in project android by JetBrains.

the class MemoryInstanceView method ensureTreeInitialized.

private void ensureTreeInitialized(@NotNull JPanel parentPanel) {
    if (myTree != null) {
        assert myTreeModel != null && myTreeRoot != null;
        return;
    }
    myTreeRoot = new MemoryObjectTreeNode<>(new InstanceObject() {

        @NotNull
        @Override
        public String getName() {
            return "";
        }
    });
    myTreeModel = new DefaultTreeModel(myTreeRoot);
    JTree tree = new Tree(myTreeModel);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.addTreeSelectionListener(e -> {
        TreePath path = e.getPath();
        if (!e.isAddedPath()) {
            return;
        }
        assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
        MemoryObjectTreeNode instanceObject = (MemoryObjectTreeNode) path.getLastPathComponent();
        assert instanceObject.getAdapter() instanceof InstanceObject;
        InstanceObject selectedInstanceObject = (InstanceObject) instanceObject.getAdapter();
        myStage.selectInstance(selectedInstanceObject);
    });
    // Not all nodes have been populated during buildTree. Here we capture the TreeExpansionEvent to check whether any children
    // under the expanded node need to be populated.
    tree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
            MemoryObjectTreeNode treeNode = (MemoryObjectTreeNode) path.getLastPathComponent();
            for (int i = 0; i < treeNode.getChildCount(); i++) {
                assert treeNode.getChildAt(i) instanceof MemoryObjectTreeNode;
                MemoryObjectTreeNode childNode = (MemoryObjectTreeNode) treeNode.getChildAt(i);
                // Anything below the top level should be FieldObjects
                assert childNode.getAdapter() instanceof FieldObject;
                FieldObject childObject = (FieldObject) childNode.getAdapter();
                if (childObject.getValueType() == ValueType.OBJECT && childNode.getChildCount() == 0) {
                    populateFields(childNode);
                    myTreeModel.nodeStructureChanged(childNode);
                }
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        // No-op. TODO remove unseen children?
        }
    });
    assert myClassObject != null;
    List<InstanceAttribute> attributes = myClassObject.getInstanceAttributes();
    ColumnTreeBuilder builder = new ColumnTreeBuilder(tree);
    for (InstanceAttribute attribute : attributes) {
        builder.addColumn(myAttributeColumns.get(attribute).getBuilder());
    }
    builder.setTreeSorter((Comparator<MemoryObjectTreeNode<InstanceObject>> comparator, SortOrder sortOrder) -> {
        myTreeRoot.sort(comparator);
        myTreeModel.nodeStructureChanged(myTreeRoot);
    });
    builder.setBackground(ProfilerColors.MONITOR_BACKGROUND);
    myTree = builder.build();
    parentPanel.add(myTree, BorderLayout.CENTER);
}
Also used : TreeExpansionListener(javax.swing.event.TreeExpansionListener) FieldObject(com.android.tools.profilers.memory.adapters.FieldObject) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) InstanceAttribute(com.android.tools.profilers.memory.adapters.ClassObject.InstanceAttribute) Comparator(java.util.Comparator) InstanceObject(com.android.tools.profilers.memory.adapters.InstanceObject) TreePath(javax.swing.tree.TreePath) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 14 with TreeExpansionEvent

use of javax.swing.event.TreeExpansionEvent 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 15 with TreeExpansionEvent

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

the class SlicePanel method createTree.

@NotNull
private JTree createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    final Tree tree = new Tree(new DefaultTreeModel(root));
    tree.setOpaque(false);
    tree.setToggleClickCount(-1);
    SliceUsageCellRendererBase renderer = myProvider.getRenderer();
    renderer.setOpaque(false);
    tree.setCellRenderer(renderer);
    UIUtil.setLineStyleAngled(tree);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionPath(new TreePath(root.getPath()));
    //ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
    //PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
    EditSourceOnDoubleClickHandler.install(tree);
    new TreeSpeedSearch(tree);
    TreeUtil.installActions(tree);
    ToolTipManager.sharedInstance().registerComponent(tree);
    myAutoScrollToSourceHandler.install(tree);
    tree.getSelectionModel().addTreeSelectionListener(e -> treeSelectionChanged());
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                List<Navigatable> navigatables = getNavigatables();
                if (navigatables.isEmpty())
                    return;
                for (Navigatable navigatable : navigatables) {
                    if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
                        navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
                    }
                    if (navigatable.canNavigateToSource()) {
                        navigatable.navigate(false);
                        if (navigatable instanceof Usage) {
                            ((Usage) navigatable).highlightInEditor();
                        }
                    }
                }
                e.consume();
            }
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) {
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            SliceNode node = fromPath(path);
            node.calculateDupNode();
        }
    });
    return tree;
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) Usage(com.intellij.usages.Usage) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Navigatable(com.intellij.pom.Navigatable) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) ArrayList(java.util.ArrayList) List(java.util.List) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TreeExpansionEvent (javax.swing.event.TreeExpansionEvent)20 TreePath (javax.swing.tree.TreePath)14 TreeExpansionListener (javax.swing.event.TreeExpansionListener)11 TreeWillExpandListener (javax.swing.event.TreeWillExpandListener)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)7 MouseEvent (java.awt.event.MouseEvent)5 JPanel (javax.swing.JPanel)5 JScrollPane (javax.swing.JScrollPane)5 ExpandVetoException (javax.swing.tree.ExpandVetoException)5 TreeNode (javax.swing.tree.TreeNode)5 BorderLayout (java.awt.BorderLayout)4 JTree (javax.swing.JTree)4 Component (java.awt.Component)3 Dimension (java.awt.Dimension)3 MouseAdapter (java.awt.event.MouseAdapter)3 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)3 Module (com.intellij.openapi.module.Module)2 Navigatable (com.intellij.pom.Navigatable)2 Tree (com.intellij.ui.treeStructure.Tree)2