Search in sources :

Example 61 with MessageBusConnection

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() {
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ContentManager(com.intellij.ui.content.ContentManager) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) Content(com.intellij.ui.content.Content) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 62 with MessageBusConnection

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();
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 63 with MessageBusConnection

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;
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ArrayList(java.util.ArrayList) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with MessageBusConnection

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);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 65 with MessageBusConnection

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];
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) MessageType(com.intellij.openapi.ui.MessageType) Document(com.intellij.openapi.editor.Document) IdeActions(com.intellij.openapi.actionSystem.IdeActions) AutoPopupController(com.intellij.codeInsight.AutoPopupController) PerformanceWatcher(com.intellij.diagnostic.PerformanceWatcher) Semaphore(com.intellij.util.concurrency.Semaphore) Disposer(com.intellij.openapi.util.Disposer) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Logger(com.intellij.openapi.diagnostic.Logger) ReferenceRange(com.intellij.psi.ReferenceRange) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) DocumentWindow(com.intellij.injected.editor.DocumentWindow) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) PsiReference(com.intellij.psi.PsiReference) Set(java.util.Set) com.intellij.codeInsight.lookup(com.intellij.codeInsight.lookup) TextRange(com.intellij.openapi.util.TextRange) KeyEvent(java.awt.event.KeyEvent) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) Queue(java.util.Queue) NotNull(org.jetbrains.annotations.NotNull) LightweightHint(com.intellij.ui.LightweightHint) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) Caret(com.intellij.openapi.editor.Caret) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProgressWrapper(com.intellij.openapi.progress.util.ProgressWrapper) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) JobScheduler(com.intellij.concurrency.JobScheduler) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) CompletionAutoPopupHandler(com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler) StringUtil(com.intellij.openapi.util.text.StringUtil) CompletionServiceImpl(com.intellij.codeInsight.completion.impl.CompletionServiceImpl) Editor(com.intellij.openapi.editor.Editor) GuiUtils(com.intellij.ui.GuiUtils) EditorWindow(com.intellij.injected.editor.EditorWindow) Disposable(com.intellij.openapi.Disposable) ElementPattern(com.intellij.patterns.ElementPattern) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Update(com.intellij.util.ui.update.Update) Result(com.intellij.openapi.application.Result) Pair(com.intellij.openapi.util.Pair) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) ObjectUtils(com.intellij.util.ObjectUtils) HintManager(com.intellij.codeInsight.hint.HintManager) javax.swing(javax.swing) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) LightweightHint(com.intellij.ui.LightweightHint)

Aggregations

MessageBusConnection (com.intellij.util.messages.MessageBusConnection)81 Project (com.intellij.openapi.project.Project)16 NotNull (org.jetbrains.annotations.NotNull)15 Module (com.intellij.openapi.module.Module)11 ModuleRootEvent (com.intellij.openapi.roots.ModuleRootEvent)10 ModuleListener (com.intellij.openapi.project.ModuleListener)8 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Disposable (com.intellij.openapi.Disposable)6 Document (com.intellij.openapi.editor.Document)6 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)5 Update (com.intellij.util.ui.update.Update)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 StringUtil (com.intellij.openapi.util.text.StringUtil)4 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 Application (com.intellij.openapi.application.Application)3 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)3 ModuleRootAdapter (com.intellij.openapi.roots.ModuleRootAdapter)3 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)3 File (java.io.File)3