Creating a new message area to show messages

I am writing a plugin for my company's source control system.

I execute a bunch of scripts using Runtime.exec(). I want to direct sysout and syserr streams to a console window in the bottom, like CVS status messages.

WindowManager seems to have access to Statusbar, but nothing else.

Is there a way to do this?

TIA.

6 comments

Is there a way to do this?


Yes there is:

- Create a ToolWindow (see com.intellij.openapi.wm.ToolWindowManager)
- Create a ConsoleView (see com.intellij.execution.filters.TextConsoleBuilder and com.intellij.execution.filters.TextConsoleBuidlerFactory (sic!)) and add it to the ToolWindow
- Feed the output of your process into the ConsoleView (see com.intellij.execution.process.OSProcessHandler, com.intellij.execution.ui.ConsoleView#attachToProcess())

HTH,
Sascha

0

Thanks a lot, Sascha. Very helpful. Truly appreciate it.

Have a couple of questions.

ToolWindowManager manager = ToolWindowManager.getInstance(project);
String id = "CMVC Console";
TextConsoleBuidlerFactory factory = TextConsoleBuidlerFactory.getInstance();
TextConsoleBuilder builder = factory.createBuilder(project);
ConsoleView view = builder.getConsole();
OSProcessHandler handler = new OSProcessHandler(proc, command);
view.attachToProcess(handler);

So far so good.

ToolWindow window = manager.getToolWindow(id);
if (window == null) {
window = manager.registerToolWindow(id, ??, ToolWindowAnchor.RIGHT);
}

I thought that this is where it fits in, I thought I can pass the ConsoleView as an argument when creating the tool window, but ConsoleView isn't a JComponent :(.

What am I missing?

Any help appreciated.

0

What am I missing?


ConsoleView.getComponent() ;)

Sascha

0

Sascha

:). Thanks, it goes through fine, the Toolwindow is created fine. it is being registered correctly and the window shows up now, but the stdout and stderr are not being sent to the console.

This is the code I use, again I am sure I am missing something silly.

if (project != null) {
ToolWindowManager manager = ToolWindowManager.getInstance(project);
String id = "CMVC Console";
TextConsoleBuidlerFactory factory = TextConsoleBuidlerFactory.getInstance();
TextConsoleBuilder builder = factory.createBuilder(project);
ConsoleView view = builder.getConsole();

OSProcessHandler handler = new OSProcessHandler(proc, command);
view.attachToProcess(handler);

ToolWindow window = manager.getToolWindow(id);

if (window == null) {
window = manager.registerToolWindow(id, view.getComponent(), ToolWindowAnchor.BOTTOM);
window.show(new Runnable(){
public void run() {
System.out.println("Do something here");
}
});
}
}

0

You should call handler.startNotify() to make it start polling the process.

Sascha

0

Amazing. It worked. Thanks again, Sascha.

As before, the complete code is attached used for those who need it in future



Attachment(s):
CmdExecutor.java
0

Please sign in to leave a comment.