Search in sources :

Example 1 with UnknownConfigurationType

use of com.intellij.execution.configurations.UnknownConfigurationType in project intellij-community by JetBrains.

the class ChooseRunConfigurationPopup method createSettingsList.

public static ItemWrapper[] createSettingsList(@NotNull Project project, @NotNull ExecutorProvider executorProvider, boolean createEditAction) {
    List<ItemWrapper> result = new ArrayList<>();
    if (createEditAction) {
        ItemWrapper<Void> edit = new ItemWrapper<Void>(null) {

            @Override
            public Icon getIcon() {
                return AllIcons.Actions.EditSource;
            }

            @Override
            public String getText() {
                return UIUtil.removeMnemonic(ActionsBundle.message("action.editRunConfigurations.text"));
            }

            @Override
            public void perform(@NotNull final Project project, @NotNull final Executor executor, @NotNull DataContext context) {
                if (new EditConfigurationsDialog(project) {

                    @Override
                    protected void init() {
                        setOKButtonText(executor.getStartActionText());
                        setOKButtonIcon(executor.getIcon());
                        myExecutor = executor;
                        super.init();
                    }
                }.showAndGet()) {
                    ApplicationManager.getApplication().invokeLater(() -> {
                        RunnerAndConfigurationSettings configuration = RunManager.getInstance(project).getSelectedConfiguration();
                        if (configuration != null) {
                            ExecutionUtil.runConfiguration(configuration, executor);
                        }
                    }, project.getDisposed());
                }
            }

            @Override
            public boolean available(Executor executor) {
                return true;
            }
        };
        edit.setMnemonic(0);
        result.add(edit);
    }
    RunManagerEx manager = RunManagerEx.getInstanceEx(project);
    final RunnerAndConfigurationSettings selectedConfiguration = manager.getSelectedConfiguration();
    if (selectedConfiguration != null) {
        boolean isFirst = true;
        final ExecutionTarget activeTarget = ExecutionTargetManager.getActiveTarget(project);
        for (ExecutionTarget eachTarget : ExecutionTargetManager.getTargetsToChooseFor(project, selectedConfiguration)) {
            result.add(new ItemWrapper<ExecutionTarget>(eachTarget, isFirst) {

                {
                    setChecked(getValue().equals(activeTarget));
                }

                @Override
                public Icon getIcon() {
                    return getValue().getIcon();
                }

                @Override
                public String getText() {
                    return getValue().getDisplayName();
                }

                @Override
                public void perform(@NotNull final Project project, @NotNull final Executor executor, @NotNull DataContext context) {
                    ExecutionTargetManager.setActiveTarget(project, getValue());
                    ExecutionUtil.runConfiguration(selectedConfiguration, executor);
                }

                @Override
                public boolean available(Executor executor) {
                    return true;
                }
            });
            isFirst = false;
        }
    }
    Map<RunnerAndConfigurationSettings, ItemWrapper> wrappedExisting = new LinkedHashMap<>();
    for (ConfigurationType type : manager.getConfigurationFactories()) {
        if (!(type instanceof UnknownConfigurationType)) {
            Map<String, List<RunnerAndConfigurationSettings>> structure = manager.getStructure(type);
            for (Map.Entry<String, List<RunnerAndConfigurationSettings>> entry : structure.entrySet()) {
                if (entry.getValue().isEmpty()) {
                    continue;
                }
                final String key = entry.getKey();
                if (key != null) {
                    boolean isSelected = entry.getValue().contains(selectedConfiguration);
                    if (isSelected) {
                        assert selectedConfiguration != null;
                    }
                    FolderWrapper folderWrapper = new FolderWrapper(project, executorProvider, key + (isSelected ? "  (mnemonic is to \"" + selectedConfiguration.getName() + "\")" : ""), entry.getValue());
                    if (isSelected) {
                        folderWrapper.setMnemonic(1);
                    }
                    result.add(folderWrapper);
                } else {
                    for (RunnerAndConfigurationSettings configuration : entry.getValue()) {
                        final ItemWrapper wrapped = ItemWrapper.wrap(project, configuration);
                        if (configuration == selectedConfiguration) {
                            wrapped.setMnemonic(1);
                        }
                        wrappedExisting.put(configuration, wrapped);
                    }
                }
            }
        }
    }
    if (!DumbService.isDumb(project)) {
        populateWithDynamicRunners(result, wrappedExisting, project, manager, selectedConfiguration);
    }
    result.addAll(wrappedExisting.values());
    return result.toArray(new ItemWrapper[result.size()]);
}
Also used : NotNull(org.jetbrains.annotations.NotNull) DataContext(com.intellij.openapi.actionSystem.DataContext) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) List(java.util.List) ConfigurationType(com.intellij.execution.configurations.ConfigurationType) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) EditConfigurationsDialog(com.intellij.execution.impl.EditConfigurationsDialog) Project(com.intellij.openapi.project.Project)

Example 2 with UnknownConfigurationType

use of com.intellij.execution.configurations.UnknownConfigurationType in project intellij-community by JetBrains.

the class CompoundRunConfigurationSettingsEditor method createEditor.

@NotNull
@Override
protected JComponent createEditor() {
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myList);
    return decorator.disableUpDownActions().setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final List<RunConfiguration> all = new ArrayList<>();
            for (ConfigurationType type : myRunManager.getConfigurationFactories()) {
                if (!(type instanceof UnknownConfigurationType)) {
                    for (RunnerAndConfigurationSettings settings : myRunManager.getConfigurationSettingsList(type)) {
                        all.add(settings.getConfiguration());
                    }
                }
            }
            final List<RunConfiguration> configurations = ContainerUtil.filter(all, configuration -> !mySnapshot.getSetToRun().contains(configuration) && canBeAdded(configuration, mySnapshot));
            JBPopupFactory.getInstance().createListPopup(new MultiSelectionListPopupStep<RunConfiguration>(null, configurations) {

                @Nullable
                @Override
                public ListSeparator getSeparatorAbove(RunConfiguration value) {
                    int i = configurations.indexOf(value);
                    if (i < 1)
                        return null;
                    RunConfiguration previous = configurations.get(i - 1);
                    return value.getType() != previous.getType() ? new ListSeparator() : null;
                }

                @Override
                public Icon getIconFor(RunConfiguration value) {
                    return value.getType().getIcon();
                }

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

                @NotNull
                @Override
                public String getTextFor(RunConfiguration value) {
                    return value.getName();
                }

                @Override
                public PopupStep<?> onChosen(List<RunConfiguration> selectedValues, boolean finalChoice) {
                    myList.clearSelection();
                    myModel.addAll(selectedValues);
                    return FINAL_CHOICE;
                }
            }).showUnderneathOf(decorator.getActionsPanel());
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int index = myList.getSelectedIndex();
            if (index == -1)
                return;
            RunConfiguration configuration = myModel.get(index);
            RunConfigurationSelector selector = RunConfigurationSelector.KEY.getData(DataManager.getInstance().getDataContext(button.getContextComponent()));
            if (selector != null) {
                selector.select(configuration);
            }
        }
    }).setToolbarPosition(ActionToolbarPosition.TOP).createPanel();
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ArrayList(java.util.ArrayList) RunConfigurationSelector(com.intellij.execution.impl.RunConfigurationSelector) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) MultiSelectionListPopupStep(com.intellij.openapi.ui.popup.MultiSelectionListPopupStep) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ConfigurationType (com.intellij.execution.configurations.ConfigurationType)2 UnknownConfigurationType (com.intellij.execution.configurations.UnknownConfigurationType)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 EditConfigurationsDialog (com.intellij.execution.impl.EditConfigurationsDialog)1 RunConfigurationSelector (com.intellij.execution.impl.RunConfigurationSelector)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Project (com.intellij.openapi.project.Project)1 ListSeparator (com.intellij.openapi.ui.popup.ListSeparator)1 MultiSelectionListPopupStep (com.intellij.openapi.ui.popup.MultiSelectionListPopupStep)1 JBList (com.intellij.ui.components.JBList)1 ArrayList (java.util.ArrayList)1