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:org.jetbrains.kotlin.idea.configuration.KotlinWithLibraryConfigurator.java

License:Apache License

protected void showError(@NotNull String message) {
    Messages.showErrorDialog(message, getMessageForOverrideDialog());
}

From source file:org.jetbrains.plugins.groovy.annotator.intentions.CreateClassActionBase.java

License:Apache License

@Nullable
public static GrTypeDefinition createClassByType(@NotNull final PsiDirectory directory,
        @NotNull final String name, @NotNull final PsiManager manager,
        @Nullable final PsiElement contextElement, @NotNull final String templateName) {
    AccessToken accessToken = WriteAction.start();

    try {/*from   ww  w  .  ja va  2 s.  c o m*/
        GrTypeDefinition targetClass = null;
        try {
            PsiFile file = GroovyTemplatesFactory.createFromTemplate(directory, name, name + ".groovy",
                    templateName);
            for (PsiElement element : file.getChildren()) {
                if (element instanceof GrTypeDefinition) {
                    targetClass = ((GrTypeDefinition) element);
                    break;
                }
            }
            if (targetClass == null) {
                throw new IncorrectOperationException(GroovyBundle.message("no.class.in.file.template"));
            }
        } catch (final IncorrectOperationException e) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                public void run() {
                    Messages.showErrorDialog(
                            GroovyBundle.message("cannot.create.class.error.text", name,
                                    e.getLocalizedMessage()),
                            GroovyBundle.message("cannot.create.class.error.title"));
                }
            });
            return null;
        }
        PsiModifierList modifiers = targetClass.getModifierList();
        if (contextElement != null && !JavaPsiFacade.getInstance(manager.getProject()).getResolveHelper()
                .isAccessible(targetClass, contextElement, null) && modifiers != null) {
            modifiers.setModifierProperty(PsiModifier.PUBLIC, true);
        }
        return targetClass;
    } catch (IncorrectOperationException e) {
        LOG.error(e);
        return null;
    } finally {
        accessToken.finish();
    }
}

From source file:org.jetbrains.plugins.groovy.grape.GrabDependencies.java

License:Apache License

public void invoke(@NotNull final Project project, Editor editor, PsiFile file)
        throws IncorrectOperationException {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    assert module != null;

    final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
    assert vfile != null;

    if (JavaPsiFacade.getInstance(project).findClass("org.apache.ivy.core.report.ResolveReport",
            file.getResolveScope()) == null) {
        Messages.showErrorDialog(
                "Sorry, but IDEA cannot @Grab the dependencies without Ivy. Please add Ivy to your module dependencies and re-run the action.",
                "Ivy Missing");
        return;//from w w  w .j av  a2  s. c  o  m
    }

    Map<String, String> queries = prepareQueries(file);

    final Sdk sdk = ModuleUtilCore.getSdk(module, JavaModuleExtensionImpl.class);
    assert sdk != null;
    SdkTypeId sdkType = sdk.getSdkType();
    assert sdkType instanceof JavaSdkType;

    final Map<String, GeneralCommandLine> lines = new HashMap<String, GeneralCommandLine>();
    for (String grabText : queries.keySet()) {
        final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
        //debug
        //javaParameters.getVMParametersList().add("-Xdebug"); javaParameters.getVMParametersList().add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239");

        DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module,
                "org.jetbrains.plugins.groovy.grape.GrapeRunner", false);
        PathsList list;
        try {
            list = GroovyScriptRunner.getClassPathFromRootModel(module,
                    ProjectRootManager.getInstance(project).getFileIndex().isInTestSourceContent(vfile),
                    javaParameters, true);
        } catch (CantRunException e) {
            NOTIFICATION_GROUP.createNotification("Can't run @Grab: " + ExceptionUtil.getMessage(e),
                    ExceptionUtil.getThrowableText(e), NotificationType.ERROR, null).notify(project);
            return;
        }
        if (list == null) {
            list = new PathsList();
        }
        list.add(PathUtil.getJarPathForClass(GrapeRunner.class));

        javaParameters.getProgramParametersList().add("--classpath");
        javaParameters.getProgramParametersList().add(list.getPathsString());
        javaParameters.getProgramParametersList().add(queries.get(grabText));

        lines.put(grabText, JdkUtil.setupJVMCommandLine(sdk, javaParameters, true));
    }

    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab annotations") {

        public void run(@NotNull ProgressIndicator indicator) {
            int jarCount = 0;
            String messages = "";

            for (Map.Entry<String, GeneralCommandLine> entry : lines.entrySet()) {
                String grabText = entry.getKey();
                indicator.setText2(grabText);
                try {
                    final GrapeProcessHandler handler = new GrapeProcessHandler(entry.getValue(), module);
                    handler.startNotify();
                    handler.waitFor();
                    jarCount += handler.jarCount;
                    messages += "<b>" + grabText + "</b>: " + handler.messages + "<p>";
                } catch (ExecutionException e) {
                    LOG.error(e);
                }
            }

            final String finalMessages = messages;
            final String title = jarCount + " Grape dependency jar" + (jarCount == 1 ? "" : "s") + " added";
            NOTIFICATION_GROUP.createNotification(title, finalMessages, NotificationType.INFORMATION, null)
                    .notify(project);
        }
    });

}

From source file:org.jetbrains.plugins.groovy.mvc.MvcConsole.java

License:Apache License

private void executeProcessImpl(final MyProcessInConsole pic, boolean toFocus) {
    final Module module = pic.module;
    final GeneralCommandLine commandLine = pic.commandLine;
    final String[] input = pic.input;
    final boolean closeOnDone = pic.closeOnDone;
    final Runnable onDone = pic.onDone;

    assert module.getProject() == myProject;

    myExecuting = true;//from w ww. j a va2s  .com

    // Module creation was cancelled
    if (module.isDisposed())
        return;

    final ModalityState modalityState = ModalityState.current();
    final boolean modalContext = modalityState != ModalityState.NON_MODAL;

    if (!modalContext && pic.showConsole) {
        show(null, toFocus);
    }

    FileDocumentManager.getInstance().saveAllDocuments();
    myConsole.print(commandLine.getCommandLineString(), ConsoleViewContentType.SYSTEM_OUTPUT);
    final OSProcessHandler handler;
    try {
        Process process = commandLine.createProcess();
        handler = new OSProcessHandler(process);

        @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
        OutputStreamWriter writer = new OutputStreamWriter(process.getOutputStream());
        for (String s : input) {
            writer.write(s);
        }
        writer.flush();

        final Ref<Boolean> gotError = new Ref<Boolean>(false);
        handler.addProcessListener(new ProcessAdapter() {
            public void onTextAvailable(ProcessEvent event, Key key) {
                if (key == ProcessOutputTypes.STDERR)
                    gotError.set(true);
                LOG.debug("got text: " + event.getText());
            }

            public void processTerminated(ProcessEvent event) {
                final int exitCode = event.getExitCode();
                if (exitCode == 0 && !gotError.get().booleanValue()) {
                    ApplicationManager.getApplication().invokeLater(new Runnable() {
                        public void run() {
                            if (myProject.isDisposed() || !closeOnDone)
                                return;
                            myToolWindow.hide(null);
                        }
                    }, modalityState);
                }
            }
        });
    } catch (final Exception e) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            public void run() {
                Messages.showErrorDialog(e.getMessage(), "Cannot Start Process");

                try {
                    if (onDone != null && !module.isDisposed())
                        onDone.run();
                } catch (Exception e) {
                    LOG.error(e);
                }
            }
        }, modalityState);
        return;
    }

    pic.setHandler(handler);
    myKillAction.setHandler(handler);

    final MvcFramework framework = MvcFramework.getInstance(module);
    myToolWindow
            .setIcon(framework == null ? JetgroovyIcons.Groovy.Groovy_13x13 : framework.getToolWindowIcon());

    myContent.setDisplayName((framework == null ? "" : framework.getDisplayName() + ":") + "Executing...");
    myConsole.scrollToEnd();
    myConsole.attachToProcess(handler);
    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        public void run() {
            handler.startNotify();
            handler.waitFor();

            ApplicationManager.getApplication().invokeLater(new Runnable() {
                public void run() {
                    if (myProject.isDisposed())
                        return;

                    module.putUserData(UPDATING_BY_CONSOLE_PROCESS, true);
                    LocalFileSystem.getInstance().refresh(false);
                    module.putUserData(UPDATING_BY_CONSOLE_PROCESS, null);

                    try {
                        if (onDone != null && !module.isDisposed())
                            onDone.run();
                    } catch (Exception e) {
                        LOG.error(e);
                    }
                    myConsole.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
                    myKillAction.setHandler(null);
                    myContent.setDisplayName("");

                    myExecuting = false;

                    final MyProcessInConsole pic = myProcessQueue.poll();
                    if (pic != null) {
                        executeProcessImpl(pic, false);
                    }
                }
            }, modalityState);
        }
    });
}

From source file:org.jetbrains.plugins.groovy.mvc.MvcFramework.java

License:Apache License

@Nullable
public GeneralCommandLine createCommandAndShowErrors(@Nullable String vmOptions, @NotNull Module module,
        final boolean forCreation, @NotNull MvcCommand command) {
    try {//from  www . java 2  s .  c om
        return createCommand(module, vmOptions, forCreation, command);
    } catch (ExecutionException e) {
        Messages.showErrorDialog(e.getMessage(), "Failed to run grails command: " + command);
        return null;
    }
}

From source file:org.jetbrains.plugins.javaFX.actions.OpenInSceneBuilderAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    LOG.assertTrue(virtualFile != null);
    final String path = virtualFile.getPath();

    final JavaFxSettings settings = JavaFxSettings.getInstance();
    String pathToSceneBuilder = settings.getPathToSceneBuilder();
    if (StringUtil.isEmptyOrSpaces(settings.getPathToSceneBuilder())) {
        final VirtualFile sceneBuilderFile = FileChooser.chooseFile(
                JavaFxSettingsConfigurable.createSceneBuilderDescriptor(), e.getProject(), getPredefinedPath());
        if (sceneBuilderFile == null)
            return;

        pathToSceneBuilder = sceneBuilderFile.getPath();
        settings.setPathToSceneBuilder(FileUtil.toSystemIndependentName(pathToSceneBuilder));
    }// w ww  .j a  va  2s  .c o  m

    final Project project = getEventProject(e);
    if (project != null) {
        final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
        if (module != null) {
            try {
                final JavaParameters javaParameters = new JavaParameters();
                javaParameters.configureByModule(module, JavaParameters.JDK_AND_CLASSES);

                final File sceneBuilderLibsFile;
                if (SystemInfo.isMac) {
                    sceneBuilderLibsFile = new File(new File(pathToSceneBuilder, "Contents"), "Java");
                } else if (SystemInfo.isWindows) {
                    File sceneBuilderRoot = new File(pathToSceneBuilder);
                    File sceneBuilderRootDir = sceneBuilderRoot.getParentFile();
                    if (sceneBuilderRootDir == null) {
                        final File foundInPath = PathEnvironmentVariableUtil.findInPath(pathToSceneBuilder);
                        if (foundInPath != null) {
                            sceneBuilderRootDir = foundInPath.getParentFile();
                        }
                    }
                    sceneBuilderRoot = sceneBuilderRootDir != null ? sceneBuilderRootDir.getParentFile() : null;
                    if (sceneBuilderRoot != null) {
                        final File libFile = new File(sceneBuilderRoot, "lib");
                        if (libFile.isDirectory()) {
                            sceneBuilderLibsFile = libFile;
                        } else {
                            final File appFile = new File(sceneBuilderRootDir, "app");
                            sceneBuilderLibsFile = appFile.isDirectory() ? appFile : null;
                        }
                    } else {
                        sceneBuilderLibsFile = null;
                    }
                } else {
                    sceneBuilderLibsFile = new File(new File(pathToSceneBuilder).getParent(), "app");
                }
                if (sceneBuilderLibsFile != null) {
                    final File[] sceneBuilderLibs = sceneBuilderLibsFile.listFiles();
                    if (sceneBuilderLibs != null) {
                        for (File jarFile : sceneBuilderLibs) {
                            javaParameters.getClassPath().add(jarFile.getPath());
                        }
                        javaParameters.setMainClass("com.oracle.javafx.authoring.Main");
                        javaParameters.getProgramParametersList().add(path);

                        final OSProcessHandler processHandler = javaParameters.createOSProcessHandler();
                        final String commandLine = processHandler.getCommandLine();
                        LOG.info("scene builder command line: " + commandLine);
                        processHandler.startNotify();
                        return;
                    }
                }
            } catch (Throwable ex) {
                LOG.info(ex);
            }
        }
    }

    if (SystemInfo.isMac) {
        pathToSceneBuilder += "/Contents/MacOS/scenebuilder-launcher.sh";
    }

    final GeneralCommandLine commandLine = new GeneralCommandLine();
    try {
        commandLine.setExePath(FileUtil.toSystemDependentName(pathToSceneBuilder));
        commandLine.addParameter(path);
        commandLine.createProcess();
    } catch (Exception ex) {
        Messages.showErrorDialog("Failed to start SceneBuilder: " + commandLine.getCommandLineString(),
                CommonBundle.getErrorTitle());
    }
}

From source file:org.jetbrains.plugins.javaFX.packaging.JavaFxEditCertificatesDialog.java

License:Apache License

@Override
protected void doOKAction() {
    if (myPanel.mySignedByKeyRadioButton.isSelected()) {
        if (StringUtil.isEmptyOrSpaces(myPanel.myAliasTF.getText())) {
            Messages.showErrorDialog(myPanel.myWholePanel, "Alias should be non-empty");
            return;
        }/*from ww w . j av a 2s.  co m*/
        final String keystore = myPanel.myKeystore.getText();
        if (StringUtil.isEmptyOrSpaces(keystore)) {
            Messages.showErrorDialog(myPanel.myWholePanel, "Path to the keystore file should be set");
            return;
        }
        if (!new File(keystore).isFile()) {
            Messages.showErrorDialog(myPanel.myWholePanel, "Keystore file should exist");
            return;
        }
        if (StringUtil.isEmptyOrSpaces(String.valueOf(myPanel.myKeypassTF.getPassword()))
                || StringUtil.isEmptyOrSpaces(String.valueOf(myPanel.myStorePassTF.getPassword()))) {
            Messages.showErrorDialog(myPanel.myWholePanel, "Passwords should be set");
            return;
        }
    }
    super.doOKAction();
}

From source file:org.jetbrains.plugins.ruby.rails.actions.shortcuts.ShortcutAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();

    final Module module = DataKeys.MODULE.getData(dataContext);
    if (module == null || !RailsFacetUtil.hasRailsSupport(module)) {
        return;// w ww .j  a v a 2  s  .  c  o  m
    }

    final BaseRailsFacetConfiguration facetConfiguration = RailsFacetUtil.getRailsFacetConfiguration(module);
    assert facetConfiguration != null; //Not null for modules with Rails Support
    String msg = null;
    switch (myState) {
    case GENERATORS_SUBTREE:
        final String[] generators = facetConfiguration.getGenerators();
        if (executeGenerateAction(generators, e)) {
            return;
        }
        msg = RBundle.message("action.registered.shortcut.execute.disabled.generators.msg", myCmdName,
                module.getName());
        break;
    case RAKE_SUBTREE:
        final RakeTask rootRakeTask = facetConfiguration.getRakeTasks();
        final RakeTask task = rootRakeTask != null ? RakeUtil.findTaksByFullCmd(rootRakeTask, myCmdName) : null;
        //If our task is valid for current module
        if (task != null) {
            RakeUtil.runRakeTask(dataContext, task);
            return;
        }
        msg = RBundle.message("action.registered.shortcut.execute.disabled.raketasks.msg", myCmdName,
                module.getName());
        break;
    }
    if (msg != null) {
        Messages.showErrorDialog(msg, RBundle.message("action.registered.shortcut.execute.disabled.title"));
    }
}

From source file:org.jetbrains.plugins.ruby.rails.facet.ui.wizard.ui.AddFacetWizard.java

License:Apache License

@Override
protected final void doOKAction() {
    int idx = getCurrentStep();
    try {/*from   w  w  w  .ja  va2  s .c o m*/
        do {
            final FacetWizardStep step = mySteps.get(idx);
            if (step != getCurrentStepObject()) {
                step.updateStep();
            }
            if (!commitStepData(step)) {
                return;
            }
            step.onStepLeaving();
            try {
                step._commit(true);
            } catch (CommitStepException e) {
                String message = e.getMessage();
                if (message != null) {
                    Messages.showErrorDialog(getCurrentStepComponent(), message);
                }
                return;
            }
            if (!isLastStep(idx)) {
                idx = getNextStep(idx);
            } else {
                break;
            }
        } while (true);
    } finally {
        myCurrentStep = idx;
        updateStep();
    }
    super.doOKAction();
}