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

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

Introduction

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

Prototype

@NotNull
    public static Icon getQuestionIcon() 

Source Link

Usage

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

License:Apache License

public static int askWhetherShouldAnnotateBaseMethod(@NotNull PsiMethod method,
        @NotNull PsiMethod superMethod) {
    String implement = !method.hasModifierProperty(PsiModifier.ABSTRACT)
            && superMethod.hasModifierProperty(PsiModifier.ABSTRACT)
                    ? InspectionsBundle.message("inspection.annotate.quickfix.implements")
                    : InspectionsBundle.message("inspection.annotate.quickfix.overrides");
    String message = InspectionsBundle.message("inspection.annotate.quickfix.overridden.method.messages",
            DescriptiveNameUtil.getDescriptiveName(method), implement,
            DescriptiveNameUtil.getDescriptiveName(superMethod));
    String title = InspectionsBundle.message("inspection.annotate.quickfix.overridden.method.warning");
    return Messages.showYesNoCancelDialog(method.getProject(), message, title, Messages.getQuestionIcon());

}

From source file:com.intellij.internal.validation.TestMacMessagesAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    new DialogWrapper(e.getProject()) {
        {//from w w w .j av  a2s . co m
            setSize(500, 500);
            setTitle("Dialog 1");
            init();
        }

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            final JButton button = new JButton("Click me");
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent event) {
                    new DialogWrapper(e.getProject()) {
                        {
                            setSize(400, 400);
                            setTitle("Dialog 2");
                            init();
                        }

                        @Nullable
                        @Override
                        protected JComponent createCenterPanel() {
                            final JButton b = new JButton("Click me again " + num);
                            num++;
                            b.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    Messages.showYesNoDialog(b, "Blah-blah", "Error",
                                            Messages.getQuestionIcon());
                                }
                            });
                            return b;
                        }
                    }.show();
                }
            });
            return button;
        }
    }.show();
}

From source file:com.intellij.javascript.flex.refactoring.moveMembers.ActionScriptMoveMembersDialog.java

License:Apache License

@Nullable
private JSClass findOrCreateTargetClass(final String fqName) {
    final String className = StringUtil.getShortName(fqName);
    final String packageName = StringUtil.getPackageName(fqName);

    final GlobalSearchScope scope = getScope();
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory
            .forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    PsiElement aClass = resolver.findClassByQName(fqName, scope);
    if (aClass instanceof JSClass)
        return (JSClass) aClass;

    if (aClass != null) {
        Messages.showErrorDialog(myProject, JSBundle.message("class.0.cannot.be.created", fqName),
                StringUtil.capitalizeWords(JSBundle.message("move.members.refactoring.name"), true));
        return null;
    }/*from w w w  . j  a v a 2 s . com*/

    int answer = Messages.showYesNoDialog(myProject,
            RefactoringBundle.message("class.0.does.not.exist", fqName),
            StringUtil.capitalizeWords(JSBundle.message("move.members.refactoring.name"), true),
            Messages.getQuestionIcon());
    if (answer != Messages.YES)
        return null;

    Module module = ModuleUtilCore.findModuleForPsiElement(mySourceClass);
    PsiDirectory baseDir = PlatformPackageUtil.getDirectory(mySourceClass);
    final PsiDirectory targetDirectory = JSRefactoringUtil.chooseOrCreateDirectoryForClass(myProject, module,
            scope, packageName, className, baseDir, ThreeState.UNSURE);
    if (targetDirectory == null) {
        return null;
    }

    final Ref<Exception> error = new Ref<>();
    final Ref<JSClass> newClass = new Ref<>();
    WriteCommandAction.runWriteCommandAction(myProject,
            RefactoringBundle.message("create.class.command", fqName), null, () -> {
                try {
                    ActionScriptCreateClassOrInterfaceFix.createClass(className, packageName, targetDirectory,
                            false);
                    newClass.set((JSClass) resolver.findClassByQName(fqName, scope));
                } catch (Exception e) {
                    error.set(e);
                }
            });

    if (!error.isNull()) {
        CommonRefactoringUtil.showErrorMessage(JSBundle.message("move.members.refactoring.name"),
                error.get().getMessage(), null, myProject);
        return null;
    }
    return newClass.get();
}

From source file:com.intellij.lang.ant.config.execution.AntBuildMessageView.java

License:Apache License

/**
 * @return can be null if user cancelled operation
 *///ww  w.java 2 s .co  m
@Nullable
public static AntBuildMessageView openBuildMessageView(Project project, AntBuildFileBase buildFile,
        String[] targets) {
    final VirtualFile antFile = buildFile.getVirtualFile();
    if (!LOG.assertTrue(antFile != null)) {
        return null;
    }

    // check if there are running instances of the same build file

    MessageView ijMessageView = MessageView.SERVICE.getInstance(project);
    Content[] contents = ijMessageView.getContentManager().getContents();
    for (Content content : contents) {
        if (content.isPinned()) {
            continue;
        }
        AntBuildMessageView buildMessageView = content.getUserData(KEY);
        if (buildMessageView == null) {
            continue;
        }

        if (!antFile.equals(buildMessageView.getBuildFile().getVirtualFile())) {
            continue;
        }

        if (buildMessageView.isStopped()) {
            ijMessageView.getContentManager().removeContent(content, true);
            continue;
        }

        int result = Messages.showYesNoCancelDialog(
                AntBundle.message("ant.is.active.terminate.confirmation.text"),
                AntBundle.message("starting.ant.build.dialog.title"), Messages.getQuestionIcon());

        switch (result) {
        case 0: // yes
            buildMessageView.stopProcess();
            ijMessageView.getContentManager().removeContent(content, true);
            continue;
        case 1: // no
            continue;
        default: // cancel
            return null;
        }
    }

    final AntBuildMessageView messageView = new AntBuildMessageView(project, buildFile, targets);
    String contentName = buildFile.getPresentableName();
    contentName = BUILD_CONTENT_NAME + " (" + contentName + ")";

    final Content content = ContentFactory.SERVICE.getInstance().createContent(messageView.getComponent(),
            contentName, true);
    content.putUserData(KEY, messageView);
    ijMessageView.getContentManager().addContent(content);
    ijMessageView.getContentManager().setSelectedContent(content);
    content.setDisposer(new Disposable() {
        @Override
        public void dispose() {
            Disposer.dispose(messageView.myAlarm);
        }
    });
    new CloseListener(content, ijMessageView.getContentManager(), project);
    // Do not inline next two variabled. Seeking for NPE.
    ToolWindow messageToolWindow = ToolWindowManager.getInstance(project)
            .getToolWindow(ToolWindowId.MESSAGES_WINDOW);
    messageToolWindow.activate(null);
    return messageView;
}

From source file:com.intellij.lang.ant.config.execution.InputRequestHandler.java

License:Apache License

private static String askUser(SegmentReader reader, Project project) {
    String prompt = reader.readLimitedString();
    String defaultValue = reader.readLimitedString();
    String[] choices = reader.readStringArray();
    MessagesEx.BaseInputInfo question;//from ww w  . j  a v a2s. c  om
    if (choices.length == 0) {
        MessagesEx.InputInfo inputInfo = new MessagesEx.InputInfo(project);
        inputInfo.setDefaultValue(defaultValue);
        question = inputInfo;
    } else {
        MessagesEx.ChoiceInfo choiceInfo = new MessagesEx.ChoiceInfo(project);
        choiceInfo.setChoices(choices, defaultValue);
        question = choiceInfo;
    }
    question.setIcon(Messages.getQuestionIcon());
    question.setTitle(AntBundle.message("user.inout.request.ant.build.input.dialog.title"));
    question.setMessage(prompt);
    question.setIcon(Messages.getQuestionIcon());
    return question.forceUserInput();
}

From source file:com.intellij.lang.ant.config.explorer.AntExplorer.java

License:Apache License

public void removeBuildFile() {
    final AntBuildFile buildFile = getCurrentBuildFile();
    if (buildFile == null) {
        return;//from   w w  w  .  j  av  a 2s.  co  m
    }
    final String fileName = buildFile.getPresentableUrl();
    final int result = Messages.showYesNoDialog(myProject,
            AntBundle.message("remove.the.reference.to.file.confirmation.text", fileName),
            AntBundle.message("confirm.remove.dialog.title"), Messages.getQuestionIcon());
    if (result != 0) {
        return;
    }
    myConfig.removeBuildFile(buildFile);
}

From source file:com.intellij.lang.ant.config.impl.configuration.AnActionListEditor.java

License:Apache License

public void addRemoveButtonForAnt(final Condition<T> removeCondition, String actionName) {
    final ReorderableListController<T>.RemoveActionDescription description = myForm.getListActionsBuilder()
            .addRemoveAction(actionName);
    description.addPostHandler(new ReorderableListController.ActionNotification<List<T>>() {
        public void afterActionPerformed(List<T> list) {
            for (T item : list) {
                if (myAdded.contains(item)) {
                    myAdded.remove(item);
                } else {
                    myRemoved.add(item);
                }//from  w w  w. j  ava  2 s . co m
            }
        }
    });
    description.setEnableCondition(removeCondition);
    description.setConfirmation(new Condition<List<T>>() {
        public boolean value(final List<T> list) {
            if (list.size() == 1) {
                return Messages.showOkCancelDialog(description.getList(),
                        AntBundle.message("delete.selected.ant.configuration.confirmation.text"),
                        ExecutionBundle.message("delete.confirmation.dialog.title"),
                        Messages.getQuestionIcon()) == 0;
            } else {
                return Messages.showOkCancelDialog(description.getList(),
                        AntBundle.message("delete.selected.ant.configurations.confirmation.text"),
                        ExecutionBundle.message("delete.confirmation.dialog.title"),
                        Messages.getQuestionIcon()) == 0;
            }
        }
    });

    description.setShowText(true);
}

From source file:com.intellij.lang.javascript.uml.FlashUmlDataModel.java

License:Apache License

@Override
public void removeEdge(DiagramEdge<Object> edge) {
    final Object source = edge.getSource().getIdentifyingElement();
    final Object target = edge.getTarget().getIdentifyingElement();
    final DiagramRelationshipInfo relationship = edge.getRelationship();
    if (!(source instanceof JSClass) || !(target instanceof JSClass)
            || relationship == DiagramRelationshipInfo.NO_RELATIONSHIP) {
        return;/*w  ww.j av  a2  s  .  c o m*/
    }

    final JSClass fromClass = (JSClass) source;
    final JSClass toClass = (JSClass) target;

    if (JSProjectUtil.isInLibrary(fromClass)) {
        return;
    }

    if (fromClass instanceof XmlBackedJSClassImpl && !toClass.isInterface()) {
        Messages.showErrorDialog(fromClass.getProject(), FlexBundle.message("base.component.needed.message"),
                FlexBundle.message("remove.edge.title"));
        return;
    }

    if (Messages.showYesNoDialog(fromClass.getProject(),
            FlexBundle.message("remove.inheritance.link.prompt", fromClass.getQualifiedName(),
                    toClass.getQualifiedName()),
            FlexBundle.message("remove.edge.title"), Messages.getQuestionIcon()) != Messages.YES) {
        return;
    }

    final Runnable runnable = () -> {
        JSReferenceList refList = !fromClass.isInterface() && toClass.isInterface()
                ? fromClass.getImplementsList()
                : fromClass.getExtendsList();
        List<FormatFixer> formatters = new ArrayList<>();
        JSRefactoringUtil.removeFromReferenceList(refList, toClass, formatters);
        if (!(fromClass instanceof XmlBackedJSClassImpl) && needsImport(fromClass, toClass)) {
            formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
        }
        FormatFixer.fixAll(formatters);
    };

    DiagramAction.performCommand(getBuilder(), runnable, FlexBundle.message("remove.relationship.command.name"),
            null, fromClass.getContainingFile());
}

From source file:com.intellij.lang.javascript.uml.FlashUmlDataModel.java

License:Apache License

@Override
@Nullable//from   w w w  .jav a2 s.c  om
public DiagramEdge<Object> createEdge(@NotNull final DiagramNode<Object> from,
        @NotNull final DiagramNode<Object> to) {
    final JSClass fromClass = (JSClass) from.getIdentifyingElement();
    final JSClass toClass = (JSClass) to.getIdentifyingElement();

    if (fromClass.isEquivalentTo(toClass)) {
        return null;
    }

    if (toClass.isInterface()) {
        if (JSPsiImplUtils.containsEquivalent(
                fromClass.isInterface() ? fromClass.getSuperClasses() : fromClass.getImplementedInterfaces(),
                toClass)) {
            return null;
        }

        Callable<DiagramEdge<Object>> callable = () -> {
            String targetQName = toClass.getQualifiedName();
            JSRefactoringUtil.addToSupersList(fromClass, targetQName, true);
            if (targetQName.contains(".") && !(fromClass instanceof XmlBackedJSClassImpl)) {
                List<FormatFixer> formatters = new ArrayList<>();
                formatters.add(
                        ImportUtils.insertImportStatements(fromClass, Collections.singletonList(targetQName)));
                formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
                FormatFixer.fixAll(formatters);
            }
            return addEdgeAndRefresh(from, to, fromClass.isInterface() ? FlashUmlRelationship.GENERALIZATION
                    : FlashUmlRelationship.INTERFACE_GENERALIZATION);
        };
        String commandName = FlexBundle.message(
                fromClass.isInterface() ? "create.extends.relationship.command.name"
                        : "create.implements.relationship.command.name",
                fromClass.getQualifiedName(), toClass.getQualifiedName());
        return DiagramAction.performCommand(getBuilder(), callable, commandName, null,
                fromClass.getContainingFile());
    } else {
        if (fromClass.isInterface()) {
            return null;
        } else if (fromClass instanceof XmlBackedJSClassImpl) {
            JSClass[] superClasses = fromClass.getSuperClasses();
            if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
                return null;
            }

            if (superClasses.length > 0) { // if base component is not resolved, replace it silently
                final JSClass currentParent = superClasses[0];
                if (Messages.showYesNoDialog(
                        FlexBundle.message("replace.base.component.prompt", currentParent.getQualifiedName(),
                                toClass.getQualifiedName()),
                        FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
                    return null;
                }
            }
            Callable<DiagramEdge<Object>> callable = () -> {
                NewFlexComponentAction.setParentComponent((MxmlJSClass) fromClass, toClass.getQualifiedName());
                return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
            };
            String commandName = FlexBundle.message("create.extends.relationship.command.name",
                    fromClass.getQualifiedName(), toClass.getQualifiedName());
            return DiagramAction.performCommand(getBuilder(), callable, commandName, null,
                    fromClass.getContainingFile());
        } else {
            final JSClass[] superClasses = fromClass.getSuperClasses();
            if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
                return null;
            }

            if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) { // if base class is not resolved, replace it silently
                final JSClass currentParent = superClasses[0];
                if (Messages.showYesNoDialog(
                        FlexBundle.message("replace.base.class.prompt", currentParent.getQualifiedName(),
                                toClass.getQualifiedName()),
                        FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
                    return null;
                }
            }
            Callable<DiagramEdge<Object>> callable = () -> {
                List<FormatFixer> formatters = new ArrayList<>();
                boolean optimize = false;
                if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
                    JSRefactoringUtil.removeFromReferenceList(fromClass.getExtendsList(), superClasses[0],
                            formatters);
                    optimize = needsImport(fromClass, superClasses[0]);
                }
                JSRefactoringUtil.addToSupersList(fromClass, toClass.getQualifiedName(), false);
                if (needsImport(fromClass, toClass)) {
                    formatters.add(ImportUtils.insertImportStatements(fromClass,
                            Collections.singletonList(toClass.getQualifiedName())));
                    optimize = true;
                }
                if (optimize) {
                    formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
                }
                FormatFixer.fixAll(formatters);
                return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
            };
            String commandName = FlexBundle.message("create.extends.relationship.command.name",
                    fromClass.getQualifiedName(), toClass.getQualifiedName());
            return DiagramAction.performCommand(getBuilder(), callable, commandName, null,
                    fromClass.getContainingFile());
        }
    }
}

From source file:com.intellij.lang.properties.refactoring.ResourceBundleKeyRenameHandler.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    ResourceBundleEditor bundleEditor = ResourceBundleUtil.getEditor(dataContext);
    if (bundleEditor == null) {
        return;//from  w w  w . java2  s  . c om
    }

    String propertyName = bundleEditor.getState(FileEditorStateLevel.NAVIGATION).getPropertyName();
    if (propertyName == null) {
        return;
    }

    ResourceBundle bundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext);
    if (bundle == null) {
        return;
    }
    Messages.showInputDialog(project,
            PropertiesBundle.message("rename.bundle.enter.new.resource.bundle.key.name.prompt.text"),
            PropertiesBundle.message("rename.resource.bundle.key.dialog.title"), Messages.getQuestionIcon(),
            propertyName, new ResourceBundleKeyRenameValidator(project, bundleEditor, bundle, propertyName));
}