Search in sources :

Example 1 with TreeExpander

use of com.intellij.ide.TreeExpander in project intellij-community by JetBrains.

the class RepositoryBrowserDialog method createToolbar.

public JComponent createToolbar(final boolean horizontal, final AnAction... additionalActions) {
    DefaultActionGroup group = new DefaultActionGroup();
    final RepositoryBrowserComponent browser = getRepositoryBrowser();
    group.add(new AddLocationAction(browser));
    group.add(new EditLocationAction(browser));
    group.add(new DiscardLocationAction(browser));
    group.add(new DetailsAction());
    group.addSeparator();
    final RefreshAction refreshAction = new RefreshAction(browser);
    refreshAction.registerCustomShortcutSet(CommonShortcuts.getRerun(), browser);
    group.add(refreshAction);
    copyUrlAction = new CopyUrlAction();
    copyUrlAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)), browser);
    mkDirAction = new MkDirAction(browser);
    mkDirAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)), browser);
    AnAction action = CommonActionsManager.getInstance().createCollapseAllAction(new TreeExpander() {

        public void expandAll() {
        }

        public boolean canExpand() {
            return false;
        }

        public void collapseAll() {
            JTree tree = browser.getRepositoryTree();
            int row = tree.getRowCount() - 1;
            while (row >= 0) {
                tree.collapseRow(row);
                row--;
            }
        }

        public boolean canCollapse() {
            return true;
        }
    }, browser);
    group.add(action);
    if ((additionalActions != null) || (!horizontal)) {
        group.addSeparator();
    }
    if (additionalActions != null) {
        for (AnAction anAction : additionalActions) {
            group.add(anAction);
        }
    }
    if (!horizontal) {
        group.add(new CloseToolWindowAction());
    }
    return ActionManager.getInstance().createActionToolbar(PLACE_TOOLBAR, group, horizontal).getComponent();
}
Also used : TreeExpander(com.intellij.ide.TreeExpander)

Example 2 with TreeExpander

use of com.intellij.ide.TreeExpander in project intellij-community by JetBrains.

the class ChooseActionsDialog method createToolbarPanel.

private JPanel createToolbarPanel() {
    final JPanel panel = new JPanel(new BorderLayout());
    DefaultActionGroup group = new DefaultActionGroup();
    final JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent();
    final CommonActionsManager commonActionsManager = CommonActionsManager.getInstance();
    final TreeExpander treeExpander = new TreeExpander() {

        public void expandAll() {
            TreeUtil.expandAll(myActionsTree.getTree());
        }

        public boolean canExpand() {
            return true;
        }

        public void collapseAll() {
            TreeUtil.collapseAll(myActionsTree.getTree(), 0);
        }

        public boolean canCollapse() {
            return true;
        }
    };
    group.add(commonActionsManager.createExpandAllAction(treeExpander, myActionsTree.getTree()));
    group.add(commonActionsManager.createCollapseAllAction(treeExpander, myActionsTree.getTree()));
    panel.add(toolbar, BorderLayout.WEST);
    group = new DefaultActionGroup();
    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    actionToolbar.setReservePlaceAutoPopupIcon(false);
    final JComponent searchToolbar = actionToolbar.getComponent();
    final Alarm alarm = new Alarm();
    myFilterComponent = new FilterComponent("KEYMAP_IN_QUICK_LISTS", 5) {

        public void filter() {
            alarm.cancelAllRequests();
            alarm.addRequest(() -> {
                if (!myFilterComponent.isShowing())
                    return;
                if (!myTreeExpansionMonitor.isFreeze())
                    myTreeExpansionMonitor.freeze();
                myFilteringPanel.setShortcut(null);
                final String filter = getFilter();
                myActionsTree.filter(filter, myQuicklists);
                final JTree tree = myActionsTree.getTree();
                TreeUtil.expandAll(tree);
                if (filter == null || filter.length() == 0) {
                    TreeUtil.collapseAll(tree, 0);
                    myTreeExpansionMonitor.restore();
                }
            }, 300);
        }
    };
    myFilterComponent.reset();
    panel.add(myFilterComponent, BorderLayout.CENTER);
    group.add(new AnAction(KeyMapBundle.message("filter.shortcut.action.text"), KeyMapBundle.message("filter.shortcut.action.text"), AllIcons.Actions.ShortcutFilter) {

        public void actionPerformed(AnActionEvent e) {
            myFilterComponent.reset();
            myActionsTree.reset(myKeymap, myQuicklists);
            myFilteringPanel.showPopup(searchToolbar);
        }
    });
    group.add(new AnAction(KeyMapBundle.message("filter.clear.action.text"), KeyMapBundle.message("filter.clear.action.text"), AllIcons.Actions.GC) {

        @Override
        public void update(AnActionEvent event) {
            boolean enabled = null != myFilteringPanel.getShortcut();
            Presentation presentation = event.getPresentation();
            presentation.setEnabled(enabled);
            presentation.setIcon(enabled ? AllIcons.Actions.Cancel : EmptyIcon.ICON_16);
        }

        public void actionPerformed(AnActionEvent e) {
            myFilteringPanel.setShortcut(null);
            //clear filtering
            myActionsTree.filter(null, myQuicklists);
            TreeUtil.collapseAll(myActionsTree.getTree(), 0);
            myTreeExpansionMonitor.restore();
        }
    });
    panel.add(searchToolbar, BorderLayout.EAST);
    return panel;
}
Also used : TreeExpander(com.intellij.ide.TreeExpander) FilterComponent(com.intellij.ui.FilterComponent) Alarm(com.intellij.util.Alarm) CommonActionsManager(com.intellij.ide.CommonActionsManager)

Example 3 with TreeExpander

use of com.intellij.ide.TreeExpander in project intellij-community by JetBrains.

the class KeymapPanel method createToolbarPanel.

private JPanel createToolbarPanel() {
    final JPanel panel = new JPanel(new GridBagLayout());
    DefaultActionGroup group = new DefaultActionGroup();
    final JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent();
    final CommonActionsManager commonActionsManager = CommonActionsManager.getInstance();
    final TreeExpander treeExpander = new TreeExpander() {

        @Override
        public void expandAll() {
            TreeUtil.expandAll(myActionsTree.getTree());
        }

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

        @Override
        public void collapseAll() {
            TreeUtil.collapseAll(myActionsTree.getTree(), 0);
        }

        @Override
        public boolean canCollapse() {
            return true;
        }
    };
    group.add(commonActionsManager.createExpandAllAction(treeExpander, myActionsTree.getTree()));
    group.add(commonActionsManager.createCollapseAllAction(treeExpander, myActionsTree.getTree()));
    group.add(new AnAction("Edit Shortcut", "Edit Shortcut", AllIcons.ToolbarDecorator.Edit) {

        {
            registerCustomShortcutSet(CommonShortcuts.ENTER, myActionsTree.getTree());
        }

        @Override
        public void update(@NotNull AnActionEvent e) {
            final String actionId = myActionsTree.getSelectedActionId();
            e.getPresentation().setEnabled(actionId != null);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            editSelection(e.getInputEvent(), false);
        }
    });
    panel.add(toolbar, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
    group = new DefaultActionGroup();
    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    actionToolbar.setReservePlaceAutoPopupIcon(false);
    final JComponent searchToolbar = actionToolbar.getComponent();
    final Alarm alarm = new Alarm();
    myFilterComponent = new FilterComponent("KEYMAP", 5) {

        @Override
        public void filter() {
            alarm.cancelAllRequests();
            alarm.addRequest(() -> {
                if (!myFilterComponent.isShowing())
                    return;
                myTreeExpansionMonitor.freeze();
                myFilteringPanel.setShortcut(null);
                final String filter = getFilter();
                myActionsTree.filter(filter, myQuickLists);
                final JTree tree = myActionsTree.getTree();
                TreeUtil.expandAll(tree);
                if (filter == null || filter.length() == 0) {
                    TreeUtil.collapseAll(tree, 0);
                    myTreeExpansionMonitor.restore();
                } else {
                    myTreeExpansionMonitor.unfreeze();
                }
            }, 300);
        }
    };
    myFilterComponent.reset();
    panel.add(myFilterComponent, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
    group.add(new DumbAwareAction(KeyMapBundle.message("filter.shortcut.action.text"), KeyMapBundle.message("filter.shortcut.action.text"), AllIcons.Actions.ShortcutFilter) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            myFilterComponent.reset();
            //noinspection ConstantConditions
            myActionsTree.reset(myEditor.getModel().getSelected(), myQuickLists);
            myFilteringPanel.showPopup(searchToolbar);
        }
    });
    group.add(new DumbAwareAction(KeyMapBundle.message("filter.clear.action.text"), KeyMapBundle.message("filter.clear.action.text"), AllIcons.Actions.GC) {

        @Override
        public void update(AnActionEvent event) {
            boolean enabled = null != myFilteringPanel.getShortcut();
            Presentation presentation = event.getPresentation();
            presentation.setEnabled(enabled);
            presentation.setIcon(enabled ? AllIcons.Actions.Cancel : EmptyIcon.ICON_16);
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            myTreeExpansionMonitor.freeze();
            myFilteringPanel.setShortcut(null);
            //clear filtering
            myActionsTree.filter(null, myQuickLists);
            TreeUtil.collapseAll(myActionsTree.getTree(), 0);
            myTreeExpansionMonitor.restore();
        }
    });
    panel.add(searchToolbar, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
    return panel;
}
Also used : TreeExpander(com.intellij.ide.TreeExpander) FilterComponent(com.intellij.ui.FilterComponent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Alarm(com.intellij.util.Alarm) CommonActionsManager(com.intellij.ide.CommonActionsManager)

Example 4 with TreeExpander

use of com.intellij.ide.TreeExpander in project intellij-community by JetBrains.

the class RunDashboardContent method createToolbar.

private JComponent createToolbar() {
    JPanel toolBarPanel = new JPanel(new GridLayout());
    DefaultActionGroup leftGroup = new DefaultActionGroup();
    leftGroup.add(ActionManager.getInstance().getAction(RUN_DASHBOARD_TOOLBAR));
    // TODO [konstantin.aleev] provide context help ID
    //leftGroup.add(new Separator());
    //leftGroup.add(new ContextHelpAction(HELP_ID));
    ActionToolbar leftActionToolBar = ActionManager.getInstance().createActionToolbar(PLACE_TOOLBAR, leftGroup, false);
    toolBarPanel.add(leftActionToolBar.getComponent());
    myTree.putClientProperty(DataManager.CLIENT_PROPERTY_DATA_PROVIDER, new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            if (KEY.getName().equals(dataId)) {
                return RunDashboardContent.this;
            }
            return null;
        }
    });
    leftActionToolBar.setTargetComponent(myTree);
    DefaultActionGroup rightGroup = new DefaultActionGroup();
    TreeExpander treeExpander = new DefaultTreeExpander(myTree);
    AnAction expandAllAction = CommonActionsManager.getInstance().createExpandAllAction(treeExpander, this);
    rightGroup.add(expandAllAction);
    AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(treeExpander, this);
    rightGroup.add(collapseAllAction);
    rightGroup.add(new Separator());
    myGroupers.stream().filter(grouper -> !grouper.getRule().isAlwaysEnabled()).forEach(grouper -> rightGroup.add(new GroupAction(grouper)));
    ActionToolbar rightActionToolBar = ActionManager.getInstance().createActionToolbar(PLACE_TOOLBAR, rightGroup, false);
    toolBarPanel.add(rightActionToolBar.getComponent());
    rightActionToolBar.setTargetComponent(myTree);
    return toolBarPanel;
}
Also used : com.intellij.ui.content(com.intellij.ui.content) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) com.intellij.ide.util.treeView(com.intellij.ide.util.treeView) NonNls(org.jetbrains.annotations.NonNls) HashSet(java.util.HashSet) ActionPresentation(com.intellij.ide.util.treeView.smartTree.ActionPresentation) Comparing(com.intellij.openapi.util.Comparing) DashboardGrouper(com.intellij.execution.dashboard.tree.DashboardGrouper) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) ExecutionBundle(com.intellij.execution.ExecutionBundle) DumbAware(com.intellij.openapi.project.DumbAware) CommonActionsManager(com.intellij.ide.CommonActionsManager) DataManager(com.intellij.ide.DataManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Splitter(com.intellij.openapi.ui.Splitter) Set(java.util.Set) com.intellij.ui(com.intellij.ui) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) Disposable(com.intellij.openapi.Disposable) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeExpander(com.intellij.ide.TreeExpander) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) List(java.util.List) JBPanelWithEmptyText(com.intellij.ui.components.JBPanelWithEmptyText) RunDashboardTreeStructure(com.intellij.execution.dashboard.tree.RunDashboardTreeStructure) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) TreeExpansionListener(javax.swing.event.TreeExpansionListener) javax.swing(javax.swing) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) TreeExpander(com.intellij.ide.TreeExpander) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander)

Example 5 with TreeExpander

use of com.intellij.ide.TreeExpander in project intellij-community by JetBrains.

the class TreeCollapseAllActionBase method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    TreeExpander expander = getExpander(e.getDataContext());
    if (expander == null) {
        return;
    }
    if (!expander.canCollapse()) {
        return;
    }
    expander.collapseAll();
}
Also used : TreeExpander(com.intellij.ide.TreeExpander)

Aggregations

TreeExpander (com.intellij.ide.TreeExpander)12 CommonActionsManager (com.intellij.ide.CommonActionsManager)7 DefaultTreeExpander (com.intellij.ide.DefaultTreeExpander)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 FilterComponent (com.intellij.ui.FilterComponent)2 Alarm (com.intellij.util.Alarm)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionBundle (com.intellij.execution.ExecutionBundle)1 DashboardGrouper (com.intellij.execution.dashboard.tree.DashboardGrouper)1 RunDashboardTreeStructure (com.intellij.execution.dashboard.tree.RunDashboardTreeStructure)1 DataManager (com.intellij.ide.DataManager)1 com.intellij.ide.util.treeView (com.intellij.ide.util.treeView)1 ActionPresentation (com.intellij.ide.util.treeView.smartTree.ActionPresentation)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 DumbAware (com.intellij.openapi.project.DumbAware)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1