April 29, 2008
As Eclipse’s plug-in developer I often ask my self: what is the current workbench selection ?? Developers may need such information for example when they want to update a given view according to an other view selection but don’t know what the provided selection exactly is or when creating a new custom Selection provider. It can also be useful for simple debug purpose.
To answer this question I wrote a simple plug-in adding a new view to my workbench showing the content of the current selection in a simple JFace TableViewer.
The view is added to the PDE category :

Here is what it looks like when two Java methods are selected in the outline view :

May be I missed something and such information is already available somewhere in the PDE … ?? If Yes, please let me know.
6 Comments |
Eclipse Misc | Tagged: Add new tag |
Permalink
Posted by Manuel
April 23, 2008
In the same series than Andy Maleh post to-if-else-or-not-to-if-else and after discussions with colleagues I am wondering how you write the following problem using Java If-Else.
Object a;
Object b;
a == null and b == null -> method1()
a == null and b != null -> method2()
a != null and b != null -> method3()
a != null and b == null -> method4()
Which method to choose taking into account performances and redability between:
if (a == null && b == null) {
method1();
} else if (a == null && b != null) {
method2();
} else if (a != null && b != null) {
method3();
} else {
method4();
}
Or
if (a == null) {
if (b == null) {
method1();
} else {
method2();
}
} else {
if (b != null) {
method3();
} else {
method4();
}
}
About readability I’ll personally choose the first solution. About performances … I am not sure there is a difference after JVm’s optimizations … ??
14 Comments |
Java |
Permalink
Posted by Manuel
April 16, 2008
Last weeks I played for the first time with JFace’s viewers (TableViewer and TreeViewer). It was really easy to integrate my first viewers inside my own Eclipse views.
All was working fine when I started to encounter performances problems when setting inputs containing thousands of entries (several seconds for ~50.000 rows in a TableViewer).
A quick look on Google pointed me to LAZY content providers and SWT.VIRTUAL in order to improve performances. Before going further with these content providers we have to identify bottle necks. When working with JFace’s viewers there is potentially 2 bottle necks:
- The retrieval of all the model objects from the viewer’s input (it’s the content provider’s job).
- The creation of UI elements.
As Tom Schindl said here (Snippet 29): “The bottle neck is often the UI and not the model“.
I checked the time consumed in my content provider to retrieve viewer’s entries. Only few milliseconds. My bottle neck is the UI !!
To solve this performances problem I just added the SWT.VIRTUAL style when creating my TableViewer. Creating the viewer this way tells JFace to create the SWT's TableItem objects on an on demand basis. TableItem objects are created only when they become visible (when the user scroll for example). As a conclusion, all I had to do to solve my performances problem is to set this magic style: SWT.VIRTUAL. It’s so easy to work with Eclipse !!!!! Isn’t it ??
Next i tried the same solution with TreeViewer. Unfortunately it didn’t worked. I had to use the SWT.VIRTUAL style WITH an ILazyTreeContentProvider in order to increase my performances as in TableViewer. It’s fine but this solution has one drawback: Sorting and Filtering are no longer available when using ILazyTreeContentProvider.
Someone told me on the Eclipse Platform newsgroup that the request to support SWT.VIRTUAL style and sorting and filtering for TreeViewer is already in the “pipe” but i can’t find such a request on Eclipse bugzilla. If someone can tell me more on that …
8 Comments |
Eclipse Misc, SWT |
Permalink
Posted by Manuel
April 9, 2008
Several months ago i discovered the Eclipse’s links directory. Today I saved again a lot of time setting up a new Eclipse installation thanks to this tip. I used Eclipse for long time before discovering this feature and that’s why i am posting about it.
Links directory allows you to tell Eclipse where to search for extensions when it starts. This directory just contains several .link files containing each one the path to an extension.
Personally I created a link directory separately from my Eclipse’s installation directory. Of course I also install my favorite plugins outside the Eclipse’installation. Each time I install a new Eclipse I just create a symbolic “link” (using ln -s , I am on a Linux workstation) in this new install pointing to my shared link directory. All my favorites plug-ins are there !!!
More Informations are available from the eclipse help
and from this old article.
No Comments » |
Eclipse Misc |
Permalink
Posted by Manuel
April 6, 2008
You are looking for a 2D library on top of SWT ??
The GEF project comes with a graphical library called Draw2d. This library can be used in any SWT application. Of course such applications are Eclipse’plug-ins but you can also use Draw2d in a standalone Java application with an SWT UI.
When dowloading the GEF plug-ins you get an eclipse plug-in called: org.eclipse.draw2d. This plug-in is in fact a “classical” jar without any Eclipse’s extension and can be used in any java application as a “classical” jar.
Here is a link to an Eclipse article introducing Draw2d.
4 Comments |
Eclipse Misc |
Permalink
Posted by Manuel
April 3, 2008
I spent time today to have an Hibernate
example running as Eclipse Plug-ins. Here is a trick to avoid NoClassDefFoundError when using Hibernate within Eclipse.
I have three Plug-ins :
com.mydomain.hibernate: Packaging of the hibernate Jar library in a Plug-in
com.mydomain.A
com.anotherdomain.B
These plugins have the following dependencies :
com.mydomain.hibernate depends on nothing (it’s a “library” Plug-in)
com.mydomain.A depends on B and on com.mydomain.hibernate
com.anotherdomain.B depends on nothing
The NoClassDefFoundError(org.hibernate.proxy.HibernateProxy) was fired when trying to map (in a database using hibernate of course) a class of com.anotherdomain.B in com.mydomain.A code.
The Eclipse ClassLoader mechanisms and the injection of new code from Hibernate in the com.anotherdomain.B are responsible for this error .
Here is THE article that helped me to understand what was happening here and to solve my problem using Eclipse-BuddyPolicy.
2 Comments |
Eclipse Misc |
Permalink
Posted by Manuel