use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.
the class PostProjectBuildTasksExecutor method subscribe.
/**
* This method is used for testing only. For production code, please use
* {@link AndroidProjectBuildNotifications#subscribe(Project, AndroidProjectBuildNotifications.AndroidProjectBuildListener)}.
*/
@VisibleForTesting
public static void subscribe(@NotNull Project project, @NotNull GradleBuildListener listener) {
MessageBusConnection connection = project.getMessageBus().connect(project);
connection.subscribe(GRADLE_BUILD_TOPIC, listener);
}
use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.
the class GradleFacet method initFacet.
@Override
public void initFacet() {
MessageBusConnection connection = getModule().getMessageBus().connect(this);
connection.subscribe(PROJECT_ROOTS, new ModuleRootAdapter() {
@Override
public void rootsChanged(ModuleRootEvent event) {
ApplicationManager.getApplication().invokeLater(() -> {
if (!isDisposed()) {
PsiDocumentManager.getInstance(getModule().getProject()).commitAllDocuments();
updateConfiguration();
}
});
}
});
updateConfiguration();
}
use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.
the class AndroidToolWindowFactory method createLogcatContent.
private static Content createLogcatContent(RunnerLayoutUi layoutUi, final Project project, DeviceContext deviceContext) {
final AndroidLogcatView logcatView = new AndroidLogcatView(project, deviceContext) {
@Override
protected boolean isActive() {
ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
return window.isVisible();
}
};
ToolWindowManagerEx.getInstanceEx(project).addToolWindowManagerListener(new ToolWindowManagerAdapter() {
boolean myToolWindowVisible;
@Override
public void stateChanged() {
ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
if (window != null) {
boolean visible = window.isVisible();
if (visible != myToolWindowVisible) {
myToolWindowVisible = visible;
logcatView.activate();
if (visible) {
ConsoleView console = logcatView.getLogConsole().getConsole();
if (console != null) {
checkFacetAndSdk(project, console);
}
}
}
}
}
});
final MessageBusConnection connection = project.getMessageBus().connect(project);
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyAndroidPlatformListener(logcatView));
JPanel logcatContentPanel = logcatView.getContentPanel();
final Content logcatContent = layoutUi.createContent(ANDROID_LOGCAT_CONTENT_ID, logcatContentPanel, "logcat", AndroidIcons.Ddms.Logcat, null);
logcatContent.putUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY, logcatView);
logcatContent.setDisposer(logcatView);
logcatContent.setCloseable(false);
logcatContent.setPreferredFocusableComponent(logcatContentPanel);
return logcatContent;
}
use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.
the class ImportDependenciesUtil method importDependencies.
public static void importDependencies(@NotNull final Module module, final boolean updateBackwardDependencies) {
synchronized (LOCK) {
final Project project = module.getProject();
module.putUserData(WAIT_FOR_IMPORTING_DEPENDENCIES_KEY, Boolean.TRUE);
if (project.getUserData(WAIT_FOR_IMPORTING_DEPENDENCIES_KEY) != Boolean.TRUE) {
project.putUserData(WAIT_FOR_IMPORTING_DEPENDENCIES_KEY, Boolean.TRUE);
StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
@Override
public void run() {
// todo: this doesn't work in module configurator after 'Apply' button pressed
if (module.isLoaded()) {
importDependenciesForMarkedModules(project, updateBackwardDependencies);
} else {
final MessageBusConnection connection = module.getMessageBus().connect();
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleAdded(@NotNull final Project project, @NotNull final Module addedModule) {
if (module.equals(addedModule)) {
connection.disconnect();
importDependenciesForMarkedModules(project, updateBackwardDependencies);
}
}
});
}
}
});
}
}
}
use of com.intellij.util.messages.MessageBusConnection in project intellij-plugins by JetBrains.
the class NotIndexedCucumberExtension method getDataObject.
public Object getDataObject(@NotNull final Project project) {
final DataObject result = new DataObject();
result.myUpdateQueue.setPassThrough(false);
PsiManager.getInstance(project).addPsiTreeChangeListener(result.myCucumberPsiTreeListener);
PsiManager.getInstance(project).addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
@Override
public void childAdded(@NotNull PsiTreeChangeEvent event) {
final PsiElement parent = event.getParent();
PsiElement child = event.getChild();
if (isStepLikeFile(child, parent)) {
final PsiFile file = (PsiFile) child;
result.myUpdateQueue.queue(new Update(parent) {
public void run() {
if (file.isValid()) {
reloadAbstractStepDefinitions(file);
createWatcher(file);
}
}
});
}
}
@Override
public void childRemoved(@NotNull PsiTreeChangeEvent event) {
final PsiElement parent = event.getParent();
final PsiElement child = event.getChild();
if (isStepLikeFile(child, parent)) {
result.myUpdateQueue.queue(new Update(parent) {
public void run() {
removeAbstractStepDefinitionsRelatedTo((PsiFile) child);
}
});
}
}
});
// clear caches after modules roots were changed
final MessageBusConnection connection = project.getMessageBus().connect();
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
final List<VirtualFile> myPreviousStepDefsProviders = new ArrayList<>();
public void beforeRootsChange(ModuleRootEvent event) {
myPreviousStepDefsProviders.clear();
collectAllStepDefsProviders(myPreviousStepDefsProviders, project);
}
public void rootsChanged(ModuleRootEvent event) {
// compare new and previous content roots
final List<VirtualFile> newStepDefsProviders = new ArrayList<>();
collectAllStepDefsProviders(newStepDefsProviders, project);
if (!compareRoots(newStepDefsProviders)) {
// clear caches on roots changed
reset(project);
}
}
private boolean compareRoots(final List<VirtualFile> newStepDefsProviders) {
if (myPreviousStepDefsProviders.size() != newStepDefsProviders.size()) {
return false;
}
for (VirtualFile root : myPreviousStepDefsProviders) {
if (!newStepDefsProviders.contains(root)) {
return false;
}
}
return true;
}
});
Disposer.register(project, connection);
return result;
}
Aggregations