Search in sources :

Example 11 with ActionCallback

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) Update(com.intellij.util.ui.update.Update)

Example 12 with ActionCallback

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) ArrayList(java.util.ArrayList) FinalizableCommand(com.intellij.openapi.wm.impl.commands.FinalizableCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ActionCallback

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) Update(com.intellij.util.ui.update.Update)

Example 14 with ActionCallback

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 15 with ActionCallback

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(com.intellij.util.Consumer) AsyncResult(com.intellij.openapi.util.AsyncResult)

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