Search in sources :

Example 66 with ActionCallback

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

the class FilteringTreeBuilder method refilterNow.

protected ActionCallback refilterNow(final Object preferredSelection, final boolean adjustSelection) {
    final ActionCallback selectionDone = new ActionCallback();
    getFilteredStructure().refilter();
    getUi().updateSubtree(getRootNode(), false);
    final Runnable selectionRunnable = () -> {
        revalidateTree();
        Object toSelect = preferredSelection != null ? preferredSelection : myLastSuccessfulSelect;
        if (adjustSelection && toSelect != null) {
            final FilteringTreeStructure.FilteringNode nodeToSelect = getFilteredStructure().getVisibleNodeFor(toSelect);
            if (nodeToSelect != null) {
                select(nodeToSelect, () -> {
                    if (getSelectedElements().contains(nodeToSelect)) {
                        myLastSuccessfulSelect = getOriginalNode(nodeToSelect);
                    }
                    selectionDone.setDone();
                });
            } else {
                TreeUtil.ensureSelection(myTree);
                selectionDone.setDone();
            }
        } else {
            selectionDone.setDone();
        }
    };
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        queueUpdate().doWhenProcessed(selectionRunnable);
    } else {
        selectionRunnable.run();
    }
    final ActionCallback result = new ActionCallback();
    selectionDone.doWhenDone(new Runnable() {

        @Override
        public void run() {
            if (!ApplicationManager.getApplication().isUnitTestMode()) {
                scrollSelectionToVisible(new Runnable() {

                    @Override
                    public void run() {
                        getReady(this).notify(result);
                    }
                }, false);
            } else {
                result.setDone();
            }
        }
    }).notifyWhenRejected(result);
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback)

Example 67 with ActionCallback

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

the class TreeUtil method showAndSelect.

@NotNull
public static ActionCallback showAndSelect(@NotNull final JTree tree, int top, int bottom, final int row, final int previous, final boolean addToSelection, final boolean scroll, final boolean resetSelection) {
    final TreePath path = tree.getPathForRow(row);
    if (path == null)
        return ActionCallback.DONE;
    final int size = tree.getRowCount();
    if (size == 0) {
        tree.clearSelection();
        return ActionCallback.DONE;
    }
    if (top < 0) {
        top = 0;
    }
    if (bottom >= size) {
        bottom = size - 1;
    }
    if (row >= tree.getRowCount())
        return ActionCallback.DONE;
    boolean okToScroll = true;
    if (tree.isShowing()) {
        if (!tree.isValid()) {
            tree.validate();
        }
    } else {
        Application app = ApplicationManager.getApplication();
        if (app != null && app.isUnitTestMode()) {
            okToScroll = false;
        }
    }
    Runnable selectRunnable = () -> {
        if (!tree.isRowSelected(row)) {
            if (addToSelection) {
                tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
            } else {
                tree.setSelectionRow(row);
            }
        } else if (resetSelection) {
            if (!addToSelection) {
                tree.setSelectionRow(row);
            }
        }
    };
    if (!okToScroll || !scroll) {
        selectRunnable.run();
        return ActionCallback.DONE;
    }
    final Rectangle rowBounds = tree.getRowBounds(row);
    if (rowBounds == null)
        return ActionCallback.DONE;
    Rectangle topBounds = tree.getRowBounds(top);
    if (topBounds == null) {
        topBounds = rowBounds;
    }
    Rectangle bottomBounds = tree.getRowBounds(bottom);
    if (bottomBounds == null) {
        bottomBounds = rowBounds;
    }
    Rectangle bounds = topBounds.union(bottomBounds);
    bounds.x = rowBounds.x;
    bounds.width = rowBounds.width;
    final Rectangle visible = tree.getVisibleRect();
    if (visible.contains(bounds)) {
        selectRunnable.run();
        return ActionCallback.DONE;
    } else {
        final Component comp = tree.getCellRenderer().getTreeCellRendererComponent(tree, path.getLastPathComponent(), true, true, false, row, false);
        if (comp instanceof SimpleColoredComponent) {
            final SimpleColoredComponent renderer = (SimpleColoredComponent) comp;
            final Dimension scrollableSize = renderer.computePreferredSize(true);
            bounds.width = scrollableSize.width;
        }
    }
    final ActionCallback callback = new ActionCallback();
    selectRunnable.run();
    final Range<Integer> range = getExpandControlRange(tree, path);
    if (range != null) {
        int delta = bounds.x - range.getFrom().intValue();
        bounds.x -= delta;
        bounds.width -= delta;
    }
    if (visible.width < bounds.width) {
        bounds.width = visible.width;
    }
    if (tree instanceof Tree && !((Tree) tree).isHorizontalAutoScrollingEnabled()) {
        bounds.x = 0;
    }
    LOG.debug("tree scroll: ", path);
    tree.scrollRectToVisible(bounds);
    // try to scroll later when the tree is ready
    Object property = tree.getClientProperty(TREE_UTIL_SCROLL_TIME_STAMP);
    long stamp = property instanceof Long ? (Long) property + 1L : Long.MIN_VALUE;
    tree.putClientProperty(TREE_UTIL_SCROLL_TIME_STAMP, stamp);
    // store relative offset because the row can be moved during the tree updating
    int offset = rowBounds.y - bounds.y;
    AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree);
    scrollToVisible(tree, path, bounds, offset, stamp, callback::setDone, builder, 3);
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) RelativePoint(com.intellij.ui.awt.RelativePoint) Tree(com.intellij.ui.treeStructure.Tree) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) Application(com.intellij.openapi.application.Application) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with ActionCallback

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

the class TreeUtil method selectInTree.

@NotNull
public static ActionCallback selectInTree(Project project, @Nullable DefaultMutableTreeNode node, boolean requestFocus, @NotNull JTree tree, boolean center) {
    if (node == null)
        return ActionCallback.DONE;
    final TreePath treePath = new TreePath(node.getPath());
    tree.expandPath(treePath);
    if (requestFocus) {
        ActionCallback result = new ActionCallback(2);
        IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result);
        selectPath(tree, treePath, center).notifyWhenDone(result);
        return result;
    }
    return selectPath(tree, treePath, center);
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with ActionCallback

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

the class ModuleStructureConfigurable method selectOrderEntry.

public ActionCallback selectOrderEntry(@NotNull Module module, @Nullable OrderEntry orderEntry) {
    for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) {
        final ActionCallback callback = extension.selectOrderEntry(module, orderEntry);
        if (callback != null) {
            return callback;
        }
    }
    Place p = new Place();
    p.putPath(ProjectStructureConfigurable.CATEGORY, this);
    Runnable r = null;
    final MasterDetailsComponent.MyNode node = findModuleNode(module);
    if (node != null) {
        p.putPath(TREE_OBJECT, module);
        p.putPath(ModuleEditor.SELECTED_EDITOR_NAME, ClasspathEditor.NAME);
        r = () -> {
            if (orderEntry != null) {
                ModuleEditor moduleEditor = ((ModuleConfigurable) node.getConfigurable()).getModuleEditor();
                ModuleConfigurationEditor editor = moduleEditor.getEditor(ClasspathEditor.NAME);
                if (editor instanceof ClasspathEditor) {
                    ((ClasspathEditor) editor).selectOrderEntry(orderEntry);
                }
            }
        };
    }
    final ActionCallback result = ProjectStructureConfigurable.getInstance(myProject).navigateTo(p, true);
    return r != null ? result.doWhenDone(r) : result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) ClasspathEditor(com.intellij.openapi.roots.ui.configuration.ClasspathEditor) ModuleEditor(com.intellij.openapi.roots.ui.configuration.ModuleEditor) Place(com.intellij.ui.navigation.Place)

Example 70 with ActionCallback

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

the class BaseStructureConfigurable method navigateTo.

@Override
public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) {
    if (place == null)
        return ActionCallback.DONE;
    final Object object = place.getPath(TREE_OBJECT);
    final String byName = (String) place.getPath(TREE_NAME);
    if (object == null && byName == null)
        return ActionCallback.DONE;
    final MyNode node = object == null ? null : findNodeByObject(myRoot, object);
    final MyNode nodeByName = byName == null ? null : findNodeByName(myRoot, byName);
    if (node == null && nodeByName == null)
        return ActionCallback.DONE;
    final NamedConfigurable config;
    if (node != null) {
        config = node.getConfigurable();
    } else {
        config = nodeByName.getConfigurable();
    }
    final ActionCallback result = new ActionCallback().doWhenDone(() -> myAutoScrollEnabled = true);
    myAutoScrollEnabled = false;
    myAutoScrollHandler.cancelAllRequests();
    final MyNode nodeToSelect = node != null ? node : nodeByName;
    selectNodeInTree(nodeToSelect, requestFocus).doWhenDone(() -> {
        setSelectedNode(nodeToSelect);
        Place.goFurther(config, place, requestFocus).notifyWhenDone(result);
    });
    return result;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) NamedConfigurable(com.intellij.openapi.ui.NamedConfigurable)

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