Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Browser; load from another Thread
SWT Browser; load from another Thread [message #452961] Tue, 29 March 2005 09:17 Go to next message
No real name is currently offline No real nameFriend
Messages: 25
Registered: July 2009
Junior Member
Hello,

What I like to do;

Load a locally stored html page. Then check, if a remote server is
available. If it is available, load the remote stored html in the browser.

I use a Job to check if the remove server is available. But then, I receive
a Wrong Thread exception.

Is there a way to solve the problem?

Following the code:



private void loadRemoteWelcomePage() {
final String url =
DigiLohnPlugin.getDefault().getPluginPreferences()
.getDefaultString(StringConstants.BROWSER_URL_KEY.getValue() );

Job job = new Job("RemoteWelcomePage") {
protected IStatus run(final IProgressMonitor monitor) {
try {
final URL xx = new URL(url);
final String host = xx.getHost();
final Socket socket = new Socket(host, 80);
isConnected = socket.isConnected();
} catch (MalformedURLException exception) {
LOGGER.error("Wrong URL received", exception);
} catch (IOException exception) {
LOGGER.error("Can not connect to the host", exception);
}
System.out.println("Job finished");
return Status.OK_STATUS;
}
};

job.schedule(10000);
job.addJobChangeListener(new JobChangeAdapter() {
/**
* @see org.eclipse.core.runtime.jobs.JobChangeAdapter
* #done(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void done(IJobChangeEvent event) {
System.out.println("Job done event received");
if (isConnected) {
System.out.println("isConnected=" + isConnected);
browser.setUrl(url);
}
}
});
}


Regards,

Cyrill
Re: SWT Browser; load from another Thread [message #452982 is a reply to message #452961] Tue, 29 March 2005 14:57 Go to previous messageGo to next message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
The call
> browser.setUrl(url);
must be made from the UI thread (the one that created the SWT Display), like
any other SWT widget call.

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/faq.html#uithread

A quick patch to your code could look like:

Display.getDefault().syncExec(
new Runnable() {
public void run(){
browser.setUrl(url);
}
}
);

For Job API related questions, you could also ask on the
news://news.eclipse.org/eclipse.platform . You'll probably get an answer
from the owner of the Job API. I'm forwarding that thread to that developer
to get his opinion - above solution might be mixing 'low level' display
calls with 'high level' Job API in a manner not intended by the Job API.
Stay tuned...

Chris
Re: SWT Browser; load from another Thread [message #452984 is a reply to message #452982] Tue, 29 March 2005 15:34 Go to previous messageGo to next message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
Here's the reply:

If you want synchronous UI updating than you can use display.syncExec. If
asyncronous is OK, you can use UIJob or WorkbenchJob.

To ask questions related to UIJob and WorkbenchJob, try the
news://news.eclipse.org/eclipse.platform newsgroup...

Chris
Re: SWT Browser; load from another Thread [message #453172 is a reply to message #452984] Thu, 31 March 2005 07:12 Go to previous message
No real name is currently offline No real nameFriend
Messages: 25
Registered: July 2009
Junior Member
Thanks!!!

Cyrill
Previous Topic:how to invoke updater module from SWT ?
Next Topic:AWT_SWT on mac osx
Goto Forum:
  


Current Time: Fri Apr 26 03:27:02 GMT 2024

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

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

Back to the top