@Override
  public void actionPerformed(AnActionEvent e) {
    final List<Descriptor> descriptors = new ArrayList<Descriptor>();
    final InspectionConfigTreeNode[] selectedNodes =
        myTree.getSelectedNodes(InspectionConfigTreeNode.class, null);
    LOG.assertTrue(selectedNodes != null);

    final List<InspectionConfigTreeNode> nodes =
        new ArrayList<InspectionConfigTreeNode>(Arrays.asList(selectedNodes));
    for (InspectionConfigTreeNode node : selectedNodes) {
      collect(descriptors, nodes, node);
    }

    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
    final List<String> availableScopes = getAvailableScopes(project, descriptors);
    final int idx =
        Messages.showChooseDialog(
            myTree,
            "Scope:",
            "Choose Scope",
            ArrayUtil.toStringArray(availableScopes),
            availableScopes.get(0),
            Messages.getQuestionIcon());
    if (idx == -1) return;
    final NamedScope chosenScope = NamedScopesHolder.getScope(project, availableScopes.get(idx));

    for (InspectionConfigTreeNode node : nodes) {
      final Descriptor descriptor = node.getDesriptor();
      if (node.getScopeName() != null || descriptor == null) continue;
      final InspectionProfileEntry tool = descriptor.getTool(); // copy
      final ScopeToolState scopeToolState =
          getSelectedProfile()
              .addScope(
                  tool,
                  chosenScope,
                  getSelectedProfile().getErrorLevel(descriptor.getKey(), chosenScope),
                  getSelectedProfile().isToolEnabled(descriptor.getKey()));
      final Descriptor addedDescriptor = new Descriptor(scopeToolState, getSelectedProfile());
      if (node.getChildCount() == 0) {
        node.add(
            new InspectionConfigTreeNode(
                descriptor,
                getSelectedProfile().getToolDefaultState(descriptor.getKey().toString()),
                true,
                true,
                false));
      }
      node.insert(new InspectionConfigTreeNode(addedDescriptor, scopeToolState, false, false), 0);
      node.setInspectionNode(false);
      node.dropCache();
      ((DefaultTreeModel) myTree.getModel()).reload(node);
      myTree.expandPath(new TreePath(node.getPath()));
    }
    myTree.revalidate();
  }
 private static void collect(
     List<Descriptor> descriptors,
     List<InspectionConfigTreeNode> nodes,
     InspectionConfigTreeNode node) {
   final Descriptor descriptor = node.getDesriptor();
   if (descriptor != null) {
     if (node.getScopeName() == null) {
       descriptors.add(descriptor);
     }
   } else if (node.getUserObject() instanceof String) {
     for (int i = 0; i < node.getChildCount(); i++) {
       final InspectionConfigTreeNode childNode = (InspectionConfigTreeNode) node.getChildAt(i);
       nodes.add(childNode);
       collect(descriptors, nodes, childNode);
     }
   }
 }