Skip to main content
Jump to: navigation, search

Menu Contributions/IFile objectContribution

< Menu Contributions
Revision as of 11:33, 28 February 2007 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

IFile object contribution

We also have to provide object contributions (which in the past were scoped by objectClass).


There will be a reserved popup ID, "org.eclipse.ui.popup.any" that will allow contributions to any popup menu.

 <extension point="org.eclipse.ui.menus">
   <menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
     <command commandId=""
         <with variable="selection">
            <!-- do something with an ISelection -->
     <command commandId=""
           <!-- the default variable is a Collection holding the ISelection,
                   or the objects from an IStructuredSelection -->

It's probably that the default variable for core expression evaluations would be selection, so you wouldn't need the <with/> clause like in the second item above.

There would probably also be a short-hand to tie the visibility to an active handler. Maybe <visibleWhen handler="true"/> This is still conjecture.

Menus API

So programmatically it is similar to all other menu contributions.

public static void addFileContribution() {
    final IMenuService menuService = (IMenuService) PlatformUI
    // an expression that walks the selection looking for objectclasses
    final ObjectClassExpression ifileExpression = new ObjectClassExpression(

    final ImageDescriptor postIcon = AbstractUIPlugin
    final ImageDescriptor loadIcon = AbstractUIPlugin
    AbstractContributionFactory factory = new AbstractContributionFactory(
            "popup:org.eclipse.ui.popup.any?after=additions") {
        public void createContributionItems(IMenuService menuService,
                List additions) {
            CommandContributionItem item = new CommandContributionItem(
                    "", null, postIcon,
                    null, null, null, "P", null,
            menuService.registerVisibleWhen(item, ifileExpression);

            item = new CommandContributionItem(
                    "", null, loadIcon,
                    null, null, null, "L", null,
            menuService.registerVisibleWhen(item, ifileExpression);

        public void releaseContributionItems(IMenuService menuService,
                List items) {

The location of org.eclipse.ui.popup.any specifies any context menu, and the expression ties it to a specific objectClass. Using the new expression syntax you can make your conditions more complex.

You can set your visibleWhen expression on each item as you create it.

In 3.3M6 registerVisibleWhen(*) method might be changing.

Back to the top