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. 

Questions:

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?

 

 

0
2 comments

A follow-up question - I found the 

EditSourceOnDoubleClickHandler.install(getTree())

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.

0
Avatar
Permanently deleted user

1) Actually you can implement TreeModel from Swing and provide any nodes:
http://www.jetbrains.org/intellij/sdk/docs/user_interface_components/lists_and_trees.html

Also, you can try to implement our TreeStructure
http://www.jetbrains.org/intellij/sdk/docs/tutorials/tree_structure_view.html

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:
http://github.com/search?q=treestructure+dataprovider+intellij&type=Code

0

Please sign in to leave a comment.