Search in sources :

Example 21 with ActionCallback

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

the class AssertFocused method _execute.

protected ActionCallback _execute(final PlaybackContext context) {
    final ActionCallback result = new ActionCallback();
    String text = getText().substring(PREFIX.length()).trim();
    final Map<String, String> expected = new LinkedHashMap<>();
    if (text.length() > 0) {
        final String[] keyValue = text.split(",");
        for (String each : keyValue) {
            final String[] eachPair = each.split("=");
            if (eachPair.length != 2) {
                context.error("Syntax error, must be comma-separated pairs key=value", getLine());
                result.setRejected();
                return result;
            }
            expected.put(eachPair[0], eachPair[1]);
        }
    }
    IdeFocusManager.findInstance().doWhenFocusSettlesDown(() -> {
        try {
            doAssert(expected, context);
            result.setDone();
        } catch (AssertionError error) {
            context.error("Assertion failed: " + error.getMessage(), getLine());
            result.setRejected();
        }
    });
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 22 with ActionCallback

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

the class FocusTrackback method _restoreFocus.

private ActionCallback _restoreFocus() {
    if (isConsumed())
        return ActionCallback.REJECTED;
    List<FocusTrackback> stack = getCleanStack();
    if (!stack.contains(this))
        return ActionCallback.REJECTED;
    Component toFocus = queryToFocus(stack, this, true);
    final ActionCallback result = new ActionCallback();
    if (toFocus != null) {
        final Component ownerBySwing = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        if (ownerBySwing != null) {
            final Window ownerBySwingWindow = SwingUtilities.getWindowAncestor(ownerBySwing);
            if (ownerBySwingWindow != null && ownerBySwingWindow == SwingUtilities.getWindowAncestor(toFocus)) {
                if (!UIUtil.isMeaninglessFocusOwner(ownerBySwing)) {
                    toFocus = ownerBySwing;
                }
            }
        }
        if (myParentWindow != null) {
            final Window to = UIUtil.getWindow(toFocus);
            if (to != null && UIUtil.findUltimateParent(to) == UIUtil.findUltimateParent(myParentWindow)) {
                // IDEADEV-34537
                requestFocus(toFocus);
                result.setDone();
            }
        } else {
            requestFocus(toFocus);
            result.setDone();
        }
    }
    if (!result.isDone()) {
        result.setRejected();
    }
    stack.remove(this);
    dispose();
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 23 with ActionCallback

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

the class CardLayoutPanel method select.

public ActionCallback select(K key, boolean now) {
    myKey = key;
    ActionCallback callback = new ActionCallback();
    if (now) {
        select(callback, key, prepare(key));
    } else {
        selectLater(callback, key);
    }
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 24 with ActionCallback

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

the class CompatibilityChecksMetadataUpdater method fetchMetadata.

@NotNull
private static ActionCallback fetchMetadata() {
    ActionCallback callback = new ActionCallback();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        String url = "https://dl.google.com/android/studio/metadata/android-component-compatibility.xml";
        try {
            Document metadata = HttpRequests.request(url).connect(request -> {
                try {
                    return loadDocument(request.getInputStream());
                } catch (JDOMException e) {
                    LOG.info("Failed to parse XML metadata", e);
                    return null;
                } catch (Throwable e) {
                    LOG.info("Failed to parse XML metadata", e);
                    return null;
                }
            });
            if (metadata != null) {
                VersionCompatibilityChecker.getInstance().updateMetadata(metadata);
                callback.setDone();
            }
        } catch (IOException e) {
            LOG.info(String.format("Failed to connect to '%1$s'", url), e);
        }
        callback.setRejected();
    });
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) IOException(java.io.IOException) Document(org.jdom.Document) JDOMUtil.loadDocument(com.intellij.openapi.util.JDOMUtil.loadDocument) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with ActionCallback

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

the class TreeBuilderSpeedSearch method findNodes.

@NotNull
private List<AbstractPsModelNode> findNodes(@NotNull String searchQuery) {
    String pattern = searchQuery.trim();
    List<AbstractPsModelNode> nodes = Lists.newArrayList();
    ActionCallback initialized = myTreeBuilder.getInitialized();
    initialized.doWhenDone(() -> myTreeBuilder.accept(AbstractPsModelNode.class, new TreeVisitor<AbstractPsModelNode>() {

        @Override
        public boolean visit(@NotNull AbstractPsModelNode node) {
            if (isMatchingElement(node, pattern)) {
                nodes.add(node);
            }
            return false;
        }
    }));
    return nodes;
}
Also used : TreeVisitor(com.intellij.ide.util.treeView.TreeVisitor) ActionCallback(com.intellij.openapi.util.ActionCallback) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

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