Multi-instances of a ViewPart

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”


2 thoughts on “Multi-instances of a ViewPart

  1. Hi,

    in our RCP we face the same problem. First I thought org.eclipse.ui.internal.ShowViewMenu has to provide an EP that allows to register views to not be open-able. Paul Webster however suggested to use the more generic transformations approach when we discussed this over at EclipseCon08.
    Haven’t tried either of it so far.


  2. Pingback: Multi-instances of a ViewPart - Part 2 « Manuel Selva’s Eclipse blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s