Search in sources :

Example 1 with ExternalSystemSettingsListenerAdapter

use of com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter in project kotlin by JetBrains.

the class GradleImportingTestCase method importProject.

@Override
protected void importProject() {
    ExternalSystemApiUtil.subscribe(myProject, GradleConstants.SYSTEM_ID, new ExternalSystemSettingsListenerAdapter() {

        @Override
        public void onProjectsLinked(@NotNull Collection settings) {
            Object item = ContainerUtil.getFirstItem(settings);
            if (item instanceof GradleProjectSettings) {
                ((GradleProjectSettings) item).setGradleJvm(GRADLE_JDK_NAME);
            }
        }
    });
    super.importProject();
}
Also used : ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) Collection(java.util.Collection)

Example 2 with ExternalSystemSettingsListenerAdapter

use of com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter in project intellij-community by JetBrains.

the class ExternalProjectsViewImpl method init.

public void init() {
    Disposer.register(myProject, this);
    initTree();
    final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(myProject);
    final ToolWindowManagerAdapter listener = new ToolWindowManagerAdapter() {

        boolean wasVisible = false;

        @Override
        public void stateChanged() {
            if (myToolWindow.isDisposed())
                return;
            boolean visible = myToolWindow.isVisible();
            if (!visible || wasVisible) {
                wasVisible = visible;
                return;
            }
            scheduleStructureUpdate();
            wasVisible = true;
        }
    };
    manager.addToolWindowManagerListener(listener, myProject);
    getShortcutsManager().addListener(new ExternalSystemShortcutsManager.Listener() {

        @Override
        public void shortcutsUpdated() {
            scheduleTasksUpdate();
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.updateNodes(RunConfigurationNode.class);
            });
        }
    });
    getTaskActivator().addListener(new ExternalSystemTaskActivator.Listener() {

        @Override
        public void tasksActivationChanged() {
            scheduleTasksUpdate();
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.updateNodes(RunConfigurationNode.class);
            });
        }
    });
    ((RunManagerEx) RunManager.getInstance(myProject)).addRunManagerListener(new RunManagerListener() {

        private void changed() {
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.visitNodes(ModuleNode.class, node -> node.updateRunConfigurations());
            });
        }

        @Override
        public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }

        @Override
        public void runConfigurationRemoved(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }

        @Override
        public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }
    });
    ExternalSystemApiUtil.subscribe(myProject, myExternalSystemId, new ExternalSystemSettingsListenerAdapter() {

        @Override
        public void onUseAutoImportChange(boolean currentValue, @NotNull final String linkedProjectPath) {
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                final List<ProjectNode> projectNodes = myStructure.getNodes(ProjectNode.class);
                for (ProjectNode projectNode : projectNodes) {
                    final ProjectData projectData = projectNode.getData();
                    if (projectData != null && projectData.getLinkedExternalProjectPath().equals(linkedProjectPath)) {
                        projectNode.updateProject();
                        break;
                    }
                }
            });
        }
    });
    myToolWindow.setAdditionalGearActions(createAdditionalGearActionsGroup());
    scheduleStructureUpdate();
}
Also used : ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) TreeState(com.intellij.ide.util.treeView.TreeState) PopupHandler(com.intellij.ui.PopupHandler) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) SmartList(com.intellij.util.SmartList) Disposer(com.intellij.openapi.util.Disposer) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) Nullable(org.jetbrains.annotations.Nullable) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) InputEvent(java.awt.event.InputEvent) java.util(java.util) ExternalSystemActionUtil(com.intellij.openapi.externalSystem.action.ExternalSystemActionUtil) ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) ExternalSystemViewGearAction(com.intellij.openapi.externalSystem.action.ExternalSystemViewGearAction) NonNls(org.jetbrains.annotations.NonNls) ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) ExternalProjectsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager) NotificationGroup(com.intellij.notification.NotificationGroup) Project(com.intellij.openapi.project.Project) ExternalSystemUiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil) com.intellij.openapi.externalSystem.model(com.intellij.openapi.externalSystem.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) ExternalSystemTaskLocation(com.intellij.openapi.externalSystem.service.execution.ExternalSystemTaskLocation) Disposable(com.intellij.openapi.Disposable) com.intellij.execution(com.intellij.execution) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) ToolWindowImpl(com.intellij.openapi.wm.impl.ToolWindowImpl) Navigatable(com.intellij.pom.Navigatable) Element(org.jdom.Element) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) SmartList(com.intellij.util.SmartList) List(java.util.List) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 3 with ExternalSystemSettingsListenerAdapter

use of com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter in project intellij-community by JetBrains.

the class ExternalToolWindowManager method handle.

@SuppressWarnings("unchecked")
public static void handle(@NotNull final Project project) {
    for (final ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        final AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
        settings.subscribe(new ExternalSystemSettingsListenerAdapter() {

            @Override
            public void onProjectsLinked(@NotNull Collection linked) {
                if (settings.getLinkedProjectsSettings().size() != 1) {
                    return;
                }
                ToolWindow toolWindow = getToolWindow(project, manager.getSystemId());
                if (toolWindow != null) {
                    toolWindow.setAvailable(true, null);
                } else {
                    StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() {

                        @Override
                        public void run() {
                            if (project.isDisposed())
                                return;
                            ExternalSystemUtil.ensureToolWindowInitialized(project, manager.getSystemId());
                            ToolWindowManager.getInstance(project).invokeLater(() -> {
                                if (project.isDisposed())
                                    return;
                                ToolWindow toolWindow1 = getToolWindow(project, manager.getSystemId());
                                if (toolWindow1 != null) {
                                    toolWindow1.setAvailable(true, null);
                                }
                            });
                        }
                    });
                }
            }

            @Override
            public void onProjectsUnlinked(@NotNull Set linkedProjectPaths) {
                if (!settings.getLinkedProjectsSettings().isEmpty()) {
                    return;
                }
                final ToolWindow toolWindow = getToolWindow(project, manager.getSystemId());
                if (toolWindow != null) {
                    UIUtil.invokeLaterIfNeeded(() -> toolWindow.setAvailable(false, null));
                }
            }
        });
    }
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) Set(java.util.Set) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) Collection(java.util.Collection) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 4 with ExternalSystemSettingsListenerAdapter

use of com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter in project intellij-community by JetBrains.

the class ExternalSystemVcsRegistrar method handle.

@SuppressWarnings("unchecked")
public static void handle(@NotNull final Project project) {
    for (final ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        final AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
        settings.subscribe(new ExternalSystemSettingsListenerAdapter() {

            @Override
            public void onProjectsLinked(@NotNull final Collection linked) {
                List<VcsDirectoryMapping> newMappings = ContainerUtilRt.newArrayList();
                final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
                ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
                for (Object o : linked) {
                    final ExternalProjectSettings settings = (ExternalProjectSettings) o;
                    VirtualFile dir = fileSystem.refreshAndFindFileByPath(settings.getExternalProjectPath());
                    if (dir == null) {
                        continue;
                    }
                    if (!dir.isDirectory()) {
                        dir = dir.getParent();
                    }
                    newMappings.addAll(VcsUtil.findRoots(dir, project));
                }
                // There is a possible case that no VCS mappings are configured for the current project. There is a single
                // mapping like <Project> - <No VCS> then. We want to replace it if only one mapping to the project root dir
                // has been detected then.
                List<VcsDirectoryMapping> oldMappings = vcsManager.getDirectoryMappings();
                if (oldMappings.size() == 1 && newMappings.size() == 1 && StringUtil.isEmpty(oldMappings.get(0).getVcs())) {
                    VcsDirectoryMapping newMapping = newMappings.iterator().next();
                    String detectedDirPath = newMapping.getDirectory();
                    VirtualFile detectedDir = fileSystem.findFileByPath(detectedDirPath);
                    if (detectedDir != null && detectedDir.equals(project.getBaseDir())) {
                        newMappings.clear();
                        newMappings.add(new VcsDirectoryMapping("", newMapping.getVcs()));
                        vcsManager.setDirectoryMappings(newMappings);
                        return;
                    }
                }
                newMappings.addAll(oldMappings);
                vcsManager.setDirectoryMappings(newMappings);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) VcsDirectoryMapping(com.intellij.openapi.vcs.VcsDirectoryMapping) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Collection(java.util.Collection) List(java.util.List)

Example 5 with ExternalSystemSettingsListenerAdapter

use of com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter in project intellij-community by JetBrains.

the class ProjectRenameAware method beAware.

public static void beAware(@NotNull Project project) {
    final ExternalSystemFacadeManager facadeManager = ServiceManager.getService(ExternalSystemFacadeManager.class);
    for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
        //noinspection unchecked
        settings.subscribe(new ExternalSystemSettingsListenerAdapter() {

            @Override
            public void onProjectRenamed(@NotNull String oldName, @NotNull String newName) {
                facadeManager.onProjectRename(oldName, newName);
            }
        });
    }
}
Also used : ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ExternalSystemFacadeManager(com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager)

Aggregations

ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)6 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)3 Collection (java.util.Collection)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 com.intellij.execution (com.intellij.execution)1 TreeState (com.intellij.ide.util.treeView.TreeState)1 NotificationGroup (com.intellij.notification.NotificationGroup)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)1 ExternalSystemActionUtil (com.intellij.openapi.externalSystem.action.ExternalSystemActionUtil)1 ExternalSystemViewGearAction (com.intellij.openapi.externalSystem.action.ExternalSystemViewGearAction)1 com.intellij.openapi.externalSystem.model (com.intellij.openapi.externalSystem.model)1 ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)1 ExternalSystemFacadeManager (com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager)1