ToolsPanel() {

    myTree =
        new CheckboxTree(
            new CheckboxTree.CheckboxTreeCellRenderer() {
              public void customizeRenderer(
                  final JTree tree,
                  final Object value,
                  final boolean selected,
                  final boolean expanded,
                  final boolean leaf,
                  final int row,
                  final boolean hasFocus) {
                if (!(value instanceof CheckedTreeNode)) return;
                Object object = ((CheckedTreeNode) value).getUserObject();

                if (object instanceof ToolsGroup) {
                  final String groupName = ((ToolsGroup) object).getName();
                  if (groupName != null) {
                    getTextRenderer()
                        .append(groupName, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
                  } else {
                    getTextRenderer()
                        .append("[unnamed group]", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
                  }
                } else if (object instanceof Tool) {
                  getTextRenderer()
                      .append(
                          ((Tool) object).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
                }
              }
            },
            new CheckedTreeNode(null)) {
          @Override
          protected void onDoubleClick(final CheckedTreeNode node) {
            editSelected();
          }

          @Override
          protected void onNodeStateChanged(final CheckedTreeNode node) {
            myIsModified = true;
          }
        };

    myTree.setRootVisible(false);
    myTree.getEmptyText().setText(ToolsBundle.message("tools.not.configured"));
    myTree.setSelectionModel(new DefaultTreeSelectionModel());
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    setLayout(new BorderLayout());
    add(
        ToolbarDecorator.createDecorator(myTree)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    ToolEditorDialog dlg = new ToolEditorDialog(ToolsPanel.this);
                    Tool tool = new Tool();
                    tool.setUseConsole(true);
                    tool.setFilesSynchronizedAfterRun(true);
                    tool.setShownInMainMenu(true);
                    tool.setShownInEditor(true);
                    tool.setShownInProjectViews(true);
                    tool.setShownInSearchResultsPopup(true);
                    tool.setEnabled(true);
                    dlg.setData(tool, getGroups());
                    dlg.show();
                    if (dlg.isOK()) {
                      insertNewTool(dlg.getData(), true);
                    }
                    myTree.requestFocus();
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    removeSelected();
                  }
                })
            .setEditAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    editSelected();
                    myTree.requestFocus();
                  }
                })
            .setMoveUpAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    moveNode(Direction.UP);
                    myIsModified = true;
                  }
                })
            .setMoveDownAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    moveNode(Direction.DOWN);
                    myIsModified = true;
                  }
                })
            .addExtraAction(
                myCopyButton =
                    new AnActionButton(
                        ToolsBundle.message("tools.copy.button"), PlatformIcons.COPY_ICON) {
                      @Override
                      public void actionPerformed(AnActionEvent e) {
                        Tool originalTool = getSelectedTool();

                        if (originalTool != null) {
                          ToolEditorDialog dlg = new ToolEditorDialog(ToolsPanel.this);
                          Tool toolCopy = new Tool();
                          toolCopy.copyFrom(originalTool);
                          dlg.setData(toolCopy, getGroups());
                          dlg.show();
                          if (dlg.isOK()) {
                            insertNewTool(dlg.getData(), true);
                          }
                          myTree.requestFocus();
                        }
                      }
                    })
            .setButtonComparator("Add", "Copy", "Edit", "Remove", "Up", "Down")
            .createPanel(),
        BorderLayout.CENTER);

    myAddButton = ToolbarDecorator.findAddButton(this);
    myEditButton = ToolbarDecorator.findEditButton(this);
    myRemoveButton = ToolbarDecorator.findRemoveButton(this);
    myMoveUpButton = ToolbarDecorator.findUpButton(this);
    myMoveDownButton = ToolbarDecorator.findDownButton(this);

    // TODO check edit and delete

    myTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                update();
              }
            });
  }
  protected void reInitWholePanelIfNeeded() {
    if (!myToReInitWholePanel) return;

    myWholePanel =
        new JPanel(new BorderLayout()) {
          public void addNotify() {
            super.addNotify();
            MasterDetailsComponent.this.addNotify();

            TreeModel m = myTree.getModel();
            if (m instanceof DefaultTreeModel) {
              DefaultTreeModel model = (DefaultTreeModel) m;
              for (int eachRow = 0; eachRow < myTree.getRowCount(); eachRow++) {
                TreePath eachPath = myTree.getPathForRow(eachRow);
                Object component = eachPath.getLastPathComponent();
                if (component instanceof TreeNode) {
                  model.nodeChanged((TreeNode) component);
                }
              }
            }
          }
        };
    mySplitter.setHonorComponentsMinimumSize(true);
    myWholePanel.add(mySplitter, BorderLayout.CENTER);

    JPanel left =
        new JPanel(new BorderLayout()) {
          public Dimension getMinimumSize() {
            final Dimension original = super.getMinimumSize();
            return new Dimension(Math.max(original.width, 100), original.height);
          }
        };

    if (isNewProjectSettings()) {
      ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree);
      DefaultActionGroup group = createToolbarActionGroup();
      if (group != null) {
        decorator.setActionGroup(group);
      }
      // left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster =
          decorator.setAsUsualTopToolbar().setPanelBorder(JBUI.Borders.empty()).createPanel();
      myNorthPanel.setVisible(false);
    } else {
      left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster = ScrollPaneFactory.createScrollPane(myTree);
    }
    left.add(myMaster, BorderLayout.CENTER);
    mySplitter.setFirstComponent(left);

    final JPanel right = new JPanel(new BorderLayout());
    right.add(myDetails.getComponent(), BorderLayout.CENTER);
    if (!isNewProjectSettings()) {
      myWholePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    }

    mySplitter.setSecondComponent(right);

    GuiUtils.replaceJSplitPaneWithIDEASplitter(myWholePanel);

    myToReInitWholePanel = false;
  }