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.util.ExportToFileUtil.java

License:Apache License

public static void exportTextToFile(Project project, String fileName, String textToExport) {
    String prepend = "";
    File file = new File(fileName);
    if (file.exists()) {
        int result = Messages.showYesNoCancelDialog(project,
                IdeBundle.message("error.text.file.already.exists", fileName),
                IdeBundle.message("title.warning"), IdeBundle.message("action.overwrite"),
                IdeBundle.message("action.append"), CommonBundle.getCancelButtonText(),
                Messages.getWarningIcon());

        if (result != 1 && result != 0) {
            return;
        }//from w w w  .  j  a va 2s . c o  m
        if (result == 1) {
            char[] buf = new char[(int) file.length()];
            try {
                FileReader reader = new FileReader(fileName);
                try {
                    reader.read(buf, 0, (int) file.length());
                    prepend = new String(buf) + SystemProperties.getLineSeparator();
                } finally {
                    reader.close();
                }
            } catch (IOException e) {
            }
        }
    }

    try {
        FileWriter writer = new FileWriter(fileName);
        try {
            writer.write(prepend + textToExport);
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        Messages.showMessageDialog(project, IdeBundle.message("error.writing.to.file", fileName),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
}

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

License:Apache License

private void createNewPackage() {
    final PsiJavaPackage selectedPackage = getTreeSelection();
    if (selectedPackage == null)
        return;/*from  w w w  .  ja va2 s  .c  o m*/

    final String newPackageName = Messages.showInputDialog(myProject,
            IdeBundle.message("prompt.enter.a.new.package.name"), IdeBundle.message("title.new.package"),
            Messages.getQuestionIcon(), "", new InputValidator() {
                public boolean checkInput(final String inputString) {
                    return inputString != null && inputString.length() > 0;
                }

                public boolean canClose(final String inputString) {
                    return checkInput(inputString);
                }
            });
    if (newPackageName == null)
        return;

    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
            final Runnable action = new Runnable() {
                public void run() {

                    try {
                        String newQualifiedName = selectedPackage.getQualifiedName();
                        if (!Comparing.strEqual(newQualifiedName, ""))
                            newQualifiedName += ".";
                        newQualifiedName += newPackageName;
                        final PsiDirectory dir = PackageUtil.findOrCreateDirectoryForPackage(myProject,
                                newQualifiedName, null, false);
                        if (dir == null)
                            return;
                        final PsiJavaPackage newPackage = JavaDirectoryService.getInstance().getPackage(dir);

                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) myTree.getSelectionPath()
                                .getLastPathComponent();
                        final DefaultMutableTreeNode newChild = new DefaultMutableTreeNode();
                        newChild.setUserObject(newPackage);
                        node.add(newChild);

                        final DefaultTreeModel model = (DefaultTreeModel) myTree.getModel();
                        model.nodeStructureChanged(node);

                        final TreePath selectionPath = myTree.getSelectionPath();
                        TreePath path;
                        if (selectionPath == null) {
                            path = new TreePath(newChild.getPath());
                        } else {
                            path = selectionPath.pathByAddingChild(newChild);
                        }
                        myTree.setSelectionPath(path);
                        myTree.scrollPathToVisible(path);
                        myTree.expandPath(path);

                    } catch (IncorrectOperationException e) {
                        Messages.showMessageDialog(getContentPane(), StringUtil.getMessage(e),
                                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                        if (LOG.isDebugEnabled()) {
                            LOG.debug(e);
                        }
                    }
                }
            };
            ApplicationManager.getApplication().runReadAction(action);
        }
    }, IdeBundle.message("command.create.new.package"), null);
}

From source file:com.intellij.ide.util.projectWizard.ExistingModuleLoader.java

License:Apache License

public boolean validate(final Project current, final Project dest) {
    if (getName() == null)
        return false;
    String moduleFilePath = getModuleDirPath();
    if (moduleFilePath == null)
        return false;
    final File file = new File(moduleFilePath);
    if (file.exists()) {
        try {/*from   www .  j  a  v  a2 s. co  m*/
            final ConversionResult result = ConversionService.getInstance().convertModule(dest, file);
            if (result.openingIsCanceled()) {
                return false;
            }
            final Document document = JDOMUtil.loadDocument(file);
            final Element root = document.getRootElement();
            final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
            final Set<String> definedMacros = PathMacros.getInstance().getAllMacroNames();
            usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$");
            usedMacros.removeAll(definedMacros);

            if (usedMacros.size() > 0) {
                final boolean ok = ProjectMacrosUtil.showMacrosConfigurationDialog(current, usedMacros);
                if (!ok) {
                    return false;
                }
            }
        } catch (JDOMException e) {
            Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"),
                    Messages.getErrorIcon());
            return false;
        } catch (IOException e) {
            Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"),
                    Messages.getErrorIcon());
            return false;
        }
    } else {
        Messages.showErrorDialog(current, IdeBundle.message("title.module.file.does.not.exist", moduleFilePath),
                CommonBundle.message("title.error"));
        return false;
    }
    return true;
}

From source file:com.intellij.ide.util.scopeChooser.EditScopesDialog.java

License:Apache License

@Override
protected void doOKAction() {
    final Object selectedObject = ((ScopeChooserConfigurable) getConfigurable()).getSelectedObject();
    if (selectedObject instanceof NamedScope) {
        mySelectedScope = (NamedScope) selectedObject;
    }/* w  ww .j  ava  2  s . c o m*/
    super.doOKAction();
    if (myCheckShared && mySelectedScope != null) {
        final Project project = getProject();
        final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
        NamedScope scope = manager.getScope(mySelectedScope.getName());
        if (scope == null) {
            if (Messages.showYesNoDialog(IdeBundle.message("scope.unable.to.save.scope.message"),
                    IdeBundle.message("scope.unable.to.save.scope.title"),
                    Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                final String newName = Messages.showInputDialog(project,
                        IdeBundle.message("add.scope.name.label"),
                        IdeBundle.message("scopes.save.dialog.title.shared"), Messages.getQuestionIcon(),
                        mySelectedScope.getName(), new InputValidator() {
                            @Override
                            public boolean checkInput(String inputString) {
                                return inputString != null && inputString.length() > 0
                                        && manager.getScope(inputString) == null;
                            }

                            @Override
                            public boolean canClose(String inputString) {
                                return checkInput(inputString);
                            }
                        });
                if (newName != null) {
                    final PackageSet packageSet = mySelectedScope.getValue();
                    scope = new NamedScope(newName, packageSet != null ? packageSet.createCopy() : null);
                    mySelectedScope = scope;
                    manager.addScope(mySelectedScope);
                }
            }
        }
    }
}

From source file:com.intellij.internal.psiView.PsiViewerDialog.java

License:Apache License

private PsiElement parseText(String text) {
    final Object source = getSource();
    try {//from   w w  w .  j a  v a2  s .c o  m
        if (source instanceof PsiViewerExtension) {
            return ((PsiViewerExtension) source).createElement(myProject, text);
        }
        if (source instanceof FileType) {
            final FileType type = (FileType) source;
            String ext = type.getDefaultExtension();
            if (myExtensionComboBox.isVisible()) {
                ext = myExtensionComboBox.getSelectedItem().toString().toLowerCase();
            }
            if (type instanceof LanguageFileType) {
                final Language language = ((LanguageFileType) type).getLanguage();
                final LanguageVersion languageVersion = (LanguageVersion) myDialectComboBox.getSelectedItem();
                return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, language,
                        languageVersion, text);
            }
            return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, type, text);
        }
    } catch (IncorrectOperationException e) {
        Messages.showMessageDialog(myProject, e.getMessage(), "Error", Messages.getErrorIcon());
    }
    return null;
}

From source file:com.intellij.profile.codeInspection.ui.ProfilesComboBox.java

License:Apache License

public void createProfilesCombo(final Profile selectedProfile, final Set<Profile> availableProfiles,
        final ProfileManager profileManager) {
    reloadProfiles(profileManager, availableProfiles, selectedProfile);

    setRenderer(new DefaultListCellRenderer() {
        @Override/*from  ww  w  . j  av a 2 s  .  c o  m*/
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            final Component rendererComponent = super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);
            if (value instanceof Profile) {
                final Profile profile = (Profile) value;
                setText(profile.getName());
                setIcon(profile.isLocal() ? AllIcons.General.Settings : AllIcons.General.ProjectSettings);
            } else if (value instanceof String) {
                setText((String) value);
            }
            return rendererComponent;
        }
    });
    addItemListener(new ItemListener() {
        private Object myDeselectedItem = null;

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (myFrozenProfilesCombo)
                return; //do not update during reloading
            if (ItemEvent.SELECTED == e.getStateChange()) {
                final Object item = e.getItem();
                if (profileManager instanceof ProjectProfileManager && item instanceof Profile
                        && ((Profile) item).isLocal()) {
                    if (Messages.showOkCancelDialog(
                            InspectionsBundle.message("inspection.new.profile.ide.to.project.warning.message"),
                            InspectionsBundle.message("inspection.new.profile.ide.to.project.warning.title"),
                            Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                        final String newName = Messages.showInputDialog(
                                InspectionsBundle.message("inspection.new.profile.text"),
                                InspectionsBundle.message("inspection.new.profile.dialog.title"),
                                Messages.getInformationIcon());
                        final Object selectedItem = getSelectedItem();
                        if (newName != null && newName.length() > 0 && selectedItem instanceof Profile) {
                            if (ArrayUtil.find(profileManager.getAvailableProfileNames(), newName) == -1
                                    && ArrayUtil.find(
                                            InspectionProfileManager.getInstance().getAvailableProfileNames(),
                                            newName) == -1) {
                                saveNewProjectProfile(newName, (Profile) selectedItem, profileManager);
                                return;
                            } else {
                                Messages.showErrorDialog(
                                        InspectionsBundle.message("inspection.unable.to.create.profile.message",
                                                newName),
                                        InspectionsBundle
                                                .message("inspection.unable.to.create.profile.dialog.title"));
                            }
                        }
                    }
                    setSelectedItem(myDeselectedItem);
                }
            } else {
                myDeselectedItem = e.getItem();
            }
        }
    });
}

From source file:com.intellij.psi.statistics.impl.StatisticsManagerImpl.java

License:Apache License

private void saveUnit(int unitNumber) {
    if (!createStoreFolder())
        return;/*from   w  w  w .j a va2 s  .  c o m*/
    StatisticsUnit unit = getUnit(unitNumber);
    String path = getPathToUnit(unitNumber);
    try {
        OutputStream out = new BufferedOutputStream(new FileOutputStream(path));
        out = new ScrambledOutputStream(out);
        try {
            unit.write(out);
        } finally {
            out.close();
        }
    } catch (IOException e) {
        Messages.showMessageDialog(IdeBundle.message("error.saving.statistics", e.getLocalizedMessage()),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    }
}

From source file:com.intellij.psi.statistics.impl.StatisticsManagerImpl.java

License:Apache License

private static boolean createStoreFolder() {
    File homeFile = new File(STORE_PATH);
    if (!homeFile.exists()) {
        if (!homeFile.mkdirs()) {
            Messages.showMessageDialog(// w  w w  .ja  va 2s  . c o m
                    IdeBundle.message("error.saving.statistic.failed.to.create.folder", STORE_PATH),
                    CommonBundle.getErrorTitle(), Messages.getErrorIcon());
            return false;
        }
    }
    return true;
}

From source file:com.intellij.refactoring.copy.CopyClassDialog.java

License:Apache License

protected void doOKAction() {
    final String packageName = myTfPackage.getText();
    final String className = getClassName();

    final String[] errorString = new String[1];
    final PsiManager manager = PsiManager.getInstance(myProject);
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(manager.getProject());
    if (packageName.length() > 0 && !nameHelper.isQualifiedName(packageName)) {
        errorString[0] = RefactoringBundle.message("invalid.target.package.name.specified");
    } else if (className != null && className.isEmpty()) {
        errorString[0] = RefactoringBundle.message("no.class.name.specified");
    } else {//  w  ww  .  ja v  a  2  s.  co m
        if (!nameHelper.isIdentifier(className)) {
            errorString[0] = RefactoringMessageUtil.getIncorrectIdentifierMessage(className);
        } else if (!myDoClone) {
            try {
                final PackageWrapper targetPackage = new PackageWrapper(manager, packageName);
                myDestination = myDestinationCB.selectDirectory(targetPackage, false);
                if (myDestination == null)
                    return;
            } catch (IncorrectOperationException e) {
                errorString[0] = e.getMessage();
            }
        }
        RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    }

    if (errorString[0] != null) {
        if (errorString[0].length() > 0) {
            Messages.showMessageDialog(myProject, errorString[0], RefactoringBundle.message("error.title"),
                    Messages.getErrorIcon());
        }
        myNameField.requestFocusInWindow();
        return;
    }
    super.doOKAction();
}

From source file:com.intellij.refactoring.copy.CopyClassesHandler.java

License:Apache License

private static void copyClassesImpl(final String copyClassName, final Project project,
        final Map<PsiFile, PsiClass[]> classes, final HashMap<PsiFile, String> map,
        final Object targetDirectory, final PsiDirectory defaultTargetDirectory, final String commandName,
        final boolean selectInActivePanel) {
    final boolean[] result = new boolean[] { false };
    Runnable command = new Runnable() {
        public void run() {
            final Runnable action = new Runnable() {
                public void run() {
                    try {
                        PsiDirectory target;
                        if (targetDirectory instanceof PsiDirectory) {
                            target = (PsiDirectory) targetDirectory;
                        } else {
                            target = ((MoveDestination) targetDirectory)
                                    .getTargetDirectory(defaultTargetDirectory);
                        }//  w ww.java  2 s .c o  m
                        PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project);
                        if (newElement != null) {
                            CopyHandler.updateSelectionInActiveProjectView(newElement, project,
                                    selectInActivePanel);
                            EditorHelper.openInEditor(newElement);

                            result[0] = true;
                        }
                    } catch (final IncorrectOperationException ex) {
                        ApplicationManager.getApplication().invokeLater(new Runnable() {
                            public void run() {
                                Messages.showMessageDialog(project, ex.getMessage(),
                                        RefactoringBundle.message("error.title"), Messages.getErrorIcon());
                            }
                        });
                    }
                }
            };
            ApplicationManager.getApplication().runWriteAction(action);
        }
    };
    CommandProcessor processor = CommandProcessor.getInstance();
    processor.executeCommand(project, command, commandName, null);

    if (result[0]) {
        ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
            public void run() {
                ToolWindowManager.getInstance(project).activateEditorComponent();
            }
        });
    }
}