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(String message,
        @Nls(capitalization = Nls.Capitalization.Title) String title, Icon icon) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:org.intellij.erlang.rebar.importWizard.RebarProjectImportBuilder.java

License:Apache License

@SuppressWarnings("DialogTitleCapitalization")
@Override/*  ww w  .  jav  a 2 s . co m*/
public boolean validate(Project current, Project dest) {
    if (!findIdeaModuleFiles(mySelectedOtpApps)) {
        return true;
    }
    final int resultCode = Messages.showYesNoCancelDialog(
            ApplicationInfoEx.getInstanceEx().getFullApplicationName() + " module files found:\n\n"
                    + StringUtil.join(mySelectedOtpApps, new Function<ImportedOtpApp, String>() {
                        public String fun(ImportedOtpApp importedOtpApp) {
                            final VirtualFile ideaModuleFile = importedOtpApp.getIdeaModuleFile();
                            return ideaModuleFile != null ? "    " + ideaModuleFile.getPath() + "\n" : "";
                        }
                    }, "") + "\nWould you like to reuse them?",
            "Module files found", Messages.getQuestionIcon());
    if (resultCode == DialogWrapper.OK_EXIT_CODE) {
        return true;
    } else if (resultCode == DialogWrapper.CANCEL_EXIT_CODE) {
        try {
            deleteIdeaModuleFiles(mySelectedOtpApps);
            return true;
        } catch (IOException e) {
            LOG.error(e);
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.jboss.forge.plugin.idea.runtime.UIPromptImpl.java

License:Open Source License

@Override
public boolean promptBoolean(final String message, final boolean defaultValue) {
    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
        @Override/*  w w w  .  ja v a 2s. co  m*/
        public void run() {
            int result = Messages.showYesNoCancelDialog(message, "", Messages.getQuestionIcon());
            booleanValue = result == Messages.CANCEL ? defaultValue : result == Messages.YES;
        }
    }, ModalityState.any());
    return booleanValue;
}

From source file:org.napile.idea.thermit.config.execution.AntBuildMessageView.java

License:Apache License

/**
 * @return can be null if user cancelled operation
 *///from   www.  ja  v a2  s . c o  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(
                ThermitBundle.message("ant.is.active.terminate.confirmation.text"),
                ThermitBundle.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 = PeerFactory.getInstance().getContentFactory()
            .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;
}