@Nullable
  private MoveDestination selectDestination() {
    final String packageName = getTargetPackage().trim();
    if (packageName.length() > 0
        && !JavaPsiFacade.getInstance(myManager.getProject())
            .getNameHelper()
            .isQualifiedName(packageName)) {
      Messages.showErrorDialog(
          myProject,
          RefactoringBundle.message("please.enter.a.valid.target.package.name"),
          RefactoringBundle.message("move.title"));
      return null;
    }
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    PackageWrapper targetPackage = new PackageWrapper(myManager, packageName);
    if (!targetPackage.exists()) {
      final int ret =
          Messages.showYesNoDialog(
              myProject,
              RefactoringBundle.message("package.does.not.exist", packageName),
              RefactoringBundle.message("move.title"),
              Messages.getQuestionIcon());
      if (ret != 0) return null;
    }

    return ((DestinationFolderComboBox) myDestinationFolderCB).selectDirectory(targetPackage, true);
  }
Ejemplo n.º 2
0
  private void chooseDirectoryAndMove(Project project, PsiFile myFile) {
    try {
      PsiDirectory directory =
          MoveClassesOrPackagesUtil.chooseDestinationPackage(project, myTargetPackage, null);

      if (directory == null) {
        return;
      }
      String error = RefactoringMessageUtil.checkCanCreateFile(directory, myFile.getName());
      if (error != null) {
        Messages.showMessageDialog(
            project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
      }
      new MoveClassesOrPackagesProcessor(
              project,
              new PsiElement[] {((PsiJavaFile) myFile).getClasses()[0]},
              new SingleSourceRootMoveDestination(
                  PackageWrapper.create(JavaDirectoryService.getInstance().getPackage(directory)),
                  directory),
              false,
              false,
              null)
          .run();
    } catch (IncorrectOperationException e) {
      LOG.error(e);
    }
  }