Search in sources :

Example 1 with ProjectDataManager

use of com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager in project intellij-community by JetBrains.

the class ExternalSystemUtil method refreshProjects.

/**
   * Asks to refresh all external projects of the target external system linked to the given ide project based on provided spec
   *
   * @param spec import specification
   */
public static void refreshProjects(@NotNull final ImportSpec spec) {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(spec.getExternalSystemId());
    if (manager == null) {
        return;
    }
    AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(spec.getProject());
    final Collection<? extends ExternalProjectSettings> projectsSettings = settings.getLinkedProjectsSettings();
    if (projectsSettings.isEmpty()) {
        return;
    }
    final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
    final ExternalProjectRefreshCallback callback;
    if (spec.getCallback() == null) {
        callback = new MyMultiExternalProjectRefreshCallback(spec.getProject(), projectDataManager, spec.getExternalSystemId());
    } else {
        callback = spec.getCallback();
    }
    Set<String> toRefresh = ContainerUtilRt.newHashSet();
    for (ExternalProjectSettings setting : projectsSettings) {
        // don't refresh project when auto-import is disabled if such behavior needed (e.g. on project opening when auto-import is disabled)
        if (!setting.isUseAutoImport() && spec.whenAutoImportEnabled())
            continue;
        toRefresh.add(setting.getExternalProjectPath());
    }
    if (!toRefresh.isEmpty()) {
        ExternalSystemNotificationManager.getInstance(spec.getProject()).clearNotifications(null, NotificationSource.PROJECT_SYNC, spec.getExternalSystemId());
        for (String path : toRefresh) {
            refreshProject(path, new ImportSpecBuilder(spec).callback(callback).build());
        }
    }
}
Also used : ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 2 with ProjectDataManager

use of com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager in project intellij-community by JetBrains.

the class GradleStartupActivity method showNotificationForUnlinkedGradleProject.

private static void showNotificationForUnlinkedGradleProject(@NotNull final Project project) {
    if (!PropertiesComponent.getInstance(project).getBoolean(SHOW_UNLINKED_GRADLE_POPUP, true) || !GradleSettings.getInstance(project).getLinkedProjectsSettings().isEmpty() || project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE || project.getBaseDir() == null) {
        return;
    }
    File baseDir = VfsUtilCore.virtualToIoFile(project.getBaseDir());
    final File gradleFile = new File(baseDir, GradleConstants.DEFAULT_SCRIPT_NAME);
    if (gradleFile.exists()) {
        String message = String.format("%s<br>\n%s", GradleBundle.message("gradle.notifications.unlinked.project.found.msg", IMPORT_EVENT_DESCRIPTION), GradleBundle.message("gradle.notifications.do.not.show"));
        GradleNotification.getInstance(project).showBalloon(GradleBundle.message("gradle.notifications.unlinked.project.found.title"), message, NotificationType.INFORMATION, new NotificationListener.Adapter() {

            @Override
            protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                notification.expire();
                if (IMPORT_EVENT_DESCRIPTION.equals(e.getDescription())) {
                    final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
                    GradleProjectImportBuilder gradleProjectImportBuilder = new GradleProjectImportBuilder(projectDataManager);
                    final GradleProjectImportProvider gradleProjectImportProvider = new GradleProjectImportProvider(gradleProjectImportBuilder);
                    AddModuleWizard wizard = new AddModuleWizard(project, gradleFile.getPath(), gradleProjectImportProvider);
                    if ((wizard.getStepCount() <= 0 || wizard.showAndGet())) {
                        ImportModuleAction.createFromWizard(project, wizard);
                    }
                } else if (DO_NOT_SHOW_EVENT_DESCRIPTION.equals(e.getDescription())) {
                    PropertiesComponent.getInstance(project).setValue(SHOW_UNLINKED_GRADLE_POPUP, false, true);
                }
            }
        });
    }
}
Also used : GradleProjectImportProvider(org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportProvider) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) GradleProjectImportBuilder(org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder) AddModuleWizard(com.intellij.ide.util.newProjectWizard.AddModuleWizard) File(java.io.File) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)2 AddModuleWizard (com.intellij.ide.util.newProjectWizard.AddModuleWizard)1 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)1 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 File (java.io.File)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1 GradleProjectImportBuilder (org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder)1 GradleProjectImportProvider (org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportProvider)1