Search in sources :

Example 1 with ExternalProjectDataSelectorDialog

use of com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog in project intellij-community by JetBrains.

the class AbstractExternalProjectImportBuilder method commit.

@Override
public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
    final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
    if (externalProjectNode != null) {
        beforeCommit(externalProjectNode, project);
    }
    final boolean isFromUI = model != null;
    final List<Module> modules = ContainerUtil.newSmartList();
    final IdeModifiableModelsProvider modelsProvider = isFromUI ? new IdeUIModifiableModelsProvider(project, model, (ModulesConfigurator) modulesProvider, artifactModel) {

        @NotNull
        @Override
        public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
            final Module module = super.newModule(filePath, moduleTypeId);
            modules.add(module);
            return module;
        }
    } : new IdeModifiableModelsProviderImpl(project) {

        @NotNull
        @Override
        public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
            final Module module = super.newModule(filePath, moduleTypeId);
            modules.add(module);
            return module;
        }
    };
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
    final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
    //noinspection unchecked
    Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
    // add current importing project settings to linked projects settings or replace if similar already exist
    projects.remove(projectSettings);
    projects.add(projectSettings);
    //noinspection unchecked
    systemSettings.copyFrom(myControl.getSystemSettings());
    //noinspection unchecked
    systemSettings.setLinkedProjectsSettings(projects);
    if (externalProjectNode != null) {
        if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
            ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(myExternalSystemId, projectSettings.getExternalProjectPath(), externalProjectNode));
            if (dialog.hasMultipleDataToSelect()) {
                dialog.showAndGet();
            } else {
                Disposer.dispose(dialog.getDisposable());
            }
        }
        if (!project.isInitialized()) {
            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings));
        } else
            finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings);
    }
    return modules;
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) NotNull(org.jetbrains.annotations.NotNull) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 2 with ExternalProjectDataSelectorDialog

use of com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog in project intellij-community by JetBrains.

the class ExternalSystemSelectProjectDataToImportAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getProject(e);
    final ProjectSystemId projectSystemId = getSystemId(e);
    final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
    final ExternalProjectInfo projectInfo;
    final ExternalSystemNode<?> externalSystemNode = ContainerUtil.getFirstItem(selectedNodes);
    if (externalSystemNode == null) {
        projectInfo = ContainerUtil.getFirstItem(ProjectDataManager.getInstance().getExternalProjectsData(project, projectSystemId));
    } else {
        final ProjectNode projectNode = externalSystemNode instanceof ProjectNode ? (ProjectNode) externalSystemNode : externalSystemNode.findParent(ProjectNode.class);
        assert projectNode != null;
        final ProjectData projectData = projectNode.getData();
        assert projectData != null;
        projectInfo = ProjectDataManager.getInstance().getExternalProjectData(project, projectSystemId, projectData.getLinkedExternalProjectPath());
    }
    final ExternalProjectDataSelectorDialog dialog;
    if (projectInfo != null) {
        dialog = new ExternalProjectDataSelectorDialog(project, projectInfo, externalSystemNode != null ? externalSystemNode.getData() : null);
        dialog.showAndGet();
    }
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) Project(com.intellij.openapi.project.Project) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ProjectNode(com.intellij.openapi.externalSystem.view.ProjectNode) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 3 with ExternalProjectDataSelectorDialog

use of com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog in project intellij-community by JetBrains.

the class GradleProjectImportBuilder method createFinalImportCallback.

@Override
protected ExternalProjectRefreshCallback createFinalImportCallback(@NotNull final Project project, @NotNull ExternalProjectSettings projectSettings) {
    return new ExternalProjectRefreshCallback() {

        @Override
        public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
            if (externalProject == null)
                return;
            Runnable selectDataTask = () -> {
                ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(GradleConstants.SYSTEM_ID, projectSettings.getExternalProjectPath(), externalProject));
                if (dialog.hasMultipleDataToSelect()) {
                    dialog.showAndGet();
                } else {
                    Disposer.dispose(dialog.getDisposable());
                }
            };
            Runnable importTask = () -> ServiceManager.getService(ProjectDataManager.class).importData(externalProject, project, false);
            if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    selectDataTask.run();
                    ApplicationManager.getApplication().executeOnPooledThread(importTask);
                });
            } else {
                importTask.run();
            }
        }

        @Override
        public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
        }
    };
}
Also used : ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExternalProjectDataSelectorDialog (com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog)3 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)2 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 NotNull (org.jetbrains.annotations.NotNull)2 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)1 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)1 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)1 IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)1 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)1 ProjectNode (com.intellij.openapi.externalSystem.view.ProjectNode)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 ModulesConfigurator (com.intellij.openapi.roots.ui.configuration.ModulesConfigurator)1 Nullable (org.jetbrains.annotations.Nullable)1