Search in sources :

Example 1 with ConfigurationType

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

the class BaseRunConfigurationAction method getChildren.

private AnAction[] getChildren(DataContext dataContext) {
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    final RunnerAndConfigurationSettings existing = context.findExisting();
    if (existing == null) {
        final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
        if (producers.size() > 1) {
            final AnAction[] children = new AnAction[producers.size()];
            int childIdx = 0;
            for (final ConfigurationFromContext fromContext : producers) {
                final ConfigurationType configurationType = fromContext.getConfigurationType();
                final RunConfiguration configuration = fromContext.getConfiguration();
                final String actionName = childActionName(configurationType, configuration);
                final AnAction anAction = new AnAction(actionName, configurationType.getDisplayName(), configuration.getIcon()) {

                    @Override
                    public void actionPerformed(AnActionEvent e) {
                        perform(fromContext, context);
                    }
                };
                anAction.getTemplatePresentation().setText(actionName, false);
                children[childIdx++] = anAction;
            }
            return children;
        }
    }
    return EMPTY_ARRAY;
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 2 with ConfigurationType

use of com.intellij.execution.configurations.ConfigurationType 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 3 with ConfigurationType

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

the class ProgramRunnerUtil method executeConfiguration.

public static void executeConfiguration(@NotNull final ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) {
    if (ExecutorRegistry.getInstance().isStarting(environment)) {
        return;
    }
    RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
    final Project project = environment.getProject();
    if (runnerAndConfigurationSettings != null) {
        if (!ExecutionTargetManager.canRun(environment)) {
            ExecutionUtil.handleExecutionError(environment, new ExecutionException(StringUtil.escapeXml("Cannot run '" + environment.getRunProfile().getName() + "' on '" + environment.getExecutionTarget().getDisplayName() + "'")));
            return;
        }
        if ((!RunManagerImpl.canRunConfiguration(environment) || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) && !DumbService.isDumb(project)) {
            if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
                return;
            }
            while (!RunManagerImpl.canRunConfiguration(environment)) {
                if (Messages.YES == Messages.showYesNoDialog(project, "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings", "Edit", "Continue Anyway", Messages.getErrorIcon())) {
                    if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
                        return;
                    }
                } else {
                    break;
                }
            }
        }
        ConfigurationType configurationType = runnerAndConfigurationSettings.getType();
        if (configurationType != null) {
            UsageTrigger.trigger("execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + environment.getExecutor().getId());
        }
    }
    try {
        if (assignNewId) {
            environment.assignNewExecutionId();
        }
        if (DumbService.isDumb(project) && Registry.is("dumb.aware.run.configurations")) {
            UIUtil.invokeLaterIfNeeded(() -> {
                if (project.isDisposed()) {
                    return;
                }
                final String toolWindowId = ExecutionManager.getInstance(project).getContentManager().getToolWindowIdByEnvironment(environment);
                ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
                if (toolWindowManager.canShowNotification(toolWindowId)) {
                    //noinspection SSBasedInspection
                    toolWindowManager.notifyByBalloon(toolWindowId, MessageType.INFO, "Some actions may not work as expected if you start a Run/debug configuration while indexing is in progress.");
                }
            });
        }
        environment.getRunner().execute(environment);
    } catch (ExecutionException e) {
        String name = runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null;
        if (name == null) {
            name = environment.getRunProfile().getName();
        }
        if (name == null && environment.getContentToReuse() != null) {
            name = environment.getContentToReuse().getDisplayName();
        }
        if (name == null) {
            name = "<Unknown>";
        }
        ExecutionUtil.handleExecutionError(project, ExecutionManager.getInstance(project).getContentManager().getToolWindowIdByEnvironment(environment), name, e);
    }
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) Project(com.intellij.openapi.project.Project) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager)

Example 4 with ConfigurationType

use of com.intellij.execution.configurations.ConfigurationType 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)

Example 5 with ConfigurationType

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

the class RunConfigurationsComboBoxAction method createPopupActionGroup.

@Override
@NotNull
protected DefaultActionGroup createPopupActionGroup(final JComponent button) {
    final DefaultActionGroup allActionsGroup = new DefaultActionGroup();
    final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(button));
    if (project != null) {
        final RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
        allActionsGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_RUN_CONFIGURATIONS));
        allActionsGroup.add(new SaveTemporaryAction());
        allActionsGroup.addSeparator();
        RunnerAndConfigurationSettings selected = RunManager.getInstance(project).getSelectedConfiguration();
        if (selected != null) {
            ExecutionTarget activeTarget = ExecutionTargetManager.getActiveTarget(project);
            for (ExecutionTarget eachTarget : ExecutionTargetManager.getTargetsToChooseFor(project, selected)) {
                allActionsGroup.add(new SelectTargetAction(project, eachTarget, eachTarget.equals(activeTarget)));
            }
            allActionsGroup.addSeparator();
        }
        final ConfigurationType[] types = runManager.getConfigurationFactories();
        for (ConfigurationType type : types) {
            final DefaultActionGroup actionGroup = new DefaultActionGroup();
            Map<String, List<RunnerAndConfigurationSettings>> structure = runManager.getStructure(type);
            for (Map.Entry<String, List<RunnerAndConfigurationSettings>> entry : structure.entrySet()) {
                DefaultActionGroup group = entry.getKey() != null ? new DefaultActionGroup(entry.getKey(), true) : actionGroup;
                group.getTemplatePresentation().setIcon(AllIcons.Nodes.Folder);
                for (RunnerAndConfigurationSettings settings : entry.getValue()) {
                    group.add(new SelectConfigAction(settings, project));
                }
                if (group != actionGroup) {
                    actionGroup.add(group);
                }
            }
            allActionsGroup.add(actionGroup);
            allActionsGroup.addSeparator();
        }
    }
    return allActionsGroup;
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) Project(com.intellij.openapi.project.Project) List(java.util.List) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ConfigurationType (com.intellij.execution.configurations.ConfigurationType)15 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)7 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)6 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)5 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)4 List (java.util.List)4 UnknownConfigurationType (com.intellij.execution.configurations.UnknownConfigurationType)3 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)3 AndroidJUnitConfigurationType (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationType)2 EditConfigurationsDialog (com.intellij.execution.impl.EditConfigurationsDialog)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Map (java.util.Map)2 MakeBeforeRunTaskProvider (com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider)1 AndroidJUnitConfigurationProducer (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationProducer)1 BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)1 RunManager (com.intellij.execution.RunManager)1 RunManagerEx (com.intellij.execution.RunManagerEx)1 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)1 DashboardRunConfigurationNode (com.intellij.execution.dashboard.DashboardRunConfigurationNode)1