Java 类com.intellij.ui.RecentsManager 实例源码

项目:intellij-ce-playground    文件:MoveClassesOrPackagesDialog.java   
@Nullable
private MoveDestination selectDestination() {
  final String packageName = getTargetPackage().trim();
  if (packageName.length() > 0 && !PsiNameHelper.getInstance(myManager.getProject()).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 != Messages.YES) return null;
  }

  return ((DestinationFolderComboBox)myDestinationFolderCB).selectDirectory(targetPackage, mySuggestToMoveToAnotherRoot);
}
项目:tools-idea    文件:MoveClassesOrPackagesDialog.java   
@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, mySuggestToMoveToAnotherRoot);
}
项目:idea-coremedia-plugin    文件:CreateBeansDialog.java   
@Override
protected void doOKAction()
{
    try
    {
        RecentsManager.getInstance(project).registerRecentEntry(RECENTS_KEY, targetPackageField.getText());

        // TODO: Diese Dinge eventuell in die Action schieben
        targetDirectory = selectTargetDirectory();
        if (targetDirectory == null)
        {
            return;
        }

        BeanGenerator.checkIfBeanGenerationIsPossible(targetDirectory, doctype);

        super.doOKAction();
    }
    catch (IncorrectOperationException e)
    {
        Messages.showMessageDialog(project, e.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
}
项目:consulo-java    文件:CreateTestDialog.java   
protected void doOKAction() {
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myTargetPackageField.getText());
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_SUPERS_KEY, mySuperClassField.getText());

  String errorMessage;
  try {
    myTargetDirectory = selectTargetDirectory();
    if (myTargetDirectory == null) return;
    errorMessage = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
  }
  catch (IncorrectOperationException e) {
    errorMessage = e.getMessage();
  }

  if (errorMessage != null) {
    Messages.showMessageDialog(myProject, errorMessage, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  }

  saveDefaultLibraryName();
  saveShowInheritedMembersStatus();
  super.doOKAction();
}
项目:consulo-java    文件:MoveClassesOrPackagesDialog.java   
@Nullable
private MoveDestination selectDestination() {
  final String packageName = getTargetPackage().trim();
  if (packageName.length() > 0 && !PsiNameHelper.getInstance(myManager.getProject()).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, mySuggestToMoveToAnotherRoot);
}
项目:intellij-ce-playground    文件:CreateClassDialog.java   
@Override
protected void doOKAction() {
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myPackageComponent.getText());
  final String packageName = getPackageName();

  final String[] errorString = new String[1];
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
        final MoveDestination destination = myDestinationCB.selectDirectory(targetPackage, false);
        if (destination == null) return;
        myTargetDirectory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
          @Override
          public PsiDirectory compute() {
            return destination.getTargetDirectory(getBaseDir(packageName));
          }
        });
        if (myTargetDirectory == null) {
          errorString[0] = ""; // message already reported by PackageUtil
          return;
        }
        errorString[0] = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
  }, CodeInsightBundle.message("create.directory.command"), null);

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
    return;
  }
  super.doOKAction();
}
项目:intellij-ce-playground    文件:CopyClassDialog.java   
protected void doOKAction(){
  final String packageName = myTfPackage.getText();
  final String className = getClassName();

  final String[] errorString = new String[1];
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiNameHelper nameHelper = PsiNameHelper.getInstance(manager.getProject());
  if (packageName.length() > 0 && !nameHelper.isQualifiedName(packageName)) {
    errorString[0] = RefactoringBundle.message("invalid.target.package.name.specified");
  } else if (className != null && className.isEmpty()) {
    errorString[0] = RefactoringBundle.message("no.class.name.specified");
  } else {
    if (!nameHelper.isIdentifier(className)) {
      errorString[0] = RefactoringMessageUtil.getIncorrectIdentifierMessage(className);
    }
    else if (!myDoClone) {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(manager, packageName);
        myDestination = myDestinationCB.selectDirectory(targetPackage, false);
        if (myDestination == null) return;
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
  }

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], RefactoringBundle.message("error.title"), Messages.getErrorIcon());
    }
    myNameField.requestFocusInWindow();
    return;
  }
  CopyFilesOrDirectoriesDialog.saveOpenInEditorState(myOpenInEditorCb.isSelected());
  super.doOKAction();
}
项目:intellij-ce-playground    文件:AddAndroidActivityPath.java   
public static void saveRecentValues(@NotNull Project project, @NotNull Map<String, Object> state) {
  for (String id : Iterables.concat(PACKAGE_NAME_PARAMETERS, CLASS_NAME_PARAMETERS)) {
    String value = (String)state.get(id);
    if (!StringUtil.isEmpty(value)) {
      RecentsManager.getInstance(project).registerRecentEntry(getRecentHistoryKey(id), value);
    }
  }
}
项目:intellij-ce-playground    文件:GrIntroduceConstantDialog.java   
@Override
protected void doOKAction() {
  final String targetClassName = getTargetClassName();

  if (myDefaultTargetClass == null || !targetClassName.isEmpty() && !Comparing.strEqual(targetClassName, myDefaultTargetClass.getQualifiedName())) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(myContext.getPlace());
    JavaPsiFacade facade = JavaPsiFacade.getInstance(myContext.getProject());
    PsiClass newClass = facade.findClass(targetClassName, GlobalSearchScope.projectScope(myContext.getProject()));

    if (newClass == null &&
        Messages.showOkCancelDialog(myContext.getProject(), GroovyRefactoringBundle.message("class.does.not.exist.in.the.module"),
                                    IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != Messages.OK) {
      return;
    }
    myTargetClassInfo = new TargetClassInfo(targetClassName, myContext.getPlace().getContainingFile().getContainingDirectory(), module, myContext.getProject());
  }
  else {
    myTargetClassInfo = new TargetClassInfo(myDefaultTargetClass);
  }


  JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getVisibilityModifier();

  RecentsManager.getInstance(myContext.getProject()).registerRecentEntry(RECENTS_KEY, targetClassName);

  super.doOKAction();
}
项目:tools-idea    文件:CreateClassDialog.java   
@Override
protected void doOKAction() {
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myPackageComponent.getText());
  final String packageName = getPackageName();

  final String[] errorString = new String[1];
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
        final MoveDestination destination = myDestinationCB.selectDirectory(targetPackage, false);
        if (destination == null) return;
        myTargetDirectory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
          @Override
          public PsiDirectory compute() {
            return destination.getTargetDirectory(getBaseDir(packageName));
          }
        });
        if (myTargetDirectory == null) {
          errorString[0] = ""; // message already reported by PackageUtil
          return;
        }
        errorString[0] = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
  }, CodeInsightBundle.message("create.directory.command"), null);

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
    return;
  }
  super.doOKAction();
}
项目:tools-idea    文件:CopyClassDialog.java   
protected void doOKAction(){
  final String packageName = myTfPackage.getText();
  final String className = getClassName();

  final String[] errorString = new String[1];
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(manager.getProject()).getNameHelper();
  if (packageName.length() > 0 && !nameHelper.isQualifiedName(packageName)) {
    errorString[0] = RefactoringBundle.message("invalid.target.package.name.specified");
  } else if (className != null && className.isEmpty()) {
    errorString[0] = RefactoringBundle.message("no.class.name.specified");
  } else {
    if (!nameHelper.isIdentifier(className)) {
      errorString[0] = RefactoringMessageUtil.getIncorrectIdentifierMessage(className);
    }
    else if (!myDoClone) {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(manager, packageName);
        myDestination = myDestinationCB.selectDirectory(targetPackage, false);
        if (myDestination == null) return;
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
  }

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], RefactoringBundle.message("error.title"), Messages.getErrorIcon());
    }
    myNameField.requestFocusInWindow();
    return;
  }
  CopyFilesOrDirectoriesDialog.saveOpenInEditorState(myOpenInEditorCb.isSelected());
  super.doOKAction();
}
项目:tools-idea    文件:MoveFilesOrDirectoriesDialog.java   
@Override
protected JComponent createNorthPanel() {
  myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);

  myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
  final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
  if (recentEntries != null) {
    myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
  }
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                 RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                 myProject,
                                                 descriptor,
                                                 TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
  final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
  FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateOKButton();
    }
  });
  myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH);
  Disposer.register(getDisposable(), myTargetDirectoryField);

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));

  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE);

  return FormBuilder.createFormBuilder().addComponent(myNameLabel)
    .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP)
    .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText))
    .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP).getPanel();
}
项目:tools-idea    文件:MoveFilesOrDirectoriesDialog.java   
@Override
protected void doOKAction() {
  //myTargetDirectoryField.getChildComponent().addCurrentTextToHistory();
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, myTargetDirectoryField.getChildComponent().getText());
  RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE = myCbSearchForReferences.isSelected();
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          String directoryName = myTargetDirectoryField.getChildComponent().getText().replace(File.separatorChar, '/');
          try {
            myTargetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(myProject), directoryName);
          }
          catch (IncorrectOperationException e) {
            // ignore
          }
        }
      };

      ApplicationManager.getApplication().runWriteAction(action);
      if (myTargetDirectory == null) {
        CommonRefactoringUtil.showErrorMessage(getTitle(),
                                               RefactoringBundle.message("cannot.create.directory"), myHelpID, myProject);
        return;
      }
      myCallback.run(MoveFilesOrDirectoriesDialog.this);
    }
  }, RefactoringBundle.message("move.title"), null);
}
项目:tools-idea    文件:GrIntroduceConstantDialog.java   
@Override
protected void doOKAction() {
  final String targetClassName = getTargetClassName();

  if (myDefaultTargetClass == null || !targetClassName.isEmpty() && !Comparing.strEqual(targetClassName, myDefaultTargetClass.getQualifiedName())) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(myContext.getPlace());
    JavaPsiFacade facade = JavaPsiFacade.getInstance(myContext.getProject());
    PsiClass newClass = facade.findClass(targetClassName, GlobalSearchScope.projectScope(myContext.getProject()));

    if (newClass == null &&
        Messages.showOkCancelDialog(myContext.getProject(), GroovyRefactoringBundle.message("class.does.not.exist.in.the.module"),
                                    IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != OK_EXIT_CODE) {
      return;
    }
    myTargetClassInfo = new TargetClassInfo(targetClassName, myContext.getPlace().getContainingFile().getContainingDirectory(), module, myContext.getProject());
  }
  else {
    myTargetClassInfo = new TargetClassInfo(myDefaultTargetClass);
  }


  JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getVisibilityModifier();

  RecentsManager.getInstance(myContext.getProject()).registerRecentEntry(RECENTS_KEY, targetClassName);

  super.doOKAction();
}
项目:consulo    文件:MoveFilesOrDirectoriesDialog.java   
@Override
protected void doOKAction() {
  PropertiesComponent.getInstance().setValue(MOVE_FILES_OPEN_IN_EDITOR, myOpenInEditorCb.isSelected(), false);
  //myTargetDirectoryField.getChildComponent().addCurrentTextToHistory();
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, myTargetDirectoryField.getChildComponent().getText());
  RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE = myCbSearchForReferences.isSelected();

  if (DumbService.isDumb(myProject)) {
    Messages.showMessageDialog(myProject, "Move refactoring is not available while indexing is in progress", "Indexing", null);
    return;
  }

  CommandProcessor.getInstance().executeCommand(myProject, () -> {
    final Runnable action = () -> {
      String directoryName = myTargetDirectoryField.getChildComponent().getText().replace(File.separatorChar, '/');
      try {
        myTargetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(myProject), directoryName);
      }
      catch (IncorrectOperationException e) {
        // ignore
      }
    };

    ApplicationManager.getApplication().runWriteAction(action);
    if (myTargetDirectory == null) {
      CommonRefactoringUtil.showErrorMessage(getTitle(),
                                             RefactoringBundle.message("cannot.create.directory"), myHelpID, myProject);
      return;
    }
    myCallback.run(this);
  }, RefactoringBundle.message("move.title"), null);
}
项目:consulo-java    文件:CreateClassDialog.java   
@Override
protected void doOKAction() {
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myPackageComponent.getText());
  final String packageName = getPackageName();

  final String[] errorString = new String[1];
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
        final MoveDestination destination = myDestinationCB.selectDirectory(targetPackage, false);
        if (destination == null) return;
        myTargetDirectory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
          @Override
          public PsiDirectory compute() {
            return destination.getTargetDirectory(getBaseDir(packageName));
          }
        });
        if (myTargetDirectory == null) {
          errorString[0] = ""; // message already reported by PackageUtil
          return;
        }
        errorString[0] = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
  }, CodeInsightBundle.message("create.directory.command"), null);

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
    return;
  }
  super.doOKAction();
}
项目:consulo-java    文件:CopyClassDialog.java   
protected void doOKAction(){
  final String packageName = myTfPackage.getText();
  final String className = getClassName();

  final String[] errorString = new String[1];
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiNameHelper nameHelper = PsiNameHelper.getInstance(manager.getProject());
  if (packageName.length() > 0 && !nameHelper.isQualifiedName(packageName)) {
    errorString[0] = RefactoringBundle.message("invalid.target.package.name.specified");
  } else if (className != null && className.isEmpty()) {
    errorString[0] = RefactoringBundle.message("no.class.name.specified");
  } else {
    if (!nameHelper.isIdentifier(className)) {
      errorString[0] = RefactoringMessageUtil.getIncorrectIdentifierMessage(className);
    }
    else if (!myDoClone) {
      try {
        final PackageWrapper targetPackage = new PackageWrapper(manager, packageName);
        myDestination = myDestinationCB.selectDirectory(targetPackage, false);
        if (myDestination == null) return;
      }
      catch (IncorrectOperationException e) {
        errorString[0] = e.getMessage();
      }
    }
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
  }

  if (errorString[0] != null) {
    if (errorString[0].length() > 0) {
      Messages.showMessageDialog(myProject, errorString[0], RefactoringBundle.message("error.title"), Messages.getErrorIcon());
    }
    myNameField.requestFocusInWindow();
    return;
  }
  super.doOKAction();
}
项目:intellij-ce-playground    文件:MoveMembersDialog.java   
@Nullable
private String validateInputData() {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final String fqName = getTargetClassName();
  if (fqName != null && fqName.isEmpty()) {
    return RefactoringBundle.message("no.destination.class.specified");
  }
  else {
    if (!PsiNameHelper.getInstance(manager.getProject()).isQualifiedName(fqName)) {
      return RefactoringBundle.message("0.is.not.a.legal.fq.name", fqName);
    }
    else {
      RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, fqName);
      final PsiClass[] targetClass = new PsiClass[]{null};
      CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
          try {
            targetClass[0] = findOrCreateTargetClass(manager, fqName);
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(
              MoveMembersImpl.REFACTORING_NAME,
              e.getMessage(),
              HelpID.MOVE_MEMBERS,
              myProject);
          }
        }

      }, RefactoringBundle.message("create.class.command", fqName), null);

      if (targetClass[0] == null) {
        return "";
      }

      if (mySourceClass.equals(targetClass[0])) {
        return RefactoringBundle.message("source.and.destination.classes.should.be.different");
      } else if (!mySourceClass.getLanguage().equals(targetClass[0].getLanguage())) {
        return RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(mySourceClass), mySourceClass.getQualifiedName(), targetClass[0].getQualifiedName());
      }
      else {
        for (MemberInfo info : myMemberInfos) {
          if (!info.isChecked()) continue;
          if (PsiTreeUtil.isAncestor(info.getMember(), targetClass[0], false)) {
            return RefactoringBundle.message("cannot.move.inner.class.0.into.itself", info.getDisplayName());
          }
        }

        if (!targetClass[0].isWritable()) {
          CommonRefactoringUtil.checkReadOnlyStatus(myProject, targetClass[0]);
          return "";
        }

        return null;
      }
    }
  }
}
项目:intellij-ce-playground    文件:IntroduceConstantDialog.java   
protected void doOKAction() {
  final String targetClassName = getTargetClassName();
  PsiClass newClass = myParentClass;

  if (!"".equals (targetClassName) && !Comparing.strEqual(targetClassName, myParentClass.getQualifiedName())) {
    newClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassName, GlobalSearchScope.projectScope(myProject));
    if (newClass == null) {
      if (Messages.showOkCancelDialog(myProject, RefactoringBundle.message("class.does.not.exist.in.the.project"), IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != Messages.OK) {
        return;
      }
      myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(targetClassName, myParentClass);
    } else {
      myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(newClass);
    }
  }

  String fieldName = getEnteredName();
  String errorString = null;
  if ("".equals(fieldName)) {
    errorString = RefactoringBundle.message("no.field.name.specified");
  } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
    errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
  } else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) {
    errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass),
                                            myParentClass.getQualifiedName(), newClass.getQualifiedName());
  }
  if (errorString != null) {
    CommonRefactoringUtil.showErrorMessage(
            IntroduceFieldHandler.REFACTORING_NAME,
            errorString,
            HelpID.INTRODUCE_FIELD,
            myProject);
    return;
  }
  if (newClass != null) {
    PsiField oldField = newClass.findFieldByName(fieldName, true);

    if (oldField != null) {
      int answer = Messages.showYesNoDialog(
              myProject,
              RefactoringBundle.message("field.exists", fieldName, oldField.getContainingClass().getQualifiedName()),
              IntroduceFieldHandler.REFACTORING_NAME,
              Messages.getWarningIcon()
      );
      if (answer != Messages.YES) {
        return;
      }
    }
  }

  JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getFieldVisibility();

  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, targetClassName);
  super.doOKAction();
}
项目:intellij-ce-playground    文件:MoveFilesOrDirectoriesDialog.java   
@Override
protected JComponent createNorthPanel() {
  myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);

  myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
  final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
  if (recentEntries != null) {
    myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
  }
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                 RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                 myProject,
                                                 descriptor,
                                                 TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
  final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
  FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateOKButton();
    }
  });
  myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH);
  Disposer.register(getDisposable(), myTargetDirectoryField);

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));

  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE);

  myOpenInEditorCb = new NonFocusableCheckBox("Open moved files in editor");
  myOpenInEditorCb.setSelected(isOpenInEditor());

  return FormBuilder.createFormBuilder().addComponent(myNameLabel)
    .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP)
    .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText))
    .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP)
    .addComponentToRightColumn(myOpenInEditorCb, UIUtil.LARGE_VGAP)
    .getPanel();
}
项目:intellij-ce-playground    文件:MoveFilesOrDirectoriesDialog.java   
@Override
protected void doOKAction() {
  PropertiesComponent.getInstance().setValue(MOVE_FILES_OPEN_IN_EDITOR, myOpenInEditorCb.isSelected(), true);
  //myTargetDirectoryField.getChildComponent().addCurrentTextToHistory();
  RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, myTargetDirectoryField.getChildComponent().getText());
  RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE = myCbSearchForReferences.isSelected();

  if (DumbService.isDumb(myProject)) {
    Messages.showMessageDialog(myProject, "Move refactoring is not available while indexing is in progress", "Indexing", null);
    return;
  }

  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          String directoryName = myTargetDirectoryField.getChildComponent().getText().replace(File.separatorChar, '/');
          try {
            myTargetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(myProject), directoryName);
          }
          catch (IncorrectOperationException e) {
            // ignore
          }
        }
      };

      DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_MODAL, new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().runWriteAction(action);
          if (myTargetDirectory == null) {
            CommonRefactoringUtil.showErrorMessage(getTitle(),
                                                   RefactoringBundle.message("cannot.create.directory"), myHelpID, myProject);
            return;
          }
          myCallback.run(MoveFilesOrDirectoriesDialog.this);
        }
      });
    }
  }, RefactoringBundle.message("move.title"), null);
}
项目:intellij-ce-playground    文件:CopyFilesOrDirectoriesDialog.java   
@Override
protected JComponent createNorthPanel() {
  myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
  final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(
    UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    public void textChanged(DocumentEvent event) {
      validateOKButton();
    }
  };

  if (myShowNewNameField) {
    myNewNameField = new JBTextField();
    myNewNameField.getDocument().addDocumentListener(documentListener);
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
  }

  if (myShowDirectoryField) {
    myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
    myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
    final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
    if (recentEntries != null) {
      myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
    }
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                   RefactoringBundle.message("the.file.will.be.copied.to.this.directory"),
                                                   myProject, descriptor,
                                                   TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
    myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        validateOKButton();
      }
    });
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);

    String shortcutText =
      KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
    formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
  }

  final JPanel wrapper = new JPanel(new BorderLayout());
  wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
  formBuilder.addComponent(wrapper);
  return formBuilder.getPanel();
}
项目:intellij-ce-playground    文件:CopyFilesOrDirectoriesDialog.java   
@Override
protected void doOKAction() {
  if (myShowNewNameField) {
    String newName = getNewName();

    if (newName.length() == 0) {
      Messages.showErrorDialog(myProject, RefactoringBundle.message("no.new.name.specified"), RefactoringBundle.message("error.title"));
      return;
    }

    if (myFileCopy && !PathUtil.isValidFileName(newName)) {
      Messages.showErrorDialog(myNewNameField, "Name is not a valid file name");
      return;
    }
  }

  saveOpenInEditorState(myOpenFilesInEditor.isSelected());
  if (myShowDirectoryField) {
    final String targetDirectoryName = myTargetDirectoryField.getChildComponent().getText();

    if (targetDirectoryName.length() == 0) {
      Messages.showErrorDialog(myProject, RefactoringBundle.message("no.target.directory.specified"),
                               RefactoringBundle.message("error.title"));
      return;
    }

    RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, targetDirectoryName);

    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            try {
              myTargetDirectory =
                DirectoryUtil.mkdirs(PsiManager.getInstance(myProject), targetDirectoryName.replace(File.separatorChar, '/'));
            }
            catch (IncorrectOperationException ignored) { }
          }
        });
      }
    }, RefactoringBundle.message("create.directory"), null);

    if (myTargetDirectory == null) {
      Messages.showErrorDialog(myProject, RefactoringBundle.message("cannot.create.directory"), RefactoringBundle.message("error.title"));
      return;
    }
  }

  super.doOKAction();
}
项目:intellij-ce-playground    文件:AddAndroidActivityPath.java   
public static List<String> getParameterValueHistory(@NotNull Parameter parameter, Project project) {
  List<String> entries = RecentsManager.getInstance(project).getRecentEntries(getRecentHistoryKey(parameter.id));
  return entries == null ? ImmutableList.<String>of() : entries;
}
项目:tools-idea    文件:MoveMembersDialog.java   
@Nullable
private String validateInputData() {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final String fqName = getTargetClassName();
  if (fqName != null && fqName.isEmpty()) {
    return RefactoringBundle.message("no.destination.class.specified");
  }
  else {
    if (!JavaPsiFacade.getInstance(manager.getProject()).getNameHelper().isQualifiedName(fqName)) {
      return RefactoringBundle.message("0.is.not.a.legal.fq.name", fqName);
    }
    else {
      RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, fqName);
      final PsiClass[] targetClass = new PsiClass[]{null};
      CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
          try {
            targetClass[0] = findOrCreateTargetClass(manager, fqName);
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(
              MoveMembersImpl.REFACTORING_NAME,
              e.getMessage(),
              HelpID.MOVE_MEMBERS,
              myProject);
          }
        }

      }, RefactoringBundle.message("create.class.command", fqName), null);

      if (targetClass[0] == null) {
        return "";
      }

      if (mySourceClass.equals(targetClass[0])) {
        return RefactoringBundle.message("source.and.destination.classes.should.be.different");
      } else if (!mySourceClass.getLanguage().equals(targetClass[0].getLanguage())) {
        return RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(mySourceClass), mySourceClass.getQualifiedName(), targetClass[0].getQualifiedName());
      }
      else {
        for (MemberInfo info : myMemberInfos) {
          if (!info.isChecked()) continue;
          if (PsiTreeUtil.isAncestor(info.getMember(), targetClass[0], false)) {
            return RefactoringBundle.message("cannot.move.inner.class.0.into.itself", info.getDisplayName());
          }
        }

        if (!targetClass[0].isWritable()) {
          CommonRefactoringUtil.checkReadOnlyStatus(myProject, targetClass[0]);
          return "";
        }

        return null;
      }
    }
  }
}
项目:tools-idea    文件:IntroduceConstantDialog.java   
protected void doOKAction() {
  final String targetClassName = getTargetClassName();
  PsiClass newClass = myParentClass;

  if (!"".equals (targetClassName) && !Comparing.strEqual(targetClassName, myParentClass.getQualifiedName())) {
    newClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassName, GlobalSearchScope.projectScope(myProject));
    if (newClass == null) {
      if (Messages.showOkCancelDialog(myProject, RefactoringBundle.message("class.does.not.exist.in.the.project"), IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != OK_EXIT_CODE) {
        return;
      }
      myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(targetClassName, myParentClass);
    } else {
      myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(newClass);
    }
  }

  String fieldName = getEnteredName();
  String errorString = null;
  if ("".equals(fieldName)) {
    errorString = RefactoringBundle.message("no.field.name.specified");
  } else if (!JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(fieldName)) {
    errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
  } else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) {
    errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass),
                                            myParentClass.getQualifiedName(), newClass.getQualifiedName());
  }
  if (errorString != null) {
    CommonRefactoringUtil.showErrorMessage(
            IntroduceFieldHandler.REFACTORING_NAME,
            errorString,
            HelpID.INTRODUCE_FIELD,
            myProject);
    return;
  }
  if (newClass != null) {
    PsiField oldField = newClass.findFieldByName(fieldName, true);

    if (oldField != null) {
      int answer = Messages.showYesNoDialog(
              myProject,
              RefactoringBundle.message("field.exists", fieldName, oldField.getContainingClass().getQualifiedName()),
              IntroduceFieldHandler.REFACTORING_NAME,
              Messages.getWarningIcon()
      );
      if (answer != 0) {
        return;
      }
    }
  }

  JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getFieldVisibility();

  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, targetClassName);
  super.doOKAction();
}
项目:tools-idea    文件:CopyFilesOrDirectoriesDialog.java   
@Override
protected JComponent createNorthPanel() {
  myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
  final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(
    UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    public void textChanged(DocumentEvent event) {
      validateOKButton();
    }
  };

  if (myShowNewNameField) {
    myNewNameField = new JTextField();
    myNewNameField.getDocument().addDocumentListener(documentListener);
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
  }

  if (myShowDirectoryField) {
    myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
    myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
    final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
    if (recentEntries != null) {
      myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
    }
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                   RefactoringBundle.message("the.file.will.be.copied.to.this.directory"),
                                                   myProject, descriptor,
                                                   TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
    myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        validateOKButton();
      }
    });
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);

    String shortcutText =
      KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
    formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
  }

  final JPanel wrapper = new JPanel(new BorderLayout());
  wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
  formBuilder.addComponent(wrapper);
  return formBuilder.getPanel();
}
项目:tools-idea    文件:CopyFilesOrDirectoriesDialog.java   
@Override
protected void doOKAction() {
  if (myShowNewNameField) {
    String newName = getNewName();

    if (newName.length() == 0) {
      Messages.showMessageDialog(myProject, RefactoringBundle.message("no.new.name.specified"), RefactoringBundle.message("error.title"),
                                 Messages.getErrorIcon());
      return;
    }

    if (myFileCopy && !PathUtil.isValidFileName(newName)) {
      Messages.showErrorDialog(myNewNameField, "Name is not a valid file name");
      return;
    }
  }

  if (myShowDirectoryField) {
    final String targetDirectoryName = myTargetDirectoryField.getChildComponent().getText();

    if (targetDirectoryName.length() == 0) {
      Messages.showMessageDialog(myProject, RefactoringBundle.message("no.target.directory.specified"),
                                 RefactoringBundle.message("error.title"), Messages.getErrorIcon());
      return;
    }

    RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, targetDirectoryName);
    saveOpenInEditorState(myOpenFilesInEditor.isSelected());

    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            try {
              myTargetDirectory =
                DirectoryUtil.mkdirs(PsiManager.getInstance(myProject), targetDirectoryName.replace(File.separatorChar, '/'));
            }
            catch (IncorrectOperationException e) {
            }
          }
        });
      }
    }, RefactoringBundle.message("create.directory"), null);

    if (myTargetDirectory == null) {
      Messages
        .showMessageDialog(myProject, RefactoringBundle.message("cannot.create.directory"), RefactoringBundle.message("error.title"),
                           Messages.getErrorIcon());
      return;
    }
  }

  super.doOKAction();
}
项目:consulo    文件:MoveFilesOrDirectoriesDialog.java   
@Override
protected JComponent createNorthPanel() {
  myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);

  myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
  final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
  if (recentEntries != null) {
    myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
  }
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
  myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                 RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                 myProject,
                                                 descriptor,
                                                 TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
  final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
  FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      validateOKButton();
    }
  });
  myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH);
  Disposer.register(getDisposable(), myTargetDirectoryField);

  String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));

  myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references"));
  myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE);

  myOpenInEditorCb = new NonFocusableCheckBox("Open moved files in editor");
  myOpenInEditorCb.setSelected(isOpenInEditor());

  return FormBuilder.createFormBuilder().addComponent(myNameLabel)
          .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP)
          .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText))
          .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP)
          .addComponentToRightColumn(myOpenInEditorCb, UIUtil.LARGE_VGAP)
          .getPanel();
}
项目:consulo    文件:CopyFilesOrDirectoriesDialog.java   
@Override
protected JComponent createNorthPanel() {
  myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
  final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(
    UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
  DocumentListener documentListener = new DocumentAdapter() {
    @Override
    public void textChanged(DocumentEvent event) {
      validateOKButton();
    }
  };

  if (myShowNewNameField) {
    myNewNameField = new JTextField();
    myNewNameField.getDocument().addDocumentListener(documentListener);
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
  }

  if (myShowDirectoryField) {
    myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
    myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
    final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
    if (recentEntries != null) {
      myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
    }
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                   RefactoringBundle.message("the.file.will.be.copied.to.this.directory"),
                                                   myProject, descriptor,
                                                   TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
    myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        validateOKButton();
      }
    });
    formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);

    String shortcutText =
      KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
    formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
  }

  final JPanel wrapper = new JPanel(new BorderLayout());
  wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
  formBuilder.addComponent(wrapper);
  return formBuilder.getPanel();
}
项目:consulo    文件:CopyFilesOrDirectoriesDialog.java   
@Override
protected void doOKAction() {
  if (myShowNewNameField) {
    String newName = getNewName();

    if (newName.length() == 0) {
      Messages.showErrorDialog(myProject, RefactoringBundle.message("no.new.name.specified"), RefactoringBundle.message("error.title"));
      return;
    }

    if (myFileCopy && !PathUtil.isValidFileName(newName)) {
      Messages.showErrorDialog(myNewNameField, "Name is not a valid file name");
      return;
    }
  }

  saveOpenInEditorState(myOpenFilesInEditor.isSelected());
  if (myShowDirectoryField) {
    final String targetDirectoryName = myTargetDirectoryField.getChildComponent().getText();

    if (targetDirectoryName.length() == 0) {
      Messages.showErrorDialog(myProject, RefactoringBundle.message("no.target.directory.specified"),
                               RefactoringBundle.message("error.title"));
      return;
    }

    RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, targetDirectoryName);

    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            try {
              myTargetDirectory =
                DirectoryUtil.mkdirs(PsiManager.getInstance(myProject), targetDirectoryName.replace(File.separatorChar, '/'));
            }
            catch (IncorrectOperationException ignored) { }
          }
        });
      }
    }, RefactoringBundle.message("create.directory"), null);

    if (myTargetDirectory == null) {
      Messages.showErrorDialog(myProject, RefactoringBundle.message("cannot.create.directory"), RefactoringBundle.message("error.title"));
      return;
    }
  }

  super.doOKAction();
}
项目:consulo-java    文件:MoveMembersDialog.java   
@Nullable
private String validateInputData() {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final String fqName = getTargetClassName();
  if (fqName != null && fqName.isEmpty()) {
    return RefactoringBundle.message("no.destination.class.specified");
  }
  else {
    if (!PsiNameHelper.getInstance(manager.getProject()).isQualifiedName(fqName)) {
      return RefactoringBundle.message("0.is.not.a.legal.fq.name", fqName);
    }
    else {
      RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, fqName);
      final PsiClass[] targetClass = new PsiClass[]{null};
      CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
          try {
            targetClass[0] = findOrCreateTargetClass(manager, fqName);
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(
              MoveMembersImpl.REFACTORING_NAME,
              e.getMessage(),
              HelpID.MOVE_MEMBERS,
              myProject);
          }
        }

      }, RefactoringBundle.message("create.class.command", fqName), null);

      if (targetClass[0] == null) {
        return "";
      }

      if (mySourceClass.equals(targetClass[0])) {
        return RefactoringBundle.message("source.and.destination.classes.should.be.different");
      } else if (!mySourceClass.getLanguage().equals(targetClass[0].getLanguage())) {
        return RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(mySourceClass), mySourceClass.getQualifiedName(), targetClass[0].getQualifiedName());
      }
      else {
        for (MemberInfo info : myMemberInfos) {
          if (!info.isChecked()) continue;
          if (PsiTreeUtil.isAncestor(info.getMember(), targetClass[0], false)) {
            return RefactoringBundle.message("cannot.move.inner.class.0.into.itself", info.getDisplayName());
          }
        }

        if (!targetClass[0].isWritable()) {
          CommonRefactoringUtil.checkReadOnlyStatus(myProject, targetClass[0]);
          return "";
        }

        return null;
      }
    }
  }
}
项目:consulo-java    文件:IntroduceConstantDialog.java   
protected void doOKAction() {
  final String targetClassName = getTargetClassName();
  PsiClass newClass = myParentClass;

  if (!"".equals (targetClassName) && !Comparing.strEqual(targetClassName, myParentClass.getQualifiedName())) {
    newClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassName, GlobalSearchScope.projectScope(myProject));
    if (newClass == null) {
      if (Messages.showOkCancelDialog(myProject, RefactoringBundle.message("class.does.not.exist.in.the.project"), IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != OK_EXIT_CODE) {
        return;
      }
      myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(targetClassName, myParentClass);
    } else {
      myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(newClass);
    }
  }

  String fieldName = getEnteredName();
  String errorString = null;
  if ("".equals(fieldName)) {
    errorString = RefactoringBundle.message("no.field.name.specified");
  } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
    errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
  } else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) {
    errorString = RefactoringBundle.message("move.to.different.language", UsageViewUtil.getType(myParentClass),
                                            myParentClass.getQualifiedName(), newClass.getQualifiedName());
  }
  if (errorString != null) {
    CommonRefactoringUtil.showErrorMessage(
            IntroduceFieldHandler.REFACTORING_NAME,
            errorString,
            HelpID.INTRODUCE_FIELD,
            myProject);
    return;
  }
  if (newClass != null) {
    PsiField oldField = newClass.findFieldByName(fieldName, true);

    if (oldField != null) {
      int answer = Messages.showYesNoDialog(
              myProject,
              RefactoringBundle.message("field.exists", fieldName, oldField.getContainingClass().getQualifiedName()),
              IntroduceFieldHandler.REFACTORING_NAME,
              Messages.getWarningIcon()
      );
      if (answer != 0) {
        return;
      }
    }
  }

  JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getFieldVisibility();

  RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, targetClassName);
  super.doOKAction();
}