Any better solution for retrieving the Project View Tree ?

Below is a working solution for retrieving the ProjectViewTree
It relies on the components-hierarchy of the 'Porject' Tool Window:


Is there a more... standard way?

4 comments

Hello Eyal,

What exactly do you need to do with the tree? There is no API for retrieving
the JTree directly, but there is a number of APIs for accessing the underlying
model.

EK> Below is a working solution for retrieving the ProjectViewTree [at
EK> least in IDEA 5.0.2 :)] It relies on the components-hierarchy of
EK> the 'Porject' Tool Window:
EK>
EK>

 
EK> private JTree findProjectViewTree(Project activeProject) {
EK> ToolWindowManager toolWindowManager =
EK> ToolWindowManager.getInstance(activeProject);
EK> ToolWindow toolWindow =
EK> toolWindowManager.getToolWindow("Project");
EK> JComponent toolWindowComponent = toolWindow.getComponent();
EK> Splitter splitter = (Splitter)
EK> toolWindowComponent.getComponent(0);
EK> Container tab = (Container)
EK> splitter.getFirstComponent().getComponent(0);
EK> Container tabWrapper = (Container) tab.getComponent(0);
EK> JScrollPane treeScroller = (JScrollPane)
EK> tabWrapper.getComponent(0);
EK> JTree tree = (JTree) treeScroller.getViewport().getView();
EK> return tree;
EK> }
EK> ]]>

EK> Is there a more... standard way?
EK>
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Hi Dmitry,

Yes, I should've mention it in my original post:


I am not interested in the model; it is a pure GUI feature I'm after:

Sometimes, your ProjectTree's depth can reach 10 levels or even more,
I want the ability to stand on any leaf, press Alt+Up, and have its root-module collapsed...

So I want to listen to some KeyEvent's coming from the JTree.
After (wierdly) getting the JTree's reference, I managed doing so with simple swing TreeNode games.

0

So, for the sake of future community members, Is there a standard way?

0

Hello Eyal,

EK> So, for the sake of future community members, Is there a standard
EK> way?

There isn't, and I don't really think it's a good idea to provide one. It
will be too easy to mess up the internal structures of the IDE by working
with the tree directly.

What may actually be a good idea is to provide possibility to expand/collapse
nodes on the model level (in ProjectViewNode).

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.