Ejemplo n.º 1
0
 private static boolean checkCreateClassOrPackage(
     final boolean createJavaClass, final PsiDirectory directory, final String name) {
   try {
     if (createJavaClass) {
       JavaDirectoryService.getInstance().checkCreateClass(directory, name);
     } else {
       directory.checkCreateSubdirectory(name);
     }
     return true;
   } catch (IncorrectOperationException ex) {
     return false;
   }
 }
  public boolean canClose(String inputString) {
    final String subDirName = inputString;

    if (subDirName.length() == 0) {
      Messages.showMessageDialog(
          myProject,
          IdeBundle.message("error.name.should.be.specified"),
          CommonBundle.getErrorTitle(),
          Messages.getErrorIcon());
      return false;
    }

    final boolean multiCreation = StringUtil.containsAnyChar(subDirName, myDelimiters);
    if (!multiCreation) {
      try {
        myDirectory.checkCreateSubdirectory(subDirName);
      } catch (IncorrectOperationException ex) {
        Messages.showMessageDialog(
            myProject,
            CreateElementActionBase.filterMessage(ex.getMessage()),
            CommonBundle.getErrorTitle(),
            Messages.getErrorIcon());
        return false;
      }
    }

    Runnable command =
        new Runnable() {
          public void run() {
            final Runnable run =
                new Runnable() {
                  public void run() {
                    LocalHistoryAction action = LocalHistoryAction.NULL;
                    try {
                      String actionName;
                      String dirPath = myDirectory.getVirtualFile().getPresentableUrl();
                      actionName =
                          IdeBundle.message(
                              "progress.creating.directory", dirPath, File.separator, subDirName);
                      action = LocalHistory.getInstance().startAction(actionName);

                      createDirectories(subDirName);

                    } catch (final IncorrectOperationException ex) {
                      ApplicationManager.getApplication()
                          .invokeLater(
                              new Runnable() {
                                public void run() {
                                  Messages.showMessageDialog(
                                      myProject,
                                      CreateElementActionBase.filterMessage(ex.getMessage()),
                                      CommonBundle.getErrorTitle(),
                                      Messages.getErrorIcon());
                                }
                              });
                    } finally {
                      action.finish();
                    }
                  }
                };
            ApplicationManager.getApplication().runWriteAction(run);
          }
        };
    CommandProcessor.getInstance()
        .executeCommand(
            myProject,
            command,
            myIsDirectory
                ? IdeBundle.message("command.create.directory")
                : IdeBundle.message("command.create.package"),
            null);

    return myCreatedElement != null;
  }