Expand non psi-based ProjectViewTree nodes


I use the custom project tree in a plugin. I wish to expand the second nesting level of the tree, but these nodes are not psi-based and extend ProjectViewNode<String>, so I can’t select a PsiElement for this purpose.

Is there any way to expand the node on creation or set the expanded state by default?

Comment actions Permalink

Why `com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane#select` is not good?

Comment actions Permalink

Because these nodes are just children of ProjectViewNode<String>, they do not have VirtualFile to select.
The node whose children I want to expand looks like this:

public class MyRootNode extends ProjectViewProjectNode {

public MyRootNode(Project project, ViewSettings viewSettings) {

public Collection<AbstractTreeNode> getChildren() {
return Arrays.asList(new SomeSection(myProject, getSettings()),
new SomeSection(myProject, getSettings()));
class SomeSection extends ProjectViewNode<String> {}
Comment actions Permalink

ProjectView was designed to work with PsiElements or VirtualFiles.

In your case you could use the following method to expand top nodes:
```com.intellij.util.ui.tree.TreeUtil#promiseExpand(javax.swing.JTree, int)```
where depth level should be set to 2.

I hope your SomeSection class implements contains(VirtualFile) method correctly to support searching of containing files.

Comment actions Permalink

What are these nodes, if it's not a secret?

Comment actions Permalink

Thanks, TreeUtil#promiseExpand works for me.

Yes, my custom nodes implements contains(VirtualFile) method.


For example

This node aggregate all gradle scripts from the project


Please sign in to leave a comment.