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

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

Introduction

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

Prototype

public BaseListPopupStep(@Nullable String title, @NotNull List<? extends T> values,
            List<? extends Icon> icons) 

Source Link

Usage

From source file:com.gogh.plugin.action.ExternalTranslationAction.java

License:Apache License

public static void showExternalTranslation(String query, DataContext dataContext) {
    final Component contextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);

    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final List<String> menuItems = new ArrayList<>();
        final List<String> urls = new ArrayList<>();
        final List<Icon> icons = new ArrayList<Icon>();

        for (Translator translator : Translators.getTranslator()) {
            String url = translator.getExternalUrl(query);
            if (url != null) {
                menuItems.add(translator.getMenuItem());
                urls.add(url);//w w w. j  ava 2 s  .  c  o m
                icons.add(translator.getIcon());
            }
        }

        ApplicationManager.getApplication()
                .invokeLater(() -> JBPopupFactory.getInstance()
                        .createListPopup(new BaseListPopupStep<String>("Choose web platform",
                                ArrayUtil.toStringArray(menuItems),
                                ArrayUtil.toObjectArray(icons, Icon.class)) {
                            @Override
                            public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
                                if (selectedValue.equals(menuItems.get(0))) {
                                    BrowserUtil.browse(urls.get(0));
                                } else if (selectedValue.equals(menuItems.get(1))) {
                                    BrowserUtil.browse(urls.get(1));
                                }
                                return FINAL_CHOICE;
                            }
                        }).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent)),
                        ModalityState.NON_MODAL);
    });
}

From source file:com.gogh.plugin.action.ExternalTranslationAction.java

License:Apache License

public static void showExternalTranslation(String query, String externalUrl, DataContext dataContext) {
    final Component contextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);

    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final List<String> urls = new ArrayList<String>();
        final List<Icon> icons = new ArrayList<Icon>();

        if (StringUtil.isEmptyOrSpaces(externalUrl)) {
            for (Translator translator : Translators.getTranslator()) {
                String url = translator.getExternalUrl(query);
                if (url != null) {
                    urls.add(url);//from   w ww .j  a v  a  2  s  .com
                    icons.add(translator.getIcon());
                }
            }
        } else {
            urls.add(externalUrl);
        }

        ApplicationManager.getApplication().invokeLater(() -> {
            if (ContainerUtil.isEmpty(urls)) {
                // do nothing
            } else if (urls.size() == 1) {
                BrowserUtil.browse(urls.get(0));
            } else {
                JBPopupFactory.getInstance()
                        .createListPopup(new BaseListPopupStep<String>("Choose web platform",
                                ArrayUtil.toStringArray(urls), ArrayUtil.toObjectArray(icons, Icon.class)) {
                            @Override
                            public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
                                BrowserUtil.browse(selectedValue);
                                return FINAL_CHOICE;
                            }
                        }).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent));
            }

        }, ModalityState.NON_MODAL);
    });
}

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

License:Apache License

private static ListPopup createPopup(final ArrayList<VirtualFile> files, final ArrayList<Icon> icons) {
    final BaseListPopupStep<VirtualFile> step = new BaseListPopupStep<VirtualFile>("File Path", files, icons) {
        @NotNull// w  w w  .ja  v  a 2s  .  c o m
        @Override
        public String getTextFor(final VirtualFile value) {
            return value.getPresentableName();
        }

        @Override
        public PopupStep onChosen(final VirtualFile selectedValue, final boolean finalChoice) {
            final File selectedFile = new File(getPresentableUrl(selectedValue));
            if (selectedFile.exists()) {
                ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
                    @Override
                    public void run() {
                        openFile(selectedFile);
                    }
                });
            }
            return FINAL_CHOICE;
        }
    };

    return JBPopupFactory.getInstance().createListPopup(step);
}

From source file:com.intellij.translation.actions.ExternalTranslationAction.java

License:Apache License

public static void showExternalTranslation(String query, String externalUrl, DataContext dataContext) {
    final Component contextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);

    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final List<String> urls = new ArrayList<String>();
        final List<Icon> icons = new ArrayList<Icon>();

        if (StringUtil.isEmptyOrSpaces(externalUrl)) {
            for (Translator translator : TranslationManager.TRANSLATOR_EP.getExtensions()) {
                String url = translator.getExternalUrl(query);
                if (url != null) {
                    urls.add(url);/*from  w w  w  .  j  a  v  a2 s  . com*/
                    icons.add(translator.getIcon());
                }
            }
        } else {
            urls.add(externalUrl);
        }

        ApplicationManager.getApplication().invokeLater(() -> {
            if (ContainerUtil.isEmpty(urls)) {
                // do nothing
            } else if (urls.size() == 1) {
                BrowserUtil.browse(urls.get(0));
            } else {
                JBPopupFactory.getInstance()
                        .createListPopup(new BaseListPopupStep<String>("Choose external translation root",
                                ArrayUtil.toStringArray(urls), ArrayUtil.toObjectArray(icons, Icon.class)) {
                            @Override
                            public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
                                BrowserUtil.browse(selectedValue);
                                return FINAL_CHOICE;
                            }
                        }).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent));
            }

        }, ModalityState.NON_MODAL);
    });
}

From source file:com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettingsConfigurable.java

License:Apache License

protected void createSubstitutedExtensionsComponent(FormBuilder builder) {
    substitutedExtensionsModel = new CollectionListModel<String>();
    substitutedExtensionsList = new JBList(substitutedExtensionsModel);
    substitutedExtensionsPanel = ToolbarDecorator.createDecorator(substitutedExtensionsList)
            .setAddAction(new AnActionButtonRunnable() {
                @Override//from   www.  jav a2 s  . c o  m
                public void run(AnActionButton anActionButton) {
                    FileTypeManager fileTypeManager = FileTypeManager.getInstance();
                    final List<String> currentItems = substitutedExtensionsModel.getItems();
                    List<FileNameMatcher> possibleItems = new ArrayList<FileNameMatcher>();
                    List<Icon> itemsIcons = new ArrayList<Icon>();

                    for (FileType fileType : fileTypeManager.getRegisteredFileTypes()) {
                        if (fileType instanceof LanguageFileType) {
                            for (FileNameMatcher matcher : fileTypeManager.getAssociations(fileType)) {
                                String presentableString = matcher.getPresentableString();
                                if (!currentItems.contains(presentableString)) {
                                    possibleItems.add(matcher);
                                    itemsIcons.add(fileType.getIcon());
                                }
                            }
                        }
                    }

                    BaseListPopupStep<FileNameMatcher> fileNameMatcherBaseListPopupStep = new BaseListPopupStep<FileNameMatcher>(
                            "Select Extension", possibleItems, itemsIcons) {
                        @Override
                        public PopupStep onChosen(FileNameMatcher selectedValue, boolean finalChoice) {
                            substitutedExtensionsModel.add(selectedValue.getPresentableString());
                            return super.onChosen(selectedValue, finalChoice);
                        }
                    };

                    JBPopupFactory.getInstance().createListPopup(fileNameMatcherBaseListPopupStep, 20)
                            .showInCenterOf(substitutedExtensionsPanel);
                }
            }).disableDownAction().disableUpAction()
            .setPreferredSize(JBUI.size(0, PerlConfigurationUtil.WIDGET_HEIGHT)).createPanel();
    builder.addLabeledComponent(new JLabel(
            "Extensions that should be handled as HTML::Mason components except *.mas (only under roots configured above):"),
            substitutedExtensionsPanel);
}

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);// www  . jav a 2s  .  c om
            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);
}

From source file:org.sonar.ide.idea.editor.ViolationGutterIconRenderer.java

License:Open Source License

@Override
public AnAction getClickAction() {
    return new AnAction() {
        @Override// w  ww .  j a  va  2s. co  m
        public void actionPerformed(AnActionEvent event) {
            List<String> text = new ArrayList<String>();
            List<Icon> icons = new ArrayList<Icon>();
            // Violations
            for (Violation violation : violations) {
                text.add(violation.getRuleName() + " : " + violation.getMessage());
                icons.add(IconLoader.getIcon(IconsUtils.getPriorityIconPath(violation)));
            }
            // Duplications
            for (Duplication duplication : duplications) {
                text.add(duplication.toString());
            }

            JBPopupFactory.getInstance()
                    .createListPopup(new BaseListPopupStep<String>("Violations", text, icons) {
                        @Override
                        public PopupStep onChosen(String selectedValue, boolean finalChoice) {
                            // TODO show rule description
                            return super.onChosen(selectedValue, finalChoice);
                        }
                    }).showInBestPositionFor(event.getDataContext());
        }
    };
}