Register a tool Window per project

I have a project component defined and inside the projectOpened method, I build and initialize my tool window. Is this the best way to make sure my tool window follows a per project basis? Sample code is shown below. I do NOT want different instances of my tool window to interfere with each other.

public void projectOpened(){
final Runnable regToolWinRunnable = new Runnable() {
public void run() {

final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
final ToolWindow toolWindow = toolWindowManager.registerToolWindow("Test Window", false, ToolWindowAnchor.BOTTOM);

//create and add tool window content
final SimpleToolWindowPanel myPanel = new ContentPanel(true);
final ContentFactory contentFactory = toolWindow.getContentManager().getFactory();
final Content content = contentFactory.createContent(myPanel, "", true);
toolWindow.getContentManager().addContent(content);

}
};

final StartupManager startupManager = StartupManager.getInstance(project);
startupManager.registerPostStartupActivity(regToolWinRunnable);
}

 

1 comment
Comment actions Permalink

Your sample code seems to be correct but if there are several open projects at the same time you'll have several different instances (one tool window for each project). But they wouldn't interfere until they access some common data, resources, models etc.

0

Please sign in to leave a comment.