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

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

Introduction

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

Prototype

int OK

To view the source code for com.intellij.openapi.ui Messages OK.

Click Source Link

Usage

From source file:com.google.idea.blaze.java.settings.BlazeJavaUserSettingsContributor.java

License:Open Source License

BlazeJavaUserSettingsContributor() {
    useJarCache = new JCheckBox();
    useJarCache.setText(String.format(
            "Use a local jar cache. More robust, but we can miss %s changes made outside the IDE.",
            Blaze.defaultBuildSystemName()));

    attachSourcesByDefault = new JCheckBox();
    attachSourcesByDefault.setSelected(false);
    attachSourcesByDefault//from  w  ww .  j  a  va2s  .c o m
            .setText("Automatically attach sources on project sync (WARNING: increases index time by 100%+)");

    attachSourcesByDefault.addActionListener((event) -> {
        BlazeJavaUserSettings settings = BlazeJavaUserSettings.getInstance();
        if (attachSourcesByDefault.isSelected() && !settings.getAttachSourcesByDefault()) {
            int result = Messages.showOkCancelDialog(
                    "You are turning on source jars by default. " + "This setting increases indexing time by "
                            + ">100%, can cost ~1GB RAM, and will increase "
                            + "project reopen time significantly. " + "Are you sure you want to proceed?",
                    "Turn On Sources By Default?", null);
            if (result != Messages.OK) {
                attachSourcesByDefault.setSelected(false);
            }
        }
    });

    attachSourcesOnDemand = new JCheckBox();
    attachSourcesOnDemand.setSelected(false);
    attachSourcesOnDemand.setText("Automatically attach sources when you open decompiled source");

    components = ImmutableList.of(useJarCache, attachSourcesOnDemand, attachSourcesByDefault);
}

From source file:com.headwire.aem.tooling.intellij.action.VerifyConfigurationAction.java

License:Apache License

/**
 * Verity the project setup// ww w . j  a  v  a2  s. c o  m
 * @param project
 * @param dataContext
 * @param progressHandler Progress Handler
 * @return True if the project was successfully verified
 */
public boolean doVerify(final Project project, final DataContext dataContext,
        final ProgressHandler progressHandler) {
    ProgressHandler progressHandlerSubTask = progressHandler == null ? new EmptyProgresssHandler()
            : progressHandler.startSubTasks(1, "progress.verify.project", project.getName());
    progressHandlerSubTask.next("progress.verify.check.environment");
    MessageManager messageManager = getMessageManager(project);
    boolean ret = true;
    int exitNow = Messages.OK;
    SlingServerTreeSelectionHandler selectionHandler = getSelectionHandler(project);
    ServerConnectionManager serverConnectionManager = ComponentProvider.getComponent(project,
            ServerConnectionManager.class);
    ServerConfigurationManager serverConfigurationManager = getConfigurationManager(project);
    if (selectionHandler != null && serverConnectionManager != null && messageManager != null) {
        ServerConfiguration source = selectionHandler.getCurrentConfiguration();
        if (source != null) {
            try {
                progressHandlerSubTask.next("progress.verify.rebind.module");
                messageManager.sendInfoNotification("server.configuration.start.verification",
                        source.getName());
                // Before we can verify we need to ensure the Configuration is properly bound to Maven
                List<ServerConfiguration.Module> unboundModules = null;
                try {
                    unboundModules = serverConnectionManager.findUnboundModules(source);
                } catch (IllegalArgumentException e) {
                    messageManager.showAlertWithOptions(NotificationType.ERROR,
                            "server.configuration.verification.failed.due.to.bind.exception", source.getName(),
                            e.getMessage());
                    return false;
                } finally {
                    serverConfigurationManager.updateCurrentServerConfiguration();
                }
                if (unboundModules != null && !unboundModules.isEmpty()) {
                    progressHandlerSubTask.next("progress.verify.update.server.configuration");
                    ret = false;
                    ProgressHandler progressHandlerSubTaskLoop = progressHandlerSubTask
                            .startSubTasks(unboundModules.size(), "Check Server Configuration Modules");
                    for (ServerConfiguration.Module module : unboundModules) {
                        progressHandlerSubTaskLoop.next("progress.veriy.update.server.configuration",
                                module.getName());
                        exitNow = messageManager.showAlertWithOptions(NotificationType.WARNING,
                                "server.configuration.unresolved.module", module.getName());
                        if (exitNow == 1) {
                            source.removeModule(module);
                            if (serverConfigurationManager != null) {
                                serverConfigurationManager.updateServerConfiguration(source);
                            }
                        } else if (exitNow == Messages.CANCEL) {
                            return false;
                        }
                    }
                }
                // Verify each Module to see if all prerequisites are met
                Repository repository = ServerConnectionManager.obtainRepository(source, messageManager);
                if (repository != null) {
                    progressHandlerSubTask.next("progress.verify.check.modules");
                    ProgressHandler progressHandlerSubTaskLoop = progressHandlerSubTask
                            .startSubTasks(2 * source.getModuleList().size(), "progress.verify.check.modules");
                    for (ServerConfiguration.Module module : source.getModuleList()) {
                        progressHandlerSubTaskLoop.next("progress.verify.check.module", module.getName());
                        if (module.isSlingPackage()) {
                            // Check if the Filter is available for Content Modules
                            Filter filter = null;
                            try {
                                filter = module.getSlingProject().loadFilter();
                                if (filter == null) {
                                    ret = false;
                                    exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                            "server.configuration.filter.file.not.found", module.getName());
                                    module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                                    if (exitNow == Messages.CANCEL) {
                                        return false;
                                    }
                                }
                            } catch (ConnectorException e) {
                                ret = false;
                                exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                        "server.configuration.filter.file.failure", module.getName(),
                                        e.getMessage());
                                module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                                if (exitNow == Messages.CANCEL) {
                                    return false;
                                }
                            }
                            // Check if the Content Modules have a Content Resource
                            List<String> resourceList = serverConnectionManager.findContentResources(module);
                            if (resourceList.isEmpty()) {
                                ret = false;
                                exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                        "server.configuration.content.folder.not.found", module.getName());
                                module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                                if (exitNow == Messages.CANCEL) {
                                    return false;
                                }
                            }
                            // Check if Content Module Folders all have a .content.xml
                            Object temp = dataContext.getData(VERIFY_CONTENT_WITH_WARNINGS);
                            boolean verifyWithWarnings = !(temp instanceof Boolean) || ((Boolean) temp);
                            if (verifyWithWarnings && filter != null) {
                                progressHandlerSubTaskLoop.next("progress.verify.check.resource.files");
                                ProgressHandler progressHandlerSubTaskLoop2 = progressHandlerSubTaskLoop
                                        .startSubTasks(resourceList.size(), "Check Resources");
                                // Get the Content Root /jcr_root)
                                for (String contentPath : resourceList) {
                                    progressHandlerSubTaskLoop2.next("progress.verify.check.resource.files",
                                            contentPath);
                                    VirtualFile rootFile = project.getProjectFile().getFileSystem()
                                            .findFileByPath(contentPath);
                                    if (rootFile != null) {
                                        // Loop over all folders and check if .content.xml file is there
                                        Result childResult = checkFolderContent(repository, messageManager,
                                                serverConnectionManager, module, null, rootFile, filter);
                                        if (childResult.isCancelled) {
                                            return false;
                                        } else if (!childResult.isOk) {
                                            ret = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    ret = false;
                }
            } catch (RuntimeException e) {
                messageManager.sendUnexpectedException(e);
            } finally {
                messageManager.sendInfoNotification("server.configuration.end.verification", source.getName());
            }
        }
    }
    return ret;
}

From source file:com.headwire.aem.tooling.intellij.action.VerifyConfigurationAction.java

License:Apache License

private Result checkFolderContent(Repository repository, MessageManager messageManager,
        ServerConnectionManager serverConnectionManager, ServerConfiguration.Module module, File rootDirectory,
        VirtualFile parentDirectory, Filter filter) {
    int exitNow = Messages.OK;
    Result ret = new Result();
    // Loop over all files in the given folder
    for (VirtualFile child : parentDirectory.getChildren()) {
        // We only need to check Folders
        if (child.isDirectory()) {
            // If the Root Directory is null then just started -> Create Root Directory File and work on its children
            if (rootDirectory == null) {
                rootDirectory = new File(parentDirectory.getPath());
            } else {
                // Get Relative Paths
                String relativeParentPath = parentDirectory.getPath()
                        .substring(rootDirectory.getPath().length());
                String relativeChildPath = child.getPath().substring(rootDirectory.getPath().length());
                List<ResourceProxy> childNodes = null;
                FilterResult filterResult = null;
                if (filter != null) {
                    // Check if the Resource is part of the Filter
                    filterResult = filter.filter(relativeChildPath);
                }//www.  j  a  va  2 s  .co  m
                // We don't need to check anything if it is part of one of the filter entries
                if (filterResult != FilterResult.ALLOW) {
                    if (filterResult == FilterResult.DENY) {
                        ret.failed();
                        // File is not part of a filter entry so it will never be deployed
                        exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                "server.configuration.content.folder.filtered.out", relativeChildPath,
                                module.getName());
                        module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                        if (exitNow == Messages.CANCEL) {
                            return ret.doExit();
                        }
                    } else if (child.findChild(Constants.CONTENT_FILE_NAME) == null) {
                        boolean isOk = false;
                        if (repository != null && childNodes == null) {
                            // First check if there are only folders as children and if all of them are inside the filters
                            boolean isGood = true;
                            for (VirtualFile grandChild : child.getChildren()) {
                                filterResult = filter.filter(relativeChildPath + "/" + grandChild.getName());
                                if (filterResult != FilterResult.ALLOW) {
                                    isGood = false;
                                    break;
                                }
                            }
                            if (isGood) {
                                isOk = true;
                            } else {
                                // .content.xml file not found in the filter -> check if that folder exists on the Server
                                childNodes = serverConnectionManager.getChildrenNodes(repository,
                                        relativeParentPath);
                                for (ResourceProxy childNode : childNodes) {
                                    String path = childNode.getPath();
                                    boolean found = path.equals(relativeChildPath);
                                    if (found) {
                                        isOk = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!isOk) {
                            ret.failed();
                            exitNow = messageManager.showAlertWithOptions(NotificationType.ERROR,
                                    "server.configuration.content.folder.configuration.not.found",
                                    relativeChildPath, module.getName());
                            module.setStatus(ServerConfiguration.SynchronizationStatus.compromised);
                            if (exitNow == Messages.CANCEL) {
                                return ret.doExit();
                            }
                        }
                    }
                }
            }
            // Check the children of the current folder
            Result childResult = checkFolderContent(repository, messageManager, serverConnectionManager, module,
                    rootDirectory, child, filter);
            if (childResult.isCancelled) {
                return ret.doExit();
            } else if (!childResult.isOk) {
                ret.failed();
            }
        }
    }
    return ret;
}

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

License:Apache License

@Override
public boolean msgConfirmOkCancel(final String title, final String text) {
    return Messages.showOkCancelDialog(this.project, text, title, Messages.getQuestionIcon()) == Messages.OK;
}

From source file:com.intellij.codeInsight.actions.AbstractLayoutCodeProcessor.java

License:Apache License

private void runProcessOnFiles(final String where, final List<PsiFile> array) {
    boolean success = FileModificationService.getInstance().preparePsiElementsForWrite(array);

    if (!success) {
        List<PsiFile> writeables = new ArrayList<PsiFile>();
        for (PsiFile file : array) {
            if (file.isWritable()) {
                writeables.add(file);//from   www.  j a va  2  s  .c o  m
            }
        }
        if (writeables.isEmpty())
            return;
        int res = Messages.showOkCancelDialog(myProject,
                CodeInsightBundle.message("error.dialog.readonly.files.message", where),
                CodeInsightBundle.message("error.dialog.readonly.files.title"), Messages.getQuestionIcon());
        if (res != Messages.OK) {
            return;
        }

        array.clear();
        array.addAll(writeables);
    }

    final Runnable[] resultRunnable = new Runnable[1];
    runLayoutCodeProcess(new Runnable() {
        @Override
        public void run() {
            resultRunnable[0] = preprocessFiles(array);
        }
    }, new Runnable() {
        @Override
        public void run() {
            if (resultRunnable[0] != null) {
                resultRunnable[0].run();
            }
        }
    }, array.size() > 1);
}

From source file:com.intellij.compiler.impl.CompilerUtil.java

License:Apache License

public static boolean askUserToContinueWithNoClearing(Project project,
        Collection<VirtualFile> affectedOutputPaths) {
    final StringBuilder paths = new StringBuilder();
    for (final VirtualFile affectedOutputPath : affectedOutputPaths) {
        if (paths.length() > 0) {
            paths.append(",\n");
        }//  w w  w.java  2s. co m
        paths.append(affectedOutputPath.getPath().replace('/', File.separatorChar));
    }
    final int answer = Messages.showOkCancelDialog(project,
            CompilerBundle.message("warning.sources.under.output.paths", paths.toString()),
            CommonBundle.getErrorTitle(), Messages.getWarningIcon());
    if (answer == Messages.OK) { // ok
        return true;
    } else {
        return false;
    }
}

From source file:com.intellij.execution.ExecutableValidator.java

License:Apache License

/**
 * Checks if executable is valid and shows the message if not.
 * This method is to be used instead of {@link #checkExecutableAndNotifyIfNeeded()} when Git fails to start from a modal dialog:
 * in that case user won't be able to click "Fix it".
 * @return true if executable was valid, false - if not valid (and a message is shown in that case).
 * @see #checkExecutableAndNotifyIfNeeded()
 *//* w  ww.  ja v a 2 s . co m*/
public boolean checkExecutableAndShowMessageIfNeeded(@Nullable Component parentComponent) {
    if (myProject.isDisposed()) {
        return false;
    }

    if (!isExecutableValid(getCurrentExecutable())) {
        if (Messages.OK == showMessage(parentComponent)) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    showSettings();
                }
            });
        }
        return false;
    }
    return true;
}

From source file:com.intellij.execution.impl.ExecutionManagerImpl.java

License:Apache License

private static boolean userApprovesStopForSameTypeConfigurations(Project project, String configName,
        int instancesCount) {
    RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
    final RunManagerConfig config = runManager.getConfig();
    if (!config.isRestartRequiresConfirmation())
        return true;

    DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
        @Override//  www. ja v a2  s  .com
        public boolean isToBeShown() {
            return config.isRestartRequiresConfirmation();
        }

        @Override
        public void setToBeShown(boolean value, int exitCode) {
            config.setRestartRequiresConfirmation(value);
        }

        @Override
        public boolean canBeHidden() {
            return true;
        }

        @Override
        public boolean shouldSaveOptionsOnCancel() {
            return false;
        }

        @NotNull
        @Override
        public String getDoNotShowMessage() {
            return CommonBundle.message("dialog.options.do.not.show");
        }
    };
    return Messages.showOkCancelDialog(project,
            ExecutionBundle.message("rerun.singleton.confirmation.message", configName, instancesCount),
            ExecutionBundle.message("process.is.running.dialog.title", configName),
            ExecutionBundle.message("rerun.confirmation.button.text"), CommonBundle.message("button.cancel"),
            Messages.getQuestionIcon(), option) == Messages.OK;
}

From source file:com.intellij.execution.impl.ExecutionManagerImpl.java

License:Apache License

private static boolean userApprovesStopForIncompatibleConfigurations(Project project, String configName,
        List<RunContentDescriptor> runningIncompatibleDescriptors) {
    RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
    final RunManagerConfig config = runManager.getConfig();
    if (!config.isRestartRequiresConfirmation())
        return true;

    DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
        @Override//  w  w w  .  java  2s  . c  om
        public boolean isToBeShown() {
            return config.isRestartRequiresConfirmation();
        }

        @Override
        public void setToBeShown(boolean value, int exitCode) {
            config.setRestartRequiresConfirmation(value);
        }

        @Override
        public boolean canBeHidden() {
            return true;
        }

        @Override
        public boolean shouldSaveOptionsOnCancel() {
            return false;
        }

        @NotNull
        @Override
        public String getDoNotShowMessage() {
            return CommonBundle.message("dialog.options.do.not.show");
        }
    };

    final StringBuilder names = new StringBuilder();
    for (final RunContentDescriptor descriptor : runningIncompatibleDescriptors) {
        String name = descriptor.getDisplayName();
        if (names.length() > 0) {
            names.append(", ");
        }
        names.append(StringUtil.isEmpty(name) ? ExecutionBundle.message("run.configuration.no.name")
                : String.format("'%s'", name));
    }

    //noinspection DialogTitleCapitalization
    return Messages.showOkCancelDialog(project,
            ExecutionBundle.message("stop.incompatible.confirmation.message", configName, names.toString(),
                    runningIncompatibleDescriptors.size()),
            ExecutionBundle.message("incompatible.configuration.is.running.dialog.title",
                    runningIncompatibleDescriptors.size()),
            ExecutionBundle.message("stop.incompatible.confirmation.button.text"),
            CommonBundle.message("button.cancel"), Messages.getQuestionIcon(), option) == Messages.OK;
}

From source file:com.intellij.find.findUsages.JavaFindUsagesHandler.java

License:Apache License

private static boolean askWhetherShouldSearchForParameterInOverridingMethods(final PsiElement psiElement,
        final PsiParameter parameter) {
    return Messages.showOkCancelDialog(psiElement.getProject(),
            FindBundle.message("find.parameter.usages.in.overriding.methods.prompt", parameter.getName()),
            FindBundle.message("find.parameter.usages.in.overriding.methods.title"),
            CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText(),
            Messages.getQuestionIcon()) == Messages.OK;
}