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.refactoring.introduceField.IntroduceConstantDialog.java

License:Apache License

protected void doOKAction() {
    final String targetClassName = getTargetClassName();
    PsiClass newClass = myParentClass;/*w w  w. j av  a2s  . c o m*/

    if (!"".equals(targetClassName) && !Comparing.strEqual(targetClassName, myParentClass.getQualifiedName())) {
        newClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassName,
                GlobalSearchScope.projectScope(myProject));
        if (newClass == null) {
            if (Messages.showOkCancelDialog(myProject,
                    RefactoringBundle.message("class.does.not.exist.in.the.project"),
                    IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != OK_EXIT_CODE) {
                return;
            }
            myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(targetClassName,
                    myParentClass);
        } else {
            myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(newClass);
        }
    }

    String fieldName = getEnteredName();
    String errorString = null;
    if ("".equals(fieldName)) {
        errorString = RefactoringBundle.message("no.field.name.specified");
    } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
        errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
    } else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) {
        errorString = RefactoringBundle.message("move.to.different.language",
                UsageViewUtil.getType(myParentClass), myParentClass.getQualifiedName(),
                newClass.getQualifiedName());
    }
    if (errorString != null) {
        CommonRefactoringUtil.showErrorMessage(IntroduceFieldHandler.REFACTORING_NAME, errorString,
                HelpID.INTRODUCE_FIELD, myProject);
        return;
    }
    if (newClass != null) {
        PsiField oldField = newClass.findFieldByName(fieldName, true);

        if (oldField != null) {
            int answer = Messages.showYesNoDialog(myProject,
                    RefactoringBundle.message("field.exists", fieldName,
                            oldField.getContainingClass().getQualifiedName()),
                    IntroduceFieldHandler.REFACTORING_NAME, Messages.getWarningIcon());
            if (answer != 0) {
                return;
            }
        }
    }

    JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getFieldVisibility();

    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, targetClassName);
    super.doOKAction();
}

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

License:Apache License

public boolean verifyValidPackageName() {
    String qName = myTargetPackage.getQualifiedName();
    if (!StringUtil.isEmpty(qName)) {
        PsiNameHelper helper = PsiNameHelper.getInstance(myProject);
        if (!helper.isQualifiedName(qName)) {
            Messages.showMessageDialog(myProject,
                    RefactoringBundle.message("invalid.target.package.name.specified"), "Invalid Package Name",
                    Messages.getErrorIcon());
            return false;
        }//  w ww  .  j  a  v a 2 s.  com
    }
    return true;
}

From source file:com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor.java

License:Apache License

@Override
protected void performRefactoring(UsageInfo[] usages) {
    // If files are being moved then I need to collect some information to delete these
    // filese from CVS. I need to know all common parents of the moved files and releative
    // paths./*from w  ww  .  ja va  2  s  . c o m*/

    // Move files with correction of references.

    try {

        final List<PsiFile> movedFiles = new ArrayList<PsiFile>();
        final Map<PsiElement, PsiElement> oldToNewMap = new HashMap<PsiElement, PsiElement>();
        for (final PsiElement element : myElementsToMove) {
            final RefactoringElementListener elementListener = getTransaction().getElementListener(element);

            if (element instanceof PsiDirectory) {
                MoveFilesOrDirectoriesUtil.doMoveDirectory((PsiDirectory) element, myNewParent);
                for (PsiElement psiElement : element.getChildren()) {
                    processDirectoryFiles(movedFiles, oldToNewMap, psiElement);
                }
            } else if (element instanceof PsiFile) {
                final PsiFile movedFile = (PsiFile) element;
                FileReferenceContextUtil.encodeFileReferences(element);
                MoveFileHandler.forElement(movedFile).prepareMovedFile(movedFile, myNewParent, oldToNewMap);

                PsiFile moving = myNewParent.findFile(movedFile.getName());
                if (moving == null) {
                    MoveFilesOrDirectoriesUtil.doMoveFile(movedFile, myNewParent);
                }
                moving = myNewParent.findFile(movedFile.getName());
                movedFiles.add(moving);
            }

            elementListener.elementMoved(element);
        }
        // sort by offset descending to process correctly several usages in one PsiElement [IDEADEV-33013]
        Arrays.sort(usages, new Comparator<UsageInfo>() {
            @Override
            public int compare(final UsageInfo o1, final UsageInfo o2) {
                return o1.getElement() == o2.getElement()
                        ? o2.getRangeInElement().getStartOffset() - o1.getRangeInElement().getStartOffset()
                        : 0;
            }
        });

        // fix references in moved files to outer files
        for (PsiFile movedFile : movedFiles) {
            MoveFileHandler.forElement(movedFile).updateMovedFile(movedFile);
            FileReferenceContextUtil.decodeFileReferences(movedFile);
        }

        retargetUsages(usages, oldToNewMap);

        // Perform CVS "add", "remove" commands on moved files.

        if (myMoveCallback != null) {
            myMoveCallback.refactoringCompleted();
        }

    } catch (IncorrectOperationException e) {
        @NonNls
        final String message = e.getMessage();
        final int index = message != null ? message.indexOf("java.io.IOException") : -1;
        if (index >= 0) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    Messages.showMessageDialog(myProject,
                            message.substring(index + "java.io.IOException".length()),
                            RefactoringBundle.message("error.title"), Messages.getErrorIcon());
                }
            });
        } else {
            LOG.error(e);
        }
    }
}

From source file:com.intellij.refactoring.move.moveInstanceMethod.MoveInstanceMethodHandler.java

License:Apache License

public void invoke(@NotNull final Project project, @NotNull final PsiElement[] elements,
        final DataContext dataContext) {
    if (elements.length != 1 || !(elements[0] instanceof PsiMethod))
        return;//from   w  w  w .j  ava2  s. com
    final PsiMethod method = (PsiMethod) elements[0];
    String message = null;
    if (!method.getManager().isInProject(method)) {
        message = "Move method is not supported for non-project methods";
    } else if (method.isConstructor()) {
        message = RefactoringBundle.message("move.method.is.not.supported.for.constructors");
    } else if (method.getLanguage() != JavaLanguage.INSTANCE) {
        message = RefactoringBundle.message("move.method.is.not.supported.for.0",
                method.getLanguage().getDisplayName());
    } else {
        final PsiClass containingClass = method.getContainingClass();
        if (containingClass != null && PsiUtil.typeParametersIterator(containingClass).hasNext()
                && TypeParametersSearcher.hasTypeParameters(method)) {
            message = RefactoringBundle.message("move.method.is.not.supported.for.generic.classes");
        } else if (method.findSuperMethods().length > 0
                || OverridingMethodsSearch.search(method, true).toArray(PsiMethod.EMPTY_ARRAY).length > 0) {
            message = RefactoringBundle
                    .message("move.method.is.not.supported.when.method.is.part.of.inheritance.hierarchy");
        } else {
            final Set<PsiClass> classes = MoveInstanceMembersUtil.getThisClassesToMembers(method).keySet();
            for (PsiClass aClass : classes) {
                /* if (aClass instanceof JspClass) {
                   message = RefactoringBundle.message("synthetic.jsp.class.is.referenced.in.the.method");
                   Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
                   CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MOVE_INSTANCE_METHOD);
                   break;
                 }  */
            }
        }
    }
    if (message != null) {
        showErrorHint(project, dataContext, message);
        return;
    }

    final List<PsiVariable> suitableVariables = new ArrayList<PsiVariable>();
    message = collectSuitableVariables(method, suitableVariables);
    if (message != null) {
        final String unableToMakeStaticMessage = MakeStaticHandler.validateTarget(method);
        if (unableToMakeStaticMessage != null) {
            showErrorHint(project, dataContext, message);
        } else {
            final String suggestToMakeStaticMessage = "Would you like to make method \'" + method.getName()
                    + "\' static and then move?";
            if (Messages.showYesNoCancelDialog(project, message + ". " + suggestToMakeStaticMessage,
                    REFACTORING_NAME, Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                MakeStaticHandler.invoke(method);
            }
        }
        return;
    }

    new MoveInstanceMethodDialog(method, suitableVariables.toArray(new PsiVariable[suitableVariables.size()]))
            .show();
}

From source file:com.intellij.refactoring.rename.inplace.InplaceRefactoring.java

License:Apache License

public static void unableToStartWarning(Project project, Editor editor) {
    final StartMarkAction startMarkAction = StartMarkAction.canStart(project);
    final String message = startMarkAction.getCommandName() + " is not finished yet.";
    final Document oldDocument = startMarkAction.getDocument();
    if (editor == null || oldDocument != editor.getDocument()) {
        final int exitCode = Messages.showYesNoDialog(project, message,
                RefactoringBundle.getCannotRefactorMessage(null), "Continue Started", "Cancel Started",
                Messages.getErrorIcon());
        navigateToStarted(oldDocument, project, exitCode);
    } else {//from  w w w  .j av a 2  s  .  c o  m
        CommonRefactoringUtil.showErrorHint(project, editor, message,
                RefactoringBundle.getCannotRefactorMessage(null), null);
    }
}

From source file:com.intellij.refactoring.rename.inplace.InplaceRefactoring.java

License:Apache License

protected boolean buildTemplateAndStart(final Collection<PsiReference> refs,
        final Collection<Pair<PsiElement, TextRange>> stringUsages, final PsiElement scope,
        final PsiFile containingFile) {
    final PsiElement context = InjectedLanguageManager.getInstance(containingFile.getProject())
            .getInjectionHost(containingFile);
    myScope = context != null ? context.getContainingFile() : scope;
    final TemplateBuilderImpl builder = new TemplateBuilderImpl(myScope);

    PsiElement nameIdentifier = getNameIdentifier();
    int offset = myEditor.getCaretModel().getOffset();
    PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, stringUsages, offset);

    boolean subrefOnPrimaryElement = false;
    boolean hasReferenceOnNameIdentifier = false;
    for (PsiReference ref : refs) {
        if (isReferenceAtCaret(selectedElement, ref)) {
            builder.replaceElement(ref, PRIMARY_VARIABLE_NAME, createLookupExpression(selectedElement), true);
            subrefOnPrimaryElement = true;
            continue;
        }//from  ww  w.j  a  v  a 2s.c  o m
        addVariable(ref, selectedElement, builder, offset);
        hasReferenceOnNameIdentifier |= isReferenceAtCaret(nameIdentifier, ref);
    }
    if (nameIdentifier != null) {
        hasReferenceOnNameIdentifier |= selectedElement.getTextRange().contains(nameIdentifier.getTextRange());
        if (!subrefOnPrimaryElement || !hasReferenceOnNameIdentifier) {
            addVariable(nameIdentifier, selectedElement, builder);
        }
    }
    for (Pair<PsiElement, TextRange> usage : stringUsages) {
        addVariable(usage.first, usage.second, selectedElement, builder);
    }
    addAdditionalVariables(builder);
    try {
        myMarkAction = startRename();
    } catch (final StartMarkAction.AlreadyStartedException e) {
        final Document oldDocument = e.getDocument();
        if (oldDocument != myEditor.getDocument()) {
            final int exitCode = Messages.showYesNoCancelDialog(myProject, e.getMessage(), getCommandName(),
                    "Navigate to Started", "Cancel Started", "Cancel", Messages.getErrorIcon());
            if (exitCode == Messages.CANCEL)
                return true;
            navigateToAlreadyStarted(oldDocument, exitCode);
            return true;
        } else {

            if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) {
                ourRenamersStack.pop();
                if (!ourRenamersStack.empty()) {
                    myOldName = ourRenamersStack.peek().myOldName;
                }
            }

            revertState();
            final TemplateState templateState = TemplateManagerImpl
                    .getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
            if (templateState != null) {
                templateState.gotoEnd(true);
            }
        }
        return false;
    }

    beforeTemplateStart();

    new WriteCommandAction(myProject, getCommandName()) {
        @Override
        protected void run(com.intellij.openapi.application.Result result) throws Throwable {
            startTemplate(builder);
        }
    }.execute();

    if (myBalloon == null) {
        showBalloon();
    }
    return true;
}

From source file:com.intellij.refactoring.util.RefactoringUIUtil.java

License:Apache License

public static void processIncorrectOperation(final Project project, IncorrectOperationException e) {
    @NonNls//from  www  . j a v  a 2s  .  co m
    String message = e.getMessage();
    final int index = message != null ? message.indexOf("java.io.IOException") : -1;
    if (index > 0) {
        message = message.substring(index + "java.io.IOException".length());
    }

    final String s = message;
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            Messages.showMessageDialog(project, s, RefactoringBundle.message("error.title"),
                    Messages.getErrorIcon());
        }
    });
}

From source file:com.intellij.testIntegration.createTest.CreateTestDialog.java

License:Apache License

protected void doOKAction() {
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, myTargetPackageField.getText());
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_SUPERS_KEY, mySuperClassField.getText());

    String errorMessage;/*from w ww .jav  a2  s . co  m*/
    try {
        myTargetDirectory = selectTargetDirectory();
        if (myTargetDirectory == null)
            return;
        errorMessage = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName());
    } catch (IncorrectOperationException e) {
        errorMessage = e.getMessage();
    }

    if (errorMessage != null) {
        Messages.showMessageDialog(myProject, errorMessage, CommonBundle.getErrorTitle(),
                Messages.getErrorIcon());
    }

    saveDefaultLibraryName();
    saveShowInheritedMembersStatus();
    super.doOKAction();
}

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

License:Apache License

@Override
protected void doOKAction() {
    String errorMessage = null;//from w ww  . ja v a  2s. c om
    if (noText(myNameField.getText())) {
        errorMessage = ToolsBundle.message("tools.filters.add.name.required.error");
    } else if (noText(myRegexpField.getText())) {
        errorMessage = ToolsBundle.message("tools.filters.add.regex.required.error");
    }

    if (errorMessage != null) {
        Messages.showMessageDialog(getContentPane(), errorMessage, CommonBundle.getErrorTitle(),
                Messages.getErrorIcon());
        return;
    }

    try {
        checkRegexp(myRegexpField.getText());
    } catch (InvalidExpressionException e) {
        Messages.showMessageDialog(getContentPane(), e.getMessage(),
                ToolsBundle.message("tools.filters.add.regex.invalid.title"), Messages.getErrorIcon());
        return;
    }
    super.doOKAction();
}

From source file:com.intellij.uiDesigner.actions.GenerateMainAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final Editor editor = e.getData(PlatformDataKeys.EDITOR);
    assert editor != null;
    final int offset = editor.getCaretModel().getOffset();
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    PsiClass psiClass = PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiClass.class);
    assert psiClass != null;

    if (!PsiUtil.hasDefaultConstructor(psiClass)) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("generate.main.no.default.constructor"),
                UIDesignerBundle.message("generate.main.title"), Messages.getErrorIcon());
        return;//from  www.  ja  v  a  2  s . com
    }

    final List<PsiFile> boundForms = FormClassIndex.findFormsBoundToClass(project, psiClass.getQualifiedName());
    final LwRootContainer rootContainer;
    try {
        rootContainer = Utils.getRootContainer(boundForms.get(0).getText(), null);
    } catch (AlienFormFileException ex) {
        Messages.showMessageDialog(project, "The form bound to the class is not a valid IntelliJ IDEA form",
                UIDesignerBundle.message("generate.main.title"), Messages.getErrorIcon());
        return;
    } catch (Exception ex) {
        LOG.error(ex);
        return;
    }

    if (rootContainer.getComponentCount() == 0) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("generate.main.empty.form"),
                UIDesignerBundle.message("generate.main.title"), Messages.getErrorIcon());
        return;
    }
    String rootBinding = rootContainer.getComponent(0).getBinding();
    if (rootBinding == null || psiClass.findFieldByName(rootBinding, true) == null) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("generate.main.no.root.binding"),
                UIDesignerBundle.message("generate.main.title"), Messages.getErrorIcon());
        return;
    }

    @NonNls
    final StringBuilder mainBuilder = new StringBuilder("public static void main(String[] args) { ");
    final JavaCodeStyleManager csm = JavaCodeStyleManager.getInstance(project);
    SuggestedNameInfo nameInfo = csm.suggestVariableName(VariableKind.LOCAL_VARIABLE, "frame", null, null);
    String varName = nameInfo.names[0];
    mainBuilder.append(JFrame.class.getName()).append(" ").append(varName).append("= new ")
            .append(JFrame.class.getName());
    mainBuilder.append("(\"").append(psiClass.getName()).append("\");");
    mainBuilder.append(varName).append(".setContentPane(new ").append(psiClass.getQualifiedName()).append("().")
            .append(rootBinding).append(");");
    mainBuilder.append(varName).append(".setDefaultCloseOperation(").append(JFrame.class.getName())
            .append(".EXIT_ON_CLOSE);");
    mainBuilder.append(varName).append(".pack();");
    mainBuilder.append(varName).append(".setVisible(true);");

    mainBuilder.append("}\n");

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                public void run() {
                    try {
                        PsiMethod method = JavaPsiFacade.getInstance(file.getProject()).getElementFactory()
                                .createMethodFromText(mainBuilder.toString(), file);
                        List<PsiGenerationInfo<PsiMethod>> infos = Collections
                                .singletonList(new PsiGenerationInfo<PsiMethod>(method));
                        List<PsiGenerationInfo<PsiMethod>> resultMembers = GenerateMembersUtil
                                .insertMembersAtOffset(file, offset, infos);
                        resultMembers.get(0).positionCaret(editor, false);
                    } catch (IncorrectOperationException e1) {
                        LOG.error(e1);
                    }
                }
            });
        }
    }, null, null);
}