List of usage examples for com.intellij.openapi.ui Messages showMessageDialog
public static void showMessageDialog(@NotNull Component parent, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon)
From source file:com.intellij.ide.util.DeleteHandler.java
License:Apache License
private static boolean clearReadOnlyFlag(final VirtualFile virtualFile, final Project project) { final boolean[] success = new boolean[1]; CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override/*from w w w. j av a 2 s.com*/ public void run() { Runnable action = new Runnable() { @Override public void run() { try { ReadOnlyAttributeUtil.setReadOnlyAttribute(virtualFile, false); success[0] = true; } catch (IOException e1) { Messages.showMessageDialog(project, e1.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } } }; ApplicationManager.getApplication().runWriteAction(action); } }, "", null); return success[0]; }
From source file:com.intellij.ide.util.ExportToFileUtil.java
License:Apache License
public static void exportTextToFile(Project project, String fileName, String textToExport) { String prepend = ""; File file = new File(fileName); if (file.exists()) { int result = Messages.showYesNoCancelDialog(project, IdeBundle.message("error.text.file.already.exists", fileName), IdeBundle.message("title.warning"), IdeBundle.message("action.overwrite"), IdeBundle.message("action.append"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon()); if (result != 1 && result != 0) { return; }//from ww w.j a v a2 s . c om if (result == 1) { char[] buf = new char[(int) file.length()]; try { FileReader reader = new FileReader(fileName); try { reader.read(buf, 0, (int) file.length()); prepend = new String(buf) + SystemProperties.getLineSeparator(); } finally { reader.close(); } } catch (IOException e) { } } } try { FileWriter writer = new FileWriter(fileName); try { writer.write(prepend + textToExport); } finally { writer.close(); } } catch (IOException e) { Messages.showMessageDialog(project, IdeBundle.message("error.writing.to.file", fileName), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } }
From source file:com.intellij.ide.util.PackageChooserDialog.java
License:Apache License
private void createNewPackage() { final PsiJavaPackage selectedPackage = getTreeSelection(); if (selectedPackage == null) return;//from w w w .j a v a2 s. c om final String newPackageName = Messages.showInputDialog(myProject, IdeBundle.message("prompt.enter.a.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", new InputValidator() { public boolean checkInput(final String inputString) { return inputString != null && inputString.length() > 0; } public boolean canClose(final String inputString) { return checkInput(inputString); } }); if (newPackageName == null) return; CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { final Runnable action = new Runnable() { public void run() { try { String newQualifiedName = selectedPackage.getQualifiedName(); if (!Comparing.strEqual(newQualifiedName, "")) newQualifiedName += "."; newQualifiedName += newPackageName; final PsiDirectory dir = PackageUtil.findOrCreateDirectoryForPackage(myProject, newQualifiedName, null, false); if (dir == null) return; final PsiJavaPackage newPackage = JavaDirectoryService.getInstance().getPackage(dir); DefaultMutableTreeNode node = (DefaultMutableTreeNode) myTree.getSelectionPath() .getLastPathComponent(); final DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(); newChild.setUserObject(newPackage); node.add(newChild); final DefaultTreeModel model = (DefaultTreeModel) myTree.getModel(); model.nodeStructureChanged(node); final TreePath selectionPath = myTree.getSelectionPath(); TreePath path; if (selectionPath == null) { path = new TreePath(newChild.getPath()); } else { path = selectionPath.pathByAddingChild(newChild); } myTree.setSelectionPath(path); myTree.scrollPathToVisible(path); myTree.expandPath(path); } catch (IncorrectOperationException e) { Messages.showMessageDialog(getContentPane(), StringUtil.getMessage(e), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); if (LOG.isDebugEnabled()) { LOG.debug(e); } } } }; ApplicationManager.getApplication().runReadAction(action); } }, IdeBundle.message("command.create.new.package"), null); }
From source file:com.intellij.internal.psiView.PsiViewerDialog.java
License:Apache License
private PsiElement parseText(String text) { final Object source = getSource(); try {//from w w w.j a v a 2s . c o m if (source instanceof PsiViewerExtension) { return ((PsiViewerExtension) source).createElement(myProject, text); } if (source instanceof FileType) { final FileType type = (FileType) source; String ext = type.getDefaultExtension(); if (myExtensionComboBox.isVisible()) { ext = myExtensionComboBox.getSelectedItem().toString().toLowerCase(); } if (type instanceof LanguageFileType) { final Language language = ((LanguageFileType) type).getLanguage(); final LanguageVersion languageVersion = (LanguageVersion) myDialectComboBox.getSelectedItem(); return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, language, languageVersion, text); } return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, type, text); } } catch (IncorrectOperationException e) { Messages.showMessageDialog(myProject, e.getMessage(), "Error", Messages.getErrorIcon()); } return null; }
From source file:com.intellij.plugins.haxe.ide.hierarchy.HaxeHierarchyTimeoutHandler.java
License:Apache License
/** * Post a modal dialog on screen to alert the user that the search was cancelled and * the results may not be complete./* ww w. j a v a 2s. com*/ * * Warns if the process was not cancelled. */ public void postCanceledDialog(Project project) { if (!canceled) { LOG.warn("Displaying cancel message dialog when the process was not canceled."); } final Project messageProject = project; ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { // TODO: Put this message and title in a resource bundle. String title = "Call Hierarchy Search Timed Out"; String msg = "Search took too long (>" + max_duration_seconds + "seconds). Results may be incomplete."; if (DEBUG) { msg += " Canceled after " + (stopTime - startTime) + " milliseconds."; } Messages.showMessageDialog(messageProject, msg, title, Messages.getWarningIcon()); } }); }
From source file:com.intellij.refactoring.copy.CopyClassDialog.java
License:Apache License
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 {//ww w.j a v a 2 s.co m 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(); }
From source file:com.intellij.refactoring.copy.CopyClassesHandler.java
License:Apache License
private static void copyClassesImpl(final String copyClassName, final Project project, final Map<PsiFile, PsiClass[]> classes, final HashMap<PsiFile, String> map, final Object targetDirectory, final PsiDirectory defaultTargetDirectory, final String commandName, final boolean selectInActivePanel) { final boolean[] result = new boolean[] { false }; Runnable command = new Runnable() { public void run() { final Runnable action = new Runnable() { public void run() { try { PsiDirectory target; if (targetDirectory instanceof PsiDirectory) { target = (PsiDirectory) targetDirectory; } else { target = ((MoveDestination) targetDirectory) .getTargetDirectory(defaultTargetDirectory); }//from w w w.j ava 2 s . c o m PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project); if (newElement != null) { CopyHandler.updateSelectionInActiveProjectView(newElement, project, selectInActivePanel); EditorHelper.openInEditor(newElement); result[0] = true; } } catch (final IncorrectOperationException ex) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon()); } }); } } }; ApplicationManager.getApplication().runWriteAction(action); } }; CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(project, command, commandName, null); if (result[0]) { ToolWindowManager.getInstance(project).invokeLater(new Runnable() { public void run() { ToolWindowManager.getInstance(project).activateEditorComponent(); } }); } }
From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor.java
License:Apache License
public boolean verifyValidPackageName() { String qName = myTargetPackage.getQualifiedName(); if (!StringUtil.isEmpty(qName)) { PsiNameHelper helper = PsiNameHelper.getInstance(myProject); if (!helper.isQualifiedName(qName)) { Messages.showMessageDialog(myProject, RefactoringBundle.message("invalid.target.package.name.specified"), "Invalid Package Name", Messages.getErrorIcon()); return false; }//w w w . j a v a 2s . c o m } return true; }
From source file:com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor.java
License:Apache License
@Override protected void performRefactoring(UsageInfo[] usages) { // If files are being moved then I need to collect some information to delete these // filese from CVS. I need to know all common parents of the moved files and releative // paths./*from w w w .j a va 2 s.c om*/ // Move files with correction of references. try { final List<PsiFile> movedFiles = new ArrayList<PsiFile>(); final Map<PsiElement, PsiElement> oldToNewMap = new HashMap<PsiElement, PsiElement>(); for (final PsiElement element : myElementsToMove) { final RefactoringElementListener elementListener = getTransaction().getElementListener(element); if (element instanceof PsiDirectory) { MoveFilesOrDirectoriesUtil.doMoveDirectory((PsiDirectory) element, myNewParent); for (PsiElement psiElement : element.getChildren()) { processDirectoryFiles(movedFiles, oldToNewMap, psiElement); } } else if (element instanceof PsiFile) { final PsiFile movedFile = (PsiFile) element; FileReferenceContextUtil.encodeFileReferences(element); MoveFileHandler.forElement(movedFile).prepareMovedFile(movedFile, myNewParent, oldToNewMap); PsiFile moving = myNewParent.findFile(movedFile.getName()); if (moving == null) { MoveFilesOrDirectoriesUtil.doMoveFile(movedFile, myNewParent); } moving = myNewParent.findFile(movedFile.getName()); movedFiles.add(moving); } elementListener.elementMoved(element); } // sort by offset descending to process correctly several usages in one PsiElement [IDEADEV-33013] Arrays.sort(usages, new Comparator<UsageInfo>() { @Override public int compare(final UsageInfo o1, final UsageInfo o2) { return o1.getElement() == o2.getElement() ? o2.getRangeInElement().getStartOffset() - o1.getRangeInElement().getStartOffset() : 0; } }); // fix references in moved files to outer files for (PsiFile movedFile : movedFiles) { MoveFileHandler.forElement(movedFile).updateMovedFile(movedFile); FileReferenceContextUtil.decodeFileReferences(movedFile); } retargetUsages(usages, oldToNewMap); // Perform CVS "add", "remove" commands on moved files. if (myMoveCallback != null) { myMoveCallback.refactoringCompleted(); } } catch (IncorrectOperationException e) { @NonNls final String message = e.getMessage(); final int index = message != null ? message.indexOf("java.io.IOException") : -1; if (index >= 0) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showMessageDialog(myProject, message.substring(index + "java.io.IOException".length()), RefactoringBundle.message("error.title"), Messages.getErrorIcon()); } }); } else { LOG.error(e); } } }
From source file:com.intellij.refactoring.util.RefactoringUIUtil.java
License:Apache License
public static void processIncorrectOperation(final Project project, IncorrectOperationException e) { @NonNls/*from www. ja v a 2s. co m*/ String message = e.getMessage(); final int index = message != null ? message.indexOf("java.io.IOException") : -1; if (index > 0) { message = message.substring(index + "java.io.IOException".length()); } final String s = message; ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showMessageDialog(project, s, RefactoringBundle.message("error.title"), Messages.getErrorIcon()); } }); }