init ToolWindow programmatically

Hi folks,

i can show and hide a toolwindow programmatically if i "initialize" it first.
But how can i do that programmatically?
Where can i get the ToolWindow object which is passed to the createToolWindowContent method?

kind regards
syt

7 comments

Hello,

Why would you need to add new tool window at runtime? Recommended approach is to create your ToolWindowFactory implementation and register it at plugin.xml like

<toolWindow id="YourId" factoryClass="YourToolWindowFactoryClass"/>

It will be automatically picked up by the ide then.

Denis

0

Hi, in my plugin i use toolwindow.show & toolwindow.hide

but i cant call these methods if the toolwindow isn't initialized.
I discovered it is initialized if i click on toolwindowbutton. Then createToolWindowContent(Project project, ToolWindow toolWindow) is called internally.
My question was how can i to that on plugin initialisation programatically.

If i'm doin this:

ToolWindowFactoryImpl.createToolWindowContent(ProjectManager.getInstance().getDefaultProject(), ToolWindowManager.getInstance(ProjectManager.getInstance().getDefaultProject()).getToolWindow("ID"));


I get a NullPointerException and i don't know why.

kind regards
syt
0

Did you specify tool window factory at your plugin.xml as I mentioned at the previous post?

Denis

0

yes, and it is working pretty well, all i want to do now is to init it programatically.

greetz
syt

0

You can try to call ToolWindowImpl.ensureContentInitialized() for that then.

Denis

0

Hi, thx for your quick reply.
I figured out that ProjectManager.getInstance().getDefaultProject() ius not returning my actually project.

I am trying to init my plugin through one of these components, but it alsways return "Default (Template) Project" instead of my Projekt

project-components
application-components
module-components

How and when can I call ProjectManager.getInstance().getDefaultProject() to get the actuall project without interacting with keyboard or mouse just programatically?

0

'Default project' != active project (all details are provided at ProjectManager.getDefaultProject() javadoc).

You can get a list of all open projects via ProjectManager.getInstance().getOpenProjects().

Alternatively, active project can be obtained during action processing via PlatformDataKeys.PROJECT.getData(DataContext)

Denis

0

Please sign in to leave a comment.