[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Updating a widget from a background running thread

Thanks Joe for this package... Why don't you put it for instance on the wiki (http://eclipse-wiki.info) to share it with everyone?
Best regards
Xavier


Joe Smith a écrit :
This is a quite problematic area in SWT. I have been developing
adaptor design patterns that make easy to write SWT programs.
The following is snipet for multiline text widgets. If you use this,
you don't have to bother about thread ownership. Just call like
this from anywhere;

   SWTTextArea mmm = new SWTTextArea(parent, "initial contens....");

   mmm.setText("your data");
   mmm.append("next data");

Currently my SWT patterns cover only my needs. But it covers
most needs and can be extened easily. If you are intrested with the
whole package, just send me an email.

======= The Text pattern
public class SWTTextArea extends Text {
public SWTTextArea(Composite parent, String label) {
super(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
setText(label);
}
protected void checkSubclass() {}


    public void setText(final String v) {
       if (SWTDevice.thread==Thread.currentThread()) {
	         super.setText(v);
	         return;
       }
	      SWTDevice.display.syncExec(new Runnable() {
        public void run() {
		            setText(v);
		       }
	      });
    }

    public void append(final String v) {
      if (SWTDevice.thread==Thread.currentThread()) {
	          super.append(v);
	          return;
      }
      SWTDevice.display.syncExec(new Runnable() {
		        public void run() {
		          append(v);
        }
	      });
    }
}





"Xavier" <xavier.mehaut@xxxxxxx> wrote in message news:d7fcg6$lcl$1@xxxxxxxxxxxxxxxxxxx

Hello,
I would like to update for instance a text field in a view from a Thread running in background. Unfortunately, this throws an error because we try to update the field from another thread wich is not a "graphical" thread.
Is there a simple means to do that properly?
regards
Xavier