private void addFilesUnderDirectory(
     @NotNull PsiDirectory directory, @NotNull ContentIterator iterator) {
   for (PsiElement child : directory.getChildren()) {
     if (child instanceof PsiFile) {
       VirtualFile virtualFile = ((PsiFile) child).getVirtualFile();
       if (virtualFile != null) {
         iterator.processFile(virtualFile);
       }
     } else if (myFindModel.isWithSubdirectories() && child instanceof PsiDirectory) {
       addFilesUnderDirectory((PsiDirectory) child, iterator);
     }
   }
 }
  /**
   * @param elementToCopy PsiFile or PsiDirectory
   * @param newName can be not null only if elements.length == 1
   * @param choice a horrible way to pass/keep user preference
   * @return first copied PsiFile (recursively); null if no PsiFiles copied
   */
  @Nullable
  public static PsiFile copyToDirectory(
      @NotNull PsiFileSystemItem elementToCopy,
      @Nullable String newName,
      @NotNull PsiDirectory targetDirectory,
      @Nullable int[] choice)
      throws IncorrectOperationException, IOException {
    if (elementToCopy instanceof PsiFile) {
      PsiFile file = (PsiFile) elementToCopy;
      String name = newName == null ? file.getName() : newName;
      if (checkFileExist(targetDirectory, choice, file, name, "Copy")) return null;
      return targetDirectory.copyFileFrom(name, file);
    } else if (elementToCopy instanceof PsiDirectory) {
      PsiDirectory directory = (PsiDirectory) elementToCopy;
      if (directory.equals(targetDirectory)) {
        return null;
      }
      if (newName == null) newName = directory.getName();
      final PsiDirectory existing = targetDirectory.findSubdirectory(newName);
      final PsiDirectory subdirectory =
          existing == null ? targetDirectory.createSubdirectory(newName) : existing;
      EncodingRegistry.doActionAndRestoreEncoding(
          directory.getVirtualFile(),
          new ThrowableComputable<VirtualFile, IOException>() {
            @Override
            public VirtualFile compute() {
              return subdirectory.getVirtualFile();
            }
          });

      PsiFile firstFile = null;
      PsiElement[] children = directory.getChildren();
      for (PsiElement child : children) {
        PsiFileSystemItem item = (PsiFileSystemItem) child;
        PsiFile f = copyToDirectory(item, item.getName(), subdirectory, choice);
        if (firstFile == null) {
          firstFile = f;
        }
      }
      return firstFile;
    } else {
      throw new IllegalArgumentException("unexpected elementToCopy: " + elementToCopy);
    }
  }
 private String canCreateAllFilesForAllLocales() {
   final String name = getBaseName();
   if (name.isEmpty()) {
     return "Base name is empty";
   }
   final Set<String> files = getFileNamesToCreate();
   if (files.isEmpty()) {
     return "No locales added";
   }
   for (PsiElement element : myDirectory.getChildren()) {
     if (element instanceof PsiFile) {
       if (element instanceof PropertiesFile) {
         PropertiesFile propertiesFile = (PropertiesFile) element;
         final String propertiesFileName = propertiesFile.getName();
         if (files.contains(propertiesFileName)) {
           return "Some of files already exist";
         }
       }
     }
   }
   return null;
 }