Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » issue - print messages in eclipse console(print messages in console)
issue - print messages in eclipse console [message #926158] Fri, 28 September 2012 10:59 Go to next message
Nagarajan Ramaswamy is currently offline Nagarajan RamaswamyFriend
Messages: 4
Registered: September 2012
Junior Member
Hi,

I am using RCP. In my application i use the eclipse console to display message to the user.

Issue : the messages does not get print at runtime. Instead it prints after the execution of the UI thread.

My console code is as below,

public class ConsoleDisplayMgr
{
private static ConsoleDisplayMgr fDefault = null;
private String fTitle = null;
private MessageConsole fMessageConsole = null;
public static final int MSG_INFORMATION = 1;
public static final int MSG_ERROR = 2;
public static final int MSG_WARNING = 3;

public ConsoleDisplayMgr(String messageTitle)
{
fDefault = this;
this.fTitle = messageTitle;
}

public static ConsoleDisplayMgr getDefault() {
return fDefault;
}
/**
*
* @param msg
* @param msgKind
*/

public void println(String msg, int msgKind)
{
if (msg == null) return;

if (!displayConsoleView())
{
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", msg);
return;
}

getNewMessageConsoleStream(msgKind).println(msg);
}


/**
*
*/

public void clear()
{
IDocument document = getMessageConsole().getDocument();
if (document != null)
document.set("");
}
/**
*
* @return
*/

private boolean displayConsoleView()
{
try
{
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null)
{
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage != null) {
activePage.showView("org.eclipse.ui.console.ConsoleView", null, 2);
}
}
}
catch (PartInitException localPartInitException)
{
return false;
}

return true;
}

/**
*
* @param msgKind
* @return
*/

private MessageConsoleStream getNewMessageConsoleStream(int msgKind)
{
int swtColorId = 6;

switch (msgKind)
{
case 1:
swtColorId = 6;
break;
case 2:
swtColorId = 12;
break;
case 3:
swtColorId = 10;
}

MessageConsoleStream msgConsoleStream = getMessageConsole().newMessageStream();
msgConsoleStream.setColor(Display.getCurrent().getSystemColor(swtColorId));

return msgConsoleStream;
}

/**
*
* @return
*/

private MessageConsole getMessageConsole()
{
if (this.fMessageConsole == null) {
createMessageConsoleStream(this.fTitle);
}
return this.fMessageConsole;
}

/**
*
* @param title
*/

private void createMessageConsoleStream(String title)
{
this.fMessageConsole = new MessageConsole(title, null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { this.fMessageConsole });
}
}
------------------------------------------------------

Is there a way to print the messages in runtime ?

Thanks
Nagarajan Ramaswamy
Re: issue - print messages in eclipse console [message #934964 is a reply to message #926158] Sat, 06 October 2012 14:10 Go to previous message
Bernard Sarter is currently offline Bernard SarterFriend
Messages: 88
Registered: August 2011
Location: Paris, France
Member
Hi,

There is in principle no problem to log in run-time.

Example:

In the start method of your plugin activator, add:
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { new MyConsole() });


with:
public class MyConsole extends MessageConsole {

public ScriptConsole() {

    super("my Console", Acivator.getDefault().getImageDescriptor("icons/myIcon.gif"));

    MessageConsoleStream outMessageStream = newMessageStream();
    MessageConsoleStream errMessageStream = newMessageStream();

    if (!GraphicsEnvironment.isHeadless()) {
       errMessageStream.setColor(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    }
    System.setOut(new PrintStream(outMessageStream));
    System.setErr(new PrintStream(errMessageStream));
}
}



All outputs made either by System.out.println() or System.err.println() or by the Eclipse logging framework, eg.: Activator.getLogger().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "myMessage") should go to your console.

Hope that helps,
Bernard.
Previous Topic:Programmatically folding of methods
Next Topic:Need a little insight as to why this does not work
Goto Forum:
  


Current Time: Thu Apr 25 02:12:14 GMT 2024

Powered by FUDForum. Page generated in 0.02761 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top