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

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

Introduction

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

Prototype

int YES

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

Click Source Link

Usage

From source file:org.twodividedbyzero.idea.findbugs.core.CheckinHandlerFactoryImpl.java

License:Open Source License

@NotNull
@Override//from ww w  .  j  a  v a2 s .co  m
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel,
        @NotNull final CommitContext commitContext) {
    return new CheckinHandler() {
        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            final JCheckBox run = new JCheckBox(ResourcesLoader.getString("checkin.text"));
            return new RefreshableOnComponent() {
                public JComponent getComponent() {
                    return JBUI.Panels.simplePanel().addToLeft(run);
                }

                @Override
                public void refresh() {
                }

                @Override
                public void saveState() {
                    WorkspaceSettings.getInstance(panel.getProject()).analyzeBeforeCheckIn = run.isSelected();
                }

                @Override
                public void restoreState() {
                    run.setSelected(WorkspaceSettings.getInstance(panel.getProject()).analyzeBeforeCheckIn);
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable final CommitExecutor executor,
                final PairConsumer<Object, Object> additionalDataConsumer) {
            if (!WorkspaceSettings.getInstance(panel.getProject()).analyzeBeforeCheckIn) {
                return super.beforeCheckin(executor, additionalDataConsumer);
            }

            new FindBugsStarter(panel.getProject(), "Running FindBugs analysis for affected files...",
                    ProgressStartType.Modal) {
                @Override
                protected boolean isCompileBeforeAnalyze() {
                    return false; // CompilerManager#make start asynchronous task
                }

                @Override
                protected void createCompileScope(@NotNull final CompilerManager compilerManager,
                        @NotNull final Consumer<CompileScope> consumer) {
                    throw new UnsupportedOperationException();
                }

                @Override
                protected boolean configure(@NotNull final ProgressIndicator indicator,
                        @NotNull final FindBugsProjects projects, final boolean justCompiled) {
                    final Collection<VirtualFile> virtualFiles = panel.getVirtualFiles();
                    projects.addFiles(virtualFiles, false, hasTests(virtualFiles));
                    return true;
                }
            }.start();
            final ToolWindowPanel toolWindowPanel = ToolWindowPanel.getInstance(panel.getProject());
            if (toolWindowPanel != null && toolWindowPanel.getResult() != null) {
                if (!toolWindowPanel.getResult().isBugCollectionEmpty()) {
                    // Based on com.intellij.openapi.vcs.checkin.CodeAnalysisBeforeCheckinHandler#processFoundCodeSmells
                    String commitButtonText = executor != null ? executor.getActionText()
                            : panel.getCommitActionName();
                    commitButtonText = StringUtil.trimEnd(commitButtonText, "...");
                    final int answer = Messages.showYesNoCancelDialog(panel.getProject(),
                            ResourcesLoader.getString("checkin.problem.text"),
                            StringUtil.capitalizeWords(ResourcesLoader.getString("checkin.problem.title"),
                                    true),
                            ResourcesLoader.getString("checkin.problem.review"), commitButtonText,
                            CommonBundle.getCancelButtonText(), UIUtil.getWarningIcon());
                    if (answer == Messages.YES) {
                        ToolWindowPanel.showWindow(panel.getProject());
                        return ReturnResult.CLOSE_WINDOW;
                    } else if (answer == Messages.CANCEL) {
                        return ReturnResult.CANCEL;
                    }
                }
            }
            return super.beforeCheckin(executor, additionalDataConsumer);
        }
    };
}

From source file:org.twodividedbyzero.idea.findbugs.core.PluginSuggestion.java

License:Open Source License

private static void showSuggestions(@NotNull final Project project,
        @NotNull final FindBugsPlugin findBugsPlugin, @NotNull final FindBugsPreferences preferences,
        @NotNull final Set<Suggestion> suggestions) {

    final StringBuilder sb = new StringBuilder();
    for (final Suggestion suggestion : suggestions) {
        sb.append("&nbsp;&nbsp;- <a href='").append(suggestion._pluginId).append("'>").append("Enable '")
                .append(suggestion._name).append("'</a><br>");
    }//from  w  ww .  j  a  va2  s  .c  o  m
    sb.append("<br><a href='").append(A_HREF_DISABLE_ANCHOR).append("'>Disable Suggestion</a>");

    FindBugsPluginImpl.NOTIFICATION_GROUP_PLUGIN_SUGGESTION.createNotification("FindBugs Plugin Suggestion",
            sb.toString(), NotificationType.INFORMATION, new NotificationListener() {
                @Override
                public void hyperlinkUpdate(@NotNull final Notification notification,
                        @NotNull final HyperlinkEvent event) {
                    if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                        final String desc = event.getDescription();
                        if (desc.equals(A_HREF_DISABLE_ANCHOR)) {
                            final int result = Messages.showYesNoDialog(project,
                                    "Notification will be disabled for all projects.\n\n"
                                            + "Settings | Appearance & Behavior | Notifications | "
                                            + FindBugsPluginImpl.NOTIFICATION_GROUP_ID_PLUGIN_SUGGESTION
                                            + "\ncan be used to configure the notification.",
                                    "FindBugs Plugin Suggestion Notification", "Disable Notification",
                                    CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
                            if (result == Messages.YES) {
                                NotificationUtil.getNotificationsConfigurationImpl().changeSettings(
                                        FindBugsPluginImpl.NOTIFICATION_GROUP_ID_PLUGIN_SUGGESTION,
                                        NotificationDisplayType.NONE, false, false);
                                notification.expire();
                            } else {
                                notification.hideBalloon();
                            }
                        } else {
                            enablePlugin(project, findBugsPlugin, desc, preferences);
                            notification.hideBalloon();
                        }
                    }
                }
            }).setImportant(false).notify(project);
}

From source file:org.twodividedbyzero.idea.findbugs.gui.preferences.PluginConfiguration.java

License:Open Source License

private void doAddPlugin(final File selectedFile) {
    try {//from   w ww  .  j a  v  a  2 s. c  om
        // TODO CUSTOM_PLUGIN: check what happen when a plugin with same pluginId is already loaded ?
        final Plugin plugin = FindBugsCustomPluginUtil.loadTemporary(selectedFile);
        if (plugin == null) {
            Messages.showErrorDialog(_parent, "Can not load plugin " + selectedFile.getPath(),
                    "Plugin Loading");
            return;
        }
        try {
            final int answer = Messages.showYesNoDialog(_parent, "Add plugin '" + plugin.getPluginId() + "'?",
                    "Add Plugin", null);
            if (answer == Messages.YES) {
                _preferences.addUserPlugin(FindBugsCustomPluginUtil.getAsString(plugin), plugin.getPluginId(),
                        true);
                updatePreferences();
                _preferences.setModified(true);
            }
        } finally {
            FindBugsCustomPluginUtil.unload(plugin);
        }
    } catch (final Throwable e) {
        //noinspection DialogTitleCapitalization
        Messages.showErrorDialog(_parent, "Error loading " + selectedFile.getPath() + ":\n\n"
                + e.getClass().getSimpleName() + ": " + e.getMessage(), "Error loading plugin");
    }
}

From source file:org.twodividedbyzero.idea.findbugs.gui.settings.ModuleSettingsPane.java

License:Open Source License

@Override
void initHeaderPane(@NotNull final JPanel topPanel) {
    overrideProjectSettingsCheckbox = new JBCheckBox(
            ResourcesLoader.getString("settings.module.overrideProjectSettings"));
    overrideProjectSettingsCheckbox.addActionListener(new ActionListener() {
        @Override//ww w .  ja va 2 s .c om
        public void actionPerformed(final ActionEvent e) {
            if (overrideProjectSettingsCheckbox.isSelected()) {
                if (Messages.YES == Messages.showYesNoDialog(overrideProjectSettingsCheckbox,
                        ResourcesLoader.getString("settings.module.loadProject.text"),
                        StringUtil.capitalizeWords(
                                ResourcesLoader.getString("settings.module.loadProject.title"), true),
                        Messages.getQuestionIcon())) {
                    reset(ProjectSettings.getInstance(project));
                }
            } else {
                if (Messages.YES == Messages
                        .showYesNoDialog(overrideProjectSettingsCheckbox,
                                ResourcesLoader.getString("settings.module.reset.text"),
                                StringUtil.capitalizeWords(
                                        ResourcesLoader.getString("settings.action.reset.title"), true),
                                Messages.getQuestionIcon())) {
                    final ModuleSettings settings = new ModuleSettings();
                    reset(settings);
                    resetModule(settings);
                }
            }
            updateControls();
        }
    });
    topPanel.add(overrideProjectSettingsCheckbox);
}