Creating a Custom Property View
Join the DZone community and get the full member experience.
Join For FreeIn an RCP application, you might need a Properties View, which shows only the properties of a specific view or a set of views. But the generic Properties View will show from all the other views that support it. Armed up with the knowledge of how a PageBookView works, lets see how to hack the Properties View to listen only to a specific view.
The isImportant() method is the one which decides whether to create an IPage for the specific IWorkbenchPart or not. The idea is to override that method and return false for all the workbenchPart that we are not interested in. Lets create the view first:
<view
class="com.eclipse_tips.views.CustomPropertiesView"
icon="icons/sample.gif"
id="com.eclipse-tips.views.customePropertiesView"
name="My Properties View">
</view>
The CustomPropertiesView should extend PropertySheet and override the isImportant():
public class CustomPropertiesView extends PropertySheet {
@Override
protected boolean isImportant(IWorkbenchPart part) {
if (part.getSite().getId().equals(IPageLayout.ID_PROJECT_EXPLORER))
return true;
return false;
}
}
In this case, I'm making the view only to respond to Project Explorer
and ignore other views. Here is the CustomPropertyView in action:
If you are on 3.5 or above, you would see the Pin Action in your Custom
Properties View. If you don't want the Pin action in your properties
view, there is no way to prevent the PropertySheet to adding the
action. The action is added to both tool bar and menu in the
createControl() method. Only way to get rid of the action is to remove
it after the PropertySheet adds it:
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
IContributionItem[] items = menuManager.getItems();
for (IContributionItem iContributionItem : items) {
if(iContributionItem instanceof ActionContributionItem) {
if(((ActionContributionItem) iContributionItem).getAction() instanceof PinPropertySheetAction) {
menuManager.remove(iContributionItem);
break;
}
}
}
IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
items = toolBarManager.getItems();
for (IContributionItem iContributionItem : items) {
if(iContributionItem instanceof ActionContributionItem) {
if(((ActionContributionItem) iContributionItem).getAction() instanceof PinPropertySheetAction)) {
toolBarManager.remove(iContributionItem);
break;
}
}
}
}
And don't forget to override the isPinned() method:
@Override
public boolean isPinned() {
return false;
}
There you go:
Opinions expressed by DZone contributors are their own.
Comments