Print message in console view [message #926134] |
Fri, 28 September 2012 10:31 |
Nagarajan Ramaswamy Messages: 4 Registered: September 2012 |
Junior Member |
|
|
Hi,
I am using eclipse console in my RCP application.
I am unable to display the messages in run time.
This means, my application runs in UI thread and only when the thread finishes its execution, the messages gets printed together in the console.
I am using the below console code,
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 });
}
--------------------------------------------------------
|
|
|
Powered by
FUDForum. Page generated in 0.03522 seconds