コード例 #1
0
  @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);
  }
コード例 #2
0
  public MoveClassesOrPackagesDialog(
      Project project,
      boolean searchTextOccurences,
      PsiElement[] elementsToMove,
      final PsiElement initialTargetElement,
      MoveCallback moveCallback) {
    super(project, true);
    myElementsToMove = elementsToMove;
    myMoveCallback = moveCallback;
    myManager = PsiManager.getInstance(myProject);
    setTitle(MoveHandler.REFACTORING_NAME);
    mySearchTextOccurencesEnabled = searchTextOccurences;

    selectInitialCard();

    init();

    if (initialTargetElement instanceof PsiClass) {
      myMakeInnerClassOfRadioButton.setSelected(true);

      myInnerClassChooser.setText(((PsiClass) initialTargetElement).getQualifiedName());

      ApplicationManager.getApplication()
          .invokeLater(
              () -> myInnerClassChooser.requestFocus(),
              ModalityState.stateForComponent(myMainPanel));
    } else if (initialTargetElement instanceof PsiPackage) {
      myClassPackageChooser.setText(((PsiPackage) initialTargetElement).getQualifiedName());
    }

    updateControlsEnabled();
    myToPackageRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateControlsEnabled();
            myClassPackageChooser.requestFocus();
          }
        });
    myMakeInnerClassOfRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateControlsEnabled();
            myInnerClassChooser.requestFocus();
          }
        });

    for (PsiElement element : elementsToMove) {
      if (element.getContainingFile() != null) {
        myOpenInEditorPanel.add(initOpenInEditorCb(), BorderLayout.EAST);
        break;
      }
    }
  }
コード例 #3
0
 @Override
 protected void canRun() throws ConfigurationException {
   if (isMoveToPackage()) {
     String name = getTargetPackage().trim();
     if (name.length() != 0
         && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(name)) {
       throw new ConfigurationException("\'" + name + "\' is invalid destination package name");
     }
   } else {
     if (findTargetClass() == null)
       throw new ConfigurationException("Destination class not found");
     final String validationError = verifyInnerClassDestination();
     if (validationError != null) throw new ConfigurationException(validationError);
   }
 }
コード例 #4
0
  private void createUIComponents() {
    myMainPanel = new JPanel();

    myWithBrowseButtonReference = createPackageChooser();
    myClassPackageChooser = createPackageChooser();

    myInnerClassChooser =
        new ClassNameReferenceEditor(
            PsiManager.getInstance(myProject), null, ProjectScope.getProjectScope(myProject));
    myInnerClassChooser.addDocumentListener(
        new DocumentAdapter() {
          public void documentChanged(DocumentEvent e) {
            validateButtons();
          }
        });

    // override CardLayout sizing behavior
    myCardPanel =
        new JPanel() {
          public Dimension getMinimumSize() {
            return myHavePackages
                ? myMovePackagePanel.getMinimumSize()
                : myMoveClassPanel.getMinimumSize();
          }

          public Dimension getPreferredSize() {
            return myHavePackages
                ? myMovePackagePanel.getPreferredSize()
                : myMoveClassPanel.getPreferredSize();
          }
        };

    myDestinationFolderCB =
        new DestinationFolderComboBox() {
          @Override
          public String getTargetPackage() {
            return MoveClassesOrPackagesDialog.this.getTargetPackage();
          }
        };
  }
コード例 #5
0
 @Nullable
 private PsiClass findTargetClass() {
   String name = myInnerClassChooser.getText().trim();
   return JavaPsiFacade.getInstance(myManager.getProject())
       .findClass(name, ProjectScope.getProjectScope(myProject));
 }