use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class ProjectViewTestUtil method checkContainsMethod.
public static void checkContainsMethod(final Object rootElement, final AbstractTreeStructure structure, Function<AbstractTreeNode, VirtualFile[]> converterFunction) {
MultiValuesMap<VirtualFile, AbstractTreeNode> map = new MultiValuesMap<>();
collect((AbstractTreeNode) rootElement, map, structure, converterFunction);
for (VirtualFile eachFile : map.keySet()) {
Collection<AbstractTreeNode> nodes = map.values();
for (final AbstractTreeNode node : nodes) {
ProjectViewNode eachNode = (ProjectViewNode) node;
boolean actual = eachNode.contains(eachFile);
boolean expected = map.get(eachFile).contains(eachNode);
if (actual != expected) {
boolean actual1 = eachNode.contains(eachFile);
boolean expected1 = map.get(eachFile).contains(eachNode);
Assert.assertTrue("file=" + eachFile + " node=" + eachNode.getTestPresentation() + " expected:" + expected, false);
}
}
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class BreakpointsFavoriteListProvider method replicate.
private void replicate(DefaultMutableTreeNode source, AbstractTreeNode destination, final List<AbstractTreeNode<Object>> destinationChildren) {
final ArrayList<AbstractTreeNode<Object>> copyChildren = new ArrayList<>();
AbstractTreeNode<Object> copy = new AbstractTreeNode<Object>(myProject, source.getUserObject()) {
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
return copyChildren;
}
@Override
protected void update(PresentationData presentation) {
}
};
for (int i = 0; i < source.getChildCount(); i++) {
final TreeNode treeNode = source.getChildAt(i);
if (treeNode instanceof DefaultMutableTreeNode) {
final DefaultMutableTreeNode sourceChild = (DefaultMutableTreeNode) treeNode;
replicate(sourceChild, copy, copyChildren);
}
}
if (checkNavigatable(copy)) {
destinationChildren.add(copy);
copy.setParent(destination);
}
}
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;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method calcParentToChildren.
/*
This is a graph theory problem. PsiFileNodes are graph nodes.
Edges go from parent file to child file according to NestingRules, for example foo.js->foo.min.js.
Parent may have several children. Child may have several parents.
There may be cycles with 3 or more nodes, but cycle with 2 nodes (A->B and B->A) is impossible because parentFileSuffix != childFileSuffix
For each child its outbound edges are removed. For example in case of a cycle all edges that form it are removed. In case of A->B->C only A->B remains.
As a result we get a number of separated parent-to-many-children sub-graphs, and use them to nest child files under parent file in Project View.
One child still may have more than one parent. For real use cases it is not expected to happen, but anyway it's not a big problem, it will be shown as a subnode more than once.
*/
@NotNull
private static MultiMap<PsiFileNode, PsiFileNode> calcParentToChildren(@NotNull final Collection<AbstractTreeNode> nodes, @NotNull final Collection<NestingRule> rules) {
// result that will contain number of separated parent-to-many-children sub-graphs
MultiMap<PsiFileNode, PsiFileNode> parentToChildren = null;
// helps to remove all outbound edges of a node that has inbound edge itself
Set<PsiFileNode> allChildNodes = null;
// temporary map for building edges
Map<Pair<String, NestingRule>, Edge<PsiFileNode>> baseNameAndRuleToEdge = null;
for (AbstractTreeNode node : nodes) {
if (!(node instanceof PsiFileNode))
continue;
final PsiFile file = ((PsiFileNode) node).getValue();
if (file == null)
continue;
for (NestingRule rule : rules) {
final String fileName = file.getName();
final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, fileName);
final boolean matchesParent = c.first;
final boolean matchesChild = c.second;
if (!matchesChild && !matchesParent)
continue;
if (baseNameAndRuleToEdge == null) {
baseNameAndRuleToEdge = new THashMap<>();
parentToChildren = new MultiMap<>();
allChildNodes = new THashSet<>();
}
if (matchesParent) {
final String baseName = fileName.substring(0, fileName.length() - rule.myParentFileSuffix.length());
final Edge<PsiFileNode> edge = getOrCreateEdge(baseNameAndRuleToEdge, baseName, rule);
edge.from = (PsiFileNode) node;
updateInfoIfEdgeComplete(parentToChildren, allChildNodes, edge);
}
if (matchesChild) {
final String baseName = fileName.substring(0, fileName.length() - rule.myChildFileSuffix.length());
final Edge<PsiFileNode> edge = getOrCreateEdge(baseNameAndRuleToEdge, baseName, rule);
edge.to = (PsiFileNode) node;
updateInfoIfEdgeComplete(parentToChildren, allChildNodes, edge);
}
}
}
return parentToChildren == null ? MultiMap.empty() : parentToChildren;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class ImportUsagesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dc = e.getDataContext();
final boolean enabled = isEnabled(dc);
if (!enabled)
return;
final Project project = CommonDataKeys.PROJECT.getData(dc);
final Collection<AbstractTreeNode> nodes = new UsageFavoriteNodeProvider().getFavoriteNodes(dc, ViewSettings.DEFAULT);
final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
if (nodes != null && !nodes.isEmpty()) {
favoritesManager.addRoots(TaskDefaultFavoriteListProvider.CURRENT_TASK, nodes);
}
}
Aggregations