Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to use MessageConsole?
How to use MessageConsole? [message #327433] Fri, 18 April 2008 19:45 Go to next message
Eclipse UserFriend
Originally posted by: NOSPAM_achan.progress.com

I'm trying to use MessageConsole in my view to show some messages. The
rate of adding these messages can be high, but MessageConsole seems to
handle it very well in terms of CPU usage.

However, I'm trying to make sure the highWater Mark is working. So I set
called setWaterMark(300, 500) to make sure it is doing the right thing. I
then set a timer to write the current date to the output stream every 5
seconds.

What I noticed is that when it is time to re-adjust the offset, there are
always a duplicate of the 1st line in the 0th line position.

Looks like the stream position is confused. I printed out the text from
document and they are correct. Just the text on the console is messed up.
Here is the code (it won't compile as a stand alone app):

public class TestMessageConsole {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);

MessageConsole msgConsole = new MessageConsole("Test", null, false);
TextConsoleViewer textConsoleViewer = new TextConsoleViewer(shell,
msgConsole);

MessageConsoleStream msgConsoleStream = msgConsole.newMessageStream();
final BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(msgConsoleStream));

msgConsole.setWaterMarks(300, 500);

display.timerExec(2000, new Runnable() {
public void run()
{
try {
bw.write((new Date()).toString() + "\n");
bw.flush();
} catch (Exception e) {

}
display.timerExec(2000, this);
}
});



shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}


Are there any sample code for using MessageConsole? Thanks.

-Aston
Re: How to use MessageConsole? [message #327450 is a reply to message #327433] Mon, 21 April 2008 03:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: NOSPAM_achan.progress.com

Is there any MessageConsole example?

Is the high water mark not broken when the high limit is reached? If I
can't use this, is there any other widget I can use? My original
prototype was using Text but that was way too slow.

Many thanks in advance for any help.

-Aston
Re: How to use MessageConsole? [message #327451 is a reply to message #327450] Mon, 21 April 2008 04:25 Go to previous message
Eclipse UserFriend
Originally posted by: NOSPAM_achan.progress.com

I may have found a solution. Instead of using watermarks, I enforce the
max # of lines myself:

doc.addDocumentPartitioningListener(new IDocumentPartitioningListener() {
public void documentPartitioningChanged(IDocument document)
{
int numOfLines = document.getNumberOfLines();

if (numOfLines > maxLine) {
int extra = numOfLines - maxLine;
IRegion region;

try {
region = document.getLineInformation(extra);
document.replace(0, region.getOffset(), ""); // replace
1st n lines with ""
document.set(document.get()); // this will move the
current pos to the end so next append will work...
} catch (BadLocationException e) {
e.printStackTrace();
}
}

Leave the watermark alone ( or probably set to -1 ).

-Aston
}
});
Previous Topic:How can I register a toolbar?
Next Topic:Recommendations on using custom file stores for eclipse.
Goto Forum:
  


Current Time: Sun Aug 11 17:15:58 GMT 2024

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

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

Back to the top