Search code examples
eclipse-plugin

Loaded class is of incorrect type: expected(org.eclipse.ui.menus.WorkbenchWindowControlContribution) got (de.blub.menu.ToolbarContributionItem)


This is my menucontribution in the plugin.xml:

<menuContribution
        locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
    <dynamic
           class="de.blub.menu.ToolbarContributionItem"
           id="some.id">
         <visibleWhen checkEnabled="false">
            <!-- some conditions -->
         </visibleWhen>
    </dynamic>  
</menuContribution>

The ToolBarContributionItem class extends CompoudStatement as required according to the Documentation:

The element provides a mechanism that will call back into the defined class to provide an IContributionItem to be shown when the menu or toolbar is built. The defined class must be a derivative of the org.eclipse.jface.action.ContributionItem base class. It can also use org.eclipse.ui.action.CompoundContributionItem and provide an implementation for the abstract getContributionItems method to provide a dynamic menu item.

public class ToolbarContributionItem extends CompoundContributionItem {
...

But I get the Error Message

!MESSAGE Loaded class is of incorrect type: expected(org.eclipse.ui.menus.WorkbenchWindowControlContribution) got (de.blub.menu.ToolbarContributionItem)
!STACK 0
java.lang.IllegalArgumentException: Loaded class is of incorrect type: expected(org.eclipse.ui.menus.WorkbenchWindowControlContribution) got (de.blub.menu.ToolbarContributionItem)
at org.eclipse.ui.internal.util.Util.safeLoadExecutableExtension(Util.java:713)

So what's the problem here?


Solution

  • The documentation is wrong, see Eclipse bug 509635.

    The class must extend org.eclipse.ui.menus.WorkbenchWindowControlContribution