Search in sources :

Example 1 with TaskData

use of com.intellij.openapi.externalSystem.model.task.TaskData in project intellij-community by JetBrains.

the class ExternalProjectsDataStorage method convert.

private static DataNode<ProjectData> convert(@NotNull ProjectSystemId systemId, @NotNull ExternalProjectPojo rootProject, @NotNull Collection<ExternalProjectPojo> childProjects, @NotNull Map<String, Collection<ExternalTaskPojo>> availableTasks) {
    ProjectData projectData = new ProjectData(systemId, rootProject.getName(), rootProject.getPath(), rootProject.getPath());
    DataNode<ProjectData> projectDataNode = new DataNode<>(PROJECT, projectData, null);
    for (ExternalProjectPojo childProject : childProjects) {
        String moduleConfigPath = childProject.getPath();
        ModuleData moduleData = new ModuleData(childProject.getName(), systemId, ModuleTypeId.JAVA_MODULE, childProject.getName(), moduleConfigPath, moduleConfigPath);
        final DataNode<ModuleData> moduleDataNode = projectDataNode.createChild(MODULE, moduleData);
        final Collection<ExternalTaskPojo> moduleTasks = availableTasks.get(moduleConfigPath);
        if (moduleTasks != null) {
            for (ExternalTaskPojo moduleTask : moduleTasks) {
                TaskData taskData = new TaskData(systemId, moduleTask.getName(), moduleConfigPath, moduleTask.getDescription());
                moduleDataNode.createChild(TASK, taskData);
            }
        }
    }
    return projectDataNode;
}
Also used : ExternalTaskPojo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Example 2 with TaskData

use of com.intellij.openapi.externalSystem.model.task.TaskData in project intellij-community by JetBrains.

the class ExternalSystemKeymapExtension method createGroup.

public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(ExternalSystemBundle.message("external.system.keymap.group"), ExternalSystemIcons.TaskGroup);
    AnAction[] externalSystemActions = ActionsTreeUtil.getActions("ExternalSystem.Actions");
    for (AnAction action : externalSystemActions) {
        ActionsTreeUtil.addAction(result, action, condition);
    }
    if (project == null)
        return result;
    MultiMap<ProjectSystemId, String> projectToActionsMapping = MultiMap.create();
    for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        projectToActionsMapping.putValues(manager.getSystemId(), ContainerUtil.<String>emptyList());
    }
    ActionManager actionManager = ActionManager.getInstance();
    if (actionManager != null) {
        for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
            AnAction eachAction = actionManager.getAction(eachId);
            if (!(eachAction instanceof MyExternalSystemAction))
                continue;
            if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
                continue;
            MyExternalSystemAction taskAction = (MyExternalSystemAction) eachAction;
            projectToActionsMapping.putValue(taskAction.getSystemId(), eachId);
        }
    }
    Map<ProjectSystemId, KeymapGroup> keymapGroupMap = ContainerUtil.newHashMap();
    for (ProjectSystemId systemId : projectToActionsMapping.keySet()) {
        if (!keymapGroupMap.containsKey(systemId)) {
            final Icon projectIcon = ExternalSystemUiUtil.getUiAware(systemId).getProjectIcon();
            KeymapGroup group = KeymapGroupFactory.getInstance().createGroup(systemId.getReadableName(), projectIcon);
            keymapGroupMap.put(systemId, group);
        }
    }
    for (Map.Entry<ProjectSystemId, Collection<String>> each : projectToActionsMapping.entrySet()) {
        Collection<String> tasks = each.getValue();
        final ProjectSystemId systemId = each.getKey();
        final KeymapGroup systemGroup = keymapGroupMap.get(systemId);
        if (systemGroup == null)
            continue;
        for (String actionId : tasks) {
            systemGroup.addActionId(actionId);
        }
        if (systemGroup instanceof Group) {
            Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
            ((Group) systemGroup).addHyperlink(new Hyperlink(icon, "Choose a task to assign a shortcut") {

                @Override
                public void onClick(MouseEvent e) {
                    SelectExternalTaskDialog dialog = new SelectExternalTaskDialog(systemId, project);
                    if (dialog.showAndGet() && dialog.getResult() != null) {
                        TaskData taskData = dialog.getResult().second;
                        String ownerModuleName = dialog.getResult().first;
                        ExternalSystemTaskAction externalSystemAction = (ExternalSystemTaskAction) getOrRegisterAction(project, ownerModuleName, taskData);
                        ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
                        Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
                        KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
                        if (keymapPanel != null) {
                            // clear actions filter
                            keymapPanel.showOption("");
                            keymapPanel.selectAction(externalSystemAction.myId);
                        }
                    }
                }
            });
        }
    }
    for (KeymapGroup keymapGroup : keymapGroupMap.values()) {
        if (isGroupFiltered(condition, keymapGroup)) {
            result.addGroup(keymapGroup);
        }
    }
    for (ActionsProvider extension : ActionsProvider.EP_NAME.getExtensions()) {
        KeymapGroup keymapGroup = extension.createGroup(condition, project);
        if (isGroupFiltered(condition, keymapGroup)) {
            result.addGroup(keymapGroup);
        }
    }
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) Settings(com.intellij.openapi.options.ex.Settings) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) MouseEvent(java.awt.event.MouseEvent) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) SelectExternalTaskDialog(com.intellij.openapi.externalSystem.service.ui.SelectExternalTaskDialog) Collection(java.util.Collection) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Example 3 with TaskData

use of com.intellij.openapi.externalSystem.model.task.TaskData in project intellij-community by JetBrains.

the class ToolWindowTaskService method processData.

@Override
protected void processData(@NotNull Collection<DataNode<TaskData>> nodes, @NotNull Project project) {
    if (nodes.isEmpty()) {
        return;
    }
    ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    ExternalSystemKeymapExtension.updateActions(project, nodes);
    MultiMap<ExternalConfigPathAware, DataNode<TaskData>> grouped = ContainerUtil.groupBy(nodes, TASK_HOLDER_RETRIEVAL_STRATEGY);
    Map<String, Collection<ExternalTaskPojo>> data = ContainerUtilRt.newHashMap();
    for (Map.Entry<ExternalConfigPathAware, Collection<DataNode<TaskData>>> entry : grouped.entrySet()) {
        data.put(entry.getKey().getLinkedExternalProjectPath(), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
    }
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Map<String, Collection<ExternalTaskPojo>> availableTasks = ContainerUtilRt.newHashMap(settings.getAvailableTasks());
    availableTasks.putAll(data);
    settings.setAvailableTasks(availableTasks);
}
Also used : ExternalConfigPathAware(com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) Collection(java.util.Collection) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Example 4 with TaskData

use of com.intellij.openapi.externalSystem.model.task.TaskData in project intellij-community by JetBrains.

the class ToggleTaskActivationAction method getTasks.

@NotNull
private static List<TaskData> getTasks(AnActionEvent e) {
    final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
    if (selectedNodes == null)
        return Collections.emptyList();
    List<TaskData> tasks = new SmartList<>();
    for (ExternalSystemNode node : selectedNodes) {
        if (node instanceof TaskNode && !node.isIgnored()) {
            tasks.add((TaskData) node.getData());
        } else if (node instanceof RunConfigurationNode) {
            final RunnerAndConfigurationSettings configurationSettings = ((RunConfigurationNode) node).getSettings();
            final ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) configurationSettings.getConfiguration();
            final ExternalSystemTaskExecutionSettings taskExecutionSettings = runConfiguration.getSettings();
            tasks.add(new TaskData(taskExecutionSettings.getExternalSystemId(), RUN_CONFIGURATION_TASK_PREFIX + configurationSettings.getName(), taskExecutionSettings.getExternalProjectPath(), null));
        } else {
            return Collections.emptyList();
        }
    }
    return tasks;
}
Also used : TaskNode(com.intellij.openapi.externalSystem.view.TaskNode) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) SmartList(com.intellij.util.SmartList) RunConfigurationNode(com.intellij.openapi.externalSystem.view.RunConfigurationNode) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with TaskData

use of com.intellij.openapi.externalSystem.model.task.TaskData in project intellij-community by JetBrains.

the class GradleArgumentsCompletionProvider method getVariants.

protected List<LookupElement> getVariants(@NotNull final DataNode<ProjectData> projectDataNode, @NotNull final String modulePath) {
    final DataNode<ModuleData> moduleDataNode = findModuleDataNode(projectDataNode, modulePath);
    if (moduleDataNode == null) {
        return Collections.emptyList();
    }
    final ModuleData moduleData = moduleDataNode.getData();
    final boolean isRoot = projectDataNode.getData().getLinkedExternalProjectPath().equals(moduleData.getLinkedExternalProjectPath());
    final Collection<DataNode<TaskData>> tasks = ExternalSystemApiUtil.getChildren(moduleDataNode, ProjectKeys.TASK);
    List<LookupElement> elements = ContainerUtil.newArrayListWithCapacity(tasks.size());
    for (DataNode<TaskData> taskDataNode : tasks) {
        final TaskData taskData = taskDataNode.getData();
        elements.add(LookupElementBuilder.create(taskData.getName()).withIcon(ExternalSystemIcons.Task));
        if (!taskData.isInherited()) {
            elements.add(LookupElementBuilder.create((isRoot ? ':' : moduleData.getId() + ':') + taskData.getName()).withIcon(ExternalSystemIcons.Task));
        }
    }
    return elements;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) LookupElement(com.intellij.codeInsight.lookup.LookupElement) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Aggregations

TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)9 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)4 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)3 NotNull (org.jetbrains.annotations.NotNull)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)2 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)2 MultiMap (com.intellij.util.containers.MultiMap)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Nullable (org.jetbrains.annotations.Nullable)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 RunManagerEx (com.intellij.execution.RunManagerEx)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)1 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)1 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)1 ProjectKeys (com.intellij.openapi.externalSystem.model.ProjectKeys)1 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)1