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();
}
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);
}
}
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;
}
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;
}
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);
}
});
}
Aggregations