Example usage for com.intellij.openapi.ui Messages showMessageDialog

List of usage examples for com.intellij.openapi.ui Messages showMessageDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showMessageDialog.

Prototype

public static void showMessageDialog(@NotNull Component parent, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Usage

From source file:com.intellij.ide.actions.CreateDirectoryOrPackageHandler.java

License:Apache License

private void showErrorDialog(String message) {
    String title = CommonBundle.getErrorTitle();
    Icon icon = Messages.getErrorIcon();
    if (myDialogParent != null) {
        Messages.showMessageDialog(myDialogParent, message, title, icon);
    } else {//from  www .  j  a va  2  s  . c  o m
        Messages.showMessageDialog(myProject, message, title, icon);
    }
}

From source file:com.intellij.ide.actions.ElementCreator.java

License:Apache License

public PsiElement[] tryCreate(@NotNull final String inputString) {
    if (inputString.length() == 0) {
        Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return PsiElement.EMPTY_ARRAY;
    }/*  www .j  ava2 s  .c om*/

    final Exception[] exception = new Exception[1];
    final SmartPsiElementPointer[][] myCreatedElements = { null };

    final String commandName = getActionName(inputString);
    new WriteCommandAction(myProject, commandName) {
        @Override
        protected void run(Result result) throws Throwable {
            LocalHistoryAction action = LocalHistoryAction.NULL;
            try {
                action = LocalHistory.getInstance().startAction(commandName);

                PsiElement[] psiElements = create(inputString);
                myCreatedElements[0] = new SmartPsiElementPointer[psiElements.length];
                SmartPointerManager manager = SmartPointerManager.getInstance(myProject);
                for (int i = 0; i < myCreatedElements[0].length; i++) {
                    myCreatedElements[0][i] = manager.createSmartPsiElementPointer(psiElements[i]);
                }
            } catch (Exception ex) {
                exception[0] = ex;
            } finally {
                action.finish();
            }
        }

        @Override
        protected UndoConfirmationPolicy getUndoConfirmationPolicy() {
            return UndoConfirmationPolicy.REQUEST_CONFIRMATION;
        }
    }.execute();

    if (exception[0] != null) {
        LOG.info(exception[0]);
        String errorMessage = CreateElementActionBase.filterMessage(exception[0].getMessage());
        if (errorMessage == null || errorMessage.length() == 0) {
            errorMessage = exception[0].toString();
        }
        Messages.showMessageDialog(myProject, errorMessage, myErrorTitle, Messages.getErrorIcon());
        return PsiElement.EMPTY_ARRAY;
    }

    List<PsiElement> result = new SmartList<PsiElement>();
    for (final SmartPsiElementPointer pointer : myCreatedElements[0]) {
        ContainerUtil.addIfNotNull(pointer.getElement(), result);
    }
    return PsiUtilBase.toPsiElementArray(result);
}

From source file:com.intellij.ide.actions.ExternalJavaDocAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;//from w ww .  ja  v a  2 s  .  c  o m
    }

    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    PsiElement element = getElement(dataContext, editor);
    if (element == null) {
        Messages.showMessageDialog(project, IdeBundle.message("message.please.select.element.for.javadoc"),
                IdeBundle.message("title.no.element.selected"), Messages.getErrorIcon());
        return;
    }

    PsiFile context = CommonDataKeys.PSI_FILE.getData(dataContext);

    PsiElement originalElement = getOriginalElement(context, editor);
    DocumentationManager.storeOriginalElement(project, originalElement, element);
    final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);

    if (provider instanceof ExternalDocumentationHandler
            && ((ExternalDocumentationHandler) provider).handleExternal(element, originalElement)) {
        return;
    }

    final List<String> urls = provider.getUrlFor(element, originalElement);
    if (urls != null && !urls.isEmpty()) {
        showExternalJavadoc(urls, PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext));
    } else if (provider instanceof ExternalDocumentationProvider) {
        final ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider) provider;
        if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) {
            externalDocumentationProvider.promptToConfigureDocumentation(element);
        }
    }
}

From source file:com.intellij.ide.actions.OpenFileAction.java

License:Apache License

public static void openFile(final VirtualFile virtualFile, final Project project) {
    FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance();
    if (editorProviderManager.getProviders(project, virtualFile).length == 0) {
        Messages.showMessageDialog(project,
                IdeBundle.message("error.files.of.this.type.cannot.be.opened",
                        ApplicationNamesInfo.getInstance().getProductName()),
                IdeBundle.message("title.cannot.open.file"), Messages.getErrorIcon());
        return;/*from  ww  w  .  ja va  2  s  .  c om*/
    }

    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
    FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}

From source file:com.intellij.ide.actions.ToggleReadOnlyAttributeAction.java

License:Apache License

public void actionPerformed(final AnActionEvent e) {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
            // Save all documents. We won't be able to save changes to the files that became read-only afterwards.
            FileDocumentManager.getInstance().saveAllDocuments();

            try {
                VirtualFile[] files = getFiles(e.getDataContext());
                for (VirtualFile file : files) {
                    ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable());
                }// w w  w.  j  a v a2s. co m
            } catch (IOException exc) {
                Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
                Messages.showMessageDialog(project, exc.getMessage(), CommonBundle.getErrorTitle(),
                        Messages.getErrorIcon());
            }
        }
    });
}

From source file:com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog.java

License:Apache License

@Override
protected void doOKAction() {
    String fileName = myAttrPanel.getFileName();
    if (fileName != null && fileName.length() == 0) {
        Messages.showMessageDialog(myAttrComponent, IdeBundle.message("error.please.enter.a.file.name"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;//from   w  w  w .  ja v a  2 s  .c om
    }
    doCreate(fileName);
    if (myCreatedElement != null) {
        super.doOKAction();
    }
}

From source file:com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog.java

License:Apache License

private void showErrorDialog(final Exception e) {
    Messages.showMessageDialog(myProject, filterMessage(e.getMessage()), getErrorMessage(),
            Messages.getErrorIcon());
}

From source file:com.intellij.ide.highlighter.custom.impl.ModifyKeywordDialog.java

License:Apache License

protected void doOKAction() {
    final String keywordName = myKeywordName.getText().trim();
    if (keywordName.length() == 0) {
        Messages.showMessageDialog(getContentPane(), IdeBundle.message("error.keyword.cannot.be.empty"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;//from w ww . j  a  va  2s.  c  o m
    }
    if (keywordName.indexOf(' ') >= 0) {
        Messages.showMessageDialog(getContentPane(), IdeBundle.message("error.keyword.may.not.contain.spaces"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    }
    super.doOKAction();
}

From source file:com.intellij.ide.todo.configurable.FilterDialog.java

License:Apache License

@Override
protected void doOKAction() {

    // Validate filter name

    myFilter.setName(myNameField.getText().trim());
    if (myFilter.getName().length() == 0) {
        Messages.showMessageDialog(myTable, IdeBundle.message("error.filter.name.should.be.specified"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;/*from   ww w. j  a  v  a 2s.  c  o  m*/
    }
    for (int i = 0; i < myFilters.size(); i++) {
        TodoFilter filter = myFilters.get(i);
        if (myFilterIndex != i && myFilter.getName().equals(filter.getName())) {
            Messages.showMessageDialog(myTable,
                    IdeBundle.message("error.filter.with.the.same.name.already.exists"),
                    CommonBundle.getErrorTitle(), Messages.getErrorIcon());
            return;
        }
    }

    // Validate that at least one pettern is selected

    if (myFilter.isEmpty()) {
        Messages.showMessageDialog(myTable,
                IdeBundle.message("error.filter.should.contain.at.least.one.pattern"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    }

    super.doOKAction();
}

From source file:com.intellij.ide.util.DeleteHandler.java

License:Apache License

public static void deletePsiElement(final PsiElement[] elementsToDelete, final Project project,
        boolean needConfirmation) {
    if (elementsToDelete == null || elementsToDelete.length == 0)
        return;//from  w  w w .java 2  s . c  o  m

    final PsiElement[] elements = PsiTreeUtil.filterAncestors(elementsToDelete);

    boolean safeDeleteApplicable = true;
    for (int i = 0; i < elements.length && safeDeleteApplicable; i++) {
        PsiElement element = elements[i];
        safeDeleteApplicable = SafeDeleteProcessor.validElement(element);
    }

    final boolean dumb = DumbService.getInstance(project).isDumb();
    if (safeDeleteApplicable && !dumb) {
        final Ref<Boolean> exit = Ref.create(false);
        final SafeDeleteDialog dialog = new SafeDeleteDialog(project, elements,
                new SafeDeleteDialog.Callback() {
                    @Override
                    public void run(final SafeDeleteDialog dialog) {
                        if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project,
                                Arrays.asList(elements), true))
                            return;
                        SafeDeleteProcessor.createInstance(project, new Runnable() {
                            @Override
                            public void run() {
                                exit.set(true);
                                dialog.close(DialogWrapper.OK_EXIT_CODE);
                            }
                        }, elements, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true)
                                .run();
                    }
                }) {
            @Override
            protected boolean isDelete() {
                return true;
            }
        };
        if (needConfirmation) {
            dialog.show();
            if (!dialog.isOK() || exit.get())
                return;
        }
    } else {
        @SuppressWarnings({ "UnresolvedPropertyKey" })
        String warningMessage = DeleteUtil.generateWarningMessage(IdeBundle.message("prompt.delete.elements"),
                elements);

        boolean anyDirectories = false;
        String directoryName = null;
        for (PsiElement psiElement : elementsToDelete) {
            if (psiElement instanceof PsiDirectory && !PsiUtilBase.isSymLink((PsiDirectory) psiElement)) {
                anyDirectories = true;
                directoryName = ((PsiDirectory) psiElement).getName();
                break;
            }
        }
        if (anyDirectories) {
            if (elements.length == 1) {
                warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories",
                        directoryName);
            } else {
                warningMessage += IdeBundle
                        .message("warning.delete.all.files.and.subdirectories.in.the.selected.directory");
            }
        }

        if (safeDeleteApplicable && dumb) {
            warningMessage += "\n\nWarning:\n  Safe delete is not available while "
                    + ApplicationNamesInfo.getInstance().getFullProductName()
                    + " updates indices,\n  no usages will be checked.";
        }

        if (needConfirmation) {
            int result = Messages.showOkCancelDialog(project, warningMessage, IdeBundle.message("title.delete"),
                    ApplicationBundle.message("button.delete"), CommonBundle.getCancelButtonText(),
                    Messages.getQuestionIcon());
            if (result != Messages.OK)
                return;
        }
    }

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void run() {
            if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements),
                    false)) {
                return;
            }

            // deleted from project view or something like that.
            if (CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()) == null) {
                CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
            }

            for (final PsiElement elementToDelete : elements) {
                if (!elementToDelete.isValid())
                    continue; //was already deleted
                if (elementToDelete instanceof PsiDirectory) {
                    VirtualFile virtualFile = ((PsiDirectory) elementToDelete).getVirtualFile();
                    if (virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SYMLINK)) {
                        ArrayList<VirtualFile> readOnlyFiles = new ArrayList<VirtualFile>();
                        CommonRefactoringUtil.collectReadOnlyFiles(virtualFile, readOnlyFiles);

                        if (!readOnlyFiles.isEmpty()) {
                            String message = IdeBundle.message("prompt.directory.contains.read.only.files",
                                    virtualFile.getPresentableUrl());
                            int _result = Messages.showYesNoDialog(project, message,
                                    IdeBundle.message("title.delete"), Messages.getQuestionIcon());
                            if (_result != Messages.YES)
                                continue;

                            boolean success = true;
                            for (VirtualFile file : readOnlyFiles) {
                                success = clearReadOnlyFlag(file, project);
                                if (!success)
                                    break;
                            }
                            if (!success)
                                continue;
                        }
                    }
                } else if (!elementToDelete.isWritable() && !(elementToDelete instanceof PsiFileSystemItem
                        && PsiUtilBase.isSymLink((PsiFileSystemItem) elementToDelete))) {
                    final PsiFile file = elementToDelete.getContainingFile();
                    if (file != null) {
                        final VirtualFile virtualFile = file.getVirtualFile();
                        if (virtualFile.isInLocalFileSystem()) {
                            int _result = MessagesEx.fileIsReadOnly(project, virtualFile)
                                    .setTitle(IdeBundle.message("title.delete"))
                                    .appendMessage(IdeBundle.message("prompt.delete.it.anyway")).askYesNo();
                            if (_result != Messages.YES)
                                continue;

                            boolean success = clearReadOnlyFlag(virtualFile, project);
                            if (!success)
                                continue;
                        }
                    }
                }

                try {
                    elementToDelete.checkDelete();
                } catch (IncorrectOperationException ex) {
                    Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(),
                            Messages.getErrorIcon());
                    continue;
                }

                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            elementToDelete.delete();
                        } catch (final IncorrectOperationException ex) {
                            ApplicationManager.getApplication().invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    Messages.showMessageDialog(project, ex.getMessage(),
                                            CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                                }
                            });
                        }
                    }
                });
            }
        }
    }, RefactoringBundle.message("safe.delete.command",
            RefactoringUIUtil.calculatePsiElementDescriptionList(elements)), null);
}