package com.karateca.ddescriber;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.project.Project;

import java.lang.Runnable;

/**
 * @author Andres Dominguez.
 */
public class ActionUtil {
  /**
   * Run a write operation within a command.
   * @param project The current project.
   * @param action The action to run.
   */
  public static void runWriteActionInsideCommand(Project project, final Runnable action) {
    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(action);
      }
    }, "Add / Remove tests", null);
  }
}

@@ -202,22 +202,117 @@
 java
-.lang.Runnable
+x.swing.tree.DefaultMutableTreeNode;%0Aimport java.lang.Runnable;%0Aimport java.util.List;%0Aimport java.util.Stack
 ;%0A%0A/
@@ -424,16 +424,21 @@
 ommand.%0A
+   *%0A
    * @pa
@@ -489,16 +489,17 @@
  action 
+ 
 The acti
@@ -800,16 +800,16 @@
       %7D%0A
-
     %7D, %22
@@ -839,11 +839,957 @@
 ll);%0A  %7D
+%0A%0A  public static DefaultMutableTreeNode populateTree(List%3CTestFindResult%3E elements) %7B%0A    TestFindResult first = elements.get(0);%0A    DefaultMutableTreeNode root = new DefaultMutableTreeNode(first);%0A%0A    if (elements.size() %3C 2) %7B%0A      return root;%0A    %7D%0A%0A    Stack%3CDefaultMutableTreeNode%3E stack = new Stack%3CDefaultMutableTreeNode%3E();%0A    int currentIndentation = first.getIndentation();%0A%0A    DefaultMutableTreeNode parent = root;%0A    DefaultMutableTreeNode last = root;%0A%0A    for (TestFindResult element : elements.subList(1, elements.size())) %7B%0A      int ind = element.getIndentation();%0A%0A      DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(element);%0A%0A      if (ind %3E currentIndentation) %7B%0A        stack.push(parent);%0A        parent = last;%0A      %7D else if (ind %3C currentIndentation) %7B%0A        parent = stack.pop();%0A      %7D%0A      last = newNode;%0A      parent.add(last);%0A%0A      currentIndentation = ind;%0A    %7D%0A%0A    return root;%0A  %7D
 %0A%7D%0A

add populateTree