Search in sources :

Example 1 with ExecutorProvider

use of com.intellij.execution.actions.ExecutorProvider in project intellij-community by JetBrains.

the class ProjectStartupConfigurable method selectAndAddConfiguration.

private void selectAndAddConfiguration(final AnActionButton button) {
    final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    final List<ChooseRunConfigurationPopup.ItemWrapper> wrappers = new ArrayList<>();
    wrappers.add(createNewWrapper(button));
    final ChooseRunConfigurationPopup.ItemWrapper[] allSettings = ChooseRunConfigurationPopup.createSettingsList(myProject, new ExecutorProvider() {

        @Override
        public Executor getExecutor() {
            return executor;
        }
    }, false);
    final Set<RunnerAndConfigurationSettings> existing = new HashSet<>(myModel.getAllConfigurations());
    for (ChooseRunConfigurationPopup.ItemWrapper setting : allSettings) {
        if (setting.getValue() instanceof RunnerAndConfigurationSettings) {
            final RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings) setting.getValue();
            if (!settings.isTemporary() && ProjectStartupRunner.canBeRun(settings) && !existing.contains(settings)) {
                wrappers.add(setting);
            }
        }
    }
    final JBList list = new JBList(wrappers);
    list.setCellRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof ChooseRunConfigurationPopup.ItemWrapper) {
                setIcon(((ChooseRunConfigurationPopup.ItemWrapper) value).getIcon());
                append(((ChooseRunConfigurationPopup.ItemWrapper) value).getText());
            }
        }
    });
    final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
        final int index = list.getSelectedIndex();
        if (index < 0)
            return;
        final ChooseRunConfigurationPopup.ItemWrapper at = (ChooseRunConfigurationPopup.ItemWrapper) list.getModel().getElementAt(index);
        if (at.getValue() instanceof RunnerAndConfigurationSettings) {
            final RunnerAndConfigurationSettings added = (RunnerAndConfigurationSettings) at.getValue();
            addConfiguration(added);
        } else {
            at.perform(myProject, executor, button.getDataContext());
        }
    }).createPopup();
    showPopup(button, popup);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ChooseRunConfigurationPopup(com.intellij.execution.actions.ChooseRunConfigurationPopup) JBList(com.intellij.ui.components.JBList) ExecutorProvider(com.intellij.execution.actions.ExecutorProvider) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

ChooseRunConfigurationPopup (com.intellij.execution.actions.ChooseRunConfigurationPopup)1 ExecutorProvider (com.intellij.execution.actions.ExecutorProvider)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 JBList (com.intellij.ui.components.JBList)1