List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(@Nullable Component component, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:com.intellij.refactoring.BaseRefactoringProcessor.java
License:Apache License
protected void doRun() { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); final Ref<UsageInfo[]> refUsages = new Ref<UsageInfo[]>(); final Ref<Language> refErrorLanguage = new Ref<Language>(); final Ref<Boolean> refProcessCanceled = new Ref<Boolean>(); final Ref<Boolean> dumbModeOccurred = new Ref<Boolean>(); final Ref<Boolean> anyException = new Ref<Boolean>(); final Runnable findUsagesRunnable = new Runnable() { @Override/*from w w w.ja v a2 s. c o m*/ public void run() { try { refUsages.set(ApplicationManager.getApplication().runReadAction(new Computable<UsageInfo[]>() { @Override public UsageInfo[] compute() { return findUsages(); } })); } catch (UnknownReferenceTypeException e) { refErrorLanguage.set(e.getElementLanguage()); } catch (ProcessCanceledException e) { refProcessCanceled.set(Boolean.TRUE); } catch (IndexNotReadyException e) { dumbModeOccurred.set(Boolean.TRUE); } catch (Throwable e) { anyException.set(Boolean.TRUE); LOG.error(e); } } }; if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(findUsagesRunnable, RefactoringBundle.message("progress.text"), true, myProject)) { return; } if (!refErrorLanguage.isNull()) { Messages.showErrorDialog(myProject, RefactoringBundle.message("unsupported.refs.found", refErrorLanguage.get().getDisplayName()), RefactoringBundle.message("error.title")); return; } if (!dumbModeOccurred.isNull()) { DumbService.getInstance(myProject) .showDumbModeNotification("Usage search is not available until indices are ready"); return; } if (!refProcessCanceled.isNull()) { Messages.showErrorDialog(myProject, "Index corruption detected. Please retry the refactoring - indexes will be rebuilt automatically", RefactoringBundle.message("error.title")); return; } if (!anyException.isNull()) { //do not proceed if find usages fails return; } assert !refUsages.isNull() : "Null usages from processor " + this; if (!preprocessUsages(refUsages)) return; final UsageInfo[] usages = refUsages.get(); assert usages != null; UsageViewDescriptor descriptor = createUsageViewDescriptor(usages); boolean isPreview = isPreviewUsages(usages); if (!isPreview) { isPreview = !ensureElementsWritable(usages, descriptor) || UsageViewUtil.hasReadOnlyUsages(usages); if (isPreview) { StatusBarUtil.setStatusBarInfo(myProject, RefactoringBundle.message("readonly.occurences.found")); } } if (isPreview) { previewRefactoring(usages); } else { execute(usages); } }
From source file:com.intellij.refactoring.copy.CopyFilesOrDirectoriesDialog.java
License:Apache License
@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; }/* w w w . j av a 2 s . c o m*/ 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(); }
From source file:com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler.java
License:Apache License
/** * @param elements/*from w ww.ja v a 2s . c o m*/ * @param newName can be not null only if elements.length == 1 * @param targetDirectory * @param openInEditor */ private static void copyImpl(@NotNull final PsiElement[] elements, @Nullable final String newName, @NotNull final PsiDirectory targetDirectory, final boolean doClone, final boolean openInEditor) { if (doClone && elements.length != 1) { throw new IllegalArgumentException("invalid number of elements to clone:" + elements.length); } if (newName != null && elements.length != 1) { throw new IllegalArgumentException( "no new name should be set; number of elements is: " + elements.length); } final Project project = targetDirectory.getProject(); Runnable command = new Runnable() { @Override public void run() { final Runnable action = new Runnable() { @Override public void run() { try { PsiFile firstFile = null; final int[] choice = elements.length > 1 || elements[0] instanceof PsiDirectory ? new int[] { -1 } : null; for (PsiElement element : elements) { PsiFile f = copyToDirectory((PsiFileSystemItem) element, newName, targetDirectory, choice); if (firstFile == null) { firstFile = f; } } if (firstFile != null) { CopyHandler.updateSelectionInActiveProjectView(firstFile, project, doClone); if (!(firstFile instanceof PsiBinaryFile) && openInEditor) { EditorHelper.openInEditor(firstFile); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { ToolWindowManager.getInstance(project).activateEditorComponent(); } }); } } } catch (final IncorrectOperationException ex) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, ex.getMessage(), RefactoringBundle.message("error.title")); } }); } catch (final IOException ex) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, ex.getMessage(), RefactoringBundle.message("error.title")); } }); } } }; ApplicationManager.getApplication().runWriteAction(action); } }; String title = RefactoringBundle .message(doClone ? "copy,handler.clone.files.directories" : "copy.handler.copy.files.directories"); CommandProcessor.getInstance().executeCommand(project, command, title, null); }
From source file:com.intellij.refactoring.lang.ExtractIncludeDialog.java
License:Apache License
@Override protected void doOKAction() { final Project project = myCurrentDirectory.getProject(); final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/'); final String targetFileName = getTargetFileName(); if (isFileExist(directoryName, targetFileName)) { Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title")); return;// w ww . j av a 2 s . c o m } final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName); if (type == null) { return; } CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { final Runnable action = new Runnable() { @Override public void run() { try { PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName); targetDirectory.checkCreateFile(targetFileName); final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory); myTargetDirectory = webPath == null ? null : targetDirectory; } catch (IncorrectOperationException e) { CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project); } } }; ApplicationManager.getApplication().runWriteAction(action); } }, RefactoringBundle.message("create.directory"), null); if (myTargetDirectory == null) return; super.doOKAction(); }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.JavaMoveClassesOrPackagesHandler.java
License:Apache License
private static void moveAsDirectory(Project project, PsiElement targetContainer, final MoveCallback callback, final PsiDirectory[] directories) { if (targetContainer instanceof PsiDirectory) { final JavaRefactoringSettings refactoringSettings = JavaRefactoringSettings.getInstance(); final MoveDirectoryWithClassesProcessor processor = new MoveDirectoryWithClassesProcessor(project, directories, (PsiDirectory) targetContainer, refactoringSettings.RENAME_SEARCH_IN_COMMENTS_FOR_PACKAGE, refactoringSettings.RENAME_SEARCH_IN_COMMENTS_FOR_PACKAGE, true, callback); processor.setPrepareSuccessfulSwingThreadCallback(new Runnable() { @Override// w w w. jav a 2 s . co m public void run() { } }); processor.run(); } else { final boolean containsJava = hasJavaFiles(directories[0]); if (!containsJava) { MoveFilesOrDirectoriesUtil.doMove(project, new PsiElement[] { directories[0] }, new PsiElement[] { targetContainer }, callback); return; } final MoveClassesOrPackagesToNewDirectoryDialog dlg = new MoveClassesOrPackagesToNewDirectoryDialog( directories[0], new PsiElement[0], false, callback) { @Override protected void performRefactoring(Project project, final PsiDirectory targetDirectory, PsiJavaPackage aPackage, boolean searchInComments, boolean searchForTextOccurences) { try { for (PsiDirectory dir : directories) { MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(dir, targetDirectory); } } catch (IncorrectOperationException e) { Messages.showErrorDialog(project, e.getMessage(), RefactoringBundle.message("cannot.move")); return; } final MoveDirectoryWithClassesProcessor processor = new MoveDirectoryWithClassesProcessor( project, directories, targetDirectory, searchInComments, searchForTextOccurences, true, callback); processor.setPrepareSuccessfulSwingThreadCallback(new Runnable() { @Override public void run() { } }); processor.run(); } }; dlg.show(); } }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.java
License:Apache License
@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; }// w w w. j a va 2 s .c o m 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); }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesToNewDirectoryDialog.java
License:Apache License
protected void doOKAction() { final String path = FileUtil.toSystemIndependentName(myDestDirectoryField.getText()); final Project project = myDirectory.getProject(); PsiDirectory directory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() { public PsiDirectory compute() { try { return DirectoryUtil.mkdirs(PsiManager.getInstance(project), path); } catch (IncorrectOperationException e) { LOG.error(e);/* ww w . j av a2 s . co m*/ return null; } } }); if (directory == null) { Messages.showErrorDialog(project, RefactoringBundle.message("cannot.find.or.create.destination.directory"), RefactoringBundle.message("cannot.move")); return; } super.doOKAction(); final PsiJavaPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory); if (aPackage == null) { Messages.showErrorDialog(project, RefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"), RefactoringBundle.message("cannot.move")); return; } final JavaRefactoringSettings refactoringSettings = JavaRefactoringSettings.getInstance(); final boolean searchInComments = isSearchInComments(); final boolean searchForTextOccurences = isSearchInNonJavaFiles(); refactoringSettings.MOVE_SEARCH_IN_COMMENTS = searchInComments; refactoringSettings.MOVE_SEARCH_FOR_TEXT = searchForTextOccurences; performRefactoring(project, directory, aPackage, searchInComments, searchForTextOccurences); }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesToNewDirectoryDialog.java
License:Apache License
protected void performRefactoring(Project project, PsiDirectory directory, PsiJavaPackage aPackage, boolean searchInComments, boolean searchForTextOccurences) { final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex() .getSourceRootForFile(directory.getVirtualFile()); if (sourceRoot == null) { Messages.showErrorDialog(project, RefactoringBundle.message("destination.directory.does.not.correspond.to.any.package"), RefactoringBundle.message("cannot.move")); return;//from w ww .j a va 2s. co m } final JavaRefactoringFactory factory = JavaRefactoringFactory.getInstance(project); final MoveDestination destination = myPreserveSourceRoot.isSelected() && myPreserveSourceRoot.isVisible() ? factory.createSourceFolderPreservingMoveDestination(aPackage.getQualifiedName()) : factory.createSourceRootMoveDestination(aPackage.getQualifiedName(), sourceRoot); MoveClassesOrPackagesProcessor processor = new MoveClassesOrPackagesProcessor(myDirectory.getProject(), myElementsToMove, destination, searchInComments, searchForTextOccurences, myMoveCallback); if (processor.verifyValidPackageName()) { processor.setPrepareSuccessfulSwingThreadCallback(new Runnable() { @Override public void run() { } }); processor.run(); } }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor.java
License:Apache License
@Override public void performRefactoring(UsageInfo[] usages) { //try to create all directories beforehand try {// w w w .j a va 2s .c om //top level directories should be created even if they are empty for (PsiDirectory directory : myDirectories) { getResultDirectory(directory).findOrCreateTargetDirectory(); } for (PsiFile psiFile : myFilesToMove.keySet()) { myFilesToMove.get(psiFile).findOrCreateTargetDirectory(); } } catch (IncorrectOperationException e) { Messages.showErrorDialog(myProject, e.getMessage(), CommonBundle.getErrorTitle()); return; } try { final List<PsiFile> movedFiles = new ArrayList<PsiFile>(); final Map<PsiElement, PsiElement> oldToNewElementsMapping = new HashMap<PsiElement, PsiElement>(); for (PsiFile psiFile : myFilesToMove.keySet()) { for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { helper.beforeMove(psiFile); } final RefactoringElementListener listener = getTransaction().getElementListener(psiFile); final PsiDirectory moveDestination = myFilesToMove.get(psiFile).getTargetDirectory(); for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { boolean processed = helper.move(psiFile, moveDestination, oldToNewElementsMapping, movedFiles, listener); if (processed) { break; } } } for (PsiElement newElement : oldToNewElementsMapping.values()) { for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { helper.afterMove(newElement); } } // fix references in moved files to outer files for (PsiFile movedFile : movedFiles) { MoveFileHandler.forElement(movedFile).updateMovedFile(movedFile); FileReferenceContextUtil.decodeFileReferences(movedFile); } myNonCodeUsages = CommonMoveUtil.retargetUsages(usages, oldToNewElementsMapping); for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { helper.postProcessUsages(usages, new Function<PsiDirectory, PsiDirectory>() { @Override public PsiDirectory fun(PsiDirectory dir) { return getResultDirectory(dir).getTargetDirectory(); } }); } for (PsiDirectory directory : myDirectories) { directory.delete(); } } catch (IncorrectOperationException e) { myNonCodeUsages = new NonCodeUsageInfo[0]; RefactoringUIUtil.processIncorrectOperation(myProject, e); } }
From source file:com.intellij.refactoring.move.moveInstanceMethod.MoveInstanceMethodDialog.java
License:Apache License
protected void doAction() { Map<PsiClass, String> parameterNames = new LinkedHashMap<PsiClass, String>(); for (final PsiClass aClass : myThisClassesMap.keySet()) { EditorTextField field = myOldClassParameterNameFields.get(aClass); if (field.isEnabled()) { String parameterName = field.getText().trim(); if (!PsiNameHelper.getInstance(myMethod.getProject()).isIdentifier(parameterName)) { Messages.showErrorDialog(getProject(), RefactoringBundle.message("move.method.enter.a.valid.name.for.parameter"), myRefactoringName); return; }/*from w w w .j a va2 s . c om*/ parameterNames.put(aClass, parameterName); } } final PsiVariable targetVariable = (PsiVariable) myList.getSelectedValue(); if (targetVariable == null) return; final MoveInstanceMethodProcessor processor = new MoveInstanceMethodProcessor(myMethod.getProject(), myMethod, targetVariable, myVisibilityPanel.getVisibility(), parameterNames); if (!verifyTargetClass(processor.getTargetClass())) return; invokeRefactoring(processor); }