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