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;
}
use of com.intellij.openapi.util.ActionCallback in project intellij-community by JetBrains.
the class PackageFileWorker method startPackagingFiles.
public static ActionCallback startPackagingFiles(final Project project, final List<VirtualFile> files, final Artifact[] artifacts, final boolean packIntoArchives) {
final ActionCallback callback = new ActionCallback();
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Packaging Files") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
for (final VirtualFile file : files) {
indicator.checkCanceled();
new ReadAction() {
@Override
protected void run(@NotNull final Result result) {
try {
packageFile(file, project, artifacts, packIntoArchives);
} catch (IOException e) {
String message = CompilerBundle.message("message.tect.package.file.io.error", e.toString());
Notifications.Bus.notify(new Notification("Package File", "Cannot package file", message, NotificationType.ERROR));
}
}
}.execute();
callback.setDone();
}
} finally {
if (!callback.isDone()) {
callback.setRejected();
}
}
}
});
return callback;
}
use of com.intellij.openapi.util.ActionCallback in project android by JetBrains.
the class ProjectStructureConfigurable method navigateTo.
@Override
@NotNull
public ActionCallback navigateTo(@Nullable Place place, boolean requestFocus) {
if (place == null) {
return ActionCallback.DONE;
}
Configurable toSelect;
Object displayName = place.getPath(CATEGORY_NAME);
if (displayName instanceof String) {
toSelect = findConfigurable((String) displayName);
} else {
toSelect = (Configurable) place.getPath(CATEGORY);
}
JComponent detailsContent = myDetails.getTargetComponent();
if (mySelectedConfigurable != toSelect) {
saveSideProportion();
removeSelected();
}
if (toSelect != null) {
detailsContent = toSelect.createComponent();
myDetails.setContent(detailsContent);
}
mySelectedConfigurable = toSelect;
if (mySelectedConfigurable != null) {
myUiState.lastEditedConfigurable = mySelectedConfigurable.getDisplayName();
}
if (toSelect instanceof MasterDetailsComponent) {
MasterDetailsComponent masterDetails = (MasterDetailsComponent) toSelect;
if (myUiState.sideProportion > 0) {
masterDetails.getSplitter().setProportion(myUiState.sideProportion);
}
masterDetails.setHistory(myHistory);
} else if (toSelect == mySdksConfigurable) {
mySdksConfigurable.setHistory(myHistory);
}
if (toSelect != null) {
mySidePanel.select(createPlaceFor(toSelect));
}
JComponent toFocus = null;
if (mySelectedConfigurable instanceof BaseConfigurable) {
BaseConfigurable configurable = (BaseConfigurable) mySelectedConfigurable;
toFocus = configurable.getPreferredFocusedComponent();
} else if (mySelectedConfigurable instanceof MasterDetailsComponent) {
MasterDetailsComponent configurable = (MasterDetailsComponent) mySelectedConfigurable;
toFocus = configurable.getMaster();
}
if (toFocus == null && detailsContent != null) {
toFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(detailsContent);
if (toFocus == null) {
toFocus = detailsContent;
}
}
myToFocus = toFocus;
if (myToFocus != null) {
requestFocus(myToFocus);
}
ActionCallback result = new ActionCallback();
goFurther(toSelect, place, requestFocus).notifyWhenDone(result);
myDetails.revalidate();
myDetails.repaint();
if (!myHistory.isNavigatingNow() && mySelectedConfigurable != null) {
myHistory.pushQueryPlace();
}
return result;
}
use of com.intellij.openapi.util.ActionCallback in project android by JetBrains.
the class BasePerspectiveConfigurable method navigateTo.
@Override
public ActionCallback navigateTo(@Nullable Place place, boolean requestFocus) {
if (place != null) {
Object path = place.getPath(getNavigationPathName());
if (path instanceof String) {
String moduleName = (String) path;
if (!isEmpty(moduleName)) {
ActionCallback callback = new ActionCallback();
getContext().setSelectedModule(moduleName, this);
selectModule(moduleName);
NamedConfigurable selectedConfigurable = getSelectedConfigurable();
if (selectedConfigurable != null) {
goFurther(selectedConfigurable, place, requestFocus).notifyWhenDone(callback);
return callback;
}
}
}
}
return ActionCallback.DONE;
}
use of com.intellij.openapi.util.ActionCallback in project android by JetBrains.
the class TreeBuilderSpeedSearch method findAndSelectElement.
@Override
public void findAndSelectElement(@NotNull String searchQuery) {
String pattern = searchQuery.trim();
clearSelection(myTree);
if (searchQuery.isEmpty()) {
return;
}
ActionCallback initialized = myTreeBuilder.getInitialized();
initialized.doWhenDone(() -> {
List<AbstractPsModelNode> nodes = Lists.newArrayList();
myTreeBuilder.accept(AbstractPsModelNode.class, new TreeVisitor<AbstractPsModelNode>() {
@Override
public boolean visit(@NotNull AbstractPsModelNode node) {
if (isMatchingElement(node, pattern)) {
nodes.add(node);
}
return false;
}
});
Color foreground = nodes.isEmpty() ? JBColor.red : getToolTipForeground();
if (mySearchPopup != null) {
mySearchPopup.mySearchField.setForeground(foreground);
}
if (nodes.isEmpty()) {
return;
}
Runnable onDone = () -> {
myTreeBuilder.expandParents(nodes);
myTreeBuilder.scrollToFirstSelectedRow();
};
myTreeBuilder.getUi().userSelect(nodes.toArray(), () -> {
AbstractTreeUi ui = myTreeBuilder.getUi();
if (ui != null) {
ui.executeUserRunnable(onDone);
} else {
onDone.run();
}
}, false, false);
});
}
Aggregations