Custom ToolWindow implementation questions

Folks, I need some guidance on how to go about a custom tool window. Ultimately I would like to reuse as much as possible of an existing code. Here's what I'm trying to do. I want to implement a custom ToolWindow which will only be available in projects with a certain facet. I have a class MyFacet and in its initFacet method I have the following code:

ToolWindow toolWindow = ToolWindowManager.getInstance(this.getModule().getProject()).registerToolWindow("MyCustomToolWindow", true, ToolWindowAnchor.LEFT, false);
toolWindow.getContentManager().addContent(new ContentImpl(new MyCustomToolWindowPanel(this.getModule().getProject()), "", true));

So far so good. Now the question is how do I implement the custom tool window panel. Its behavior should be similar to the Structure or a Project view - i.e. it should display a tree with some Xml files and certain tags inside those files, and upon double-clicking the file or a tag it should open the corresponding file in the  editor and highlight that tag. 


1) If I create my own tree from scratch, which objects should I populate it with? PsiElements? PsiReferences?
2) How do I open the file in editor and scroll to the position when user clicks the element in the tool window tree?
3) How do I make sure that the tree in my tool window has fonts and colors that are matching the default intellij theme? I tried creating a sample tree, just to see what it looks like, and I used the DnDAwareTree class, but the tree has a gray background color, instead of white or the dark one from the Darcula theme.
4) I did review the tool_window example from the SDK docs, but unfortunately it's not enough. Are there any more advanced examples?




A follow-up question - I found the 


method, but when I double-click on my tree node, nothing happens. I debugged it a little bit and it turns out that it reaches OpenSourceUtil.openSourcesFrom() but the data context there does not contain any navigatables.  So how do I make it work? My tree user objects are PsiElements which are either XmlFile or XmlTag.

Permanently deleted user

1) Actually you can implement TreeModel from Swing and provide any nodes:

Also, you can try to implement our TreeStructure

2) Your tree may implement DataProvider to provide navigatable array
to make EditSourceOnDoubleClickHandler work as expected.

3) L&F for a tree is supported by default. You should not change colors manually.

4) You can search through GitHub:


Please sign in to leave a comment.