Search in sources :

Example 1 with BreakpointItemsTreeController

use of com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemsTreeController in project intellij-community by JetBrains.

the class BreakpointsDialog method createMasterView.

private JComponent createMasterView() {
    myTreeController = new BreakpointItemsTreeController(myRulesEnabled) {

        @Override
        public void nodeStateWillChangeImpl(CheckedTreeNode node) {
            if (node instanceof BreakpointItemNode) {
                ((BreakpointItemNode) node).getBreakpointItem().saveState();
            }
            super.nodeStateWillChangeImpl(node);
        }

        @Override
        public void nodeStateDidChangeImpl(CheckedTreeNode node) {
            super.nodeStateDidChangeImpl(node);
            if (node instanceof BreakpointItemNode) {
                myDetailController.doUpdateDetailView(true);
            }
        }

        @Override
        protected void selectionChangedImpl() {
            super.selectionChangedImpl();
            saveCurrentItem();
            myDetailController.updateDetailView();
        }
    };
    final JTree tree = new BreakpointsCheckboxTree(myProject, myTreeController) {

        @Override
        protected void onDoubleClick(CheckedTreeNode node) {
            if (node instanceof BreakpointsGroupNode) {
                TreePath path = TreeUtil.getPathFromRoot(node);
                if (isExpanded(path)) {
                    collapsePath(path);
                } else {
                    expandPath(path);
                }
            } else {
                navigate(false);
            }
        }
    };
    PopupHandler.installPopupHandler(tree, new ActionGroup() {

        @NotNull
        @Override
        public AnAction[] getChildren(@Nullable AnActionEvent e) {
            ActionGroup group = new ActionGroup("Move to group", true) {

                @NotNull
                @Override
                public AnAction[] getChildren(@Nullable AnActionEvent e) {
                    Set<String> groups = getBreakpointManager().getAllGroups();
                    AnAction[] res = new AnAction[groups.size() + 3];
                    int i = 0;
                    res[i++] = new MoveToGroupAction(null);
                    for (String group : groups) {
                        res[i++] = new MoveToGroupAction(group);
                    }
                    res[i++] = new Separator();
                    res[i] = new MoveToGroupAction();
                    return res;
                }
            };
            List<AnAction> res = new ArrayList<>();
            res.add(group);
            Object component = tree.getLastSelectedPathComponent();
            if (tree.getSelectionCount() == 1 && component instanceof BreakpointsGroupNode && ((BreakpointsGroupNode) component).getGroup() instanceof XBreakpointCustomGroup) {
                res.add(new SetAsDefaultGroupAction((XBreakpointCustomGroup) ((BreakpointsGroupNode) component).getGroup()));
            }
            if (tree.getSelectionCount() == 1 && component instanceof BreakpointItemNode) {
                res.add(new EditDescriptionAction((XBreakpointBase) ((BreakpointItemNode) component).getBreakpointItem().getBreakpoint()));
            }
            return res.toArray(new AnAction[res.size()]);
        }
    }, ActionPlaces.UNKNOWN, ActionManager.getInstance());
    new AnAction("BreakpointDialog.GoToSource") {

        @Override
        public void actionPerformed(AnActionEvent e) {
            navigate(true);
            close(OK_EXIT_CODE);
        }
    }.registerCustomShortcutSet(CommonShortcuts.ENTER, tree, myDisposable);
    new AnAction("BreakpointDialog.ShowSource") {

        @Override
        public void actionPerformed(AnActionEvent e) {
            navigate(true);
            close(OK_EXIT_CODE);
        }
    }.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(), tree, myDisposable);
    DefaultActionGroup breakpointTypes = XBreakpointUtil.breakpointTypes().filter(XBreakpointType::isAddBreakpointButtonVisible).map(AddXBreakpointAction::new).toListAndThen(DefaultActionGroup::new);
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(tree).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            JBPopupFactory.getInstance().createActionGroupPopup(null, breakpointTypes, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.NUMBERING, false).show(button.getPreferredPopupPoint());
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            myTreeController.removeSelectedBreakpoints(myProject);
        }
    }).setRemoveActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            for (BreakpointItem item : myTreeController.getSelectedBreakpoints(true)) {
                if (item.allowedToRemove()) {
                    return true;
                }
            }
            return false;
        }
    }).setToolbarPosition(ActionToolbarPosition.TOP).setToolbarBorder(IdeBorderFactory.createEmptyBorder());
    for (ToggleActionButton action : myToggleRuleActions) {
        decorator.addExtraAction(action);
    }
    JPanel decoratedTree = decorator.createPanel();
    decoratedTree.setBorder(IdeBorderFactory.createEmptyBorder());
    JScrollPane pane = UIUtil.getParentOfType(JScrollPane.class, tree);
    if (pane != null)
        pane.setBorder(IdeBorderFactory.createBorder());
    myTreeController.setTreeView(tree);
    myTreeController.buildTree(myBreakpointItems);
    initSelection(myBreakpointItems);
    final BreakpointPanelProvider.BreakpointsListener listener = new BreakpointPanelProvider.BreakpointsListener() {

        @Override
        public void breakpointsChanged() {
            myRebuildAlarm.cancelAndRequest();
        }
    };
    for (BreakpointPanelProvider provider : myBreakpointsPanelProviders) {
        provider.addListener(listener, myProject, myListenerDisposable);
    }
    return decoratedTree;
}
Also used : BreakpointItemsTreeController(com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemsTreeController) HashSet(com.intellij.util.containers.HashSet) BreakpointItemNode(com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemNode) BreakpointsCheckboxTree(com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointsCheckboxTree) NotNull(org.jetbrains.annotations.NotNull) List(java.util.List) BreakpointsGroupNode(com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointsGroupNode) XBreakpointType(com.intellij.xdebugger.breakpoints.XBreakpointType) TreePath(javax.swing.tree.TreePath) XBreakpointCustomGroup(com.intellij.xdebugger.impl.breakpoints.ui.grouping.XBreakpointCustomGroup)

Aggregations

HashSet (com.intellij.util.containers.HashSet)1 XBreakpointType (com.intellij.xdebugger.breakpoints.XBreakpointType)1 XBreakpointCustomGroup (com.intellij.xdebugger.impl.breakpoints.ui.grouping.XBreakpointCustomGroup)1 BreakpointItemNode (com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemNode)1 BreakpointItemsTreeController (com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemsTreeController)1 BreakpointsCheckboxTree (com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointsCheckboxTree)1 BreakpointsGroupNode (com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointsGroupNode)1 List (java.util.List)1 TreePath (javax.swing.tree.TreePath)1 NotNull (org.jetbrains.annotations.NotNull)1