Search in sources :

Example 36 with ModuleData

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

the class DetachExternalProjectAction method perform.

@Override
public void perform(@NotNull final Project project, @NotNull ProjectSystemId projectSystemId, @NotNull ProjectData projectData, @NotNull AnActionEvent e) {
    e.getPresentation().setText(ExternalSystemBundle.message("action.detach.external.project.text", projectSystemId.getReadableName()));
    final ProjectNode projectNode = ExternalSystemDataKeys.SELECTED_PROJECT_NODE.getData(e.getDataContext());
    assert projectNode != null;
    ExternalSystemApiUtil.getLocalSettings(project, projectSystemId).forgetExternalProjects(Collections.singleton(projectData.getLinkedExternalProjectPath()));
    ExternalSystemApiUtil.getSettings(project, projectSystemId).unlinkExternalProject(projectData.getLinkedExternalProjectPath());
    ExternalProjectsManager.getInstance(project).forgetExternalProjectData(projectSystemId, projectData.getLinkedExternalProjectPath());
    // Process orphan modules.
    List<Module> orphanModules = ContainerUtilRt.newArrayList();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(projectSystemId, module))
            continue;
        String path = ExternalSystemApiUtil.getExternalRootProjectPath(module);
        if (projectData.getLinkedExternalProjectPath().equals(path)) {
            orphanModules.add(module);
        }
    }
    if (!orphanModules.isEmpty()) {
        projectNode.getGroup().remove(projectNode);
        ProjectDataManager.getInstance().removeData(ProjectKeys.MODULE, orphanModules, Collections.<DataNode<ModuleData>>emptyList(), projectData, project, false);
    }
}
Also used : ProjectNode(com.intellij.openapi.externalSystem.view.ProjectNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module)

Aggregations

ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)36 DataNode (com.intellij.openapi.externalSystem.model.DataNode)22 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)13 Module (com.intellij.openapi.module.Module)9 NotNull (org.jetbrains.annotations.NotNull)6 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)5 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)2 SourceFileContainerInfo (com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2 ModuleDependencyData (com.intellij.openapi.externalSystem.model.project.ModuleDependencyData)2 AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)2 ProjectNode (com.intellij.openapi.externalSystem.view.ProjectNode)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Variant (com.android.builder.model.Variant)1