Creating a Custom Property View

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/

0
Average: 4 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Prasad Kulkarni replied on Mon, 2009/05/25 - 6:43am

Hi, Same artical i could see everywhere but no where i found, where in custmizing the default property view there are some articals though as in the following link, but they are not serving my purpose, i dont have a custom view so that i can customize the property tab itself, but my requirement is i have standard project explorer view itself where in i have some text file so on click of that i want one more tab in the properties view which should display some details from that file, http://www.eclipsepluginsite.com/perspectives.html http://www.eclipse.org/articles/Article-Properties-View/properties-view.html So please let me know how can i link the project explorer view and the property view. i.e. whenever i click on the text file (click can either be single click or the double click) i want one extra tab which should display some details from the text file, please suggest any best examples related to my requirement.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.