Search in sources :

Example 1 with AbstractTreeBuilder

use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.

the class DissociateResourceBundleAction method dissociate.

public static void dissociate(final Collection<ResourceBundle> resourceBundles, final Project project) {
    final Set<PsiFileSystemItem> toUpdateInProjectView = new HashSet<>();
    for (ResourceBundle resourceBundle : resourceBundles) {
        for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
            PsiDirectory containingDirectory = propertiesFile.getContainingFile().getContainingDirectory();
            if (containingDirectory != null) {
                toUpdateInProjectView.add(containingDirectory);
            }
        }
        ResourceBundleManager.getInstance(project).dissociateResourceBundle(resourceBundle);
    }
    AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
    if (currentProjectViewPane == null) {
        return;
    }
    AbstractTreeBuilder treeBuilder = currentProjectViewPane.getTreeBuilder();
    if (treeBuilder != null) {
        for (PsiFileSystemItem item : toUpdateInProjectView) {
            treeBuilder.queueUpdateFrom(item, false);
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) HashSet(com.intellij.util.containers.HashSet)

Example 2 with AbstractTreeBuilder

use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.

the class ContentEntryTreeEditor method setContentEntryEditor.

/**
   * @param contentEntryEditor : null means to clear the editor
   */
public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) {
    if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) {
        return;
    }
    if (myFileSystemTree != null) {
        Disposer.dispose(myFileSystemTree);
        myFileSystemTree = null;
    }
    if (myContentEntryEditor != null) {
        myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener);
        myContentEntryEditor = null;
    }
    if (contentEntryEditor == null) {
        ((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT);
        myTreePanel.setVisible(false);
        if (myFileSystemTree != null) {
            Disposer.dispose(myFileSystemTree);
        }
        return;
    }
    myTreePanel.setVisible(true);
    myContentEntryEditor = contentEntryEditor;
    myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener);
    final ContentEntry entry = contentEntryEditor.getContentEntry();
    assert entry != null : contentEntryEditor;
    final VirtualFile file = entry.getFile();
    if (file != null) {
        myDescriptor.setRoots(file);
    } else {
        String path = VfsUtilCore.urlToPath(entry.getUrl());
        myDescriptor.setTitle(FileUtil.toSystemDependentName(path));
    }
    final Runnable init = () -> {
        //noinspection ConstantConditions
        myFileSystemTree.updateTree();
        myFileSystemTree.select(file, null);
    };
    myFileSystemTree = new FileSystemTreeImpl(myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) {

        @Override
        protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) {
            return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
        }
    };
    myFileSystemTree.showHiddens(true);
    Disposer.register(myProject, myFileSystemTree);
    final NewFolderAction newFolderAction = new MyNewFolderAction();
    final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
    mousePopupGroup.add(myEditingActionsGroup);
    mousePopupGroup.addSeparator();
    mousePopupGroup.add(newFolderAction);
    myFileSystemTree.registerMouseListener(mousePopupGroup);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) NewFolderAction(com.intellij.openapi.fileChooser.actions.NewFolderAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ContentEntry(com.intellij.openapi.roots.ContentEntry) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 3 with AbstractTreeBuilder

use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.

the class SelectSdkDialogFixture method selectPathToSdk.

public SelectSdkDialogFixture selectPathToSdk(@NotNull File pathToSdk) {
    final JTextField textField = myRobot.finder().findByType(JTextField.class);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            textField.setText(pathToSdk.getPath());
        }
    });
    final Tree tree = myRobot.finder().findByType(myDialog, Tree.class);
    final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree);
    pause(new Condition("Wait until path is updated") {

        @Override
        public boolean test() {
            //noinspection ConstantConditions
            return execute(new GuiQuery<Boolean>() {

                @Override
                protected Boolean executeInEDT() throws Throwable {
                    return (textField.getText().equals(pathToSdk.getPath()) && !builder.getUi().getUpdater().hasNodesToUpdate());
                }
            });
        }
    }, SHORT_TIMEOUT);
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) GuiQuery(org.fest.swing.edt.GuiQuery) Tree(com.intellij.ui.treeStructure.Tree)

Example 4 with AbstractTreeBuilder

use of com.intellij.ide.util.treeView.AbstractTreeBuilder 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 5 with AbstractTreeBuilder

use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.

the class ConfigureTasksActivationDialog method createTreeBuilder.

private static AbstractTreeBuilder createTreeBuilder(@NotNull Project project, @NotNull SimpleNode root, @NotNull Tree tree) {
    final DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(root));
    tree.setModel(treeModel);
    tree.setRootVisible(false);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    final AbstractTreeBuilder treeBuilder = new AbstractTreeBuilder(tree, treeModel, new SimpleTreeStructure.Impl(root), null);
    Disposer.register(project, treeBuilder);
    return treeBuilder;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Aggregations

AbstractTreeBuilder (com.intellij.ide.util.treeView.AbstractTreeBuilder)5 Tree (com.intellij.ui.treeStructure.Tree)2 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 ResourceBundle (com.intellij.lang.properties.ResourceBundle)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Application (com.intellij.openapi.application.Application)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 NewFolderAction (com.intellij.openapi.fileChooser.actions.NewFolderAction)1 FileSystemTreeImpl (com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 SimpleColoredComponent (com.intellij.ui.SimpleColoredComponent)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 HashSet (com.intellij.util.containers.HashSet)1