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) 

Source Link

Document

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

Usage

From source file:de.mprengemann.intellij.plugin.androidicons.dialogs.AndroidMultiDrawableImporter.java

License:Apache License

private void importZipArchive(VirtualFile virtualFile) {
    final String filePath = virtualFile.getCanonicalPath();
    if (filePath == null) {
        return;/*from   ww  w .  j  av  a  2s .  com*/
    }
    final File tempDir = new File(ImageInformation.getTempDir(), virtualFile.getNameWithoutExtension());
    final String archiveName = virtualFile.getName();
    new Task.Modal(project, "Importing Archive...", true) {
        @Override
        public void run(@NotNull final ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(true);
            try {
                FileUtils.forceMkdir(tempDir);
                ZipUtil.extract(new File(filePath), tempDir, new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        final String mimeType = new MimetypesFileTypeMap().getContentType(name);
                        final String type = mimeType.split("/")[0];
                        return type.equals("image");
                    }
                }, true);
                progressIndicator.checkCanceled();

                final Iterator<File> fileIterator = FileUtils.iterateFiles(tempDir, TrueFileFilter.INSTANCE,
                        TrueFileFilter.INSTANCE);
                while (fileIterator.hasNext()) {
                    File file = fileIterator.next();
                    if (file.isDirectory() || file.isHidden()) {
                        continue;
                    }
                    final String fileRoot = file.getParent().toUpperCase();
                    final String name = FilenameUtils.getBaseName(file.toString());
                    if (name.startsWith(".") || fileRoot.contains("__MACOSX")) {
                        continue;
                    }
                    for (Resolution resolution : RESOLUTIONS) {
                        if (name.toUpperCase().contains("-" + resolution)
                                || name.toUpperCase().contains("_" + resolution)
                                || fileRoot.contains(resolution.toString())) {
                            controller.addZipImage(file, resolution);
                            break;
                        }
                    }
                }
                progressIndicator.checkCanceled();

                final Map<Resolution, List<ImageInformation>> zipImages = controller.getZipImages();
                final List<Resolution> foundResolutions = new ArrayList<Resolution>();
                int foundAssets = 0;
                for (Resolution resolution : zipImages.keySet()) {
                    final List<ImageInformation> assetInformation = zipImages.get(resolution);
                    if (assetInformation != null && !assetInformation.isEmpty()) {
                        foundAssets += assetInformation.size();
                        foundResolutions.add(resolution);
                    }
                }
                progressIndicator.checkCanceled();

                final int finalFoundAssets = foundAssets;
                UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() {
                    public void run() {
                        final String title = String.format("Import '%s'", archiveName);
                        if (foundResolutions.isEmpty() || finalFoundAssets == 0) {
                            Messages.showErrorDialog("No assets found.", title);
                            FileUtils.deleteQuietly(tempDir);
                            return;
                        }
                        final String[] options = new String[] { "Import", "Cancel" };
                        final String description = String.format("Import %d assets for %s to %s.",
                                finalFoundAssets, StringUtils.join(foundResolutions, ", "),
                                controller.getTargetRoot());
                        final int selection = Messages.showDialog(description, title, options, 0,
                                Messages.getQuestionIcon());
                        if (selection == 0) {
                            controller.getZipTask(project, tempDir).queue();
                            close(0);
                        } else {
                            FileUtils.deleteQuietly(tempDir);
                        }
                    }
                });
            } catch (ProcessCanceledException e) {
                FileUtils.deleteQuietly(tempDir);
            } catch (IOException e) {
                LOGGER.error(e);
            }
        }
    }.queue();
}

From source file:de.mprengemann.intellij.plugin.androidicons.images.RefactoringTask.java

License:Apache License

private boolean checkFileExist(@Nullable PsiDirectory targetDirectory, int[] choice, PsiFile file, String name,
        String title) {/*www . j  a  v  a2s  .  co  m*/
    if (targetDirectory == null) {
        return false;
    }
    final PsiFile existing = targetDirectory.findFile(name);
    if (existing == null || existing.equals(file)) {
        return false;
    }
    int selection;
    if (choice == null || choice[0] == -1) {
        final String message = String.format("File '%s' already exists in directory '%s'", name,
                targetDirectory.getVirtualFile().getPath());
        String[] options = choice == null ? new String[] { "Overwrite", "Skip" }
                : new String[] { "Overwrite", "Skip", "Overwrite for all", "Skip for all" };
        selection = Messages.showDialog(message, title, options, 0, Messages.getQuestionIcon());
        if (selection == 2 || selection == 3) {
            this.selection = selection;
        }
    } else {
        selection = choice[0];
    }

    if (choice != null && selection > 1) {
        choice[0] = selection % 2;
        selection = choice[0];
    }

    if (selection == 0 && file != existing) {
        existing.delete();
    } else {
        return true;
    }

    return false;
}

From source file:de.mprengemann.intellij.plugin.androidicons.util.RefactorHelper.java

License:Apache License

public static boolean checkFileExist(@Nullable PsiDirectory targetDirectory, int[] choice, PsiFile file,
        String name, String title) {
    if (targetDirectory == null) {
        return false;
    }//  w  w w  . j  a  v  a  2 s  .co m
    final PsiFile existing = targetDirectory.findFile(name);
    if (existing != null && !existing.equals(file)) {
        int selection;
        if (choice == null || choice[0] == -1) {
            String message = String.format("File '%s' already exists in directory '%s'", name,
                    targetDirectory.getVirtualFile().getPath());
            String[] options = choice == null ? new String[] { "Overwrite", "Skip" }
                    : new String[] { "Overwrite", "Skip", "Overwrite for all", "Skip for all" };
            selection = Messages.showDialog(message, title, options, 0, Messages.getQuestionIcon());
            if (selection == 2 || selection == 3) {
                RefactorHelper.selection = selection;
            }
        } else {
            selection = choice[0];
        }

        if (choice != null && selection > 1) {
            choice[0] = selection % 2;
            selection = choice[0];
        }

        if (selection == 0 && file != existing) {
            existing.delete();
        } else {
            return true;
        }
    }

    return false;
}

From source file:org.jetbrains.idea.svn.integrate.QuickMergeInteractionImpl.java

License:Apache License

@NotNull
@Override//from  w w  w . j ava2 s.  c  om
public LocalChangesAction selectLocalChangesAction(final boolean mergeAll) {
    if (!mergeAll) {
        final LocalChangesAction[] possibleResults = { LocalChangesAction.shelve, LocalChangesAction.inspect,
                LocalChangesAction.continueMerge, LocalChangesAction.cancel };
        final int result = Messages.showDialog(
                "There are local changes that will intersect with merge changes.\nDo you want to continue?",
                myTitle, new String[] { "Shelve local changes", "Inspect changes", "Continue merge", "Cancel" },
                0, Messages.getQuestionIcon());
        return possibleResults[result];
    } else {
        final LocalChangesAction[] possibleResults = { LocalChangesAction.shelve,
                LocalChangesAction.continueMerge, LocalChangesAction.cancel };
        final int result = Messages.showDialog(
                "There are local changes that can potentially intersect with merge changes.\nDo you want to continue?",
                myTitle, new String[] { "Shelve local changes", "Continue merge", "Cancel" }, 0,
                Messages.getQuestionIcon());
        return possibleResults[result];
    }
}

From source file:org.zmlx.hg4idea.execution.HgDeleteModifyPromptHandler.java

License:Apache License

public HgPromptChoice promptUser(@NotNull final String message, @NotNull final HgPromptChoice[] choices,
        @NotNull final HgPromptChoice defaultChoice) {

    Matcher localDelMatcher = LOCAL_DELETE_REMOTE_MODIFIED_CONFLICT_MESSAGE_PATTERN.matcher(message);
    Matcher localModifyMatcher = REMOTE_DELETE_LOCAL_MODIFIED_CONFLICT_MESSAGE_PATTERN.matcher(message);
    String filename;/* w w w .  ja va  2s .  co m*/
    final String modifiedMessage;
    if (localDelMatcher.matches()) {
        filename = localDelMatcher.group(1);
        modifiedMessage = "File " + filename
                + " is deleted locally, but modified remotely. Do you want to keep the modified version or remove the file?";
    } else if (localModifyMatcher.matches()) {
        filename = localModifyMatcher.group(1);
        modifiedMessage = "File " + filename
                + " is deleted remotely, but modified locally. Do you want to keep the modified version or remove the file?";
    } else {
        modifiedMessage = message;
    }
    final int[] chosen = new int[] { -1 };
    try {
        EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                String[] choicePresentationArray = new String[choices.length];
                for (int i = 0; i < choices.length; ++i) {
                    choicePresentationArray[i] = choices[i].toString();
                }
                chosen[0] = Messages.showDialog(modifiedMessage, "Delete-Modify Conflict",
                        choicePresentationArray, defaultChoice.getChosenIndex(), Messages.getQuestionIcon());
            }
        });
    } catch (InterruptedException | InvocationTargetException e) {
        LOG.error(e);
        return defaultChoice;
    }
    return chosen[0] >= 0 ? choices[chosen[0]] : HgPromptChoice.ABORT;
}