use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class TodoTreeHelper method getDirectoryChildren.
public Collection<AbstractTreeNode> getDirectoryChildren(PsiDirectory psiDirectory, TodoTreeBuilder builder, boolean isFlatten) {
ArrayList<AbstractTreeNode> children = new ArrayList<>();
if (!isFlatten || !skipDirectory(psiDirectory)) {
final Iterator<PsiFile> iterator = builder.getFiles(psiDirectory);
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
// Add files
final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
TodoFileNode todoFileNode = new TodoFileNode(getProject(), psiFile, builder, false);
if (psiDirectory.equals(containingDirectory) && !children.contains(todoFileNode)) {
children.add(todoFileNode);
continue;
}
// Add directories (find first ancestor directory that is in our psiDirectory)
PsiDirectory _dir = psiFile.getContainingDirectory();
while (_dir != null) {
if (skipDirectory(_dir)) {
break;
}
final PsiDirectory parentDirectory = _dir.getParentDirectory();
TodoDirNode todoDirNode = new TodoDirNode(getProject(), _dir, builder);
if (parentDirectory != null && psiDirectory.equals(parentDirectory) && !children.contains(todoDirNode)) {
children.add(todoDirNode);
break;
}
_dir = parentDirectory;
}
}
} else {
// flatten packages
final PsiDirectory parentDirectory = psiDirectory.getParentDirectory();
if (parentDirectory == null || !skipDirectory(parentDirectory) || !ProjectRootManager.getInstance(getProject()).getFileIndex().isInContent(parentDirectory.getVirtualFile())) {
final Iterator<PsiFile> iterator = builder.getFiles(psiDirectory);
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
// Add files
TodoFileNode todoFileNode = new TodoFileNode(getProject(), psiFile, builder, false);
if (psiDirectory.equals(psiFile.getContainingDirectory()) && !children.contains(todoFileNode)) {
children.add(todoFileNode);
continue;
}
// Add directories
final PsiDirectory _dir = psiFile.getContainingDirectory();
if (skipDirectory(_dir)) {
continue;
}
TodoDirNode todoDirNode = new TodoDirNode(getProject(), _dir, builder);
if (PsiTreeUtil.isAncestor(psiDirectory, _dir, true) && !children.contains(todoDirNode) && !builder.isDirectoryEmpty(_dir)) {
children.add(todoDirNode);
}
}
} else {
final Iterator<PsiFile> iterator = builder.getFiles(psiDirectory);
while (iterator.hasNext()) {
final PsiFile psiFile = iterator.next();
final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
TodoFileNode todoFileNode = new TodoFileNode(getProject(), psiFile, builder, false);
if (psiDirectory.equals(containingDirectory) && !children.contains(todoFileNode)) {
children.add(todoFileNode);
}
}
}
}
Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
return children;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class CachingChildrenTreeNode method groupElements.
private void groupElements(Grouper grouper) {
ArrayList<AbstractTreeNode<TreeElement>> ungrouped = new ArrayList<>();
Collection<AbstractTreeNode> children = getChildren();
for (final AbstractTreeNode child : children) {
CachingChildrenTreeNode<TreeElement> node = (CachingChildrenTreeNode<TreeElement>) child;
if (node instanceof TreeElementWrapper) {
ungrouped.add(node);
}
}
if (!ungrouped.isEmpty()) {
processUngrouped(ungrouped, grouper);
}
Collection<AbstractTreeNode> result = new LinkedHashSet<>();
for (AbstractTreeNode child : children) {
AbstractTreeNode parent = child.getParent();
if (parent != this) {
if (!result.contains(parent))
result.add(parent);
} else {
result.add(child);
}
}
setChildren(result);
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class CachingChildrenTreeNode method processUngrouped.
private void processUngrouped(@NotNull List<AbstractTreeNode<TreeElement>> ungrouped, @NotNull Grouper grouper) {
Map<TreeElement, AbstractTreeNode> ungroupedObjects = collectValues(ungrouped);
Collection<Group> groups = grouper.group(this, ungroupedObjects.keySet());
Map<Group, GroupWrapper> groupNodes = createGroupNodes(groups);
for (Group group : groups) {
if (group == null) {
LOG.error(grouper + " returned null group: " + groups);
}
GroupWrapper groupWrapper = groupNodes.get(group);
Collection<TreeElement> children = group.getChildren();
for (TreeElement node : children) {
if (node == null) {
LOG.error(group + " returned null child: " + children);
}
CachingChildrenTreeNode child = createChildNode(node);
groupWrapper.addSubElement(child);
AbstractTreeNode abstractTreeNode = ungroupedObjects.get(node);
abstractTreeNode.setParent(groupWrapper);
}
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class CachingChildrenTreeNode method setChildren.
protected void setChildren(Collection<AbstractTreeNode> children) {
clearChildren();
for (AbstractTreeNode node : children) {
myChildren.add((CachingChildrenTreeNode) node);
node.setParent(this);
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (!(parent instanceof PsiDirectoryNode))
return children;
final Collection<NestingRule> rules = getNestingRules();
if (rules.isEmpty())
return children;
final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = calcParentToChildren(children, rules);
if (parentToChildren.isEmpty())
return children;
// initial ArrayList size may be not exact, not a big problem
final Collection<AbstractTreeNode> newChildren = new ArrayList<>(children.size() - parentToChildren.size());
final Set<PsiFileNode> childrenToMoveDown = new THashSet<>(parentToChildren.values());
for (AbstractTreeNode node : children) {
if (!(node instanceof PsiFileNode)) {
newChildren.add(node);
continue;
}
if (childrenToMoveDown.contains(node)) {
continue;
}
final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode) node);
if (childrenOfThisFile.isEmpty()) {
newChildren.add(node);
continue;
}
newChildren.add(new NestingTreeNode((PsiFileNode) node, childrenOfThisFile));
}
return newChildren;
}
Aggregations