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