private void addCheckbox(final JPanel panel, final TreeAction action) {
    String text =
        action instanceof FileStructureFilter
            ? ((FileStructureFilter) action).getCheckBoxText()
            : action instanceof FileStructureNodeProvider
                ? ((FileStructureNodeProvider) action).getCheckBoxText()
                : null;

    if (text == null) return;

    Shortcut[] shortcuts =
        action instanceof FileStructureFilter
            ? ((FileStructureFilter) action).getShortcut()
            : ((FileStructureNodeProvider) action).getShortcut();

    final JCheckBox chkFilter = new JCheckBox();
    UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, chkFilter);

    final boolean selected = getDefaultValue(action);
    chkFilter.setSelected(selected);
    myTreeActionsOwner.setActionIncluded(
        action, action instanceof FileStructureFilter ? !selected : selected);
    chkFilter.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            final boolean state = chkFilter.isSelected();
            if (!myAutoClicked.contains(chkFilter)) {
              saveState(action, state);
            }
            myTreeActionsOwner.setActionIncluded(
                action, action instanceof FileStructureFilter ? !state : state);
            // final String filter = mySpeedSearch.isPopupActive() ?
            // mySpeedSearch.getEnteredPrefix() : null;
            // mySpeedSearch.hidePopup();
            Object selection =
                ContainerUtil.getFirstItem(myAbstractTreeBuilder.getSelectedElements());
            if (selection instanceof FilteringTreeStructure.FilteringNode) {
              selection = ((FilteringTreeStructure.FilteringNode) selection).getDelegate();
            }
            myTreeStructure.rebuildTree();
            myFilteringStructure.rebuild();

            final Object sel = selection;
            final Runnable runnable =
                new Runnable() {
                  public void run() {
                    ApplicationManager.getApplication()
                        .runReadAction(
                            new Runnable() {
                              @Override
                              public void run() {
                                myAbstractTreeBuilder
                                    .refilter(sel, true, false)
                                    .doWhenProcessed(
                                        new Runnable() {
                                          @Override
                                          public void run() {
                                            if (mySpeedSearch.isPopupActive()) {
                                              mySpeedSearch.refreshSelection();
                                            }
                                          }
                                        });
                              }
                            });
                  }
                };
            if (ApplicationManager.getApplication().isUnitTestMode()) {
              runnable.run();
            } else {
              ApplicationManager.getApplication().invokeLater(runnable);
            }
          }
        });
    chkFilter.setFocusable(false);

    if (shortcuts.length > 0) {
      text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
      new AnAction() {
        public void actionPerformed(final AnActionEvent e) {
          chkFilter.doClick();
        }
      }.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree);
    }
    chkFilter.setText(text);
    panel.add(chkFilter);
    myCheckBoxes.put(action.getClass(), chkFilter);
  }
  BeforeRunStepsPanel(StepsBeforeRunListener listener) {
    myListener = listener;
    myModel = new CollectionListModel<BeforeRunTask>();
    myList = new JBList(myModel);
    myList.getEmptyText().setText(ExecutionBundle.message("before.launch.panel.empty"));
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(new MyListCellRenderer());

    myModel.addListDataListener(
        new ListDataListener() {
          @Override
          public void intervalAdded(ListDataEvent e) {
            adjustVisibleRowCount();
            updateText();
          }

          @Override
          public void intervalRemoved(ListDataEvent e) {
            adjustVisibleRowCount();
            updateText();
          }

          @Override
          public void contentsChanged(ListDataEvent e) {}

          private void adjustVisibleRowCount() {
            myList.setVisibleRowCount(Math.max(4, Math.min(8, myModel.getSize())));
          }
        });

    ToolbarDecorator myDecorator = ToolbarDecorator.createDecorator(myList);
    if (!SystemInfo.isMac) {
      myDecorator.setAsUsualTopToolbar();
    }
    myDecorator.setEditAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            int index = myList.getSelectedIndex();
            if (index == -1) return;
            Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> selection = getSelection();
            if (selection == null) return;
            BeforeRunTask task = selection.getFirst();
            BeforeRunTaskProvider<BeforeRunTask> provider = selection.getSecond();
            if (provider.configureTask(myRunConfiguration, task)) {
              myModel.setElementAt(task, index);
            }
          }
        });
    myDecorator.setEditActionUpdater(
        new AnActionButtonUpdater() {
          @Override
          public boolean isEnabled(AnActionEvent e) {
            Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> selection = getSelection();
            return selection != null && selection.getSecond().isConfigurable();
          }
        });
    myDecorator.setAddAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            doAddAction(button);
          }
        });
    myDecorator.setAddActionUpdater(
        new AnActionButtonUpdater() {
          @Override
          public boolean isEnabled(AnActionEvent e) {
            return checkBeforeRunTasksAbility(true);
          }
        });

    myShowSettingsBeforeRunCheckBox =
        new JCheckBox(ExecutionBundle.message("configuration.edit.before.run"));
    myShowSettingsBeforeRunCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            updateText();
          }
        });

    myPanel = myDecorator.createPanel();

    setLayout(new BorderLayout());
    add(myPanel, BorderLayout.CENTER);
    add(myShowSettingsBeforeRunCheckBox, BorderLayout.SOUTH);
  }