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

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

Introduction

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

Prototype

@NotNull
    public static Icon getWarningIcon() 

Source Link

Usage

From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesImpl.java

License:Apache License

private static boolean checkMovePackage(Project project, PsiJavaPackage aPackage) {
    final PsiDirectory[] directories = aPackage.getDirectories();
    final VirtualFile[] virtualFiles = aPackage.occursInPackagePrefixes();
    if (directories.length > 1 || virtualFiles.length > 0) {
        final StringBuffer message = new StringBuffer();
        RenameUtil.buildPackagePrefixChangedMessage(virtualFiles, message, aPackage.getQualifiedName());
        if (directories.length > 1) {
            DirectoryAsPackageRenameHandlerBase.buildMultipleDirectoriesInPackageMessage(message,
                    aPackage.getQualifiedName(), directories);
            message.append("\n\n");
            String report = RefactoringBundle.message(
                    "all.these.directories.will.be.moved.and.all.references.to.0.will.be.changed",
                    aPackage.getQualifiedName());
            message.append(report);//from ww w  .j  av  a 2  s .  c  om
        }
        message.append("\n");
        message.append(RefactoringBundle.message("do.you.wish.to.continue"));
        int ret = Messages.showYesNoDialog(project, message.toString(),
                RefactoringBundle.message("warning.title"), Messages.getWarningIcon());
        if (ret != 0) {
            return false;
        }
    }
    return true;
}

From source file:com.intellij.refactoring.rename.DirectoryAsPackageRenameHandlerBase.java

License:Apache License

private void doRename(PsiElement element, final Project project, PsiElement nameSuggestionContext,
        Editor editor) {//from www. ja  v a2  s  .  co m
    final PsiDirectory psiDirectory = (PsiDirectory) element;
    final T aPackage = getPackage(psiDirectory);
    final String qualifiedName = aPackage != null ? getQualifiedName(aPackage) : "";
    if (aPackage == null || qualifiedName.length() == 0/*default package*/
            || !isIdentifier(psiDirectory.getName(), project)) {
        PsiElementRenameHandler.rename(element, project, nameSuggestionContext, editor);
    } else {
        PsiDirectory[] directories = aPackage.getDirectories();
        final VirtualFile[] virtualFiles = occursInPackagePrefixes(aPackage);
        if (virtualFiles.length == 0 && directories.length == 1) {
            PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor);
        } else { // the directory corresponds to a package that has multiple associated directories
            final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            boolean inLib = false;
            for (PsiDirectory directory : directories) {
                inLib |= !projectFileIndex.isInContent(directory.getVirtualFile());
            }

            final PsiDirectory[] projectDirectories = aPackage
                    .getDirectories(GlobalSearchScope.projectScope(project));
            if (inLib) {
                final Module module = ModuleUtilCore.findModuleForPsiElement(psiDirectory);
                LOG.assertTrue(module != null);
                PsiDirectory[] moduleDirs = null;
                if (nameSuggestionContext instanceof PsiPackageBase) {
                    moduleDirs = aPackage.getDirectories(GlobalSearchScope.moduleScope(module));
                    if (moduleDirs.length <= 1) {
                        moduleDirs = null;
                    }
                }
                final String promptMessage = "Package \'" + aPackage.getName()
                        + "\' contains directories in libraries which cannot be renamed. Do you want to rename "
                        + (moduleDirs == null ? "current directory" : "current module directories");
                if (projectDirectories.length > 0) {
                    int ret = Messages.showYesNoCancelDialog(project,
                            promptMessage + " or all directories in project?",
                            RefactoringBundle.message("warning.title"),
                            RefactoringBundle.message("rename.current.directory"),
                            RefactoringBundle.message("rename.directories"), CommonBundle.getCancelButtonText(),
                            Messages.getWarningIcon());
                    if (ret == 2)
                        return;
                    renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage,
                            ret == 0 ? (moduleDirs == null ? new PsiDirectory[] { psiDirectory } : moduleDirs)
                                    : projectDirectories);
                } else {
                    if (Messages.showOkCancelDialog(project, promptMessage + "?",
                            RefactoringBundle.message("warning.title"),
                            Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) {
                        renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage,
                                psiDirectory);
                    }
                }
            } else {
                final StringBuffer message = new StringBuffer();
                RenameUtil.buildPackagePrefixChangedMessage(virtualFiles, message, qualifiedName);
                buildMultipleDirectoriesInPackageMessage(message, getQualifiedName(aPackage), directories);
                message.append(
                        RefactoringBundle.message("directories.and.all.references.to.package.will.be.renamed",
                                psiDirectory.getVirtualFile().getPresentableUrl()));
                int ret = Messages.showYesNoCancelDialog(project, message.toString(),
                        RefactoringBundle.message("warning.title"),
                        RefactoringBundle.message("rename.package.button.text"),
                        RefactoringBundle.message("rename.directory.button.text"),
                        CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                if (ret == 0) {
                    PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor);
                } else if (ret == 1) {
                    renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory);
                }
            }
        }
    }
}

From source file:com.intellij.refactoring.rename.PsiElementRenameHandler.java

License:Apache License

public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext,
        Editor editor) {//w ww  . j  a  v a2 s. c  o  m
    if (element != null && !canRename(project, editor, element)) {
        return;
    }

    if (nameSuggestionContext != null && !PsiManager.getInstance(project).isInProject(nameSuggestionContext)) {
        final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
        if (ApplicationManager.getApplication().isUnitTestMode())
            throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
        if (Messages.showYesNoDialog(project, message, RefactoringBundle.getCannotRefactorMessage(null),
                Messages.getWarningIcon()) != Messages.YES) {
            return;
        }
    }

    FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");

    rename(element, project, nameSuggestionContext, editor);
}

From source file:com.intellij.refactoring.typeMigration.TypeMigrationLabeler.java

License:Apache License

boolean addRoot(final TypeMigrationUsageInfo usageInfo, final PsiType type, final PsiElement place,
        boolean alreadyProcessed) {
    if (myShowWarning && myMigrationRoots.size() > 10
            && !ApplicationManager.getApplication().isUnitTestMode()) {
        myShowWarning = false;//  w  w w.j  a  v a 2s.  com
        try {
            final Runnable checkTimeToStopRunnable = new Runnable() {
                public void run() {
                    if (Messages.showYesNoCancelDialog(
                            "Found more than 10 roots to migrate. Do you want to preview?", "Type Migration",
                            Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) {
                        myException = new MigrateException();
                    }
                }
            };
            SwingUtilities.invokeLater(checkTimeToStopRunnable);
        } catch (Exception e) {
            //do nothing
        }
    }
    if (myException != null)
        throw myException;
    rememberRootTrace(usageInfo, type, place, alreadyProcessed);
    if (!alreadyProcessed && !getTypeEvaluator().setType(usageInfo, type)) {
        alreadyProcessed = true;
    }

    if (!alreadyProcessed)
        myMigrationRoots.addFirst(new Pair<TypeMigrationUsageInfo, PsiType>(usageInfo, type));
    return alreadyProcessed;
}

From source file:com.intellij.refactoring.util.duplicates.DuplicatesImpl.java

License:Apache License

private static boolean replaceMatch(final Project project, final MatchProvider provider, final Match match,
        @NotNull final Editor editor, final int idx, final int size, Ref<Boolean> showAll,
        final String confirmDuplicatePrompt, boolean skipPromptWhenOne) {
    final ArrayList<RangeHighlighter> highlighters = previewMatch(project, match, editor);
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        if ((!skipPromptWhenOne || size > 1) && (showAll.get() == null || !showAll.get())) {
            final String prompt = provider.getConfirmDuplicatePrompt(match);
            final ReplacePromptDialog promptDialog = new ReplacePromptDialog(false,
                    provider.getReplaceDuplicatesTitle(idx, size), project) {
                @Override/*from w  w  w.  ja v a 2 s  .c  o m*/
                protected String getMessage() {
                    final String message = super.getMessage();
                    return prompt != null ? message + prompt : message;
                }
            };
            promptDialog.show();
            final boolean allChosen = promptDialog.getExitCode() == FindManager.PromptResult.ALL;
            showAll.set(allChosen);
            if (allChosen && confirmDuplicatePrompt != null && prompt == null) {
                if (Messages.showOkCancelDialog(project,
                        "In order to replace all occurrences method signature will be changed. Proceed?",
                        CommonBundle.getWarningTitle(),
                        Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE)
                    return true;
            }
            if (promptDialog.getExitCode() == FindManager.PromptResult.SKIP)
                return false;
            if (promptDialog.getExitCode() == FindManager.PromptResult.CANCEL)
                return true;
        }
    }
    HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighters.get(0));

    new WriteCommandAction(project, MethodDuplicatesHandler.REFACTORING_NAME) {
        @Override
        protected void run(Result result) throws Throwable {
            try {
                provider.processMatch(match);
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
        }
    }.execute();

    return false;
}

From source file:com.intellij.tasks.actions.SwitchTaskAction.java

License:Apache License

public static void removeTask(final @Nonnull Project project, LocalTask task, TaskManager manager) {
    if (task.isDefault()) {
        Messages.showInfoMessage(project, "Default task cannot be removed", "Cannot Remove");
    } else {/*  w  w w.  ja v a  2s .  co m*/

        List<ChangeListInfo> infos = task.getChangeLists();
        List<LocalChangeList> lists = ContainerUtil.mapNotNull(infos,
                new NullableFunction<ChangeListInfo, LocalChangeList>() {
                    public LocalChangeList fun(ChangeListInfo changeListInfo) {
                        LocalChangeList changeList = ChangeListManager.getInstance(project)
                                .getChangeList(changeListInfo.id);
                        return changeList != null && !changeList.isDefault() ? changeList : null;
                    }
                });

        boolean removeIt = true;
        l: for (LocalChangeList list : lists) {
            if (!list.getChanges().isEmpty()) {
                int result = Messages.showYesNoCancelDialog(project,
                        "Changelist associated with '" + task.getSummary() + "' is not empty.\n"
                                + "Do you want to remove it and move the changes to the active changelist?",
                        "Changelist Not Empty", Messages.getWarningIcon());
                switch (result) {
                case 0:
                    break l;
                case 1:
                    removeIt = false;
                    break;
                default:
                    return;
                }
            }
        }
        if (removeIt) {
            for (LocalChangeList list : lists) {
                ChangeListManager.getInstance(project).removeChangeList(list);
            }
        }
        manager.removeTask(task);
    }
}

From source file:com.intellij.tools.BaseToolsPanel.java

License:Apache License

private void removeSelected() {
    CheckedTreeNode node = getSelectedToolNode();
    if (node != null) {
        int result = Messages.showYesNoDialog(this, ToolsBundle.message("tools.delete.confirmation"),
                CommonBundle.getWarningTitle(), Messages.getWarningIcon());
        if (result != 0) {
            return;
        }//from   w  ww. j a  va 2s  .  c o m
        myIsModified = true;
        if (node.getUserObject() instanceof Tool) {
            Tool tool = (Tool) node.getUserObject();
            CheckedTreeNode parentNode = (CheckedTreeNode) node.getParent();
            ((ToolsGroup) parentNode.getUserObject()).removeElement(tool);
            removeNodeFromParent(node);
            if (parentNode.getChildCount() == 0) {
                removeNodeFromParent(parentNode);
            }
        } else if (node.getUserObject() instanceof ToolsGroup) {
            removeNodeFromParent(node);
        }
        update();
        myTree.requestFocus();
    }
}

From source file:com.intellij.uiDesigner.propertyInspector.editors.string.StringEditorDialog.java

License:Apache License

@Nullable
public static String saveModifiedPropertyValue(final Module module, final StringDescriptor descriptor,
        final Locale locale, final String editedValue, final PsiFile formFile) {
    final PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
    final PropertiesFile propFile = manager.findPropertiesFile(module, descriptor.getDottedBundleName(),
            locale);/*  ww  w.ja v a2s.c  o m*/
    if (propFile != null) {
        final IProperty propertyByKey = propFile.findPropertyByKey(descriptor.getKey());
        if (propertyByKey instanceof Property && !editedValue.equals(propertyByKey.getValue())) {
            final Collection<PsiReference> references = findPropertyReferences((Property) propertyByKey,
                    module);

            String newKeyName = null;
            if (references.size() > 1) {
                final int rc = Messages.showYesNoCancelDialog(module.getProject(),
                        UIDesignerBundle.message("edit.text.multiple.usages", propertyByKey.getUnescapedKey(),
                                references.size()),
                        UIDesignerBundle.message("edit.text.multiple.usages.title"),
                        UIDesignerBundle.message("edit.text.change.all"),
                        UIDesignerBundle.message("edit.text.make.unique"), CommonBundle.getCancelButtonText(),
                        Messages.getWarningIcon());
                if (rc == 2) {
                    return null;
                }
                if (rc == 1) {
                    newKeyName = promptNewKeyName(module.getProject(), propFile, descriptor.getKey());
                    if (newKeyName == null)
                        return null;
                }
            }
            final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler
                    .getInstance(module.getProject()).ensureFilesWritable(propFile.getVirtualFile());
            if (operationStatus.hasReadonlyFiles()) {
                return null;
            }
            final String newKeyName1 = newKeyName;
            CommandProcessor.getInstance().executeCommand(module.getProject(), new Runnable() {
                public void run() {
                    UndoUtil.markPsiFileForUndo(formFile);
                    ApplicationManager.getApplication().runWriteAction(new Runnable() {
                        public void run() {
                            PsiDocumentManager.getInstance(module.getProject()).commitAllDocuments();
                            try {
                                if (newKeyName1 != null) {
                                    propFile.addProperty(newKeyName1, editedValue);
                                } else {
                                    final IProperty propertyByKey = propFile
                                            .findPropertyByKey(descriptor.getKey());
                                    if (propertyByKey != null) {
                                        propertyByKey.setValue(editedValue);
                                    }
                                }
                            } catch (IncorrectOperationException e) {
                                LOG.error(e);
                            }
                        }
                    });
                }
            }, UIDesignerBundle.message("command.update.property"), null);
            return newKeyName;
        }
    }
    return null;
}

From source file:com.intellij.usages.UsageLimitUtil.java

License:Apache License

@NotNull
public static Result showTooManyUsagesWarning(@NotNull final Project project, @NotNull final String message,
        @NotNull final UsageViewPresentation usageViewPresentation) {
    final String[] buttons = { UsageViewBundle.message("button.text.continue"),
            UsageViewBundle.message("button.text.abort") };
    int result = runOrInvokeAndWait(new Computable<Integer>() {
        @Override/*w ww .j  a  va  2 s.com*/
        public Integer compute() {
            String title = UsageViewBundle.message("find.excessive.usages.title",
                    StringUtil.capitalize(StringUtil.pluralize(usageViewPresentation.getUsagesWord())));
            return Messages.showOkCancelDialog(project, message, title, buttons[0], buttons[1],
                    Messages.getWarningIcon());
        }
    });
    return result == Messages.OK ? Result.CONTINUE : Result.ABORT;
}

From source file:com.intellij.util.net.HttpConfigurable.java

License:Apache License

@Deprecated
public void writeExternal(Element element) throws WriteExternalException {
    XmlSerializer.serializeInto(getState(), element);
    if (USE_PROXY_PAC && USE_HTTP_PROXY && !ApplicationManager.getApplication().isDisposed()) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override//ww w  .j  av  a 2  s.  co m
            public void run() {
                IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
                if (frame != null) {
                    USE_PROXY_PAC = false;
                    Messages.showMessageDialog(frame.getComponent(),
                            "Proxy: both 'use proxy' and 'autodetect proxy' settings were set."
                                    + "\nOnly one of these options should be selected.\nPlease re-configure.",
                            "Proxy Setup", Messages.getWarningIcon());
                    editConfigurable(frame.getComponent());
                }
            }
        }, ModalityState.NON_MODAL);
    }
}