DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Creating a Custom Property View

Creating a Custom Property View

Prakash  user avatar by
Prakash
·
May. 18, 09 · Java Zone · Interview
Like (0)
Save
Tweet
17.16K Views

Join the DZone community and get the full member experience.

Join For Free

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/

Property (programming)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Evaluate Software Quality Assurance Success: KPIs, SLAs, Release Cycles, and Costs
  • Caching Across Layers in Software Architecture
  • Monolith vs Microservices Architecture: To Split or Not to Split?
  • Major PostgreSQL Features You Should Know About

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo