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(@Nullable Component component, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

From source file:com.perl5.lang.perl.idea.intentions.StringToHeredocConverter.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element)
        throws IncorrectOperationException {
    String markerText = Messages.showInputDialog(project, "What here-doc marker should we use?",
            "Input a Heredoc Marker", Messages.getQuestionIcon(), HEREDOC_MARKER, null);
    if (markerText != null)
        if (markerText.isEmpty())
            Messages.showErrorDialog(project, "Empty heredoc markers are not supported", "Marker Error");
        else // converting
        {/*  w w w .  j a va 2 s .  co m*/
            HEREDOC_MARKER = markerText;
            PsiElement parentElement = element.getParent();
            char quoteSymbol = '"';
            if (parentElement instanceof PsiPerlStringSq)
                quoteSymbol = '\'';
            else if (parentElement instanceof PsiPerlStringXq)
                quoteSymbol = '`';

            List<PsiElement> heredocElements = PerlElementFactory.createHereDocElements(project, quoteSymbol,
                    markerText, element.getText());

            PsiFile currentFile = element.getContainingFile();

            PsiElement newLineItem = null;
            int newLineIndex = currentFile.getText().indexOf("\n", element.getTextOffset());
            if (newLineIndex > 1)
                newLineItem = currentFile.findElementAt(newLineIndex);

            if (newLineItem == null) // last statement without newline
            {
                currentFile.addAfter(heredocElements.get(3), currentFile.getLastChild());
                currentFile.addAfter(heredocElements.get(1), currentFile.getLastChild());
                currentFile.addAfter(heredocElements.get(2), currentFile.getLastChild());
                currentFile.addAfter(heredocElements.get(3), currentFile.getLastChild());
            } else {
                PsiElement container = newLineItem.getParent();
                container.addAfter(heredocElements.get(3), container.addAfter(heredocElements.get(2),
                        container.addAfter(heredocElements.get(1), newLineItem)));
            }
            parentElement.replace(heredocElements.get(0));
        }
}

From source file:com.perl5.lang.perl.idea.intentions.StringToHeredocConverterIntention.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element)
        throws IncorrectOperationException {
    String markerText = Messages.showInputDialog(project, "What here-doc marker should we use?",
            "Input a Heredoc Marker", Messages.getQuestionIcon(), HEREDOC_MARKER, null);
    if (markerText != null) {
        if (markerText.isEmpty()) {
            Messages.showErrorDialog(project, "Empty heredoc markers are not supported", "Marker Error");
        } else // converting
        {/*from  w  w  w.  j  a  va 2s.c o  m*/
            HEREDOC_MARKER = markerText;
            super.invoke(project, editor, element);
        }
    }
}

From source file:com.perl5.lang.perl.idea.intentions.StringToHeredocIntention.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element)
        throws IncorrectOperationException {
    ApplicationManager.getApplication().invokeLater(() -> {
        String markerText = Messages.showInputDialog(project,
                PerlBundle.message("perl.intention.heredoc.dialog.prompt"),
                PerlBundle.message("perl.intention.heredoc.dialog.title"), Messages.getQuestionIcon(),
                HEREDOC_MARKER, null);/*from  w ww .jav  a  2  s . c  om*/
        if (markerText != null) {
            if (markerText.isEmpty()) {
                Messages.showErrorDialog(project, PerlBundle.message("perl.intention.heredoc.error.message"),
                        PerlBundle.message("perl.intention.heredoc.error.title"));
            } else // converting
            {
                HEREDOC_MARKER = markerText;
                WriteCommandAction.runWriteCommandAction(project, () -> super.invoke(project, editor, element));
            }
        }
    });
}

From source file:com.perl5.lang.perl.xsubs.PerlXSubsState.java

License:Apache License

public void reparseXSubs() {
    if (parserTask != null) {
        Messages.showErrorDialog(myProject,
                "Another process currently deparsing XSubs, please wait for further notifications",
                "XSubs Deparsing In Process");
        return;// w  w w .  j a va 2  s.  c  o m
    }

    final Map<String, Long> newFilesMap = new THashMap<String, Long>();

    for (VirtualFile classRoot : ProjectRootManager.getInstance(myProject).orderEntries().getClassesRoots()) {
        VfsUtil.processFilesRecursively(classRoot, new Processor<VirtualFile>() {
            @Override
            public boolean process(VirtualFile virtualFile) {
                if (isXSFile(virtualFile)) {
                    String filePath = virtualFile.getCanonicalPath();
                    if (filePath != null) {
                        //                     System.err.println("Found " + filePath);
                        newFilesMap.put(filePath, VfsUtilCore.virtualToIoFile(virtualFile).lastModified());
                    }
                }
                return true;
            }
        });
    }

    GeneralCommandLine commandLine = PerlPluginUtil.getPluginScriptCommandLine(myProject,
            "xs_parser_simple.pl");

    if (commandLine != null) {
        try {
            final CapturingProcessHandler processHandler = new CapturingProcessHandler(
                    commandLine.createProcess());

            parserTask = new Task.Backgroundable(myProject, "XSubs Scanning", false) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    ProcessOutput processOutput = processHandler.runProcess();
                    final String stdout = processOutput.getStdout();
                    List<String> stderr = processOutput.getStderrLines(false);

                    final StringBuilder messageBuilder = new StringBuilder();
                    if (!stderr.isEmpty()) {
                        for (String errorMessage : stderr) {
                            if (errorMessage.equals("\n")) {
                                messageBuilder.append("<br/>");
                            } else {
                                messageBuilder.append("<p>");
                                messageBuilder.append(errorMessage);
                                messageBuilder.append("</p>");
                            }
                        }
                    }

                    if (!stdout.isEmpty() && !myProject.isDisposed()) {
                        new WriteAction<Object>() {
                            @Override
                            protected void run(@NotNull Result<Object> result) throws Throwable {
                                try {
                                    VirtualFile newFile = myProject.getBaseDir().findOrCreateChildData(this,
                                            DEPARSED_FILE_NAME);
                                    newFile.setWritable(true);
                                    OutputStream outputStream = newFile.getOutputStream(null);
                                    outputStream.write(stdout.getBytes());
                                    outputStream.close();
                                    newFile.setWritable(false);
                                    FileContentUtil.reparseFiles(newFile);

                                    isActual = true;

                                    messageBuilder.append("<p>");
                                    messageBuilder.append("Deparsing completed successfully!");
                                    messageBuilder.append("</p><br/>");

                                    if (messageBuilder.length() > 0) {
                                        Notifications.Bus.notify(new Notification("PERL5_DEPARSING_REPORT",
                                                "XSubs deparsing finished", messageBuilder.toString(),
                                                NotificationType.INFORMATION));
                                    }

                                } catch (IOException e) {
                                    Notifications.Bus.notify(new Notification("PERL5_DEPARSING_ERROR",
                                            "Error creating XSubs deparsed file", e.getMessage(),
                                            NotificationType.ERROR));
                                } finally {
                                    PerlXSubsState.this.parserTask = null;
                                }
                            }
                        }.execute();
                    }
                }
            };
            parserTask.queue();

        } catch (ExecutionException e) {
            Notifications.Bus.notify(new Notification("PERL5_START_ERROR", "XSubs deparser report",
                    e.getMessage(), NotificationType.ERROR));
        }
    }

    filesMap = newFilesMap;
}

From source file:com.ritesh.idea.plugin.state.SettingsPage.java

License:Apache License

private void testConnection() {
    final MutableObject connException = new MutableObject();
    if (StringUtils.isEmpty(loginPanel.getUrl()) || StringUtils.isEmpty(loginPanel.getUsername())
            || StringUtils.isEmpty(loginPanel.getPassword())) {
        Messages.showErrorDialog(project, "Connection information provided is invalid.", "Invalid Settings");
        return;//www . ja va  2s .  c o m
    }
    TaskUtil.queueTask(project, PluginBundle.message(PluginBundle.CONNECTION_TEST_TITLE), true,
            new ThrowableFunction<ProgressIndicator, Void>() {
                @Override
                public Void throwableCall(ProgressIndicator params) throws Exception {
                    try {
                        params.setIndeterminate(true);
                        ReviewDataProvider.getInstance(project).testConnection(loginPanel.getUrl(),
                                loginPanel.getUsername(), loginPanel.getPassword());
                        // The task was not cancelled and is successful
                        connException.setValue(Boolean.TRUE);
                    } catch (InvalidConfigurationException a) {
                    } catch (final Exception exception) {
                        connException.setValue(exception);
                    }
                    return null;
                }
            }, null, null);

    if (connException.getValue() == Boolean.TRUE) {
        Messages.showInfoMessage(project, PluginBundle.message(PluginBundle.LOGIN_SUCCESS_MESSAGE),
                PluginBundle.message(PluginBundle.CONNECTION_STATUS_TITLE));
    } else if (connException.getValue() instanceof Exception) {
        final ExceptionHandler.Message message = ExceptionHandler
                .getMessage((Exception) connException.getValue());
        Messages.showErrorDialog(message.message, PluginBundle.message(PluginBundle.CONNECTION_STATUS_TITLE));
    }
}

From source file:com.ritesh.idea.plugin.ui.action.ShowReviewBoard.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    try {/*from  w ww. j  a  v  a2  s.co m*/
        final Project project = e.getProject();
        final IVcsDiffProvider vcsDiffProvider = VcsDiffProviderFactory.getVcsDiffProvider(project,
                ReviewDataProvider.getConfiguration(project));
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            public void run() {
                FileDocumentManager.getInstance().saveAllDocuments();
            }
        });
        if (vcsDiffProvider == null) {
            Notifications.Bus.notify(new Notification("ReviewBoard",
                    PluginBundle.message(PluginBundle.UNSUPPORTED_VCS_TITLE),
                    PluginBundle.message(PluginBundle.UNSUPPORTED_VCS_MESSAGE), NotificationType.WARNING));
            return;
        }
        if (vcsDiffProvider.isFromRevision(project, e) || Messages.showOkCancelDialog(project,
                "Upload all local changes?", "Confirmation", AllIcons.General.BalloonWarning) == Messages.OK) {
            TaskUtil.queueTask(project, "Generating diff", false,
                    new ThrowableFunction<ProgressIndicator, Object>() {
                        @Override
                        public Object throwableCall(ProgressIndicator params) throws Exception {
                            final String diffContent;
                            try {
                                diffContent = vcsDiffProvider.generateDiff(project, e);
                                ApplicationManager.getApplication().invokeLater(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (isEmpty(diffContent)) {
                                            Messages.showErrorDialog(project, "Cannot generate diff", "Error");
                                        } else {
                                            showCreateReviewPanel(project, diffContent);
                                        }
                                    }
                                });
                            } catch (Exception ex) {
                                ExceptionHandler.handleException(ex);
                            }
                            return null;
                        }
                    }, null, null);

        }
    } catch (Exception ex) {
        ExceptionHandler.handleException(ex);
    }
}

From source file:com.urswolfer.intellij.plugin.gerrit.rest.GerritUtil.java

License:Apache License

@SuppressWarnings("UnresolvedPropertyKey")
public boolean testGitExecutable(final Project project) {
    final GitVcsApplicationSettings settings = GitVcsApplicationSettings.getInstance();
    final String executable = settings.getPathToGit();
    final GitVersion version;
    try {/*from  www  .  j a va  2 s.c o  m*/
        version = GitVersion.identifyVersion(executable);
    } catch (Exception e) {
        Messages.showErrorDialog(project, e.getMessage(), GitBundle.getString("find.git.error.title"));
        return false;
    }

    if (!version.isSupported()) {
        Messages.showWarningDialog(project,
                GitBundle.message("find.git.unsupported.message", version.toString(), GitVersion.MIN),
                GitBundle.getString("find.git.success.title"));
        return false;
    }
    return true;
}

From source file:com.urswolfer.intellij.plugin.gerrit.ui.SettingsPanel.java

License:Apache License

public SettingsPanel() {
    gerritLoginInfoTextField.setText(LoginPanel.LOGIN_CREDENTIALS_INFO);
    gerritLoginInfoTextField.setBackground(pane.getBackground());
    testButton.addActionListener(new ActionListener() {
        @Override//from ww w.j a va  2s.  co m
        public void actionPerformed(ActionEvent e) {
            String password = isPasswordModified() ? getPassword() : gerritSettings.getPassword();
            try {
                GerritAuthData.Basic gerritAuthData = new GerritAuthData.Basic(getHost(), getLogin(), password);
                if (gerritUtil.checkCredentials(ProjectManager.getInstance().getDefaultProject(),
                        gerritAuthData)) {
                    Messages.showInfoMessage(pane, "Connection successful", "Success");
                } else {
                    Messages.showErrorDialog(pane, "Can't login to " + getHost() + " using given credentials",
                            "Login Failure");
                }
            } catch (Exception ex) {
                log.info(ex);
                Messages.showErrorDialog(pane, String.format("Can't login to %s: %s", getHost(),
                        gerritUtil.getErrorTextFromException(ex)), "Login Failure");
            }
            setPassword(password);
        }
    });

    hostTextField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            String text = hostTextField.getText();
            if (text.endsWith("/")) {
                hostTextField.setText(text.substring(0, text.length() - 1));
            }
        }
    });

    passwordField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            passwordModified = true;
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            passwordModified = true;
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            passwordModified = true;
        }
    });

    automaticRefreshCheckbox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateAutomaticRefresh();
        }
    });
}

From source file:consulo.devkit.action.GenerateIconsClassAction.java

License:Apache License

private static void addFile(final Module module, final String classQName) {
    final Project project = module.getProject();
    try {/*from   ww  w  . j  a v  a  2  s.  c o  m*/
        DirectoryIndex directoryIndex = DirectoryIndex.getInstance(module.getProject());

        ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

        VirtualFile[] contentFolderFiles = moduleRootManager.getContentFolderFiles(
                ContentFolderScopes.of(ProductionResourceContentFolderTypeProvider.getInstance()));

        List<VirtualFile> iconsDirs = ContainerUtil.map(contentFolderFiles,
                virtualFile -> virtualFile.findChild(ourIconsDirName));

        final List<VirtualFile> icons = new ArrayList<>();
        for (VirtualFile iconDir : iconsDirs) {
            VfsUtil.visitChildrenRecursively(iconDir, new VirtualFileVisitor() {
                @Override
                public boolean visitFile(@NotNull VirtualFile file) {
                    if ("png".equalsIgnoreCase(file.getExtension())) {
                        icons.add(file);
                    }
                    return super.visitFile(file);
                }
            });
        }

        MultiMap<String, VirtualFile> map = new MultiMap<>();

        for (VirtualFile iconFile : icons) {
            VirtualFile parentFile = iconFile.getParent();
            String packageName = directoryIndex.getPackageName(parentFile);

            assert packageName != null;
            if (packageName.length() == ourIconsDirName.length()) {
                map.putValue("", iconFile);
            } else {
                map.putValue(packageName.substring(ourIconsDirName.length() + 1, packageName.length()),
                        iconFile);
            }
        }

        QualifiedName p = QualifiedName.fromDottedString(classQName);

        final String packageName = p.getParent().toString();
        final String className = p.getLastComponent();

        IconClassBuilder iconClassBuilder = new IconClassBuilder(packageName, className);

        for (Map.Entry<String, Collection<VirtualFile>> entry : map.entrySet()) {
            String key = entry.getKey();
            QualifiedName qualifiedName = QualifiedName.fromDottedString(key);

            GenerateDirNode generateDirNode = iconClassBuilder.getOrCreate(qualifiedName);

            for (VirtualFile virtualFile : entry.getValue()) {
                generateDirNode.addIcon(key, virtualFile);
            }
        }

        String classText = iconClassBuilder.build().toString();

        String fileName = className + JavaFileType.DOT_DEFAULT_EXTENSION;
        final PsiFile psiFile = ApplicationManager.getApplication()
                .runReadAction((Computable<PsiFile>) () -> PsiFileFactory.getInstance(project)
                        .createFileFromText(fileName, JavaFileType.INSTANCE, classText));
        WriteCommandAction.runWriteCommandAction(project,
                (Runnable) () -> CodeStyleManager.getInstance(project).reformat(psiFile));

        contentFolderFiles = moduleRootManager.getContentFolderFiles(ContentFolderScopes.onlyProduction());

        if (contentFolderFiles.length == 0) {
            Messages.showErrorDialog(project, "No production directories", "Error");
            return;
        }

        VirtualFile directoryForAdd = contentFolderFiles[0];
        QualifiedName qualifiedName = QualifiedName.fromDottedString(packageName);
        for (final String part : qualifiedName.getComponents()) {
            final VirtualFile finalDirectoryForAdd = directoryForAdd;
            VirtualFile temp = finalDirectoryForAdd.findChild(part);

            if (temp == null || !temp.isDirectory()) {
                temp = WriteCommandAction.runWriteCommandAction(project,
                        (ThrowableComputable<VirtualFile, IOException>) () -> finalDirectoryForAdd
                                .createChildDirectory(null, part));
            }
            directoryForAdd = temp;
        }

        final VirtualFile temp = directoryForAdd;
        VirtualFile file = WriteCommandAction.runWriteCommandAction(project,
                (ThrowableComputable<VirtualFile, IOException>) () -> {
                    VirtualFile child = temp.findOrCreateChildData(null, psiFile.getName());

                    child.setBinaryContent(psiFile.getText().getBytes(CharsetToolkit.UTF8_CHARSET));
                    return child;
                });

        UIUtil.invokeLaterIfNeeded(() -> OpenFileAction.openFile(file, project));
    } catch (Throwable throwable) {
        UIUtil.invokeLaterIfNeeded(
                () -> Messages.showErrorDialog(project, ExceptionUtil.getThrowableText(throwable), "Error"));
    }
}

From source file:consulo.devkit.module.library.ConsuloPluginLibraryType.java

License:Apache License

@Nullable
@Override// w  ww  .  j  a  v  a  2s. c  o  m
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent jComponent,
        @Nullable VirtualFile virtualFile, @NotNull Project project) {
    DialogBuilder builder = new DialogBuilder();
    builder.title("Enter Plugin ID");
    ChoosePluginPanel centerPanel = new ChoosePluginPanel(project);
    builder.centerPanel(centerPanel);
    builder.setPreferredFocusComponent(centerPanel.getTextField());
    builder.dimensionKey("ConsuloPluginLibraryType#ChoosePluginPanel");

    if (!builder.showAndGet()) {
        return null;
    }

    IdeaPluginDescriptor pluginDescriptor = centerPanel.getPluginDescriptor();
    if (pluginDescriptor == null) {
        Messages.showErrorDialog(project, "Plugin is not found",
                ApplicationInfo.getInstance().getFullVersion());
        return null;
    }

    Ref<VirtualFile> libRef = Ref.create();

    String pluginId = pluginDescriptor.getPluginId().getIdString();

    new Task.Modal(project, "Downloading plugin: " + pluginDescriptor.getPluginId().getIdString(), false) {
        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            String url = RepositoryHelper.buildUrlForDownload(UpdateSettings.getInstance().getChannel(),
                    pluginId, null, true, false);

            try {
                File tempFile = FileUtil.createTempFile("download", "zip");

                HttpRequests.request(url).saveToFile(tempFile, progressIndicator);

                File depDir = new File(project.getBasePath(), DEP_LIBRARY);
                depDir.mkdir();

                ZipUtil.extract(tempFile, depDir, null);

                tempFile.delete();

                libRef.set(LocalFileSystem.getInstance()
                        .refreshAndFindFileByIoFile(new File(depDir, pluginId + "/lib")));
            } catch (IOException e) {
                //
            }
        }
    }.queue();

    VirtualFile libDirectory = libRef.get();
    if (libDirectory == null) {
        Messages.showErrorDialog(project, "Plugin directory is not found",
                ApplicationInfo.getInstance().getFullVersion());
        return null;
    }

    return new NewLibraryConfiguration(LIBRARY_PREFIX + pluginId, this, DummyLibraryProperties.INSTANCE) {
        @Override
        public void addRoots(@NotNull LibraryEditor libraryEditor) {
            for (VirtualFile file : libDirectory.getChildren()) {
                if (file.isDirectory()) {
                    continue;
                }
                VirtualFile localVirtualFileByPath = ArchiveVfsUtil.getArchiveRootForLocalFile(file);
                if (localVirtualFileByPath == null) {
                    continue;
                }
                libraryEditor.addRoot(localVirtualFileByPath, BinariesOrderRootType.getInstance());
            }
        }
    };
}