当前位置: 动力学知识库 > 问答 > 编程问答 >

eclipse - Overwriting views in the ecplise ui view extension point

问题描述:

I'm developing an Eclipse RCP application consisting of several plugins. One of those plugins (the "common ui" plugin) provides a view that is used by several other plugins. The view is defined in the plugin.xml of the common ui plugin, as well as its toolbar and context menu contributions (in the menus extension point).

There is one plugin, however, let's call it "special business plugin" that needs some additions to the view provided by the common ui plugin. Therefore, I have extended the viewpart class from the common ui viewpart class (to add additional columns and own label and content providers).

The extended viewpart needs the same menu contributions as the common viewpart. Of course, I don't want to write them twice, I just want to use the menu contributions that are defined in the plugin.xml of the common plugin. However, they are bound to the view id of the common viewpart. If I use the same view id for the special viewpart, the special viewpart does not get opened, instead the common view part does (of course, because they share the same id). If I use a different id, I have to write the menu contributions twice, which I want to avoid.

So, how do I overwrite a view defined by another plugin when I want to use the same menu contributions as view I want to overwrite?

plugin.xml of the common plugin

<plugin>

<extension point="org.eclipse.ui.views">

<view

allowMultiple="true"

category="org.eclipse.ui"

class="com.mycompany.client.common.ui.view.CommonViewPart"

icon="icons/CommonView.gif"

id="com.mycompany.client.common.ui.view.CommonView"

name="%CommonView"

restorable="false">

</view>

</extension>

<extension point="org.eclipse.ui.menus">

<menuContribution

locationURI="toolbar:com.mycompany.client.common.ui.view.CommonView">

<command

commandId="com.mycompany.client.common.ui.handler.RefreshCommand"

label="%refresh"

style="push">

</command>

</menuContribution>

</extenstion>

</plugin>

plugin.xml of the special plugin

<plugin>

<extension point="org.eclipse.ui.views">

<view

allowMultiple="true"

category="org.eclipse.ui"

class="com.mycompany.client.special.view.SpecialViewPart"

icon="icons/CommonView.gif"

id="com.mycompany.client.common.ui.view.CommonView"

name="%CommonView"

restorable="false">

</view>

</extension>

</plugin>

The views are opened by a handler with the following code line:

Common:

AbstractViewPart view = (AbstractViewPart).

getActiveWorkbenchPage(event).showView(CommonViewPart.ID, null,

IWorkbenchPage.VIEW_VISIBLE);

Special:

AbstractViewPart view = (AbstractViewPart).

getActiveWorkbenchPage(event).showView(SpecialViewPart.ID, null,

IWorkbenchPage.VIEW_VISIBLE);

网友答案:

In this case you can't overwrite one definition with another. There are a couple of options.

  1. You can use something like Product Customization to remove the common view definition in some cases. It's pretty heavy weight for what you are doing.
  2. Provide the common view definition in a separate, small plugin. Then don't include that small plugin in the RCP product that includes your specialized view.
分享给朋友:
您可能感兴趣的文章:
随机阅读: