use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.
the class SettingsTreeView method select.
ActionCallback select(@Nullable final Configurable configurable) {
if (myBuilder.isSelectionBeingAdjusted()) {
return ActionCallback.REJECTED;
}
final ActionCallback callback = new ActionCallback();
myQueuedConfigurable = configurable;
myQueue.queue(new Update(this) {
public void run() {
if (configurable == myQueuedConfigurable) {
if (configurable == null) {
fireSelected(null, callback);
} else {
myBuilder.getReady(this).doWhenDone(() -> {
if (configurable != myQueuedConfigurable)
return;
MyNode editorNode = findNode(configurable);
FilteringTreeStructure.FilteringNode editorUiNode = myBuilder.getVisibleNodeFor(editorNode);
if (editorUiNode == null)
return;
if (!myBuilder.getSelectedElements().contains(editorUiNode)) {
myBuilder.select(editorUiNode, () -> fireSelected(configurable, callback));
} else {
myBuilder.scrollSelectionToVisible(() -> fireSelected(configurable, callback), false);
}
});
}
}
}
@Override
public void setRejected() {
super.setRejected();
callback.setRejected();
}
});
return callback;
}
use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.
the class ToolWindowImpl method getReady.
@NotNull
@Override
public ActionCallback getReady(@NotNull final Object requestor) {
final ActionCallback result = new ActionCallback();
myShowing.getReady(this).doWhenDone(() -> {
ArrayList<FinalizableCommand> cmd = new ArrayList<>();
cmd.add(new FinalizableCommand(null) {
@Override
public void run() {
IdeFocusManager.getInstance(myToolWindowManager.getProject()).doWhenFocusSettlesDown(() -> {
if (myContentManager.isDisposed())
return;
myContentManager.getReady(requestor).notify(result);
});
}
});
myToolWindowManager.execute(cmd);
});
return result;
}
use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.
the class FilteringTreeBuilder method refilter.
public ActionCallback refilter(@Nullable final Object preferredSelection, final boolean adjustSelection, final boolean now) {
if (myRefilterQueue != null) {
myRefilterQueue.cancelAllUpdates();
}
final ActionCallback callback = new ActionCallback();
final Runnable afterCancelUpdate = new Runnable() {
@Override
public void run() {
if (myRefilterQueue == null || now) {
refilterNow(preferredSelection, adjustSelection).doWhenDone(callback.createSetDoneRunnable());
} else {
myRefilterQueue.queue(new Update(this) {
@Override
public void run() {
refilterNow(preferredSelection, adjustSelection).notifyWhenDone(callback);
}
@Override
public void setRejected() {
super.setRejected();
callback.setDone();
}
});
}
}
};
if (!isDisposed()) {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
getUi().cancelUpdate().doWhenProcessed(afterCancelUpdate);
} else {
afterCancelUpdate.run();
}
}
return callback;
}
use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.
the class WindowSystemPlaybackCall method getUiReady.
public static ActionCallback getUiReady(final PlaybackContext context) {
final ActionCallback result = new ActionCallback();
context.flushAwtAndRunInEdt(() -> UiActivityMonitor.getInstance().getBusy().getReady(context).notify(result));
return result;
}
use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.
the class CallCommand method _execute.
@Override
protected ActionCallback _execute(final PlaybackContext context) {
final ActionCallback cmdResult = new ActionCallback();
final String cmd = getText().substring(PREFIX.length()).trim();
final int open = cmd.indexOf("(");
if (open == -1) {
context.error("( expected", getLine());
return ActionCallback.DONE;
}
final int close = cmd.lastIndexOf(")");
if (close == -1) {
context.error(") expected", getLine());
return ActionCallback.DONE;
}
final String methodName = cmd.substring(0, open);
String[] args = cmd.substring(open + 1, close).split(",");
final boolean noArgs = args.length == 1 && args[0].length() == 0;
Class[] types = noArgs ? new Class[1] : new Class[args.length + 1];
types[0] = PlaybackContext.class;
for (int i = 1; i < types.length; i++) {
types[i] = String.class;
}
try {
Pair<Method, Class> methodClass = findMethod(context, methodName, types);
if (methodClass == null) {
context.error("No method \"" + methodName + "\" found in facade classes: " + context.getCallClasses(), getLine());
return ActionCallback.REJECTED;
}
Method m = methodClass.getFirst();
if (!m.getReturnType().isAssignableFrom(AsyncResult.class)) {
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object", getLine());
return ActionCallback.REJECTED;
}
Object[] actualArgs = noArgs ? new Object[1] : new Object[args.length + 1];
actualArgs[0] = context;
System.arraycopy(args, 0, actualArgs, 1, actualArgs.length - 1);
AsyncResult result = (AsyncResult<String>) m.invoke(null, actualArgs);
if (result == null) {
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object, but was null", getLine());
return ActionCallback.REJECTED;
}
result.doWhenDone(new Consumer<String>() {
@Override
public void consume(String s) {
if (s != null) {
context.message(s, getLine());
}
cmdResult.setDone();
}
}).doWhenRejected(s -> {
context.error(s, getLine());
cmdResult.setRejected();
});
} catch (InvocationTargetException ignored) {
context.error("InvocationTargetException while executing command: " + cmd, getLine());
} catch (IllegalAccessException ignored) {
context.error("IllegalAccessException while executing command: " + cmd, getLine());
}
return cmdResult;
}
Aggregations