private void removeSelected() {
   CheckedTreeNode node = getSelectedToolNode();
   if (node != null) {
     int result =
         Messages.showYesNoDialog(
             this,
             ToolsBundle.message("tools.delete.confirmation"),
             CommonBundle.getWarningTitle(),
             Messages.getWarningIcon());
     if (result != 0) {
       return;
     }
     myIsModified = true;
     if (node.getUserObject() instanceof Tool) {
       Tool tool = (Tool) node.getUserObject();
       CheckedTreeNode parentNode = (CheckedTreeNode) node.getParent();
       ((ToolsGroup) parentNode.getUserObject()).removeElement(tool);
       removeNodeFromParent(node);
       if (parentNode.getChildCount() == 0) {
         removeNodeFromParent(parentNode);
       }
     } else if (node.getUserObject() instanceof ToolsGroup) {
       removeNodeFromParent(node);
     }
     update();
     myTree.requestFocus();
   }
 }
  private void editSelected() {
    CheckedTreeNode node = getSelectedToolNode();
    if (node != null && node.getUserObject() instanceof Tool) {
      Tool selected = (Tool) node.getUserObject();
      if (selected != null) {
        String oldGroupName = selected.getGroup();
        ToolEditorDialog dlg = new ToolEditorDialog(this);
        dlg.setData(selected, getGroups());
        dlg.show();
        if (dlg.isOK()) {
          selected.copyFrom(dlg.getData());
          String newGroupName = selected.getGroup();
          if (!Comparing.equal(oldGroupName, newGroupName)) {
            CheckedTreeNode oldGroupNode = (CheckedTreeNode) node.getParent();
            removeNodeFromParent(node);
            ((ToolsGroup) oldGroupNode.getUserObject()).removeElement(selected);
            if (oldGroupNode.getChildCount() == 0) {
              removeNodeFromParent(oldGroupNode);
            }

            insertNewTool(selected, true);
          } else {
            (getModel()).nodeChanged(node);
          }
          myIsModified = true;
          update();
        }
      }
    }
  }
  private ToolsGroup[] getGroupList() {
    ArrayList<ToolsGroup> result = new ArrayList<ToolsGroup>();
    MutableTreeNode root = (MutableTreeNode) myTree.getModel().getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      final CheckedTreeNode node = (CheckedTreeNode) root.getChildAt(i);
      for (int j = 0; j < node.getChildCount(); j++) {
        final CheckedTreeNode toolNode = (CheckedTreeNode) node.getChildAt(j);
        ((Tool) toolNode.getUserObject()).setEnabled(toolNode.isChecked());
      }

      result.add((ToolsGroup) node.getUserObject());
    }

    return result.toArray(new ToolsGroup[result.size()]);
  }
 private void moveNode(final Direction direction) {
   CheckedTreeNode node = getSelectedNode();
   if (node != null) {
     if (isMovingAvailable(node, direction)) {
       moveNode(node, direction);
       if (node.getUserObject() instanceof Tool) {
         ToolsGroup group = (ToolsGroup) (((CheckedTreeNode) node.getParent()).getUserObject());
         Tool tool = (Tool) node.getUserObject();
         moveElementInsideGroup(tool, group, direction);
       }
       TreePath path = new TreePath(node.getPath());
       myTree.getSelectionModel().setSelectionPath(path);
       myTree.expandPath(path);
       myTree.requestFocus();
     }
   }
 }
 private CheckedTreeNode insertNewTool(final CheckedTreeNode groupNode, final Tool toolCopy) {
   CheckedTreeNode toolNode = new CheckedTreeNode(toolCopy);
   toolNode.setChecked(toolCopy.isEnabled());
   ((ToolsGroup) groupNode.getUserObject()).addElement(toolCopy);
   groupNode.add(toolNode);
   nodeWasInserted(toolNode);
   return toolNode;
 }
  private CheckedTreeNode findGroupNode(final String group) {
    for (int i = 0; i < getTreeRoot().getChildCount(); i++) {
      CheckedTreeNode node = (CheckedTreeNode) getTreeRoot().getChildAt(i);
      ToolsGroup g = (ToolsGroup) node.getUserObject();
      if (Comparing.equal(group, g.getName())) return node;
    }

    return null;
  }
 @Nullable
 private ToolsGroup getSelectedToolGroup() {
   CheckedTreeNode node = getSelectedToolNode();
   if (node == null) return null;
   return node.getUserObject() instanceof ToolsGroup ? (ToolsGroup) node.getUserObject() : null;
 }