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

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

Introduction

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

Prototype

@OkCancelResult
@Deprecated
public static int showOkCancelDialog(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:com.intellij.ide.actions.ExportSettingsAction.java

License:Apache License

@Override
public void actionPerformed(@Nullable AnActionEvent e) {
    ApplicationManager.getApplication().saveSettings();

    ChooseComponentsToExportDialog dialog = new ChooseComponentsToExportDialog(
            getExportableComponentsMap(true, true), true,
            IdeBundle.message("title.select.components.to.export"),
            IdeBundle.message("prompt.please.check.all.components.to.export"));
    if (!dialog.showAndGet()) {
        return;//from  w  w  w  . ja  v  a2s  .  co m
    }

    Set<ExportableComponent> markedComponents = dialog.getExportableComponents();
    if (markedComponents.isEmpty()) {
        return;
    }

    Set<File> exportFiles = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
    for (ExportableComponent markedComponent : markedComponents) {
        ContainerUtil.addAll(exportFiles, markedComponent.getExportFiles());
    }

    final File saveFile = dialog.getExportFile();
    try {
        if (saveFile.exists()) {
            final int ret = Messages.showOkCancelDialog(
                    IdeBundle.message("prompt.overwrite.settings.file",
                            FileUtil.toSystemDependentName(saveFile.getPath())),
                    IdeBundle.message("title.file.already.exists"), Messages.getWarningIcon());
            if (ret != Messages.OK)
                return;
        }
        final JarOutputStream output = new JarOutputStream(
                new BufferedOutputStream(new FileOutputStream(saveFile)));
        try {
            final File configPath = new File(PathManager.getConfigPath());
            final HashSet<String> writtenItemRelativePaths = new HashSet<String>();
            for (File file : exportFiles) {
                final String rPath = FileUtil.getRelativePath(configPath, file);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                if (file.exists()) {
                    ZipUtil.addFileOrDirRecursively(output, saveFile, file, relativePath, null,
                            writtenItemRelativePaths);
                }
            }

            exportInstalledPlugins(saveFile, output, writtenItemRelativePaths);

            final File magicFile = new File(FileUtil.getTempDirectory(),
                    ImportSettingsFilenameFilter.SETTINGS_JAR_MARKER);
            FileUtil.createIfDoesntExist(magicFile);
            magicFile.deleteOnExit();
            ZipUtil.addFileToZip(output, magicFile, ImportSettingsFilenameFilter.SETTINGS_JAR_MARKER,
                    writtenItemRelativePaths, null);
        } finally {
            output.close();
        }
        ShowFilePathAction.showDialog(getEventProject(e),
                IdeBundle.message("message.settings.exported.successfully"),
                IdeBundle.message("title.export.successful"), saveFile, null);
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.writing.settings", e1.toString()),
                IdeBundle.message("title.error.writing.file"));
    }
}

From source file:com.intellij.ide.actions.ImportSettingsAction.java

License:Apache License

private static void doImport(String path) {
    final File saveFile = new File(path);
    try {// w w  w  . jav a  2  s. co m
        if (!saveFile.exists()) {
            Messages.showErrorDialog(IdeBundle.message("error.cannot.find.file", presentableFileName(saveFile)),
                    IdeBundle.message("title.file.not.found"));
            return;
        }

        @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
        final ZipEntry magicEntry = new ZipFile(saveFile)
                .getEntry(ImportSettingsFilenameFilter.SETTINGS_JAR_MARKER);
        if (magicEntry == null) {
            Messages.showErrorDialog(
                    IdeBundle.message("error.file.contains.no.settings.to.import",
                            presentableFileName(saveFile), promptLocationMessage()),
                    IdeBundle.message("title.invalid.file"));
            return;
        }

        MultiMap<File, ExportableComponent> fileToComponents = ExportSettingsAction
                .getExportableComponentsMap(false, true);
        List<ExportableComponent> components = getComponentsStored(saveFile, fileToComponents.values());
        fileToComponents.values().retainAll(components);
        final ChooseComponentsToExportDialog dialog = new ChooseComponentsToExportDialog(fileToComponents,
                false, IdeBundle.message("title.select.components.to.import"),
                IdeBundle.message("prompt.check.components.to.import"));
        if (!dialog.showAndGet()) {
            return;
        }

        final Set<ExportableComponent> chosenComponents = dialog.getExportableComponents();
        Set<String> relativeNamesToExtract = new HashSet<String>();
        for (final ExportableComponent chosenComponent : chosenComponents) {
            final File[] exportFiles = chosenComponent.getExportFiles();
            for (File exportFile : exportFiles) {
                final File configPath = new File(PathManager.getConfigPath());
                final String rPath = FileUtil.getRelativePath(configPath, exportFile);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                relativeNamesToExtract.add(relativePath);
            }
        }

        relativeNamesToExtract.add(PluginManager.INSTALLED_TXT);

        final File tempFile = new File(PathManager.getPluginTempPath() + "/" + saveFile.getName());
        FileUtil.copy(saveFile, tempFile);
        File outDir = new File(PathManager.getConfigPath());
        final ImportSettingsFilenameFilter filenameFilter = new ImportSettingsFilenameFilter(
                relativeNamesToExtract);
        StartupActionScriptManager.ActionCommand unzip = new StartupActionScriptManager.UnzipCommand(tempFile,
                outDir, filenameFilter);
        StartupActionScriptManager.addActionCommand(unzip);
        // remove temp file
        StartupActionScriptManager.ActionCommand deleteTemp = new StartupActionScriptManager.DeleteCommand(
                tempFile);
        StartupActionScriptManager.addActionCommand(deleteTemp);

        UpdateSettings.getInstance().forceCheckForUpdateAfterRestart();

        String key = ApplicationManager.getApplication().isRestartCapable()
                ? "message.settings.imported.successfully.restart"
                : "message.settings.imported.successfully";
        final int ret = Messages.showOkCancelDialog(
                IdeBundle.message(key, ApplicationNamesInfo.getInstance().getProductName(),
                        ApplicationNamesInfo.getInstance().getFullProductName()),
                IdeBundle.message("title.restart.needed"), Messages.getQuestionIcon());
        if (ret == Messages.OK) {
            ((ApplicationEx) ApplicationManager.getApplication()).restart(true);
        }
    } catch (ZipException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file", presentableFileName(saveFile),
                e1.getMessage(), promptLocationMessage()), IdeBundle.message("title.invalid.file"));
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file.2",
                presentableFileName(saveFile), e1.getMessage()), IdeBundle.message("title.error.reading.file"));
    }
}

From source file:com.intellij.ide.fileTemplates.impl.AllFileTemplatesConfigurable.java

License:Apache License

private void onReset() {
    FileTemplate selected = myCurrentTab.getSelectedTemplate();
    if (selected instanceof BundledFileTemplate) {
        if (Messages.showOkCancelDialog(IdeBundle.message("prompt.reset.to.original.template"),
                IdeBundle.message("title.reset.template"),
                Messages.getQuestionIcon()) != DialogWrapper.OK_EXIT_CODE) {
            return;
        }/*from w ww.  j av a2 s  . c  o  m*/
        ((BundledFileTemplate) selected).revertToDefaults();
        myEditor.reset();
        myModified = true;
    }
}

From source file:com.intellij.ide.plugins.InstalledPluginsTableModel.java

License:Apache License

private void warnAboutMissedDependencies(final Boolean newVal,
        final IdeaPluginDescriptor... ideaPluginDescriptors) {
    final Set<PluginId> deps = new HashSet<PluginId>();
    final List<IdeaPluginDescriptor> descriptorsToCheckDependencies = new ArrayList<IdeaPluginDescriptor>();
    if (newVal) {
        Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors);
    } else {//from  w w w  . ja  va 2  s  .c o  m
        descriptorsToCheckDependencies.addAll(getAllPlugins());
        descriptorsToCheckDependencies.removeAll(Arrays.asList(ideaPluginDescriptors));

        for (Iterator<IdeaPluginDescriptor> iterator = descriptorsToCheckDependencies.iterator(); iterator
                .hasNext();) {
            IdeaPluginDescriptor descriptor = iterator.next();
            final Boolean enabled = myEnabled.get(descriptor.getPluginId());
            if (enabled == null || !enabled.booleanValue()) {
                iterator.remove();
            }
        }
    }

    for (final IdeaPluginDescriptor ideaPluginDescriptor : descriptorsToCheckDependencies) {
        PluginManager.checkDependants(ideaPluginDescriptor, new Function<PluginId, IdeaPluginDescriptor>() {
            @Override
            @Nullable
            public IdeaPluginDescriptor fun(final PluginId pluginId) {
                return PluginManager.getPlugin(pluginId);
            }
        }, new Condition<PluginId>() {
            @Override
            public boolean value(final PluginId pluginId) {
                Boolean enabled = myEnabled.get(pluginId);
                if (enabled == null) {
                    return false;
                }
                if (newVal && !enabled.booleanValue()) {
                    deps.add(pluginId);
                }

                if (!newVal) {
                    if (ideaPluginDescriptor instanceof IdeaPluginDescriptorImpl
                            && ((IdeaPluginDescriptorImpl) ideaPluginDescriptor).isDeleted())
                        return true;
                    final PluginId pluginDescriptorId = ideaPluginDescriptor.getPluginId();
                    for (IdeaPluginDescriptor descriptor : ideaPluginDescriptors) {
                        if (pluginId.equals(descriptor.getPluginId())) {
                            deps.add(pluginDescriptorId);
                            break;
                        }
                    }
                }
                return true;
            }
        });
    }
    if (!deps.isEmpty()) {
        final String listOfSelectedPlugins = StringUtil.join(ideaPluginDescriptors,
                new Function<IdeaPluginDescriptor, String>() {
                    @Override
                    public String fun(IdeaPluginDescriptor pluginDescriptor) {
                        return pluginDescriptor.getName();
                    }
                }, ", ");
        final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<IdeaPluginDescriptor>();
        final String listOfDependencies = StringUtil.join(deps, new Function<PluginId, String>() {
            @Override
            public String fun(final PluginId pluginId) {
                final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId);
                assert pluginDescriptor != null;
                pluginDependencies.add(pluginDescriptor);
                return pluginDescriptor.getName();
            }
        }, "<br>");
        final String message = !newVal
                ? "<html>The following plugins <br>" + listOfDependencies + "<br>are enabled and depend"
                        + (deps.size() == 1 ? "s" : "") + " on selected plugins. "
                        + "<br>Would you like to disable them too?</html>"
                : "<html>The following plugins on which " + listOfSelectedPlugins + " depend"
                        + (ideaPluginDescriptors.length == 1 ? "s" : "") + " are disabled:<br>"
                        + listOfDependencies + "<br>Would you like to enable them?</html>";
        if (Messages.showOkCancelDialog(message,
                newVal ? "Enable Dependant Plugins" : "Disable Plugins with Dependency on this",
                Messages.getQuestionIcon()) == Messages.OK) {
            for (PluginId pluginId : deps) {
                myEnabled.put(pluginId, newVal);
            }

            updatePluginDependencies();
            hideNotApplicablePlugins(newVal,
                    pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()]));
        }
    }
}

From source file:com.intellij.ide.ui.customization.CustomizableActionsPanel.java

License:Apache License

private void editToolbarIcon(String actionId, DefaultMutableTreeNode node) {
    final AnAction anAction = ActionManager.getInstance().getAction(actionId);
    if (isToolbarAction(node) && anAction.getTemplatePresentation() != null
            && anAction.getTemplatePresentation().getIcon() == null) {
        final int exitCode = Messages.showOkCancelDialog(
                IdeBundle.message("error.adding.action.without.icon.to.toolbar"),
                IdeBundle.message("title.unable.to.add.action.without.icon.to.toolbar"),
                Messages.getInformationIcon());
        if (exitCode == Messages.OK) {
            mySelectedSchema.addIconCustomization(actionId, null);
            anAction.getTemplatePresentation().setIcon(AllIcons.Toolbar.Unknown);
            anAction.setDefaultIcon(false);
            node.setUserObject(Pair.create(actionId, AllIcons.Toolbar.Unknown));
            myActionsTree.repaint();// w ww  .j av  a 2 s .  c o  m
            setCustomizationSchemaForCurrentProjects();
        }
    }
}

From source file:com.intellij.ide.util.projectWizard.ProjectJdkStep.java

License:Apache License

public boolean validate() throws ConfigurationException {
    final Sdk jdk = myProjectSdksConfigurable.getSelectedJdk();
    if (jdk == null && !ApplicationManager.getApplication().isUnitTestMode()) {
        int result = Messages.showOkCancelDialog(IdeBundle.message("prompt.confirm.project.no.jdk"),
                IdeBundle.message("title.no.jdk.specified"), Messages.getWarningIcon());
        if (result != 0) {
            return false;
        }// w  w  w.j a va 2s .  co  m
    }
    myProjectSdksConfigurable.apply();
    return true;
}

From source file:com.intellij.ide.util.projectWizard.ProjectWizardUtil.java

License:Apache License

public static boolean createDirectoryIfNotExists(final String promptPrefix, String directoryPath,
        boolean promptUser) {
    File dir = new File(directoryPath);
    if (!dir.exists()) {
        if (promptUser) {
            final int answer = Messages.showOkCancelDialog(
                    IdeBundle.message("promot.projectwizard.directory.does.not.exist", promptPrefix,
                            dir.getPath(), ApplicationNamesInfo.getInstance().getFullProductName()),
                    IdeBundle.message("title.directory.does.not.exist"), Messages.getQuestionIcon());
            if (answer != 0) {
                return false;
            }//w  ww.  j a v  a 2 s .c  o m
        }
        try {
            VfsUtil.createDirectories(dir.getPath());
        } catch (IOException e) {
            Messages.showErrorDialog(IdeBundle.message("error.failed.to.create.directory", dir.getPath()),
                    CommonBundle.getErrorTitle());
            return false;
        }
    }
    return true;
}

From source file:com.intellij.plugins.haxe.ide.refactoring.memberPushDown.PushDownProcessor.java

License:Apache License

@Override
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
    final UsageInfo[] usagesIn = refUsages.get();
    final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos);
    pushDownConflicts.checkSourceClassConflicts();

    if (usagesIn.length == 0) {
        if (myClass.isEnum() || myClass.hasModifierProperty(PsiModifier.FINAL)) {
            if (Messages.showOkCancelDialog(
                    (myClass.isEnum()//from   w  ww.j ava2 s  .  c  o  m
                            ? "Enum " + myClass.getQualifiedName() + " doesn't have constants to inline to. "
                            : "Final class " + myClass.getQualifiedName() + "does not have inheritors. ")
                            + "Pushing members down will result in them being deleted. "
                            + "Would you like to proceed?",
                    JavaPushDownHandler.REFACTORING_NAME, Messages.getWarningIcon()) != Messages.OK) {
                return false;
            }
        } else {
            String noInheritors = myClass.isInterface()
                    ? RefactoringBundle.message("interface.0.does.not.have.inheritors",
                            myClass.getQualifiedName())
                    : RefactoringBundle.message("class.0.does.not.have.inheritors", myClass.getQualifiedName());
            final String message = noInheritors + "\n"
                    + RefactoringBundle.message("push.down.will.delete.members");
            final int answer = Messages.showYesNoCancelDialog(message, JavaPushDownHandler.REFACTORING_NAME,
                    Messages.getWarningIcon());
            if (answer == Messages.YES) {
                myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass);
                if (myCreateClassDlg != null) {
                    pushDownConflicts.checkTargetClassConflicts(null, false,
                            myCreateClassDlg.getTargetDirectory());
                    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
                } else {
                    return false;
                }
            } else if (answer != Messages.NO)
                return false;
        }
    }
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            ApplicationManager.getApplication().runReadAction(new Runnable() {
                @Override
                public void run() {
                    for (UsageInfo usage : usagesIn) {
                        final PsiElement element = usage.getElement();
                        if (element instanceof PsiClass) {
                            pushDownConflicts.checkTargetClassConflicts((PsiClass) element, usagesIn.length > 1,
                                    element);
                        }
                    }
                }
            });
        }
    };

    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable,
            RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) {
        return false;
    }

    for (UsageInfo info : usagesIn) {
        final PsiElement element = info.getElement();
        if (element instanceof PsiFunctionalExpression) {
            pushDownConflicts.getConflicts().putValue(element,
                    RefactoringBundle.message("functional.interface.broken"));
        }
    }
    final PsiAnnotation annotation = AnnotationUtil.findAnnotation(myClass,
            CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE);
    if (annotation != null && isMoved(LambdaUtil.getFunctionalInterfaceMethod(myClass))) {
        pushDownConflicts.getConflicts().putValue(annotation,
                RefactoringBundle.message("functional.interface.broken"));
    }
    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
}

From source file:com.intellij.profile.codeInspection.ui.ProfilesComboBox.java

License:Apache License

public void createProfilesCombo(final Profile selectedProfile, final Set<Profile> availableProfiles,
        final ProfileManager profileManager) {
    reloadProfiles(profileManager, availableProfiles, selectedProfile);

    setRenderer(new DefaultListCellRenderer() {
        @Override/*ww w .  j  a v  a  2 s .  co m*/
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            final Component rendererComponent = super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);
            if (value instanceof Profile) {
                final Profile profile = (Profile) value;
                setText(profile.getName());
                setIcon(profile.isLocal() ? AllIcons.General.Settings : AllIcons.General.ProjectSettings);
            } else if (value instanceof String) {
                setText((String) value);
            }
            return rendererComponent;
        }
    });
    addItemListener(new ItemListener() {
        private Object myDeselectedItem = null;

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (myFrozenProfilesCombo)
                return; //do not update during reloading
            if (ItemEvent.SELECTED == e.getStateChange()) {
                final Object item = e.getItem();
                if (profileManager instanceof ProjectProfileManager && item instanceof Profile
                        && ((Profile) item).isLocal()) {
                    if (Messages.showOkCancelDialog(
                            InspectionsBundle.message("inspection.new.profile.ide.to.project.warning.message"),
                            InspectionsBundle.message("inspection.new.profile.ide.to.project.warning.title"),
                            Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                        final String newName = Messages.showInputDialog(
                                InspectionsBundle.message("inspection.new.profile.text"),
                                InspectionsBundle.message("inspection.new.profile.dialog.title"),
                                Messages.getInformationIcon());
                        final Object selectedItem = getSelectedItem();
                        if (newName != null && newName.length() > 0 && selectedItem instanceof Profile) {
                            if (ArrayUtil.find(profileManager.getAvailableProfileNames(), newName) == -1
                                    && ArrayUtil.find(
                                            InspectionProfileManager.getInstance().getAvailableProfileNames(),
                                            newName) == -1) {
                                saveNewProjectProfile(newName, (Profile) selectedItem, profileManager);
                                return;
                            } else {
                                Messages.showErrorDialog(
                                        InspectionsBundle.message("inspection.unable.to.create.profile.message",
                                                newName),
                                        InspectionsBundle
                                                .message("inspection.unable.to.create.profile.dialog.title"));
                            }
                        }
                    }
                    setSelectedItem(myDeselectedItem);
                }
            } else {
                myDeselectedItem = e.getItem();
            }
        }
    });
}

From source file:com.intellij.refactoring.extractMethod.AbstractExtractMethodDialog.java

License:Apache License

@Override
protected void doOKAction() {
    final String error = myValidator.check(getMethodName());
    if (error != null) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            Messages.showInfoMessage(error, RefactoringBundle.message("error.title"));
            return;
        }//from   w w  w.  j a  va  2 s.c  om
        if (Messages.showOkCancelDialog(error + ". " + RefactoringBundle.message("do.you.wish.to.continue"),
                RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) != 0) {
            return;
        }
    }
    super.doOKAction();
}