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);
}
}
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;
}
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) {
}
}
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;
}
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);
}
Aggregations