Example usage for com.intellij.openapi.ui.popup.util BaseListPopupStep setDefaultOptionIndex

List of usage examples for com.intellij.openapi.ui.popup.util BaseListPopupStep setDefaultOptionIndex

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup.util BaseListPopupStep setDefaultOptionIndex.

Prototype

public void setDefaultOptionIndex(int aDefaultOptionIndex) 

Source Link

Usage

From source file:com.intellij.ui.popup.PopupFactoryImpl.java

License:Apache License

@NotNull
@Override/* w  w w. j a  v a 2s  . co m*/
public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes,
        final Runnable onNo, int defaultOptionIndex) {

    final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title,
            new String[] { yesText, noText }) {
        @Override
        public PopupStep onChosen(String selectedValue, final boolean finalChoice) {
            if (selectedValue.equals(yesText)) {
                onYes.run();
            } else {
                onNo.run();
            }
            return FINAL_CHOICE;
        }

        @Override
        public void canceled() {
            onNo.run();
        }

        @Override
        public boolean isMnemonicsNavigationEnabled() {
            return true;
        }
    };
    step.setDefaultOptionIndex(defaultOptionIndex);

    final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
    return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText);
}

From source file:krasa.formatter.plugin.ProjectSettingsForm.java

License:Apache License

public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes,
        final Runnable onNo, int defaultOptionIndex) {

    final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title,
            new String[] { yesText, noText }) {
        public PopupStep onChosen(String selectedValue, final boolean finalChoice) {
            if (selectedValue.equals(yesText)) {
                onYes.run();/*from   ww  w . j  a va  2s  .co m*/
            } else {
                onNo.run();
            }
            return FINAL_CHOICE;
        }

        public void canceled() {
        }

        public boolean isMnemonicsNavigationEnabled() {
            return true;
        }
    };
    step.setDefaultOptionIndex(defaultOptionIndex);

    final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
    return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText);
}

From source file:org.jetbrains.plugins.groovy.console.GroovyShellActionBase.java

License:Apache License

private void runGroovyShell(Project project) {
    List<Module> modules = new ArrayList<Module>();
    final Map<Module, String> versions = new HashMap<Module, String>();

    for (Module module : getGroovyCompatibleModules(project)) {
        GroovyShellRunner runner = GroovyShellRunner.getAppropriateRunner(module);
        if (runner != null) {
            modules.add(module);/*  w w w . j ava  2  s. com*/
            versions.put(module, runner.getTitle(module));
        }
    }

    if (modules.size() == 1) {
        doRun(modules.get(0));
        return;
    }

    Collections.sort(modules, ModulesAlphaComparator.INSTANCE);

    BaseListPopupStep<Module> step = new BaseListPopupStep<Module>("Which module to use classpath of?", modules,
            PlatformIcons.CONTENT_ROOT_ICON_CLOSED) {
        @NotNull
        @Override
        public String getTextFor(Module value) {
            return value.getName() + versions.get(value);
        }

        @Override
        public String getIndexedString(Module value) {
            return value.getName();
        }

        @Override
        public boolean isSpeedSearchEnabled() {
            return true;
        }

        @Override
        public PopupStep onChosen(Module selectedValue, boolean finalChoice) {
            PropertiesComponent.getInstance(selectedValue.getProject()).setValue(GROOVY_SHELL_LAST_MODULE,
                    selectedValue.getName());
            doRun(selectedValue);
            return null;
        }
    };

    for (int i = 0; i < modules.size(); i++) {
        Module module = modules.get(i);
        if (module.getName()
                .equals(PropertiesComponent.getInstance(project).getValue(GROOVY_SHELL_LAST_MODULE))) {
            step.setDefaultOptionIndex(i);
            break;
        }
    }
    JBPopupFactory.getInstance().createListPopup(step).showCenteredInCurrentWindow(project);
}