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:
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:
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("org.eclipse.ui.views.properties.NewPropertySheetCommand", null);4: } catch (Exception e) {
5: // handle exception
6: }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())){4:
5: // this is one of the property view instance
6: PropertySheet propertyView = (PropertySheet) viewReferences[i].getView(true);
7: 8: // just toggle the pinned property
9: boolean pinned = propertyView.isPinned(); 10: propertyView.setPinned(!pinned); 11: } 12: }As I mentioned, all these info is subject to change, and I'll add more info to this tip as the bug gets updated.
2 comments:
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.
Nicolas
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
Post a Comment