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

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

Introduction

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

Prototype

public static int showDialog(String message, @Nls(capitalization = Nls.Capitalization.Title) String title,
        String @NotNull [] options, int defaultOptionIndex, @Nullable Icon icon,
        @Nullable DialogWrapper.DoNotAskOption doNotAskOption) 

Source Link

Document

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

Usage

From source file:com.android.tools.idea.avdmanager.AvdSummaryAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    AvdInfo info = getAvdInfo();/*from w w w .ja  va2  s.  c om*/
    if (info == null) {
        return;
    }

    HtmlBuilder htmlBuilder = new HtmlBuilder();
    htmlBuilder.openHtmlBody();
    htmlBuilder.addHtml("<br>Name: ").add(info.getName());
    htmlBuilder.addHtml("<br>CPU/ABI: ").add(AvdInfo.getPrettyAbiType(info));

    htmlBuilder.addHtml("<br>Path: ").add(info.getDataFolderPath());

    if (info.getStatus() != AvdInfo.AvdStatus.OK) {
        htmlBuilder.addHtml("<br>Error: ").add(info.getErrorMessage());
    } else {
        AndroidVersion version = info.getAndroidVersion();
        htmlBuilder.addHtml("<br>Target: ")
                .add(String.format("%1$s (API level %2$s)", info.getTag(), version.getApiString()));

        // display some extra values.
        Map<String, String> properties = info.getProperties();
        String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME);
        if (skin != null) {
            htmlBuilder.addHtml("<br>Skin: ").add(skin);
        }

        String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE);
        if (sdcard == null) {
            sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH);
        }
        if (sdcard != null) {
            htmlBuilder.addHtml("<br>SD Card: ").add(sdcard);
        }

        String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT);
        if (snapshot != null) {
            htmlBuilder.addHtml("<br>Snapshot: ").add(snapshot);
        }

        // display other hardware
        HashMap<String, String> copy = new HashMap<String, String>(properties);
        // remove stuff we already displayed (or that we don't want to display)
        copy.remove(AvdManager.AVD_INI_ABI_TYPE);
        copy.remove(AvdManager.AVD_INI_CPU_ARCH);
        copy.remove(AvdManager.AVD_INI_SKIN_NAME);
        copy.remove(AvdManager.AVD_INI_SKIN_PATH);
        copy.remove(AvdManager.AVD_INI_SDCARD_SIZE);
        copy.remove(AvdManager.AVD_INI_SDCARD_PATH);
        copy.remove(AvdManager.AVD_INI_IMAGES_2);

        if (copy.size() > 0) {
            for (Map.Entry<String, String> entry : copy.entrySet()) {
                htmlBuilder.addHtml("<br>").add(entry.getKey()).add(": ").add(entry.getValue());
            }
        }
    }
    htmlBuilder.closeHtmlBody();
    String[] options = { "Copy to Clipboard and Close", "Close" };
    int i = Messages.showDialog((Project) null, htmlBuilder.getHtml(), "Details for " + info.getName(), options,
            0, AllIcons.General.InformationDialog);
    if (i == 0) {
        CopyPasteManager.getInstance()
                .setContents(new StringSelection(StringUtil.stripHtml(htmlBuilder.getHtml(), true)));
    }
}

From source file:com.android.tools.idea.run.EmulatorTargetChooser.java

License:Apache License

@Nullable
private String chooseAvd() {
    IAndroidTarget buildTarget = myFacet.getConfiguration().getAndroidTarget();
    assert buildTarget != null;
    AvdInfo[] avds = myFacet.getValidCompatibleAvds();
    if (avds.length > 0) {
        return avds[0].getName();
    }//from  w ww  . j av a  2s.c  om
    final Project project = myFacet.getModule().getProject();
    AvdManager manager;
    try {
        manager = myFacet.getAvdManager(new AvdManagerLog() {
            @Override
            public void error(Throwable t, String errorFormat, Object... args) {
                super.error(t, errorFormat, args);

                if (errorFormat != null) {
                    final String msg = String.format(errorFormat, args);
                    LOG.error(msg);
                }
            }
        });
    } catch (final AndroidLocation.AndroidLocationException e) {
        LOG.info(e);
        UIUtil.invokeLaterIfNeeded(new Runnable() {
            @Override
            public void run() {
                Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
            }
        });
        return null;
    }
    final AvdManager finalManager = manager;
    assert finalManager != null;
    return UIUtil.invokeAndWaitIfNeeded(new Computable<String>() {
        @Override
        public String compute() {
            int result = Messages.showDialog(project,
                    "To run using the emulator, you must have an AVD defined.", "Define AVD",
                    new String[] { "Cancel", "Create AVD" }, 1, null);
            AvdInfo createdAvd = null;
            if (result == 1) {
                AvdOptionsModel avdOptionsModel = new AvdOptionsModel(null);
                ModelWizardDialog dialog = AvdWizardUtils.createAvdWizard(null, project, avdOptionsModel);
                if (dialog.showAndGet()) {
                    createdAvd = avdOptionsModel.getCreatedAvd();
                }
            }
            return createdAvd == null ? null : createdAvd.getName();
        }
    });
}

From source file:com.android.tools.idea.sdk.install.patch.PatchInstallerUtil.java

License:Apache License

/**
 * If a patch fails to install because Studio is locking some of the files, we have to restart studio. Ask if the user wants
 * to, and then move things into place so they can be picked up on restart.
 *//* www. j  a v a2  s  . co m*/
private static void askAboutRestart(@NotNull PatchRunner patchRunner, @NotNull PatchOperation op,
        @NotNull final File patchFile, @NotNull FileOp fop, @NotNull final ProgressIndicator progress) {
    final ApplicationEx application = ApplicationManagerEx.getApplicationEx();
    application.invokeLater(() -> {
        String[] options;
        ApplicationNamesInfo names = ApplicationNamesInfo.getInstance();
        boolean restartable = application.isRestartCapable();
        if (restartable) {
            options = new String[] { "Cancel", "Restart Later", "Restart Now" };
        } else {
            options = new String[] { "Cancel", String.format("Exit %s", names.getProductName()) };
        }
        String message;
        if (op.getExisting() != null) {
            message = String.format(
                    "%1$s is currently in use by %2$s and cannot be updated. Please restart to complete installation.",
                    op.getExisting().getDisplayName(), names.getFullProductName());
        } else {
            message = String.format(
                    "Some files in the destination are currently in use by %1$s. Please restart to complete installation.",
                    names.getFullProductName());
        }
        int result = Messages.showDialog((Project) null, message, "Restart Required", options,
                options.length - 1, AllIcons.General.QuestionDialog);
        if (result == 0) {
            progress.logInfo("Cancelled");
        } else {
            if (setupPatchDir(patchFile, patchRunner.getPatcherJar(), op.getPackage(), op.getRepoManager(), fop,
                    progress)) {
                if (result == 1 && restartable) {
                    progress.logInfo("Installation will continue after restart");
                } else {
                    application.exit(true, true);
                }
            }
        }
    }, ModalityState.any());
}

From source file:com.android.tools.idea.sdk.wizard.SdkQuickfixWizard.java

License:Apache License

@Override
public void init() {
    ScopedStateStore state = getState();
    addPath(new SdkQuickfixPath(getDisposable()));

    Set<IPkgDesc> problems = findProblemPackages();
    int selectedOption = 1; // Install all, default when there are no problems.

    if (!problems.isEmpty()) {
        StringBuilder warningBuilder = new StringBuilder(
                "Due to your system configuration and the packages to be installed, \n"
                        + "it is likely that the following packages cannot be successfully installed while ");
        warningBuilder.append(ApplicationNamesInfo.getInstance().getFullProductName());
        warningBuilder.append(/*  ww  w . j a  v a 2  s .c  o m*/
                " is running. \n\nPlease exit and install the following packages using the standalone SDK manager:");
        for (IPkgDesc problemPkg : problems) {
            warningBuilder.append("\n    -");
            warningBuilder.append(problemPkg.getListDescription());
        }
        if (problems.size() == myRequestedPackages.size()) {
            selectedOption = Messages.showDialog(getProject(), warningBuilder.toString(), "Warning",
                    new String[] {
                            String.format("Exit %s and launch SDK Manager",
                                    ApplicationNamesInfo.getInstance().getProductName()),
                            "Attempt to install packages" },
                    0, AllIcons.General.Warning);
        } else {
            String[] options = new String[] {
                    String.format("Exit %s and launch SDK Manager",
                            ApplicationNamesInfo.getInstance().getProductName()),
                    "Attempt to install all packages", "Install safe packages" };

            selectedOption = Messages.showDialog(getProject(), warningBuilder.toString(), "Warning", options, 2,
                    AllIcons.General.Warning);
        }
    }
    if (selectedOption == 0) {
        startSdkManagerAndExit();
    } else {
        for (IPkgDesc desc : myRequestedPackages) {
            if (selectedOption == 2 && problems.contains(desc)) {
                state.listPush(SKIPPED_INSTALL_REQUESTS_KEY, desc);
            } else {
                state.listPush(INSTALL_REQUESTS_KEY, desc);
            }
        }
    }
    super.init();
}

From source file:com.android.tools.idea.sdk.wizard.SdkQuickfixWizard.java

License:Apache License

@Override
public void performFinishingActions() {
    List<IPkgDesc> skipped = myState.get(SKIPPED_INSTALL_REQUESTS_KEY);
    if (skipped != null && !skipped.isEmpty()) {
        StringBuilder warningBuilder = new StringBuilder(
                "The following packages were not installed.\n\n Would you like to exit ");
        warningBuilder.append(ApplicationNamesInfo.getInstance().getFullProductName());
        warningBuilder.append(" and install the following packages using the standalone SDK manager?");
        for (IPkgDesc problemPkg : skipped) {
            warningBuilder.append("\n");
            warningBuilder.append(problemPkg.getListDescription());
        }/*  w ww  .j av a2  s .  co  m*/
        String restartOption = String.format("Exit %s and launch SDK Manager",
                ApplicationNamesInfo.getInstance().getProductName());
        int result = Messages.showDialog(getProject(), warningBuilder.toString(), "Warning",
                new String[] { restartOption, "Skip installation" }, 0, AllIcons.General.Warning);
        if (result == 0) {
            startSdkManagerAndExit();
        }
    }
    // We've already installed things, so clearly there's an SDK.
    AndroidSdkData data = AndroidSdkUtils.tryToChooseAndroidSdk();
    SdkState.getInstance(data).loadAsync(SdkState.DEFAULT_EXPIRATION_PERIOD_MS, false, null, null, null, true);
}

From source file:com.android.tools.idea.uibuilder.actions.GenerateLayoutTestSkeletonAction.java

License:Apache License

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
    NlModel model = getModel(event.getProject());
    if (model == null) {
        return;//  ww w  .j  a va2 s. c  o m
    }
    int option = Messages.showDialog(model.getProject(),
            "Generate LayoutTest skeleton with the current layout components.", "Generate LayoutTest Skeleton",
            new String[] { "Copy to Clipboard", "Cancel" }, 0, AndroidIcons.AndroidTestRoot);

    if (option == 0) {
        CopyPasteManager.getInstance().setContents(new StringSelection(generateModelFixture(model)));
    }
}

From source file:com.anecdote.ideaplugins.commitlog.GenerateCommentAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    CheckinProjectPanel panel = (CheckinProjectPanel) e.getData(CheckinProjectPanel.PANEL_KEY);
    JTextArea commentEditor = e.getData(CHANGES_BAR_COMMENT_EDITOR_DATA_KEY);
    if (panel != null || commentEditor != null) {
        final Project project = panel != null ? panel.getProject()
                : DataKeys.PROJECT.getData(e.getDataContext());
        if (project != null) {
            int confirmation = Messages.showDialog(project, "Generate commit comment?         ",
                    "Confirm Generate Comment", new String[] { GENERATE, CommonBundle.getCancelButtonText() },
                    0, Messages.getQuestionIcon());
            if (confirmation == 0) {
                CommitLogProjectComponent projectComponent = project
                        .getComponent(CommitLogProjectComponent.class);
                String commitMessage;
                Collection<File> files;
                if (panel != null) {
                    commitMessage = panel.getCommitMessage();
                    files = panel.getFiles();
                } else {
                    commitMessage = commentEditor.getText();
                    LocalChangeList changeList = e.getData(SELECTED_CHANGE_LIST_DATA_KEY);
                    if (changeList == null) {
                        return;
                    }/*  w  w  w.ja  va2 s  . c  om*/
                    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
                    files = new HashSet<File>();
                    for (Change change : changeList.getChanges()) {
                        FilePath filepath = ChangesUtil.getFilePath(change);
                        files.add(filepath.getIOFile());
                    }
                }
                CommitLogBuilder commitLogBuilder = CommitLogBuilder.createCommitLogBuilder(
                        projectComponent.getTextualCommitCommentTemplate(), commitMessage, project, files);
                try {
                    String commitLog = commitLogBuilder.buildCommitLog(new Date());
                    if (panel != null) {
                        panel.setCommitMessage(commitLog);
                    } else {
                        commentEditor.setText(commitLog);
                        commentEditor.requestFocusInWindow();
                    }
                } catch (CommitLogTemplateParser.TextTemplateParserException e1) {
                    int result = Messages.showDialog(project,
                            "Error parsing Comment Template :\n" + e1.getMessage()
                                    + "\n\nEdit Comment Template now?",
                            "Error Generating Comment",
                            new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 0,
                            Messages.getErrorIcon());
                    if (result == 0) {
                        projectComponent.setFocusCommentTemplateEditor(true);
                        ShowSettingsUtil.getInstance().editConfigurable(project, projectComponent);
                    }
                }
            }
        }
    }
}

From source file:com.ansorgit.plugins.bash.settings.facet.ui.AbstractFileTreeTable.java

License:Apache License

public boolean clearSubdirectoriesOnDemandOrCancel(final VirtualFile parent, final String message,
        final String title) {
    Map<VirtualFile, T> mappings = myModel.myCurrentMapping;
    Map<VirtualFile, T> subdirectoryMappings = new THashMap<VirtualFile, T>();
    for (VirtualFile file : mappings.keySet()) {
        if (file != null && (parent == null || VfsUtil.isAncestor(parent, file, true))) {
            subdirectoryMappings.put(file, mappings.get(file));
        }//from  w w  w  . j  a va 2s  .  c  o  m
    }
    if (subdirectoryMappings.isEmpty()) {
        return true;
    } else {
        int ret = Messages.showDialog(myModule.getProject(), message, title,
                new String[] { "Override", "Do Not Override", "Cancel" }, 0, Messages.getWarningIcon());
        if (ret == 0) {
            for (VirtualFile file : subdirectoryMappings.keySet()) {
                myModel.setValueAt(null, new DefaultMutableTreeNode(file), 1);
            }
        }
        return ret != 2;
    }
}

From source file:com.contentful.ideagenerator.forms.GeneratorDialog.java

License:Apache License

private void initGenerate() {
    btnGenerate.addActionListener(new ActionListener() {
        @Override/*  w ww. j  a va2 s .c o m*/
        public void actionPerformed(ActionEvent e) {
            PackageChooserDialog dialog = new PackageChooserDialog("Choose destination package", project);

            if (dialog.showAndGet()) {
                PsiPackage selectedPackage = dialog.getSelectedPackage();
                final String sourceRoot = extractSourceRoot(selectedPackage);
                if (sourceRoot == null) {
                    return;
                }

                final String qualifiedName = selectedPackage.getQualifiedName();
                final CMASpace space = spaces.get(comboSpace.getSelectedIndex());

                setUIEnabled(false);
                progressBar.setVisible(true);

                ProgressManager.getInstance().run(new Task.Backgroundable(project, "Generating Files", false) {
                    @Override
                    public void run(final ProgressIndicator progressIndicator) {
                        Exception exception = null;

                        try {
                            new Generator().generate(space.getResourceId(), qualifiedName, sourceRoot,
                                    tokenTextField.getText());
                        } catch (Exception e) {
                            exception = e;
                        } finally {
                            final Exception finalException = exception;
                            SwingUtilities.invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    progressBar.setVisible(false);
                                    String message;
                                    if (finalException == null) {
                                        message = "Done! \\o/";
                                    } else {
                                        message = "Failed: " + finalException.getMessage();
                                    }

                                    Messages.showDialog(project, message, "Code Generation Completed",
                                            new String[] { "OK" }, 0, null);

                                    VirtualFileManager.getInstance().syncRefresh();

                                    dispose();
                                }
                            });
                        }
                    }
                });
            }
        }
    });
}

From source file:com.headwire.aem.tooling.intellij.communication.MessageManager.java

License:Apache License

public int showAlertWithOptions(@Nullable NotificationType type, @NotNull final String messageId,
        Object... arguments) {/*from w ww . ja  v a 2 s.  c om*/
    String title = getTitle(messageId);
    String message = getMessage(messageId, arguments);
    // Make sure the Message is also placed inside the Log Console
    sendNotification(title, message, type);
    List<String> selections = new ArrayList<String>();
    for (int i = 0; i < 3; i++) {
        String selectionText = AEMBundle.message(messageId + "." + i);
        if (StringUtils.isNotBlank(selectionText)) {
            selections.add(selectionText);
        }
    }
    int ret = 0;
    if (selections.isEmpty()) {
        ret = Messages.showOkCancelDialog(message, title, getIcon(type));
    } else {
        String[] options = selections.toArray(new String[selections.size()]);
        ret = Messages.showDialog(myProject, message, title, options, 0, getIcon(type));
    }
    return ret;
}