Search in sources :

Example 1 with GradleProjectImportProvider

use of org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportProvider 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

AddModuleWizard (com.intellij.ide.util.newProjectWizard.AddModuleWizard)1 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)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