Initialize tool window on execution of project

Hey guys,

I'm developing a tool window plugin to display a log. My problem is, the tool window only initializes once I click on it. Instead, how can I have it initialize as soon as a user starts running the project? Pretty much like the built in Run tool window. I'm using the createToolWindowContent method to initialize the tool window.

I used this tutorial to start off on things.
http://www.jetbrains.org/intellij/sdk/docs/user_interface_components/tool_windows.html#how-to-create-a-tool-window

1

The current toolwindow initialization behavior is intentionally implemented to achieve optimum performance when the project is loaded. Why do you need to initialize the toolwindow before anyone looks at it?

0

I'm implementing a customized Log Viewer. Once a project is run, the log output is written to a text file which my log viewer is supposed to read from and display in real-time. Without the tool window being initialized, there's no way for the log viewer to display the output. So my problem is the user has to click on and open the tool window for it to be initialized. For example if the user never opens the log viewer but runs a project, the log viewer will not capture any of the output. So i'm wondering if there is a way to initialize the Tool Window when the user runs the project rather than depending on a them explicitly clicking on and opening it.

1

Why don't you create a separate component for capturing the log output, initialize it whenever you need to, and use the toolwindow just as the UI to display the output?

0

ATM when the `createToolWindowContent` is called, a JPanel is built which contains a JTable to display the output and a few other copmponents. The JPanel is then added to the Tool Window component. Then a new thread is created to monitor and update the log table as required. The code structure is shown below.

 
public void createToolWindowContent( @NotNull Project project,  @NotNull ToolWindow toolWindow){

     //panel with jtable and other components for the log viewer
      panel = new ContentPanel();

      //add the JPanel built above to the toolWindow
      final
ContentFactory contentFactory = toolWindow.getContentManager().getFactory();
      final Content content = contentFactory.createContent(panel, "", true);
      toolWindow.getContentManager().addContent(content);
      toolWindow.setAutoHide(false);
      //startMonitor method creates a thread which continuously monitor the log file and updates the JTable
      startMonitor();
  }


What I need is pretty similar to how the in-built 'Run' tool window behaves. Whenever the user runs the project, the 'Run' toolWindow pops up and starts displaying stuff. Seperating the logic would still require a way to detect if a user has clicked 'Run' which is the core of my problem.ha

The above link states this:

"if you’d like to show your and hide toolwindow dynamically while the user is working with the project, you need to use the second method for toolwindow registration.
The second method involves simply calling ToolWindowManager.registerToolWindow() from your plugin code. The method has multiple overloads that can be used depending on your task."

Is that a possible solution?
thank you for the responses

1

Is there a better way to tackle this issue? some help would be highly appreciated!

1

请先登录再写评论。