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

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

Introduction

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

Prototype

public static void showErrorDialog(String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:com.hp.alm.ali.idea.genesis.GenesisAction.java

License:Apache License

public void actionPerformed(AnActionEvent anActionEvent) {
    final GenesisDialog genesis = new GenesisDialog();
    genesis.show();/* www . j a v a  2 s.c  o m*/
    if (genesis.isOK()) {
        Checkout checkout = genesis.getCheckout();
        if (checkout != null) {
            VcsConfiguration configuration = VcsConfiguration
                    .getInstance(ProjectManager.getInstance().getDefaultProject());
            configuration.PERFORM_CHECKOUT_IN_BACKGROUND = false;
            Project p = ProjectManager.getInstance().getDefaultProject();
            checkout.setTarget(genesis.getTarget());
            checkout.doCheckout(p, new CheckoutProvider.Listener() {
                // 11.0.1
                public void directoryCheckedOut(File file, VcsKey vcsKey) {
                }

                // 10.5.4
                public void directoryCheckedOut(File file) {
                }

                public void checkoutCompleted() {
                    ProjectManagerAdapter adapter = new ProjectManagerAdapter() {
                        public void projectOpened(Project project) {
                            AliProjectConfiguration conf = project.getComponent(AliProjectConfiguration.class);
                            conf.ALM_LOCATION = genesis.getAlmLocation();
                            conf.ALM_PROJECT = genesis.getProject();
                            conf.ALM_DOMAIN = genesis.getDomain();
                            conf.ALM_USERNAME = genesis.getUsername();
                            conf.ALM_PASSWORD = genesis.getPassword();
                        }
                    };

                    ProjectManager.getInstance().addProjectManagerListener(adapter);
                    try {
                        VirtualFile file = LocalFileSystem.getInstance()
                                .findFileByIoFile(new File(genesis.getTarget()));
                        AddModuleWizard wizard = ImportModuleAction.createImportWizard(null, null, file,
                                ProjectImportProvider.PROJECT_IMPORT_PROVIDER.getExtensions());
                        NewProjectUtil.createNewProject(null, wizard);
                    } catch (Exception e) {
                        Messages.showErrorDialog(
                                "Failed to complete the operation. Please invoke the project wizard manually.\nSources were "
                                        + "checked out to the following location:\n\n " + genesis.getTarget(),
                                "Operation Failed");
                    }
                    ProjectManager.getInstance().removeProjectManagerListener(adapter);
                }
            });
        }
    }
}

From source file:com.hp.alm.ali.idea.impl.SvnCheckoutProvider.java

License:Apache License

public static void doCheckout(Project project, File target, String url, SVNRevision revision, Depth depth,
        boolean ignoreExternals, CheckoutProvider.Listener listener) {
    try {/*from w w  w.j  a v a 2  s .co m*/
        Class<?> clazz = Class.forName("org.jetbrains.idea.svn.checkout.SvnCheckoutProvider");
        Method method = clazz.getMethod("doCheckout", Project.class, File.class, String.class,
                SVNRevision.class, Depth.class, boolean.class, CheckoutProvider.Listener.class);
        method.invoke(null, project, target, url, revision, depth, ignoreExternals, listener);
    } catch (Exception e) {
        Messages.showErrorDialog(
                "Failed to complete the operation. Please checkout the source code from the following subversion repository and invoke the project wizard manually:\n\n "
                        + "SVN URL: " + url,
                "Operation failed");
    }
}

From source file:com.hp.alm.ali.idea.ui.editor.BaseEditor.java

License:Apache License

protected void buttonPerformed(Button button) {
    super.buttonPerformed(button);

    switch (button) {
    case Save:/* w w  w  .j ava 2  s  .c  o  m*/
        StringBuffer message = new StringBuffer();
        String error = validate(message);
        if (error != null) {
            Messages.showErrorDialog(message.toString(), error);
            return;
        }
        if (saveHandler.save(getModified(), entity)) {
            close(true);
        }
    }
}

From source file:com.igormaznitsa.ideamindmap.swing.PlainTextEditor.java

License:Apache License

public PlainTextEditor(final Project project, final String text) {
    super(new BorderLayout());
    this.editor = new EmptyTextEditor(project);

    final JToolBar menu = new JToolBar();

    final JButton buttonImport = new JButton("Import", AllIcons.Buttons.IMPORT);
    final PlainTextEditor theInstance = this;

    buttonImport.addActionListener(new ActionListener() {
        @Override/*from   w  ww  .  j  ava 2s.c om*/
        public void actionPerformed(ActionEvent e) {
            final File home = new File(System.getProperty("user.home")); //NOI18N

            final File toOpen = IdeaUtils.chooseFile(theInstance, true,
                    BUNDLE.getString("PlainTextEditor.buttonLoadActionPerformed.title"), home,
                    TEXT_FILE_FILTER);

            if (toOpen != null) {
                try {
                    final String text = FileUtils.readFileToString(toOpen, "UTF-8"); //NOI18N
                    editor.setText(text);
                } catch (Exception ex) {
                    LOGGER.error("Error during text file loading", ex); //NOI18N
                    Messages.showErrorDialog(
                            BUNDLE.getString("PlainTextEditor.buttonLoadActionPerformed.msgError"), "Error");
                }
            }

        }
    });

    final JButton buttonExport = new JButton("Export", AllIcons.Buttons.EXPORT);
    buttonExport.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final File home = new File(System.getProperty("user.home")); //NOI18N
            final File toSave = IdeaUtils.chooseFile(theInstance, true,
                    BUNDLE.getString("PlainTextEditor.buttonSaveActionPerformed.saveTitle"), home,
                    TEXT_FILE_FILTER);
            if (toSave != null) {
                try {
                    final String text = getText();
                    FileUtils.writeStringToFile(toSave, text, "UTF-8"); //NOI18N
                } catch (Exception ex) {
                    LOGGER.error("Error during text file saving", ex); //NOI18N
                    Messages.showErrorDialog(
                            BUNDLE.getString("PlainTextEditor.buttonSaveActionPerformed.msgError"), "Error");
                }
            }
        }
    });

    final JButton buttonCopy = new JButton("Copy", AllIcons.Buttons.COPY);
    buttonCopy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final StringSelection stringSelection = new StringSelection(editor.getSelectedText());
            final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
            clpbrd.setContents(stringSelection, null);
        }
    });

    final JButton buttonPaste = new JButton("Paste", AllIcons.Buttons.PASTE);
    buttonPaste.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                final String clipboardText = (String) Toolkit.getDefaultToolkit().getSystemClipboard()
                        .getData(DataFlavor.stringFlavor);
                editor.replaceSelection(clipboardText);
            } catch (UnsupportedFlavorException ex) {
                // no text data in clipboard
            } catch (IOException ex) {
                LOGGER.error("Error during paste from clipboard", ex); //NOI18N
            }
        }
    });

    final JButton buttonClearAll = new JButton("Clear All", AllIcons.Buttons.CLEARALL);
    buttonClearAll.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            editor.clear();
        }
    });

    menu.add(buttonImport);
    menu.add(buttonExport);
    menu.add(buttonCopy);
    menu.add(buttonPaste);
    menu.add(buttonClearAll);

    this.add(menu, BorderLayout.NORTH);
    this.add(editor, BorderLayout.CENTER);

    // I made so strange trick to move the caret into the start of document, all other ways didn't work :(
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            editor.replaceSelection(text);
        }
    });
}

From source file:com.intellij.application.options.ExportSchemeAction.java

License:Apache License

public static <T extends Named, E extends ExternalizableScheme> void doExport(final E scheme,
        SchemesManager<T, E> manager) {
    if (scheme != null) {
        try {/* w  w  w  .j a  v a  2  s .  c  o  m*/
            ShareSchemeDialog dialog = new ShareSchemeDialog();
            dialog.init(scheme);

            dialog.show();

            if (dialog.isOK()) {
                try {
                    manager.exportScheme(scheme, dialog.getName(), dialog.getDescription());
                    Messages.showMessageDialog("Scheme '" + scheme.getName() + "' was shared successfully as '"
                            + dialog.getName() + " '", "Share Scheme", Messages.getInformationIcon());
                } catch (IOException e) {
                    Messages.showErrorDialog(
                            "Cannot share scheme '" + scheme.getName() + "': " + e.getLocalizedMessage(),
                            "Share Shceme");
                }

            }

        } catch (WriteExternalException e1) {
            Messages.showErrorDialog("Cannot share scheme: " + e1.getLocalizedMessage(), "Share Scheme");
        }
    }
}

From source file:com.intellij.codeInsight.daemon.impl.actions.AbstractSuppressByNoInspectionCommentFix.java

License:Apache License

@Override
public void invoke(@NotNull final Project project, @Nullable Editor editor, @NotNull final PsiElement element)
        throws IncorrectOperationException {
    PsiElement container = getContainer(element);
    if (container == null)
        return;/*from  w  w w.  j a  va  2  s  . c o  m*/

    if (!FileModificationService.getInstance().preparePsiElementForWrite(container))
        return;

    final List<? extends PsiElement> comments = getCommentsFor(container);
    if (comments != null) {
        for (PsiElement comment : comments) {
            if (comment instanceof PsiComment && SuppressionUtil.isSuppressionComment(comment)) {
                replaceSuppressionComment(comment);
                return;
            }
        }
    }

    boolean caretWasBeforeStatement = editor != null
            && editor.getCaretModel().getOffset() == container.getTextRange().getStartOffset();
    try {
        createSuppression(project, element, container);
    } catch (IncorrectOperationException e) {
        if (!ApplicationManager.getApplication().isUnitTestMode() && editor != null) {
            Messages.showErrorDialog(editor.getComponent(),
                    InspectionsBundle.message("suppress.inspection.annotation.syntax.error", e.getMessage()));
        }
    }

    if (caretWasBeforeStatement) {
        editor.getCaretModel().moveToOffset(container.getTextRange().getStartOffset());
    }
    UndoUtil.markPsiFileForUndo(element.getContainingFile());
}

From source file:com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils.java

License:Apache License

public static void setupMethodBody(final PsiMethod method, final PsiClass aClass, final FileTemplate template)
        throws IncorrectOperationException {
    PsiType returnType = method.getReturnType();
    if (returnType == null) {
        returnType = PsiType.VOID;/*from  w  ww. jav  a  2s.  c  om*/
    }

    JVMElementFactory factory = JVMElementFactories.getFactory(aClass.getLanguage(), aClass.getProject());

    LOG.assertTrue(!aClass.isInterface(), "Interface bodies should be already set up");

    FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(template.getExtension());
    Properties properties = new Properties();
    properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnType.getPresentableText());
    properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE,
            PsiTypesUtil.getDefaultValueOfType(returnType));

    JavaTemplateUtil.setClassAndMethodNameProperties(properties, aClass, method);

    @NonNls
    String methodText;
    CodeStyleManager csManager = CodeStyleManager.getInstance(method.getProject());
    try {
        String bodyText = template.getText(properties);
        if (!bodyText.isEmpty())
            bodyText += "\n";
        methodText = returnType.getPresentableText() + " foo () {\n" + bodyText + "}";
        methodText = FileTemplateUtil.indent(methodText, method.getProject(), fileType);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Exception e) {
        throw new IncorrectOperationException("Failed to parse file template", e);
    }

    if (methodText != null) {
        PsiMethod m;
        try {
            m = factory.createMethodFromText(methodText, aClass);
        } catch (IncorrectOperationException e) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    Messages.showErrorDialog(QuickFixBundle.message("new.method.body.template.error.text"),
                            QuickFixBundle.message("new.method.body.template.error.title"));
                }
            });
            return;
        }
        PsiCodeBlock oldBody = method.getBody();
        PsiCodeBlock newBody = m.getBody();
        LOG.assertTrue(newBody != null);
        if (oldBody != null) {
            oldBody.replace(newBody);
        } else {
            method.addBefore(newBody, null);
        }
        csManager.reformat(method);
    }
}

From source file:com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils.java

License:Apache License

public static void scheduleFileOrPackageCreationFailedMessageBox(final IncorrectOperationException e,
        final String name, final PsiDirectory directory, final boolean isPackage) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override/*from   w  w  w . j a v a 2  s.  c o m*/
        public void run() {
            Messages.showErrorDialog(
                    QuickFixBundle.message(
                            isPackage ? "cannot.create.java.package.error.text"
                                    : "cannot.create.java.file.error.text",
                            name, directory.getVirtualFile().getName(), e.getLocalizedMessage()),
                    QuickFixBundle.message(isPackage ? "cannot.create.java.package.error.title"
                            : "cannot.create.java.file.error.title"));
        }
    });
}

From source file:com.intellij.codeInsight.generation.OverrideImplementUtil.java

License:Apache License

public static void setupMethodBody(final PsiMethod result, final PsiMethod originalMethod,
        final PsiClass targetClass, final FileTemplate template) throws IncorrectOperationException {
    if (targetClass.isInterface()) {
        final PsiCodeBlock body = result.getBody();
        if (body != null) {
            body.delete();//from   w ww  .  j  a  v a  2s . co  m
        }
    }

    FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(template.getExtension());
    PsiType returnType = result.getReturnType();
    if (returnType == null) {
        returnType = PsiType.VOID;
    }
    Properties properties = FileTemplateManager.getInstance().getDefaultProperties(targetClass.getProject());
    properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnType.getPresentableText());
    properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE,
            PsiTypesUtil.getDefaultValueOfType(returnType));
    properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(originalMethod, result));
    JavaTemplateUtil.setClassAndMethodNameProperties(properties, targetClass, result);

    JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(),
            originalMethod.getProject());
    if (factory == null) {
        factory = JavaPsiFacade.getInstance(originalMethod.getProject()).getElementFactory();
    }
    @NonNls
    String methodText;

    try {
        methodText = "void foo () {\n" + template.getText(properties) + "\n}";
        methodText = FileTemplateUtil.indent(methodText, result.getProject(), fileType);
    } catch (Exception e) {
        throw new IncorrectOperationException("Failed to parse file template", e);
    }
    if (methodText != null) {
        PsiMethod m;
        try {
            m = factory.createMethodFromText(methodText, originalMethod);
        } catch (IncorrectOperationException e) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    Messages.showErrorDialog(
                            CodeInsightBundle.message("override.implement.broken.file.template.message"),
                            CodeInsightBundle.message("override.implement.broken.file.template.title"));
                }
            });
            return;
        }
        PsiCodeBlock oldBody = result.getBody();
        if (oldBody != null) {
            oldBody.replace(m.getBody());
        }
    }
}

From source file:com.intellij.codeInspection.ui.actions.ExportHTMLAction.java

License:Apache License

private void dupm2XML(final String outputDirectoryName) {
    try {//from w w w  .  j a v  a 2 s  .c  o  m
        new File(outputDirectoryName).mkdirs();
        final InspectionTreeNode root = myView.getTree().getRoot();
        final IOException[] ex = new IOException[1];
        TreeUtil.traverse(root, new TreeUtil.Traverse() {
            @Override
            public boolean accept(final Object node) {
                if (node instanceof InspectionNode) {
                    InspectionNode toolNode = (InspectionNode) node;
                    Element problems = new Element(PROBLEMS);
                    InspectionToolWrapper toolWrapper = toolNode.getToolWrapper();

                    final Set<InspectionToolWrapper> toolWrappers = getWorkedTools(toolNode);
                    for (InspectionToolWrapper wrapper : toolWrappers) {
                        InspectionToolPresentation presentation = myView.getGlobalInspectionContext()
                                .getPresentation(wrapper);
                        presentation.exportResults(problems);
                    }
                    PathMacroManager.getInstance(myView.getProject()).collapsePaths(problems);
                    try {
                        JDOMUtil.writeDocument(new Document(problems),
                                outputDirectoryName + File.separator + toolWrapper.getShortName()
                                        + InspectionApplication.XML_EXTENSION,
                                CodeStyleSettingsManager.getSettings(null).getLineSeparator());
                    } catch (IOException e) {
                        ex[0] = e;
                    }
                }
                return true;
            }
        });
        if (ex[0] != null) {
            throw ex[0];
        }
        final Element element = new Element(InspectionApplication.INSPECTIONS_NODE);
        final String profileName = myView.getCurrentProfileName();
        if (profileName != null) {
            element.setAttribute(InspectionApplication.PROFILE, profileName);
        }
        JDOMUtil.writeDocument(new Document(element),
                outputDirectoryName + File.separator + InspectionApplication.DESCRIPTIONS
                        + InspectionApplication.XML_EXTENSION,
                CodeStyleSettingsManager.getSettings(null).getLineSeparator());
    } catch (final IOException e) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Messages.showErrorDialog(myView, e.getMessage());
            }
        });
    }
}