How to access the components of a custom Tool Window post-creation

Answered

Hello everyone,

In my plugin a user action results in the creation of a list of issues. I would like to display that list of issues, with listeners, in a JList in a Tool Window.

So far, I have followed the instructions offered here: https://jetbrains.org/intellij/sdk/docs/user_interface_components/tool_windows.html
I have registered my custom ToolWindowFactory in the plugin.xml file, and when called, it creates a custom ToolWindow with a JLabel, JPanel, and JList. ( As dictated by a .form file.)

The following code is used to create an instance of the ToolWindow:

ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow("IssueToolWindow");
toolWindow.activate(null);

This part works fine.

However, once the Tool Window is created, how do I access its components to add the aforementioned issues to the JList to be displayed?

Thank you ever so much for helping a rookie out!
Jenna

3 comments
Comment actions Permalink

You can use instance check on toolwindow tab content.
Get all tabs using "toolWindow.getContentManager().getContents()" and then filter them by "content.getComponent() instanceOf MyTabPanel", assuming tab was created as "contentFactory.createContent(new MyTabPanel())".


1
Comment actions Permalink

Thank you so much for the answer! This has helped me along the right path! I did run into a new issue, and I worry it's because I am just not using the Tool Window in the intended manner:
If I add all individual components, as defined in the myToolWindow.form file, in the above method, I can access them. However, it also adds each of them as individual panes in the Tool Window, allowing for unwanted focus on singular Swing components that were intended to be part of a whole.
Is there a way to disable this behaviour?

Alternatively, as I'm beginning to fear I am not using Tool Windows as is intended, is it possible to generate AnActionEvent upon Tool Window creation? I'm currently relying on the menu to provide the AnActionEvent, but if one could be generated from the creation of a Tool Window, that might make this a bit more straight forward, given that the list I am seeking to display through the Tool Window is generated using an Editor and Project reference.

Again, thank you very much for helping a rookie!

0
Comment actions Permalink

>Is there a way to disable this behaviour?
I'm not sure I understand the problem.
If you're having problems with layout generated by UI Designer from .form file, it can be replaced with plain Swing implementation.

>is it possible to generate AnActionEvent upon Tool Window creation?
No, it's not. Why do you need it?
createToolWindowContent has Project in a parameter. and com.intellij.openapi.fileEditor.FileEditorManager can be used to get active editors in a given project.
Could it be, that you want to add toolwindow tab from code that calls "activate()", rather than from ToolWindowFactory ?

0

Please sign in to leave a comment.