Search in sources :

Example 41 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class ProjectSubset method showModuleSelectionDialog.

/**
   * Displays the "Select Modules" dialog. This method is invoked when the search for a module containing a file returns more than one
   * result. The user now needs to select the module(s) to include.
   *
   * @param searchResults includes the modules that might contain the given file.
   * @param selection     all the modules that need to be included in the project.
   * @param file          the file to include in the project.
   */
private void showModuleSelectionDialog(@NotNull List<ModuleSearchResult> searchResults, @NotNull DataNode<ProjectData> projectInfo, @NotNull List<DataNode<ModuleData>> selection, @NotNull File file) {
    List<DataNode<ModuleData>> finalSelection = Lists.newArrayList(selection);
    List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList();
    Map<String, ModuleSearchResult> resultsByModuleName = Maps.newHashMap();
    for (ModuleSearchResult result : searchResults) {
        DataNode<ModuleData> module = result.moduleNode;
        modulesToDisplayInDialog.add(module);
        if (result.selected) {
            finalSelection.remove(module);
        }
        String moduleName = getNameOf(module);
        resultsByModuleName.put(moduleName, result);
    }
    invokeLaterIfNeeded(() -> {
        ModulesToImportDialog dialog = new ModulesToImportDialog(modulesToDisplayInDialog, myProject);
        String description = String.format("The file '%1$s' may be include in one of the following modules.", file.getName());
        dialog.setDescription(description);
        dialog.clearSelection();
        if (dialog.showAndGet()) {
            Collection<DataNode<ModuleData>> selectedModules = dialog.getSelectedModules();
            if (!selectedModules.isEmpty()) {
                for (DataNode<ModuleData> selectedModule : selectedModules) {
                    String name = getNameOf(selectedModule);
                    ModuleSearchResult result = resultsByModuleName.get(name);
                    if (result != null) {
                        SourceFileContainerInfo containerInfo = result.containerInfo;
                        if (containerInfo != null) {
                            containerInfo.updateSelectedVariantIn(selectedModule);
                        }
                    }
                }
                finalSelection.addAll(selectedModules);
                setSelection(finalSelection);
                populate(myProject, projectInfo, finalSelection, DEFAULT_REQUEST);
            }
        }
    });
}
Also used : SourceFileContainerInfo(com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData)

Example 42 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class DataNodeCaches method indexByModuleName.

@NotNull
private static Map<String, DataNode<ModuleData>> indexByModuleName(@NotNull Collection<DataNode<ModuleData>> moduleDataNodes) {
    Map<String, DataNode<ModuleData>> mapping = Maps.newHashMap();
    for (DataNode<ModuleData> moduleDataNode : moduleDataNodes) {
        ModuleData data = moduleDataNode.getData();
        mapping.put(data.getExternalName(), moduleDataNode);
    }
    return mapping;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class Projects method getModulesToImport.

@NotNull
private static Collection<DataNode<ModuleData>> getModulesToImport(@NotNull Project project, @NotNull DataNode<ProjectData> projectInfo, boolean selectModulesToImport) {
    Collection<DataNode<ModuleData>> modules = findAll(projectInfo, ProjectKeys.MODULE);
    ProjectSubset subview = ProjectSubset.getInstance(project);
    if (!ApplicationManager.getApplication().isUnitTestMode() && ProjectSubset.getInstance(project).isFeatureEnabled() && modules.size() > 1) {
        if (selectModulesToImport) {
            // Importing a project. Allow user to select which modules to include in the project.
            Collection<DataNode<ModuleData>> selection = subview.showModuleSelectionDialog(modules);
            if (selection != null) {
                return selection;
            }
        } else {
            // We got here because a project was synced with Gradle. Make sure that we don't add any modules that were not selected during
            // project import (if applicable.)
            String[] persistedModuleNames = subview.getSelection();
            if (persistedModuleNames != null) {
                int moduleCount = persistedModuleNames.length;
                if (moduleCount > 0) {
                    List<String> moduleNames = Lists.newArrayList(persistedModuleNames);
                    List<DataNode<ModuleData>> selectedModules = Lists.newArrayListWithExpectedSize(moduleCount);
                    for (DataNode<ModuleData> module : modules) {
                        String name = module.getData().getExternalName();
                        if (moduleNames.contains(name)) {
                            selectedModules.add(module);
                        }
                    }
                    return selectedModules;
                }
            }
        }
    }
    // Delete any stored module selection.
    subview.clearSelection();
    // Import all modules, not just subset.
    return modules;
}
Also used : ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class ModulesToImportDialogTest method createModule.

@NotNull
private static DataNode<ModuleData> createModule(@NotNull String name, boolean isGradleProject) {
    String path = "~/project/" + name;
    ModuleData data = new ModuleData(name, GradleConstants.SYSTEM_ID, StdModuleTypes.JAVA.getId(), name, path, path);
    DataNode<ModuleData> module = new DataNode<>(MODULE, data, null);
    if (isGradleProject) {
        List<String> taskNames = Collections.emptyList();
        module.createChild(GRADLE_MODULE_MODEL, new GradleModuleModel("app", taskNames, ":" + name, null, null));
    }
    return module;
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class AndroidGradleProjectResolverIdeaTest method testPopulateModuleContentRootsWithJavaProject.

public void testPopulateModuleContentRootsWithJavaProject() {
    ProjectData project = myProjectResolver.createProject();
    DataNode<ProjectData> projectNode = new DataNode<>(PROJECT, project, null);
    DataNode<ModuleData> moduleDataNode = myProjectResolver.createModule(myJavaModuleModel, projectNode);
    myProjectResolver.populateModuleContentRoots(myJavaModuleModel, moduleDataNode);
    // Verify module does not have AndroidGradleModel.
    Collection<DataNode<AndroidModuleModel>> androidModelNodes = getChildren(moduleDataNode, ANDROID_MODEL);
    assertThat(androidModelNodes).isEmpty();
    // Verify module has IdeaGradleProject.
    Collection<DataNode<GradleModuleModel>> gradleModelNodes = getChildren(moduleDataNode, GRADLE_MODULE_MODEL);
    assertThat(gradleModelNodes).hasSize(1);
    DataNode<GradleModuleModel> gradleModelNode = getFirstItem(gradleModelNodes);
    assertNotNull(gradleModelNode);
    assertEquals(myJavaModuleModel.getGradleProject().getPath(), gradleModelNode.getData().getGradlePath());
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Aggregations

DataNode (com.intellij.openapi.externalSystem.model.DataNode)51 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)22 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)14 NotNull (org.jetbrains.annotations.NotNull)12 Module (com.intellij.openapi.module.Module)11 File (java.io.File)9 Project (com.intellij.openapi.project.Project)7 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)6 Nullable (org.jetbrains.annotations.Nullable)6 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)5 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)4 IdeaModule (org.gradle.tooling.model.idea.IdeaModule)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 Pair (com.intellij.openapi.util.Pair)3 MultiMap (com.intellij.util.containers.MultiMap)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2