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-community by JetBrains.
the class VfsTestUtil method getEvents.
@NotNull
public static List<VFileEvent> getEvents(@NotNull Runnable action) {
List<VFileEvent> allEvents = new ArrayList<>();
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
allEvents.addAll(events);
}
});
try {
action.run();
} finally {
connection.disconnect();
}
return allEvents;
}
use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.
the class VcsEventWatcher method projectOpened.
@Override
public void projectOpened() {
MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
ApplicationManager.getApplication().invokeLater(() -> VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(), ModalityState.NON_MODAL, myProject.getDisposed());
}
});
WolfTheProblemSolver.getInstance(myProject).addProblemListener(new MyProblemListener(), myProject);
}
use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.
the class CompletionProgressIndicator method showErrorHint.
private static LightweightHint showErrorHint(Project project, Editor editor, String text) {
final LightweightHint[] result = { null };
final EditorHintListener listener = (project1, hint, flags) -> result[0] = hint;
final MessageBusConnection connection = project.getMessageBus().connect();
connection.subscribe(EditorHintListener.TOPIC, listener);
assert text != null;
HintManager.getInstance().showErrorHint(editor, StringUtil.escapeXml(text), HintManager.UNDER);
connection.disconnect();
return result[0];
}
Aggregations