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

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

Introduction

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

Prototype

@NotNull
    public static Icon getErrorIcon() 

Source Link

Usage

From source file:com.intellij.ide.fileTemplates.impl.FTManager.java

License:Apache License

/** Save template to file. If template is new, it is saved to specified directory. Otherwise it is saved to file from which it was read.
 *  If template was not modified, it is not saved.
 *  todo: review saving algorithm//  w ww  .  j  a  v a 2 s  . c  om
 */
private static void saveTemplate(File parentDir, FileTemplateBase template, final String lineSeparator)
        throws IOException {
    final File templateFile = new File(parentDir, template.getName() + "." + template.getExtension());

    FileOutputStream fileOutputStream;
    try {
        fileOutputStream = new FileOutputStream(templateFile);
    } catch (FileNotFoundException e) {
        // try to recover from the situation 'file exists, but is a directory'
        FileUtil.delete(templateFile);
        fileOutputStream = new FileOutputStream(templateFile);
    }
    OutputStreamWriter outputStreamWriter;
    try {
        outputStreamWriter = new OutputStreamWriter(fileOutputStream, CONTENT_ENCODING);
    } catch (UnsupportedEncodingException e) {
        Messages.showMessageDialog(IdeBundle.message("error.unable.to.save.file.template.using.encoding",
                template.getName(), CONTENT_ENCODING), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        outputStreamWriter = new OutputStreamWriter(fileOutputStream);
    }
    String content = template.getText();

    if (!lineSeparator.equals("\n")) {
        content = StringUtil.convertLineSeparators(content, lineSeparator);
    }

    outputStreamWriter.write(content);
    outputStreamWriter.close();
    fileOutputStream.close();
}

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.j  a  va2s. 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  ww  w .  j av  a 2  s  .co  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.plugins.PluginManagerMain.java

License:Apache License

/**
 * Start a new thread which downloads new list of plugins from the site in
 * the background and updates a list of plugins in the table.
 *///from  w  w w .  j  a v  a2 s.com
protected void loadPluginsFromHostInBackground() {
    setDownloadStatus(true);

    new SwingWorker() {
        List<IdeaPluginDescriptor> list = null;
        List<String> errorMessages = new ArrayList<String>();

        @Override
        public Object construct() {
            try {
                list = RepositoryHelper.loadPluginsFromRepository(null);
            } catch (Exception e) {
                LOG.info(e);
                errorMessages.add(e.getMessage());
            }
            for (String host : UpdateSettings.getInstance().getStoredPluginHosts()) {
                if (!acceptHost(host))
                    continue;
                final ArrayList<PluginDownloader> downloaded = new ArrayList<PluginDownloader>();
                try {
                    UpdateChecker.checkPluginsHost(host, downloaded, false, null);
                    for (PluginDownloader downloader : downloaded) {
                        final PluginNode pluginNode = PluginDownloader.createPluginNode(host, downloader);
                        if (pluginNode != null) {
                            if (list == null)
                                list = new ArrayList<IdeaPluginDescriptor>();
                            list.add(pluginNode);
                        }
                    }
                } catch (ProcessCanceledException ignore) {
                } catch (Exception e) {
                    LOG.info(e);
                    errorMessages.add(e.getMessage());
                }
            }
            return list;
        }

        @Override
        public void finished() {
            UIUtil.invokeLaterIfNeeded(new Runnable() {
                @Override
                public void run() {
                    setDownloadStatus(false);
                    if (list != null) {
                        modifyPluginsList(list);
                        propagateUpdates(list);
                    }
                    if (!errorMessages.isEmpty()) {
                        if (Messages.OK == Messages.showOkCancelDialog(
                                IdeBundle.message("error.list.of.plugins.was.not.loaded",
                                        StringUtil.join(errorMessages, ", ")),
                                IdeBundle.message("title.plugins"), CommonBundle.message("button.retry"),
                                CommonBundle.getCancelButtonText(), Messages.getErrorIcon())) {
                            loadPluginsFromHostInBackground();
                        }
                    }
                }
            });
        }
    }.start();
}

From source file:com.intellij.ide.ReopenProjectAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final int modifiers = e.getModifiers();
    final boolean forceOpenInNewFrame = (modifiers & InputEvent.CTRL_MASK) != 0
            || (modifiers & InputEvent.SHIFT_MASK) != 0;
    Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (!new File(myProjectPath).exists()) {
        if (Messages.showDialog(project, "The path " + FileUtil.toSystemDependentName(myProjectPath)
                + " does not exist.\n"
                + "If it is on a removable or network drive, please make sure that the drive is connected.",
                "Reopen Project", new String[] { "OK", "&Remove From List" }, 0,
                Messages.getErrorIcon()) == 1) {
            RecentProjectsManagerBase.getInstance().removePath(myProjectPath);
            ((WelcomeFrame) WelcomeFrame.getInstance()).getScreen().removeRecentProjectItem(this);
        }/*from w  w  w .j  a  v a2s  .  c o m*/
        return;
    }
    RecentProjectsManagerBase.getInstance().doOpenProject(myProjectPath, project, forceOpenInNewFrame);
}

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   www. j  a v a 2 s. c  om
    }
    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.ui.laf.LafManagerImpl.java

License:Apache License

/**
 * Sets current LAF. The method doesn't update component hierarchy.
 *///  ww w  .  j  a  v  a 2  s.c  o  m
@Override
public void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo) {
    if (findLaf(lookAndFeelInfo.getClassName()) == null) {
        LOG.error("unknown LookAndFeel : " + lookAndFeelInfo);
        return;
    }
    try {
        LookAndFeel laf = ((LookAndFeel) Class.forName(lookAndFeelInfo.getClassName()).newInstance());
        if (laf instanceof MetalLookAndFeel) {
            MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
        }

        boolean dark = laf instanceof BuildInLookAndFeel && ((BuildInLookAndFeel) laf).isDark();
        JBColor.setDark(dark);
        IconLoader.setUseDarkIcons(dark);
        fireUpdate();
        UIManager.setLookAndFeel(laf);
    } catch (Exception e) {
        Messages.showMessageDialog(
                IdeBundle.message("error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    }
    myCurrentLaf = lookAndFeelInfo;

    checkLookAndFeel(lookAndFeelInfo, false);
}

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  .j av a  2  s .  co  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);
}

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  . c  om*/
        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];
}