Eclipse Search


Oct 21, 2008

Multi instance Property View - a first look

Currently the workbench supports only one instance of the PropertyView. So if you ever wanted to compare the properties of two different elements, you have to open two windows and select each element in a different window. Yes, this is ugly and becomes more uglier when you wanted to compare three or more elements. Thanks to Markus, Eclipse 3.5 (Galileo) will host a multi-instance Property View. The code is not even checked into the CVS, so what ever I write is based on patch available in the bug. So the final version could be little different than what it is now.

So first things first. How does the new multi-instance Property View looks like? Well, just like the old one except for the two new buttons in the tool bar:
multi instance property view
The first button is to toggle the pin property and the second one is to open up a new instance of the property view. Once you click on the second one, you will get another instance of the view. The first instance is pinned to the selection for your convenience (if its not already pinned). You can move around the new instance to other place and change the selection to a different object and you can compare the properties. I've pinned the first instance to MyFile1.txt and the current selection is MyFile2.txt. Now I can compare the properties of these two files side-by-side:

Multi instance Property view
You can create any number of instances and arrange them in any place in your perspective and use them. If you change any preferences like pinning of selection or column widths or hide categories, etc, all those changes are isolated to the particular instance which you are changing. The rest will stay unaffected. You can close any/all of the instances. When the workbench is closed and restarted, all the secondary instances will be gone. You will start only one view.
This is all good, so that the user wants to manipulate. As a plug-in developer how can we manipulate this? Opening a new instance is implemented as a Command. So if you want to create a new instance, then all you need to do is to call the command programmatically:

   1: try {
   2: IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class);
   3:     handlerService.executeCommand("", null);
   4: } catch (Exception e) {
   5:     // handle exception
   6: }
There is currently no way to get the handle of the newly created instance. It would be very nice if the command returns the newly created view instead of null. Probably a dirty workaround would be to add a IPartListener before executing the command and look for the PropertyView created in the listener. I didn't try, but hope that would work.

Had the command taken a parameter for the secondary id, it would be easier for you to find the newly created instance. But the command neither had option for that. We still can iterate thru the view references in the window and get hold of the views. With the views, you can get/set the pinned property on them:

   1: IViewReference[] viewReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
   2: for (int i = 0; i < viewReferences.length; i++) {
   3:     if("org.eclipse.ui.views.PropertySheet".equals(viewReferences[i].getId())){
   5:         // this is one of the property view instance
   6:         PropertySheet propertyView = (PropertySheet) viewReferences[i].getView(true);
   8:         // just toggle the pinned property
   9:         boolean pinned = propertyView.isPinned();
  10:         propertyView.setPinned(!pinned);
  11:     }
  12: }
I don't see any API to get hold of the current selection in the view, but you can trigger a property view to show the properties of an element by firing the selectionChanged method and then calling setPinned(true);

As I mentioned, all these info is subject to change, and I'll add more info to this tip as the bug gets updated.


  1. Hi,

    Opening several property views is good, but this seems rather complicated just to compare files.

    Since the workbench can send selection including multiple items, it may be easier and more intuitive to display all files' properties in the same property view.

    Currently, the property view hides all content when 2+ items are seleted. This could be another bug to open...

    Thanks for writing about this.


  2. Nicolas,
    This is not to compare files! Its to compare the properties of any element that supports the Property View. I took file just an example.

    Displaying properties of multiple elements is supported in the property view, but its up to the content provider to utilize it