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