Search in sources :

Example 31 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)

Example 32 with ActionCallback

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ActionCallback(com.intellij.openapi.util.ActionCallback) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadAction(com.intellij.openapi.application.ReadAction) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Result(com.intellij.openapi.application.Result)

Example 33 with ActionCallback

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) IdeSdksConfigurable(com.android.tools.idea.gradle.structure.IdeSdksConfigurable) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with ActionCallback

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

Example 35 with ActionCallback

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

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