Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts
2010-03-09
2007-02-26
Writing to the statusbar in Eclipse from a non-UI thread
If you are dealing with the UI in Eclispe and need access to a certian part, e.g. the Statusbar in this case, it is quite easily achieved. On the other hand if you would like to simply write a message to this afore mentioned status bar, it is a whole new deal. You wrie your code that in the end extracts the site in question. As you get hold of the current statusline manager from the site, this is the way to go. Or,..?. well, when you start to debug the code you find that you run into NullPointerExceptions. The site or its view parts are null. This happens if certain methods in e.g. JFace is called from a non-UI thread. It actually says so in the Javadoc, in some places. I.e. the getActiveWorkbenchWindow method in IWorkbench exposes this behaviour.
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:
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.
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.
2007-02-06
Eclipse Pluginfest, Jfokus and speaking
It has gone two weeks now since the Eclipse Pluginfest in London. Time flies! There are some imagery from the event on the event Wiki.
I had an ambition to do some kind of reporting from the venue. But, we where very tied up in the exciting activities going on, and Adrian Taylor of Macrobug covered the event well. So check out his posts for day one and two. As the plug-in suite we brought with us to the fest are internal to my customer, so I cannot reveal to much of what went on regarding those. But, I can mention some intersting findings like the integration with IBM Rational Software Developer; it took some time to install (45 mins, a large number of plug-ins in our Eclipse 3.2 installation required to be updated) but proved to be an intersting tool. It does however resemble Borland's Together Architect, including model - code synchronisation. We will scrutinize this tool a bit further. It might be a candidate for replacing Together Architect ...
Further, there was a number of other interesting tools and prodcuts tried out together. We took a peek at the tool provided by Macrobug and some pre-view stuff from Symbian. All looks promising. The project manager for CDT, Dough Schaffer, told us about what is in the pipe. Another Doug, Doug Gaff from WindRiver, had an update on DSDP, Device Software Development Platform, and Mobile Tools for Java, MTJ. Two projects to keep a close eye on.
Last week the first Java conference in the Stockholm area took off; Jfokus. It is a joint "venture", sponserd, by Ciber, Sun Microsystems, SICS, IBS, JayWay, et. al. It has, had, four tracks and telling from the interest this might be increased next time. Speaking of interest, when the number of attendees rose past what the booked rooms could handle they had to close the registration site. The goal was to reach circa 300 attendees, when the registration site closed the number had reached 470!
Anyhow, I was asked early on if I could say something about OSGi, a technology I have been working with daily for some time now. The problem faced was a bit complicated; how much "introduction" should there be? Some people just wants to know what it is, whereas others would like to know how to employ it effieciently. Well, I kept to an introductory talk this time and time permitting there could be a quick demo. It turned out that most people probably knew quite a lot about OSGi, most of them probably knows far more about it than myself, and would have liked to see more practical stuff. And the demo? I had to fire up Eclipse as I hadn't planned for it. So there was a looooong delay before it came up (I am talking to my boss regarding a new laptop!). Did basically a reduced version of what me and Anders showed at JavaForum last year.
Lesson learned; fire up the IDE in the background just in case. If that eats to much memory - nag your boss once again. Also, we've probably had enough intros to OSGi now, next time there will something more practical with more code! The technology has really taken off lately, more and more people know about it today.
Another lesson, and a good one for that matter, is that prior to my little presentation I took some voice lessons. It has helped alot! A former collegue approached me after the presentation and informed me that I was very clear(!). That was great news! Seemingly my practicing has had some effect. Taking these lesson is quite fun as there has been a great deal of progress now when I in the beginning of the process. Also, I do realise that there is much much more that needs to be done in this area. So I am looking forward to more sessions of learning how to get in control of my voice ... Well, maybe someday I will be able to speak properly ...
I can reveal who is helping me with this; it is a very taleneted singer, soprano and artist. She has an alternate site also.
I had an ambition to do some kind of reporting from the venue. But, we where very tied up in the exciting activities going on, and Adrian Taylor of Macrobug covered the event well. So check out his posts for day one and two. As the plug-in suite we brought with us to the fest are internal to my customer, so I cannot reveal to much of what went on regarding those. But, I can mention some intersting findings like the integration with IBM Rational Software Developer; it took some time to install (45 mins, a large number of plug-ins in our Eclipse 3.2 installation required to be updated) but proved to be an intersting tool. It does however resemble Borland's Together Architect, including model - code synchronisation. We will scrutinize this tool a bit further. It might be a candidate for replacing Together Architect ...
Further, there was a number of other interesting tools and prodcuts tried out together. We took a peek at the tool provided by Macrobug and some pre-view stuff from Symbian. All looks promising. The project manager for CDT, Dough Schaffer, told us about what is in the pipe. Another Doug, Doug Gaff from WindRiver, had an update on DSDP, Device Software Development Platform, and Mobile Tools for Java, MTJ. Two projects to keep a close eye on.
Last week the first Java conference in the Stockholm area took off; Jfokus. It is a joint "venture", sponserd, by Ciber, Sun Microsystems, SICS, IBS, JayWay, et. al. It has, had, four tracks and telling from the interest this might be increased next time. Speaking of interest, when the number of attendees rose past what the booked rooms could handle they had to close the registration site. The goal was to reach circa 300 attendees, when the registration site closed the number had reached 470!
Anyhow, I was asked early on if I could say something about OSGi, a technology I have been working with daily for some time now. The problem faced was a bit complicated; how much "introduction" should there be? Some people just wants to know what it is, whereas others would like to know how to employ it effieciently. Well, I kept to an introductory talk this time and time permitting there could be a quick demo. It turned out that most people probably knew quite a lot about OSGi, most of them probably knows far more about it than myself, and would have liked to see more practical stuff. And the demo? I had to fire up Eclipse as I hadn't planned for it. So there was a looooong delay before it came up (I am talking to my boss regarding a new laptop!). Did basically a reduced version of what me and Anders showed at JavaForum last year.
Lesson learned; fire up the IDE in the background just in case. If that eats to much memory - nag your boss once again. Also, we've probably had enough intros to OSGi now, next time there will something more practical with more code! The technology has really taken off lately, more and more people know about it today.
Another lesson, and a good one for that matter, is that prior to my little presentation I took some voice lessons. It has helped alot! A former collegue approached me after the presentation and informed me that I was very clear(!). That was great news! Seemingly my practicing has had some effect. Taking these lesson is quite fun as there has been a great deal of progress now when I in the beginning of the process. Also, I do realise that there is much much more that needs to be done in this area. So I am looking forward to more sessions of learning how to get in control of my voice ... Well, maybe someday I will be able to speak properly ...
I can reveal who is helping me with this; it is a very taleneted singer, soprano and artist. She has an alternate site also.
2007-01-09
Adding a third party JAR to your Eclipse plugin
I often get the question "How to add a third party JAR-file to my Eclipse plugin". It is not that tricky, but neither that obvious. Two solutions has been posted on the Eclipse newslists, but it can be quite hard to find it as the sheer number of posts is overhelming.
Here is two ways of doing it:
1. Turn the JAR-file(s) into plugin(s)
This is probably the simplest solution, but maybe not always achieving the desired granularity though. "Use New" -> "Project" -> "Plug-in Development" -> "Plug-in from existing JAR Archive". That will turn the JAR-file into a single JAR-plugin. Check that all required packages are re-exported.
2. Include the JAR-file(s) in the plugin in question:
Here is two ways of doing it:
1. Turn the JAR-file(s) into plugin(s)
This is probably the simplest solution, but maybe not always achieving the desired granularity though. "Use New" -> "Project" -> "Plug-in Development" -> "Plug-in from existing JAR Archive". That will turn the JAR-file into a single JAR-plugin. Check that all required packages are re-exported.
2. Include the JAR-file(s) in the plugin in question:
- Use the "Import" -> "File System" to import the JAR-file(s) into your plugin project. E.g.
'/lib' directory - Then use "Add..." to add the JAR-file(s) to the classpath section of the Manifest/plugin.xml runtime tab.
- Press "New..." to add "." library back to the the classpath (without quotes).
- Check that the binary build exports the new JAR-file(s) on the Build tab.
- Press save, important for the changes to come through.
- Select the project in question in the package explorer view, right click and select "PDE Tools" -> "Update classpath". This will add the newly added JAR-file(s) to the project´s classpath.
Subscribe to:
Posts (Atom)