Monday, September 19, 2005

Using eclipse console view in RCP

In RCP it is possible to add the eclipse console as a view to a new RCP. Here is an example how to add the console view to your perspective and link all output messages to it:

public class MyPerspective implements IPerspectiveFactory {

public void createInitialLayout(IPageLayout layout) {
MessageConsole myConsole = new MessageConsole("Console", null); // declare console

ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{
myConsole});

MessageConsoleStream stream = myConsole.newMessageStream();

PrintStream myS = new PrintStream(stream);
System.setOut(myS); // link standard output stream to the console
System.setErr(myS); // link error output stream to the console
....
}


Now every System.out.println or log4j output will come out on the console. VoilĂ  :-)

PS: the code above MUST
come directly after createInitialLayout(IPageLayout layout) and before any other code!


2 Comments:

Blogger Marco Lopes said...

Great example. The first one that fully explains how to redirect system.outs to an RCP app.

12:02 PM  
Blogger Tim Cleland said...

Thanks! Just wanted to add that putting the following code in the same function will add the console view to your app.

layout.addView(IConsoleConstants.ID_CONSOLE_VIEW, IPageLayout.BOTTOM, .7f, editorArea);

You'll also need to add the dependency on the plugin org.eclipse.ui.console to your plugin.xml

1:41 PM  

Post a Comment

<< Home