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);
}
}
});
}
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;
}
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;
}
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;
}
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());
}
Aggregations