Search in sources :

Example 6 with TreeState

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

the class ChangesTreeList method setChangesToDisplay.

public void setChangesToDisplay(final List<T> changes, @Nullable final VirtualFile toSelect) {
    final DefaultTreeModel model = buildTreeModel(changes, myChangeDecorator);
    TreeState state = null;
    if (!myAlwaysExpandList) {
        state = TreeState.createOn(this, getRoot());
    }
    setModel(model);
    myIsModelFlat = isCurrentModelFlat();
    setChildIndent(myShowFlatten && myIsModelFlat);
    if (!myAlwaysExpandList) {
        //noinspection ConstantConditions
        state.applyTo(this, getRoot());
        return;
    }
    final Runnable runnable = new Runnable() {

        @Override
        public void run() {
            if (myProject.isDisposed())
                return;
            TreeUtil.expandAll(ChangesTreeList.this);
            int selectedTreeRow = -1;
            if (myShowCheckboxes) {
                if (myIncludedChanges.size() > 0) {
                    ChangesBrowserNode root = (ChangesBrowserNode) model.getRoot();
                    Enumeration enumeration = root.depthFirstEnumeration();
                    while (enumeration.hasMoreElements()) {
                        ChangesBrowserNode node = (ChangesBrowserNode) enumeration.nextElement();
                        @SuppressWarnings("unchecked") final CheckboxTree.NodeState state = getNodeStatus(node);
                        if (node != root && state == CheckboxTree.NodeState.CLEAR) {
                            collapsePath(new TreePath(node.getPath()));
                        }
                    }
                    enumeration = root.depthFirstEnumeration();
                    while (enumeration.hasMoreElements()) {
                        ChangesBrowserNode node = (ChangesBrowserNode) enumeration.nextElement();
                        @SuppressWarnings("unchecked") final CheckboxTree.NodeState state = getNodeStatus(node);
                        if (state == CheckboxTree.NodeState.FULL && node.isLeaf()) {
                            selectedTreeRow = getRowForPath(new TreePath(node.getPath()));
                            break;
                        }
                    }
                }
            }
            if (toSelect != null) {
                int rowInTree = findRowContainingFile((TreeNode) model.getRoot(), toSelect);
                if (rowInTree > -1) {
                    selectedTreeRow = rowInTree;
                }
            }
            if (selectedTreeRow >= 0) {
                setSelectionRow(selectedTreeRow);
            }
            TreeUtil.showRowCentered(ChangesTreeList.this, selectedTreeRow, false);
        }
    };
    if (ApplicationManager.getApplication().isDispatchThread()) {
        runnable.run();
    } else {
        SwingUtilities.invokeLater(runnable);
    }
}
Also used : TreeState(com.intellij.ide.util.treeView.TreeState) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable)

Example 7 with TreeState

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

the class ShelvedChangesViewManager method updateChangesContent.

private void updateChangesContent() {
    myUpdatePending = false;
    final List<ShelvedChangeList> changeLists = new ArrayList<>(myShelveChangesManager.getShelvedChangeLists());
    changeLists.addAll(myShelveChangesManager.getRecycledShelvedChangeLists());
    if (changeLists.size() == 0) {
        if (myContent != null) {
            myContentManager.removeContent(myContent);
            myContentManager.selectContent(ChangesViewContentManager.LOCAL_CHANGES);
        }
        myContent = null;
    } else {
        if (myContent == null) {
            myTree.updateUI();
            JPanel rootPanel = createRootPanel();
            myContent = new MyShelfContent(rootPanel, VcsBundle.message("shelf.tab"), false);
            myContent.setCloseable(false);
            myContentManager.addContent(myContent);
        }
        TreeState state = TreeState.createOn(myTree);
        myTree.setModel(buildChangesModel());
        state.applyTo(myTree);
        if (myPostUpdateRunnable != null) {
            myPostUpdateRunnable.run();
        }
    }
    myPostUpdateRunnable = null;
}
Also used : TreeState(com.intellij.ide.util.treeView.TreeState)

Example 8 with TreeState

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

the class ConfigureTasksActivationDialog method updateTree.

private void updateTree(@Nullable CachingSimpleNode nodeToUpdate) {
    Set<CachingSimpleNode> toUpdate = ContainerUtil.newIdentityTroveSet();
    if (nodeToUpdate == null) {
        for (DefaultMutableTreeNode node : myTree.getSelectedNodes(DefaultMutableTreeNode.class, null)) {
            final Object userObject = node.getUserObject();
            if (userObject instanceof SimpleNode && ((SimpleNode) userObject).getParent() instanceof CachingSimpleNode) {
                toUpdate.add((CachingSimpleNode) ((SimpleNode) userObject).getParent());
            }
        }
    } else {
        toUpdate.add(nodeToUpdate);
    }
    if (toUpdate.isEmpty()) {
        toUpdate.add(myRootNode);
    }
    Element treeStateElement = new Element("root");
    try {
        TreeState.createOn(myTree).writeExternal(treeStateElement);
    } catch (WriteExternalException ignore) {
    }
    for (CachingSimpleNode node : toUpdate) {
        cleanUpEmptyNodes(node);
    }
    TreeState treeState = new TreeState();
    try {
        treeState.readExternal(treeStateElement);
        treeState.applyTo(myTree);
    } catch (InvalidDataException ignore) {
    }
}
Also used : TreeState(com.intellij.ide.util.treeView.TreeState) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 9 with TreeState

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

the class BreakpointItemsTreeController method buildTree.

public void buildTree(@NotNull Collection<? extends BreakpointItem> breakpoints) {
    final TreeState state = TreeState.createOn(myTreeView, myRoot);
    myRoot.removeAllChildren();
    myNodes.clear();
    myGroups.clear();
    for (BreakpointItem breakpoint : breakpoints) {
        BreakpointItemNode node = new BreakpointItemNode(breakpoint);
        CheckedTreeNode parent = getParentNode(breakpoint);
        parent.add(node);
        myNodes.put(breakpoint, node);
    }
    TreeUtil.sortRecursively(myRoot, myComparator);
    myInBuild = true;
    ((DefaultTreeModel) (myTreeView.getModel())).nodeStructureChanged(myRoot);
    state.applyTo(myTreeView, myRoot);
    myInBuild = false;
}
Also used : TreeState(com.intellij.ide.util.treeView.TreeState) BreakpointItem(com.intellij.xdebugger.impl.breakpoints.ui.BreakpointItem) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 10 with TreeState

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

the class ChangesListView method updateModel.

public void updateModel(@NotNull DefaultTreeModel newModel) {
    TreeState state = TreeState.createOn(this, getRoot());
    state.setScrollToSelection(false);
    DefaultTreeModel oldModel = getModel();
    setModel(newModel);
    ChangesBrowserNode newRoot = getRoot();
    expandPath(new TreePath(newRoot.getPath()));
    state.applyTo(this, newRoot);
    expandDefaultChangeList(oldModel, newRoot);
}
Also used : TreeState(com.intellij.ide.util.treeView.TreeState) TreePath(javax.swing.tree.TreePath) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChangesBrowserNode(com.intellij.openapi.vcs.changes.ui.ChangesBrowserNode)

Aggregations

TreeState (com.intellij.ide.util.treeView.TreeState)11 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)4 InvalidDataException (com.intellij.openapi.util.InvalidDataException)3 TreePath (javax.swing.tree.TreePath)3 ChangesBrowserNode (com.intellij.openapi.vcs.changes.ui.ChangesBrowserNode)2 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 PostfixTemplate (com.intellij.codeInsight.template.postfix.templates.PostfixTemplate)1 Language (com.intellij.lang.Language)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 WriteExternalException (com.intellij.openapi.util.WriteExternalException)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 CheckboxTree (com.intellij.ui.CheckboxTree)1 JBColor (com.intellij.ui.JBColor)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 Consumer (com.intellij.util.Consumer)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 MultiMap (com.intellij.util.containers.MultiMap)1 UIUtil (com.intellij.util.ui.UIUtil)1 TreeUtil (com.intellij.util.ui.tree.TreeUtil)1