Search in sources :

Example 26 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-plugins by JetBrains.

the class AppTest method callClientAssert.

private void callClientAssert(VirtualFile file) throws IOException, InterruptedException {
    semaphore.down();
    ActionCallback callback = client.test(null, DocumentFactoryManager.getInstance().getId(file), getTestName(false), APP_TEST_CLASS_ID);
    callback.doWhenProcessed(() -> semaphore.up());
    await();
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 27 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-plugins by JetBrains.

the class Client method getDocumentImage.

//public AsyncResult<BufferedImage> getDocumentImage(DocumentFactoryManager.DocumentInfo documentInfo) {
//  final AsyncResult<BufferedImage> result = new AsyncResult<BufferedImage>();
//  getDocumentImage(documentInfo, result);
//  return result;
//}
public void getDocumentImage(DocumentInfo documentInfo, final AsyncResult<BufferedImage> result) {
    final ActionCallback callback = new ActionCallback("getDocumentImage");
    boolean hasError = true;
    try {
        beginMessage(ClientMethod.getDocumentImage, callback, result, () -> {
            Reader reader = SocketInputHandler.getInstance().getReader();
            try {
                result.setDone(reader.readImage());
            } catch (IOException e) {
                LogMessageUtil.LOG.error(e);
                result.setRejected();
            }
        });
        out.writeShort(documentInfo.getId());
        hasError = false;
    } finally {
        finalizeMessageAndFlush(hasError, callback);
    }
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) IOException(java.io.IOException)

Example 28 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-plugins by JetBrains.

the class Client method renderDocumentAndDependents.

public AsyncResult<List<DocumentInfo>> renderDocumentAndDependents(@Nullable List<DocumentInfo> infos, THashMap<ModuleInfo, List<LocalStyleHolder>> outdatedLocalStyleHolders, final AsyncResult<List<DocumentInfo>> result) {
    if ((infos == null || infos.isEmpty()) && outdatedLocalStyleHolders.isEmpty()) {
        result.setDone(infos);
        return result;
    }
    final ActionCallback callback = new ActionCallback("renderDocumentAndDependents");
    boolean hasError = true;
    try {
        beginMessage(ClientMethod.renderDocumentsAndDependents, callback, result, () -> {
            final int[] ids;
            try {
                ids = SocketInputHandler.getInstance().getReader().readIntArray();
            } catch (IOException e) {
                LogMessageUtil.processInternalError(e);
                return;
            }
            DocumentFactoryManager documentFactoryManager = DocumentFactoryManager.getInstance();
            List<DocumentInfo> rendered = new ArrayList<>(ids.length);
            for (int id : ids) {
                rendered.add(documentFactoryManager.getInfo(id));
            }
            result.setDone(rendered);
        });
        out.writeUInt29(outdatedLocalStyleHolders.size());
        outdatedLocalStyleHolders.forEachKey(moduleInfo -> {
            out.writeUInt29(moduleInfo.getId());
            return true;
        });
        out.write(infos);
        hasError = false;
    } finally {
        finalizeMessageAndFlush(hasError, callback);
    }
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 29 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-plugins by JetBrains.

the class Client method unregisterModule.

public ActionCallback unregisterModule(final Module module) {
    boolean hasError = true;
    final ActionCallback callback = new ActionCallback("renderDocumentAndDependents");
    try {
        hasError = false;
        beginMessage(ClientMethod.unregisterModule, callback, null, () -> {
            try {
                SocketInputHandler.getInstance().unregisterDocumentFactories();
            } catch (IOException e) {
                LogMessageUtil.LOG.error(e);
            }
        });
        writeId(module);
    } finally {
        try {
            registeredModules.remove(module);
        } finally {
            finalizeMessageAndFlush(hasError, callback);
        }
    }
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) IOException(java.io.IOException)

Example 30 with ActionCallback

use of com.intellij.openapi.util.ActionCallback in project intellij-plugins by JetBrains.

the class DesignerApplicationManager method attachProjectAndModuleListeners.

void attachProjectAndModuleListeners(Disposable parentDisposable) {
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosed(Project project) {
            if (isApplicationClosed()) {
                return;
            }
            Client client = Client.getInstance();
            if (client.getRegisteredProjects().contains(project)) {
                client.closeProject(project);
            }
        }
    });
    // unregistered module is more complicated - we cannot just remove all document factories which belong to project as in case of close project
    // we must remove all document factories belong to module and all dependents (dependent may be from another module, so, we process moduleRemoved synchronous
    // one by one)
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            Client client = Client.getInstance();
            if (!client.isModuleRegistered(module)) {
                return;
            }
            if (unregisterTaskQueueProcessor == null) {
                unregisterTaskQueueProcessor = new QueueProcessor<>(module1 -> {
                    boolean hasError = true;
                    final ActionCallback callback;
                    initialRenderQueue.suspend();
                    try {
                        callback = Client.getInstance().unregisterModule(module1);
                        hasError = false;
                    } finally {
                        if (hasError) {
                            initialRenderQueue.resume();
                        }
                    }
                    callback.doWhenProcessed(() -> initialRenderQueue.resume());
                });
            }
            unregisterTaskQueueProcessor.add(module);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) ActionCallback(com.intellij.openapi.util.ActionCallback) Module(com.intellij.openapi.module.Module)

Aggregations

ActionCallback (com.intellij.openapi.util.ActionCallback)70 NotNull (org.jetbrains.annotations.NotNull)16 IOException (java.io.IOException)5 Notification (com.intellij.notification.Notification)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrayList (java.util.ArrayList)4 ProjectView (com.intellij.ide.projectView.ProjectView)3 Configurable (com.intellij.openapi.options.Configurable)3 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)3 AsyncResult (com.intellij.openapi.util.AsyncResult)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Project (com.intellij.openapi.project.Project)2 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)2 MasterDetailsComponent (com.intellij.openapi.ui.MasterDetailsComponent)2 NamedConfigurable (com.intellij.openapi.ui.NamedConfigurable)2 TypingTarget (com.intellij.openapi.ui.TypingTarget)2 FocusCommand (com.intellij.openapi.wm.FocusCommand)2