If you are to produce code that calls these methods but does not have a UI-thread available? Well, then we can create one. It is quite simple once you've got the hang of it. It might look a bit complicated at first as it comprises using an anonymous inner class (which is a bit of favorite of mine as they resemble, to some extent, closures - without being it - ok, let the comments come!). Below is a code snippet that will produce a message on the status line:
final Display display = Display.getDefault();
new Thread() {
public void run() {
display.syncExec(new Runnable() {
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
public void run() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IWorkbenchPart part = page.getActivePart();
IWorkbenchPartSite site = part.getSite();
IViewSite vSite = ( IViewSite ) site;
IActionBars actionBars = vSite.getActionBars();
if( actionBars == null )
return ;
IStatusLineManager statusLineManager =
actionBars.getStatusLineManager();
if( statusLineManager == null )
return ;
statusLineManager.setMessage( message );
}
});
}
}.start();
If you want to the clear the statusline, pass null as argument to the setMessage method. Too many method calls? I "chopped"them up a bit to make it clear. One does find code here and there in the open source community where the author has more or less kept the calls figuring out the site reference to one line.
There are few posts on EclipseZone about, or touching, the subject. One of the more intersting threads can be read here.
4 comments:
Do we need to use Thread?
Why not just use Display.getDefault().syncExec()?
Thank you for your comment.
The Thread thing was present in the example in the Eclipse FAQ so I let be in. Haven't tried doing it without the Thread yet (it was some time ago ... ). Have you tried? Can it be removed?
After a quick investigation I've found thatr the thread thing is required by the rendering in the underlying graphics. I.e. all communictaion with widgets etc. has to be done from within a UI-thread.
Hi, thanks for your post.It was helpful.
Post a Comment