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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:net.groboclown.idea.p4ic.v2.ui.alerts.ConfigurationProblemHandler.java

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("Configuration problem", getException());

    if (isInvalid()) {
        return;//w  ww  .j a  va 2  s  .c  om
    }

    int result = Messages.showYesNoDialog(getProject(),
            P4Bundle.message("configuration.connection-problem-ask", getExceptionMessage()),
            P4Bundle.message("configuration.check-connection"), Messages.getErrorIcon());
    if (result == Messages.YES) {
        // Signal to the API to try again only if
        // the user selected "okay".
        tryConfigChange();
    } else {
        // Work offline
        goOffline();
    }
}

From source file:net.groboclown.idea.p4ic.v2.ui.alerts.InvalidClientHandler.java

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("Invalid client " + clientName);

    ApplicationManager.getApplication().assertIsDispatchThread();

    int result = Messages.showYesNoDialog(getProject(),
            P4Bundle.message("configuration.connection-problem-ask", getExceptionMessage()),
            P4Bundle.message("configuration.check-connection"), Messages.getErrorIcon());
    if (result == Messages.YES) {
        // Signal to the API to try again only if
        // the user selected "okay".
        tryConfigChange();//from   www .j  a va  2 s  . c  om
    } else {
        // Work offline
        goOffline();
    }
}

From source file:net.groboclown.idea.p4ic.v2.ui.alerts.SSLFingerprintProblemHandler.java

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("SSL fingerprint problem", getException());

    if (isInvalid()) {
        return;//from  w  w w . j av  a2  s .c  o  m
    }

    // TODO this needs to better handle the SSL fingerprint issues.

    int result = Messages.showYesNoDialog(getProject(),
            P4Bundle.message("configuration.ssl-fingerprint-problem.ask", getExceptionMessage()),
            P4Bundle.message("configuration.ssl-fingerprint-problem.title"), Messages.getErrorIcon());
    if (result == Messages.YES) {
        // Signal to the API to try again only if
        // the user selected "okay".
        tryConfigChange();
    } else {
        // Work offline
        goOffline();
    }
}

From source file:org.coding.git.util.CodingNetNotifications.java

License:Apache License

@Messages.YesNoResult
public static boolean showYesNoDialog(@Nullable Project project, @NotNull String title,
        @NotNull String message) {
    return Messages.YES == Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon());
}

From source file:org.community.intellij.plugins.communitycase.actions.Init.java

License:Apache License

/**
 * {@inheritDoc}/*w ww.  ja  v  a  2s  .com*/
 */
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false);
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle(Bundle.getString("init.destination.directory.title"));
    fcd.setDescription(Bundle.getString("init.destination.directory.description"));
    fcd.setHideIgnored(false);
    final VirtualFile baseDir = project.getBaseDir();
    final VirtualFile[] files = FileChooser.chooseFiles(project, fcd, baseDir);
    if (files.length == 0) {
        return;
    }
    final VirtualFile root = files[0];
    if (Util.isUnder(root)) {
        final int v = Messages.showYesNoDialog(project,
                Bundle.message("init.warning.already.under.git",
                        StringUtil.escapeXml(root.getPresentableUrl())),
                Bundle.getString("init.warning.title"), Messages.getWarningIcon());
        if (v != 0) {
            return;
        }
    }
    LineHandler h = new LineHandler(project, root, Command.INIT);
    h.setRemote(true);
    HandlerUtil.doSynchronously(h, Bundle.getString("initializing.title"), h.printableCommandLine());
    if (!h.errors().isEmpty()) {
        UiUtil.showOperationErrors(project, h.errors(), " init");
        return;
    }
    int rc = Messages.showYesNoDialog(project, Bundle.getString("init.add.root.message"),
            Bundle.getString("init.add.root.title"), Messages.getQuestionIcon());
    if (rc != 0) {
        return;
    }
    final String path = root.equals(baseDir) ? "" : root.getPath();
    Vcs.getInstance(project)
            .runInBackground(new Task.Backgroundable(project, Bundle.getString("common.refreshing")) {

                public void run(@NotNull ProgressIndicator indicator) {
                    refreshAndConfigureVcsMappings(project, root, path);
                }
            });
}

From source file:org.community.intellij.plugins.communitycase.update.BaseRebaseProcess.java

License:Apache License

/**
 * Merge files/*from w w  w . j a  v a2 s.co  m*/
 *
 * @param root      the project root
 * @param cancelled the cancelled indicator
 * @param ex        the exception holder
 * @param reverse   if true, reverse merge provider will be used
 */
private void mergeFiles(final VirtualFile root, final Ref<Boolean> cancelled, final Ref<Throwable> ex,
        final boolean reverse) {
    com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        public void run() {
            try {
                List<VirtualFile> affectedFiles = ChangeUtils.unmergedFiles(myProject, root);
                while (affectedFiles.size() != 0) {
                    AbstractVcsHelper.getInstance(myProject).showMergeDialog(affectedFiles,
                            reverse ? myVcs.getReverseMergeProvider() : myVcs.getMergeProvider());
                    affectedFiles = ChangeUtils.unmergedFiles(myProject, root);
                    if (affectedFiles.size() != 0) {
                        int result = Messages.showYesNoDialog(myProject,
                                Bundle.message("update.rebase.unmerged",
                                        StringUtil.escapeXml(root.getPresentableUrl())),
                                Bundle.getString("update.rebase.unmerged.title"), Messages.getErrorIcon());
                        if (result != 0) {
                            cancelled.set(true);
                            return;
                        }
                    }
                }
            } catch (Throwable t) {
                ex.set(t);
            }
        }
    });
}

From source file:org.cordovastudio.utils.CordovaStudioUtils.java

License:Apache License

public static void addRunConfiguration(@NotNull final CordovaFacet facet, @Nullable final String activityClass,
        final boolean ask, @Nullable final TargetSelectionMode targetSelectionMode,
        @Nullable final String preferredAvdName) {
    final Module module = facet.getModule();
    final Project project = module.getProject();

    final Runnable r = new Runnable() {
        @Override/*from  ww  w  .ja  va  2s  .  c  o m*/
        public void run() {
            final RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
            final RunnerAndConfigurationSettings settings = runManager.createRunConfiguration(module.getName(),
                    CordovaRunConfigurationType.getInstance().getFactory());
            final CordovaRunConfiguration configuration = (CordovaRunConfiguration) settings.getConfiguration();
            configuration.setModule(module);

            if (activityClass != null) {
                configuration.MODE = CordovaRunConfiguration.LAUNCH_SPECIFIC_ACTIVITY;
                configuration.ACTIVITY_CLASS = activityClass;
            } else {
                configuration.MODE = CordovaRunConfiguration.LAUNCH_DEFAULT_ACTIVITY;
            }

            if (targetSelectionMode != null) {
                configuration.setTargetSelectionMode(targetSelectionMode);
            }
            if (preferredAvdName != null) {
                configuration.PREFERRED_AVD = preferredAvdName;
            }
            runManager.addConfiguration(settings, false);
            runManager.setActiveConfiguration(settings);
        }
    };
    if (!ask) {
        r.run();
    } else {
        UIUtil.invokeLaterIfNeeded(new Runnable() {
            @Override
            public void run() {
                final String moduleName = facet.getModule().getName();
                final int result = Messages.showYesNoDialog(project,
                        "Do you want to create run configuration for module " + moduleName + "?",
                        "Create Run Configuration", Messages.getQuestionIcon());
                if (result == Messages.YES) {
                    r.run();
                }
            }
        });
    }
}

From source file:org.intellij.plugins.relaxNG.convert.IdeaDriver.java

License:Apache License

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public void convert(SchemaType inputType, IdeaErrorHandler errorHandler, VirtualFile... inputFiles) {
    if (inputFiles.length == 0) {
        throw new IllegalArgumentException();
    }//from w w w  .ja v  a2 s. co m

    try {
        final InputFormat inFormat = getInputFormat(inputType);
        if (inputFiles.length > 1) {
            if (!(inFormat instanceof MultiInputFormat)) {
                throw new IllegalArgumentException();
            }
        }

        final VirtualFile inputFile = inputFiles[0];
        final SchemaType type = settings.getOutputType();
        final String outputType = type.toString().toLowerCase();

        final ArrayList<String> inputParams = new ArrayList<>();

        if (inputType != SchemaType.DTD) {
            final Charset charset = inputFile.getCharset();
            inputParams.add("encoding=" + charset.name());
        }

        final ArrayList<String> outputParams = new ArrayList<>();
        settings.addAdvancedSettings(inputParams, outputParams);

        //      System.out.println("INPUT: " + inputParams);
        //      System.out.println("OUTPUT: " + outputParams);

        Resolver catalogResolver = BasicResolver.getInstance();
        final SchemaCollection sc;
        final String input = inputFile.getPath();
        final String uri = UriOrFile.toUri(input);
        try {
            if (inFormat instanceof MultiInputFormat) {
                final MultiInputFormat format = (MultiInputFormat) inFormat;
                final String[] uris = new String[inputFiles.length];
                for (int i = 0; i < inputFiles.length; i++) {
                    uris[i] = UriOrFile.toUri(inputFiles[i].getPath());
                }
                sc = format.load(uris, ArrayUtil.toStringArray(inputParams), outputType, errorHandler,
                        catalogResolver);
            } else {
                sc = inFormat.load(uri, ArrayUtil.toStringArray(inputParams), outputType, errorHandler,
                        catalogResolver);
            }
        } catch (IOException e) {
            errorHandler.fatalError(new SAXParseException(e.getMessage(), null, uri, -1, -1, e));
            return;
        }

        final File destination = new File(settings.getOutputDestination());
        final File outputFile;
        if (destination.isDirectory()) {
            final String name = new File(input).getName();
            final int ext = name.lastIndexOf('.');
            outputFile = new File(destination, (ext > 0 ? name.substring(0, ext) : name) + "." + outputType);
        } else {
            outputFile = destination;
        }

        try {
            final int indent = settings.getIndent();
            final int length = settings.getLineLength();
            final OutputDirectory od = new LocalOutputDirectory(sc.getMainUri(), outputFile, "." + outputType,
                    settings.getOutputEncoding(), length > 0 ? length : DEFAULT_LINE_LENGTH,
                    indent > 0 ? indent : DEFAULT_INDENT) {
                @Override
                public Stream open(String sourceUri, String encoding) throws IOException {
                    final String s = reference(null, sourceUri);
                    final File file = new File(outputFile.getParentFile(), s);
                    if (file.exists()) {
                        final String msg = "The file '" + file.getAbsolutePath()
                                + "' already exists. Overwrite it?";
                        final int choice = Messages.showYesNoDialog(myProject, msg, "Output File Exists",
                                Messages.getWarningIcon());
                        if (choice == Messages.YES) {
                            return super.open(sourceUri, encoding);
                        } else if (choice == 1) {
                            throw new CanceledException();
                        }
                    }
                    return super.open(sourceUri, encoding);
                }
            };

            final OutputFormat of = getOutputFormat(settings.getOutputType());

            of.output(sc, od, ArrayUtil.toStringArray(outputParams), inputType.toString().toLowerCase(),
                    errorHandler);
        } catch (IOException e) {
            errorHandler.fatalError(
                    new SAXParseException(e.getMessage(), null, UriOrFile.fileToUri(outputFile), -1, -1, e));
        }
    } catch (CanceledException | InvalidParamsException | InputFailedException e) {
        // user abort
    } catch (SAXParseException e) {
        errorHandler.error(e);
    } catch (OutputFailedException e) {
        // handled by ErrorHandler
    } catch (SAXException e) {
        // cannot happen or is already handled
    }
}

From source file:org.jetbrains.android.actions.AndroidEnableAdbServiceAction.java

License:Apache License

private static boolean askForClosingDebugSessions(@NotNull Project project) {
    final List<Pair<ProcessHandler, RunContentDescriptor>> pairs = new ArrayList<Pair<ProcessHandler, RunContentDescriptor>>();

    for (Project p : ProjectManager.getInstance().getOpenProjects()) {
        final ProcessHandler[] processes = ExecutionManager.getInstance(p).getRunningProcesses();

        for (ProcessHandler process : processes) {
            if (!process.isProcessTerminated()) {
                final AndroidSessionInfo info = process.getUserData(AndroidDebugRunner.ANDROID_SESSION_INFO);
                if (info != null) {
                    pairs.add(Pair.create(process, info.getDescriptor()));
                }//from w w  w  .  j  av a 2 s. c  o  m
            }
        }
    }

    if (pairs.size() == 0) {
        return true;
    }

    final StringBuilder s = new StringBuilder();

    for (Pair<ProcessHandler, RunContentDescriptor> pair : pairs) {
        if (s.length() > 0) {
            s.append('\n');
        }
        s.append(pair.getSecond().getDisplayName());
    }

    final int r = Messages.showYesNoDialog(project,
            AndroidBundle.message("android.debug.sessions.will.be.closed", s),
            AndroidBundle.message("android.disable.adb.service.title"), Messages.getQuestionIcon());
    return r == Messages.YES;
}

From source file:org.jetbrains.android.AndroidResourceRenameResourceProcessor.java

License:Apache License

private static void prepareResourceFileRenaming(PsiFile file, String newName,
        Map<PsiElement, String> allRenames, AndroidFacet facet) {
    Project project = file.getProject();
    ResourceManager manager = facet.getLocalResourceManager();
    String type = manager.getFileResourceType(file);
    if (type == null)
        return;//w  ww  . j  av  a2s  .c o m
    String name = file.getName();

    if (AndroidCommonUtils.getResourceName(type, name)
            .equals(AndroidCommonUtils.getResourceName(type, newName))) {
        return;
    }

    List<PsiFile> resourceFiles = manager.findResourceFiles(type,
            AndroidCommonUtils.getResourceName(type, name), true, false);
    List<PsiFile> alternativeResources = new ArrayList<PsiFile>();
    for (PsiFile resourceFile : resourceFiles) {
        if (!resourceFile.getManager().areElementsEquivalent(file, resourceFile)
                && resourceFile.getName().equals(name)) {
            alternativeResources.add(resourceFile);
        }
    }
    if (alternativeResources.size() > 0) {
        int r = 0;
        if (ASK) {
            r = Messages.showYesNoDialog(project, message("rename.alternate.resources.question"),
                    message("rename.dialog.title"), Messages.getQuestionIcon());
        }
        if (r == 0) {
            for (PsiFile candidate : alternativeResources) {
                allRenames.put(candidate, newName);
            }
        } else {
            return;
        }
    }
    PsiField[] resFields = AndroidResourceUtil.findResourceFieldsForFileResource(file, false);
    for (PsiField resField : resFields) {
        String newFieldName = AndroidCommonUtils.getResourceName(type, newName);
        allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(newFieldName));
    }
}