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

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

Introduction

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

Prototype

@YesNoCancelResult
public static int showYesNoCancelDialog(@NotNull Component parent, String message,
        @Nls(capitalization = Nls.Capitalization.Title) String title, Icon icon) 

Source Link

Usage

From source file:com.android.tools.idea.rendering.webp.ConvertFromWebpAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();/* w w w.  j  a v  a2  s .  c o  m*/
    if (project == null) {
        return;
    }

    int answer = Messages.showYesNoCancelDialog(project, "Delete .webp files after saving as .png?", TITLE,
            null);
    if (answer == Messages.CANCEL) {
        return;
    }
    boolean delete = answer == Messages.YES;
    VirtualFile[] files = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    perform(project, files, delete);
}

From source file:com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration.java

License:Apache License

@NotNull
@Override// w w  w . ja va2  s.  c o m
public List<ValidationError> checkConfiguration(@NotNull AndroidFacet facet) {
    List<ValidationError> errors = Lists.newArrayList();

    Module module = facet.getModule();
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    switch (TESTING_TYPE) {
    case TEST_ALL_IN_PACKAGE:
        final PsiPackage testPackage = facade.findPackage(PACKAGE_NAME);
        if (testPackage == null) {
            errors.add(ValidationError
                    .warning(ExecutionBundle.message("package.does.not.exist.error.message", PACKAGE_NAME)));
        }
        break;
    case TEST_CLASS:
        PsiClass testClass = null;
        try {
            testClass = getConfigurationModule().checkModuleAndClassName(CLASS_NAME,
                    ExecutionBundle.message("no.test.class.specified.error.text"));
        } catch (RuntimeConfigurationException e) {
            errors.add(ValidationError.fromException(e));
        }
        if (testClass != null && !JUnitUtil.isTestClass(testClass)) {
            errors.add(ValidationError
                    .warning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME)));
        }
        break;
    case TEST_METHOD:
        errors.addAll(checkTestMethod());
        break;
    }
    if (INSTRUMENTATION_RUNNER_CLASS.length() > 0) {
        if (facade.findClass(INSTRUMENTATION_RUNNER_CLASS,
                module.getModuleWithDependenciesAndLibrariesScope(true)) == null) {
            errors.add(ValidationError
                    .fatal(AndroidBundle.message("instrumentation.runner.class.not.specified.error")));
        }
    }

    final AndroidFacetConfiguration configuration = facet.getConfiguration();
    if (!facet.requiresAndroidModel() && !configuration.getState().PACK_TEST_CODE) {
        final int count = getTestSourceRootCount(module);
        if (count > 0) {
            final String shortMessage = "Test code not included into APK";
            final String fixMessage = "Code and resources under test source " + (count > 1 ? "roots" : "root")
                    + " aren't included into debug APK.\nWould you like to include them and recompile "
                    + module.getName() + " module?"
                    + "\n(You may change this option in Android facet settings later)";
            Runnable quickFix = new Runnable() {
                @Override
                public void run() {
                    final int result = Messages.showYesNoCancelDialog(getProject(), fixMessage, shortMessage,
                            Messages.getQuestionIcon());
                    if (result == Messages.YES) {
                        configuration.getState().PACK_TEST_CODE = true;
                    }
                }
            };
            errors.add(ValidationError.fatal(shortMessage, quickFix));
        }
    }

    return errors;
}

From source file:com.atlassian.theplugin.idea.config.ProjectConfigurationComponent.java

License:Apache License

private void migrateOldPrivateProjectSettings(final JDomProjectConfigurationDao cfgFactory) {
    final SAXBuilder builder = new SAXBuilder(false);
    final File privateCfgFile = getPrivateOldCfgFilePath();
    boolean someMigrationHappened = false;
    if (privateCfgFile != null) {
        try {//from w  w  w  .j  av  a2  s  .  co  m
            final Document privateRoot = builder.build(privateCfgFile);
            final PrivateProjectConfiguration ppc = cfgFactory
                    .loadOldPrivateConfiguration(privateRoot.getRootElement());
            for (PrivateServerCfgInfo privateServerCfgInfo : ppc.getPrivateServerCfgInfos()) {
                try {
                    final PrivateServerCfgInfo newPsci = privateCfgDao.load(privateServerCfgInfo.getServerId());
                    if (newPsci == null) {
                        privateCfgDao.save(privateServerCfgInfo);
                        someMigrationHappened = true;
                    }
                } catch (ServerCfgFactoryException e) {
                    // ignore here - just don't try to overwrite it with data from old XML file
                }
            }
        } catch (Exception e) {
            handleServerCfgFactoryException(project, e);
        }
    }

    if (someMigrationHappened) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            public void run() {
                int value = Messages.showYesNoCancelDialog(project,
                        "Configuration has been succesfully migrated to new location (home directory).\n"
                                + "Would you like to delete the old configuration file?\n\nDelete file: ["
                                + privateCfgFile + "]",
                        PluginUtil.PRODUCT_NAME + " upgrade process", Messages.getQuestionIcon());

                if (value == DialogWrapper.OK_EXIT_CODE) {
                    if (!privateCfgFile.delete()) {
                        Messages.showWarningDialog(project,
                                "Cannot remove file [" + privateCfgFile.getAbsolutePath()
                                        + "].\nTry removing it manually.\n" + PluginUtil.PRODUCT_NAME
                                        + " should still behave correctly.",
                                PluginUtil.PRODUCT_NAME);
                    }

                }
            }
        });
    }
}

From source file:com.github.intelliguard.action.AbstractExportAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Module module = getModule(e);
    if (module == null) {
        return;/*from   w ww  .j a  v a 2  s.c o m*/
    }
    final GuardFacet guardFacet = getGuardFacet(module);
    if (guardFacet == null) {
        return;
    }

    final ExportOptionsForm exportOptionsForm = FormDialogWrapper.showExportOptionsForm(guardFacet);
    if (exportOptionsForm == null) {
        // user aborted
        return;
    }

    GuardFacetConfiguration configuration = guardFacet.getConfiguration();
    configuration.mainclass = exportOptionsForm.getMainClass();
    configuration.inFile = exportOptionsForm.getJarPath();
    configuration.outFile = exportOptionsForm.getObfuscatedJarPath();

    String errorMessage = null;
    if (configuration.inFile.length() == 0) {
        errorMessage = "Output jar path not specified";
    } else if (configuration.outFile.length() == 0) {
        errorMessage = "Obfuscation jar path not specified";
    } else if (configuration.inFile.equals(configuration.outFile)) {
        errorMessage = "Output jar path and obfuscated jar path can not be the same";
    }
    if (errorMessage != null) {
        Messages.showErrorDialog(module.getProject(), errorMessage, "Export error");
        return;
    }

    // output configuration to toolwindow
    final String config = generateConfiguration(guardFacet);
    final ProgressInfoReceiver receiver = module.getProject().getComponent(GuardProjectComponent.class)
            .createProgressInfoReceiver();
    receiver.info(config);

    // ask for saving to file
    final int answer = Messages.showYesNoCancelDialog(module.getProject(),
            "Would you like to export configuration to a file?", "Export configuration",
            Icons.OBFUSCATION_NODE_ICON);
    if (answer == 0) {
        // show file chooser
        final Component component = DataKeys.CONTEXT_COMPONENT.getData(e.getDataContext());
        final JFileChooser jFileChooser = FileChooserFactory.createPreferredDirectoryFileChooser(
                "Save '" + module.getName() + "' obfuscation settings", module.getModuleFilePath());
        // suggest a suitable name for the output file
        jFileChooser.setSelectedFile(new File(jFileChooser.getCurrentDirectory(),
                module.getName() + "-obfuscation." + getConfigFileExtension()));
        int res = jFileChooser.showSaveDialog(component);
        if (res == JFileChooser.APPROVE_OPTION) {
            final File selectedFile = jFileChooser.getSelectedFile();
            if (!selectedFile.exists() || selectedFile.canWrite()) {
                dumpFile(config, selectedFile);
            }
        }
    }

    UiUtils.showInfoBallon(module.getProject(), "Generated obfuscation settings");
}

From source file:com.hp.alm.ali.idea.entity.EntityEditManager.java

License:Apache License

public int askUser() {
    return Messages.showYesNoCancelDialog(project,
            "There are unsaved changes, if you proceed they will be discarded. Proceed?", "HP ALI",
            Messages.getQuestionIcon());
}

From source file:com.igormaznitsa.ideamindmap.editor.MindMapDialogProvider.java

License:Apache License

@Override
public Boolean msgConfirmYesNoCancel(final String title, final String text) {
    final int result = Messages.showYesNoCancelDialog(this.project, text, title, Messages.getQuestionIcon());
    return result == Messages.CANCEL ? null : result == Messages.YES;
}

From source file:com.intellij.analysis.BaseClassesAnalysisAction.java

License:Apache License

@Override
protected void analyze(@NotNull final Project project, final AnalysisScope scope) {
    FileDocumentManager.getInstance().saveAllDocuments();

    ProgressManager.getInstance()/*from  w w w .  jav  a  2s .  c o m*/
            .run(new Task.Backgroundable(project, AnalysisScopeBundle.message("analyzing.project"), true) {
                @Override
                public void run(@NotNull final ProgressIndicator indicator) {
                    indicator.setIndeterminate(true);
                    indicator.setText(AnalysisScopeBundle.message("checking.class.files"));

                    final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
                    final boolean upToDate = compilerManager
                            .isUpToDate(compilerManager.createProjectCompileScope(myProject));

                    ApplicationManager.getApplication().invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            if (!upToDate) {
                                final int i = Messages.showYesNoCancelDialog(getProject(),
                                        AnalysisScopeBundle.message("recompile.confirmation.message"),
                                        AnalysisScopeBundle.message("project.is.out.of.date"),
                                        Messages.getWarningIcon());

                                if (i == 2)
                                    return;

                                if (i == 0) {
                                    compileAndAnalyze(project, scope);
                                } else {
                                    doAnalyze(project, scope);
                                }
                            } else {
                                doAnalyze(project, scope);
                            }
                        }
                    });
                }
            });
}

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.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 ww  . j av  a 2 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.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 {/*from   ww  w .  j av  a2 s . 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);
    }
}