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 MxmlPreviewToolWindowManager method initToolWindow.
private void initToolWindow() {
toolWindowForm = new MxmlPreviewToolWindowForm();
String toolWindowId = FlashUIDesignerBundle.message("mxml.preview.tool.window.title");
toolWindow = ToolWindowManager.getInstance(project).registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, project, false);
toolWindow.setIcon(PlatformIcons.UI_FORM_ICON);
PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
toolWindowVisible = propertiesComponent.getBoolean(SETTINGS_TOOL_WINDOW_VISIBLE);
if (toolWindowVisible) {
toolWindow.show(null);
} else {
toolWindow.hide(null);
}
((ToolWindowManagerEx) ToolWindowManager.getInstance(project)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {
@Override
public void stateChanged() {
if (project.isDisposed() || toolWindow == null || !toolWindow.isAvailable()) {
return;
}
final boolean currentVisible = toolWindow.isVisible();
if (currentVisible == toolWindowVisible) {
return;
}
toolWindowVisible = currentVisible;
PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
if (currentVisible) {
propertiesComponent.setValue(SETTINGS_TOOL_WINDOW_VISIBLE, true);
if (!lastPreviewChecked) {
lastPreviewChecked = true;
if (checkLastImage()) {
return;
}
}
render(true, false);
} else {
propertiesComponent.unsetValue(SETTINGS_TOOL_WINDOW_VISIBLE);
}
}
});
JPanel contentPanel = toolWindowForm.getContentPanel();
ContentManager contentManager = toolWindow.getContentManager();
Content content = contentManager.getFactory().createContent(contentPanel, null, false);
content.setCloseable(false);
content.setPreferredFocusableComponent(contentPanel);
contentManager.addContent(content);
contentManager.setSelectedContent(content, true);
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(project);
connection.subscribe(DesignerApplicationManager.MESSAGE_TOPIC, new DocumentRenderedListener() {
private boolean isApplicable(DocumentFactoryManager.DocumentInfo info) {
return toolWindowVisible && toolWindowForm.getFile() != null && info.equals(DocumentFactoryManager.getInstance().getNullableInfo(toolWindowForm.getFile()));
}
@Override
public void documentRendered(DocumentFactoryManager.DocumentInfo info) {
if (isApplicable(info) && !toolWindowForm.waitingForGetDocument) {
UIUtil.invokeLaterIfNeeded(() -> render(false, false));
}
}
@Override
public void errorOccurred() {
}
});
}
use of com.intellij.util.messages.MessageBusConnection in project intellij-plugins by JetBrains.
the class AppTest method applicationLaunchedAndInitialized.
@Override
protected void applicationLaunchedAndInitialized() {
((MySocketInputHandler) SocketInputHandler.getInstance()).fail = fail;
((MySocketInputHandler) SocketInputHandler.getInstance()).semaphore = semaphore;
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(myModule);
connection.subscribe(DesignerApplicationManager.MESSAGE_TOPIC, new DocumentRenderedListener() {
@Override
public void documentRendered(DocumentInfo info) {
semaphore.up();
}
@Override
public void errorOccurred() {
fail.set(true);
semaphore.up();
}
});
}
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;
}
use of com.intellij.util.messages.MessageBusConnection in project intellij-plugins by JetBrains.
the class BndLaunchState method startProcess.
@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
OSProcessHandler handler = super.startProcess();
MessageBusConnection connection = myProject.getMessageBus().connect();
connection.subscribe(CompilerTopics.COMPILATION_STATUS, this);
HotSwapUI hotSwapManager = HotSwapUI.getInstance(myProject);
hotSwapManager.addListener(this);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
connection.disconnect();
hotSwapManager.removeListener(BndLaunchState.this);
myLauncher.cleanup();
}
});
return handler;
}
Aggregations