Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » swt.widgets.Text error when append
swt.widgets.Text error when append [message #664386] Fri, 08 April 2011 15:32 Go to next message
Peter Boccia is currently offline Peter BocciaFriend
Messages: 38
Registered: December 2010
Member
Hi all again,

I resolved the previous issue with swt.widgets.Text in multi-line form.

Now I have redirected all the output in a handler for append the new messages:

private void redirectSystemStreams() {
OutputStream out = new OutputStream() {
@Override
public void write(final int b) throws IOException {
updateTextPane(String.valueOf((char) b));
}

@Override
public void write(byte[] b, int off, int len) throws IOException {
updateTextPane(new String(b, off, len));
}

@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
};

System.setOut(new PrintStream(out, true));
}

//with this method to append text to the Text
private void updateTextPane(final String text) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
//receivedText is a private Text
receivedText.append(text);
}
});
}


Now I receive this error:

org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3526)
at org.eclipse.swt.SWT.error(SWT.java:3446)
at org.eclipse.swt.SWT.error(SWT.java:3417)
at org.eclipse.swt.widgets.Widget.error(Widget.java:953)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:886)
...



It's clear an error linked to the method UpdateText but why? I have also tried with .asyncExec but still the same error.

Give me the last help please! Sad

Peter
Re: swt.widgets.Text error when append [message #664528 is a reply to message #664386] Sun, 10 April 2011 21:12 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Peter,

Invalid thread access means that you access a widget method from a thread
that is not the UIThread of this widget's display. If you call asyncExec
() on another session's display, you will also get this exception. You
should therefore replace Display.getDefault() with receivedText.getDisplay
().

And you should always prefer asyncExec() over syncExec() unless you have
a very good reason to use the latter.

HTH, Ralf

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: swt.widgets.Text error when append [message #664530 is a reply to message #664528] Sun, 10 April 2011 22:16 Go to previous messageGo to next message
Peter Boccia is currently offline Peter BocciaFriend
Messages: 38
Registered: December 2010
Member
Ralf,

I'm sorry I've just read the API for Text
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/reference/api/org/eclipse/swt/widgets/Text .html
and Text don't have getDisplay(). Which method are you talking about?

Thank you for the reply,
Peter
Re: swt.widgets.Text error when append [message #664553 is a reply to message #664530] Mon, 11 April 2011 06:52 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 335
Registered: July 2009
Senior Member
Peter,

read on to the "members inherited from ..." section. Text is derived
from Widget, which provides getDisplay().

HTH
Rüdiger

On 11.04.2011 00:16, Peter Boccia wrote:
> Ralf,
>
> I'm sorry I've just read the API for Text
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/reference/api/org/eclipse/swt/widgets/Text .html
> and Text don't have getDisplay(). Which method are you talking about?
>
> Thank you for the reply,
> Peter
Re: swt.widgets.Text error when append [message #664595 is a reply to message #664553] Mon, 11 April 2011 10:20 Go to previous messageGo to next message
Peter Boccia is currently offline Peter BocciaFriend
Messages: 38
Registered: December 2010
Member
Thank you Ralf!
It works but in RAP it does NOT scroll automatically at the end of the text? I just read a bug of this issue, it's dated July 2010, but no one fixed it.
How can I auto-scroll to the end?
I try putting a personal ScrollBar but it doesn't work.

Thank you.
Re: swt.widgets.Text error when append [message #664604 is a reply to message #664595] Mon, 11 April 2011 11:04 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Peter,
we have this bug opened:
319227: [Text] Multi text does not auto-scroll on append, insert operation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=319227
but, it's hard (or even impossible) to fix it with current client side
implementation.
The only way (currently) to scroll to the end is to call setText with
the complete text. Of course, this will lead to performance problems
with really large texts - like in your case, append to the log and set
the complete log. Maybe a console with last events/logs on the top
(instead of the bottom) will solve your problem - no need for scrolling.
HTH,
Ivan

On 4/11/2011 1:20 PM, Peter Boccia wrote:
> Thank you Ralf!
> It works but in RAP it does NOT scroll automatically at the end of the
> text? I just read a bug of this issue, it's dated July 2010, but no
> one fixed it.
> How can I auto-scroll to the end?
> I try putting a personal ScrollBar but it doesn't work.
>
> Thank you.
Re: swt.widgets.Text error when append [message #664904 is a reply to message #664604] Tue, 12 April 2011 13:15 Go to previous messageGo to next message
Peter Boccia is currently offline Peter BocciaFriend
Messages: 38
Registered: December 2010
Member
Yes Ivan,

I was talking right about that bug.
I resolved in a simple way:

//set a selection at the beginning of the text
text.setSelection(0);
//insert the text at the head +\n if is not yet in the string
text.insert(newMessage+"\n")


It's easy to understand: to make all the new messages always displayed I choose the contrariway solution: the newest message at the head of the text instead of the end.

Typically in a chat the newest message go in the end and the scrollbar go down at the end, but on RAP this is not possible.

So this might be the easiest way to do it.

I hope this time is me to had help someone.

Peter
Re: swt.widgets.Text error when append [message #671810 is a reply to message #664904] Thu, 19 May 2011 04:10 Go to previous message
Penka  is currently offline Penka Friend
Messages: 7
Registered: July 2009
Junior Member
Hi,
This may work too. But we should call setFocus() for it to work.
text.setSelection(text.getText().length());
text.setFocus();
Previous Topic:Clustering Solutions
Next Topic:Updating the view/refreshing an image
Goto Forum:
  


Current Time: Fri Apr 26 17:18:24 GMT 2024

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

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

Back to the top