Over a million developers have joined DZone.

Creating a Custom Property View

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

In 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:

From http://blog.eclipse-tips.com/

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}