Multi-instances of a ViewPart - Part 2

May 21, 2008

As discussed in a previous post I created an application with a View allowing multi instances.

An other problem I encountered with multi instances views is about Views persistence between several launches.

When the workbench is closed Eclipse automatically remember each opened view’s position. This way the next time I’ll start my workbench these opened views will be automatically displayed.

In my case this behavior is not the good one since view’s content is not persistent across launches. For example if the user leaves its workbench with 6 opened instances of my view he ‘ll get 6 empty views at next launch …

To solve this problem I just added an IWorkbenchListener closing all the opened instances of my view when the workbench is closing down. Closing a view is done by the IWorkbenchPage.hideView() method.


Multi-instances of a ViewPart

May 15, 2008

I didn’t blogged for a while because I am working on a new Eclipse application. This application defines a new View. This view is created with allowMultiple = true.

This view is associated with a given file extension. Each time the user double click on such a file a new instance of the view is created using IWorkbenchPage.showView(primaryId, secondaryId).

I quickly got my multi instances view mechanism functional. The next step was to manage “correctly” the behavior of :

Window -> Show View -> MyMultiInstanceView ???

What happens when the user clicks other there … ???

Launching my app in debug mode told me than my view is created (by Eclipse and not explicitily by my code) in that case with a secondaryId == null. Of course this resulted in a famous NullPointerException ;0)

A first and simple solution is to check the secondaryId and provide an empty view (or a view with a simple message)  when this Id is null …

I decided to use an other solution using the “master view” (the one displayed when the user clicks windows -> show view) to display informations about all the other opened views (the ones with a secondaryId != null associated to a file).  This view just contains a ListViewer showing all the other opened views. A double click on a given element of that list gives brings the associated view to the top. When a view is closed by the user, the associated entry in the view is removed.

This solution help me to solve the problem of providing the user a way to open a “meaningless view” in its perspective.

Here I had to “search” for something to display in the master view. Since new instances can only be created programatically it could be nice in some cases for plug-ins developers to be able to tell the platform: “don’t create Show View menu entry for this view”


Eclipse Selection Service Tip

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 :

Current Selection View

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

Current Selection View

May be I missed something and such information is already available somewhere in the PDE … ?? If Yes, please let me know.


JFace’s Viewers Performances

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:

  1. The retrieval of all the model objects from the viewer’s input (it’s the content provider’s job).
  2. 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 …


links Directory

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 Eclipse Helpand from this old article.


Draw2d outside Eclipse

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.


Eclipse and Hibernate and Class Loaders

April 3, 2008

I spent time today to have an Hibernate Hibernate Logo 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.


Eclipse Feature Tip - Help About Dialog

March 5, 2008

Last week i was working on an Eclipse feature for the first time. I created my feature, added plug-ins into it, deployed it and it worked perfectly at the first time. All my plug-ins where there and available !!!!

Nice, then I just checked that my feature was present in the Help -> About-> Feature Details dialog … and here comes the bad news : my feature was not visible. After long investigations and discussions (available here, you need to login) on the eclipse platform news group and thanks to Ed Merks and Nick Boldt I have the solution to my problem.

To have a feature displayed in the Help -> About-> Feature Details you need to define a Branding plug-in for that feature in the feature.xml file. If no Branding plug-in is specified Eclipse will look for a Branding plug-in with the same ID than the feature’s ID.

In this plug-in there must be a about.ini, about.properties and about.mapping files. For more informations on these files and there content you can look the Eclipse Help here.


Unhandled event loop exception

February 21, 2008

Lot of people wonder what the famous Unhandled event loop exception is !!!???

This is no more than an uncaught Exception occurring with in the Eclipse workbench Main thread (or the UI thread, it’s the same).

When writing Eclipse plugins we often write code that will be executed within the Main thread. For example when contributing a new hello world button within the main Eclipse toolbar we must implement a given interface with a run() method.

In this method we write the code responsible to display to the user the “Hello world message”. If this code throws a new Exception without catching it then the Exception is forwarded to the caller. This caller is the Eclipse code but not our !!!!

In this Eclipse code the Exception is forwarded up to the Workbench.runEventLoop(IExceptionHandler, Display) method that catch it and log a new Unhandled event loop exception Error message. This message also contains our source Exception displayed as Reason :

When you see an Unhandled event loop exception , don’t worry and just look for the reason, it’s often a silly mistake :o)


Eclipse Profiling / Memory Analyzer Part 3

February 5, 2008

Hi,

This blog was started 3 weeks ago and only contains 9 posts today. Most of the traffic on the blog was generated by the two posts about “Profile Your Eclipse Plugins with SAP Memory Analyzer” here and here.

Eclipse’s plugins profiling seems to be a real question for a lot of us !!! This new tool help us to quickly identify memory leaks in our applications but what about time performances ??

How do you profile your plugins time performances ?? I would be intersted in any suggestions on this topi so pelase let me know.

Regards

Manu