Possibility to replace the execution class of a view contribution

Motivation

In order to eliminate the necessity of modifying the standard code, there is a new possibility to replace the execution class of a view contribution. Assuming that you have to override the standard item view to add a customer-specific functionality. So you extend the class ArticleTableView and create you own custom article view class with the additional logic. Now if you contribute you custom class in a view contribution, you have both views in the PIM RichClient: the standard item view and your custom item view. So you have to modify the plugin.xml of the plugin com.heiler.ppm.article.ui to hide the standard item view.

Solution

Now from PIM 7.0.01.00 there is a new possibility to contribute you own custom class without modifying the standard code. There is a new extension point - com.heiler.ppm.std.core.contributionClassProviders - which allows you to replace the execution class of a standard contribution with your own custom class. In order to allow the using of this extension point, all standard view contributions were modified. Now the class attribute of a view contribution contains instead of the name of the view class the name of the specific class factory. This factory is called when the execution class of a view contribution is loaded. At this point we can check, if there are extensions of the com.heiler.ppm.std.core.contributionClassProviders for the corresponding view ID.

Now a standard view contribution looks like this:

<extension
point="org.eclipse.ui.views">
<view
allowMultiple="true"
icon="icons/ArticleList.gif"
class="com.heiler.ppm.std.core.contribution.ContributionClassFactory:com.heiler.ppm.article.ui.internal.view.ArticleTableView:Article"
category="com.heiler.ppm.views.categories.Article"
name="%view.articles.name"
id="com.heiler.ppm.article.ui.views.ArticleTableView"/>
</extension>

So if you can see, the class attribute contains following parts: the name of the factory class + the name of the base class + (optional) initialization data. All parts are separated by the ':'

The ContributionClassFactory tries to find an extension of the point com.heiler.ppm.std.core.contributionClassProviders which is contributed for the id defined in the standard view contribution.

<extension
point="com.heiler.ppm.std.core.contributionClassProviders">
<classProvider
class="com.heiler.ppm.custom.article.ui.internal.CustomArticleView:Article"
contributionId="com.heiler.ppm.article.ui.views.ArticleTableView">
</classProvider>
</extension>

If a corresponding extension was found - the custom class defining in the custom contribution will be loaded for the view contribution. If there is no corresponding extension - the base class defining in the view contribution will be loaded.

Base class

The original view contribution contains in the class attribute the name of the base class. This class will be instantiated when no classProvider contribution for the view ID was found. Please note that the corresponding custom view class should extend the base class defined in the original view contribution. If the custom view class is not an instance of the base class, a CoreException will be thrown.

Priority

By using of the priority attribute you can determine which custom contribution for a particular contribution ID. If there are sereral classProvider contributions for the same contributionId, the one with the highest priority will be used. If the priority attribute is omitted - the priority of 100 is used. So set the value of the priority attribute to a number higher then 100 to ensure, that a specific classProvider contribution is used.

<extension
point="com.heiler.ppm.std.core.contributionClassProviders">
<classProvider
class="com.heiler.ppm.custom.article.ui.internal.CustomArticleView:Article"
contributionId="com.heiler.ppm.article.ui.views.ArticleTableView"
priority="200">
</classProvider>
</extension>

Additional attributes

You can also add additional attributes to the classProvider contribution such as name or icon. In this case the custom view name and icon will be shown in the view title.

<extension
point="com.heiler.ppm.std.core.contributionClassProviders">
<classProvider
class="com.heiler.ppm.custom.article.ui.internal.CustomArticleView:Article"
contributionId="com.heiler.ppm.article.ui.views.ArticleTableView"
priority="200"
name="%view.vips.name"
icon="icons/vip.gif">
</classProvider>
</extension>

Note: since the additional attributes are not defined in the extension point com.heiler.ppm.std.core.contributionClassProviders - a warning will be shown in the plugin.xml editor. You can just ignore this warnings.

The custom name and icon are shown in the view title and in the "Open view..." dialog:

images/download/attachments/32309284/custom_item_view.png

Outlook

Basically the possibility to replace the ecexution class is not view specific. Theoretically it would work in any other contribution which have a class attribute. The new extension point com.heiler.ppm.std.core.contributionClassProviders and the factory class ContributionClassFactory are quite generic and are not view specific. However, currently only view contributions are enabled for the replacing of the execution class. If you need this possibility for other kind of contributions in the standard code, please contact the PIM development team and explain your request.

Download

You can find a full source code example for this here.