protected void waitForFolding(JTextComponent target, int maxMiliSeconds) {
    // wait for parser and folding hierarchy creation
    int time = (int) maxMiliSeconds / 100;

    AbstractDocument adoc = (AbstractDocument) target.getDocument();

    // Dump fold hierarchy
    FoldHierarchy hierarchy = FoldHierarchy.get(target);
    int foldCount = 0;
    while (foldCount == 0 && time > 0) {

      adoc.readLock();
      try {
        hierarchy.lock();
        try {
          foldCount = hierarchy.getRootFold().getFoldCount();
        } finally {
          hierarchy.unlock();
        }
      } finally {
        adoc.readUnlock();
      }

      try {
        Thread.currentThread().sleep(100);
      } catch (InterruptedException ex) {
        time = 0;
      }
      time--;
    }
  }
  public static String foldHierarchyToString(JTextComponent target) {
    String ret = "";
    AbstractDocument adoc = (AbstractDocument) target.getDocument();

    // Dump fold hierarchy
    FoldHierarchy hierarchy = FoldHierarchy.get(target);
    adoc.readLock();
    try {
      hierarchy.lock();
      try {
        Fold root = hierarchy.getRootFold();
        ret = (root == null) ? "root is null" : foldToStringChildren(root, 0); // NOI18N
      } finally {
        hierarchy.unlock();
      }
    } finally {
      adoc.readUnlock();
    }
    return ret;
  }