Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:15:33+00:00 2026-05-22T17:15:33+00:00

This is a general question but my current problem revolves around menu handling. In

  • 0

This is a general question but my current problem revolves around menu handling.

In a normal plugin with contributes menu actions you would configure ActionSets etc in the plugin.xml configuration. This is obviously sensible.

I am working on a RCP application (actually RAP) and I’m wondering if it’s worth the effort to configure everything via plugin.xml. My plugin does not have to interact with an other unknown plugins so, theoretically, I have control. I can add menus and actions programmatically.

I have been trying to configure a menu which contains a submenu. I have tried defining ActionSets and linking one inside the other but without success. Some items need to be disabled depending on the user role.

I figure I could have coded the whole lot in a few minutes but I’m not sure if that fits with the eclipse ‘ethos’.

What opinions are out there? The application will get fairly big so I’d like to get the approach right from the start. Perhaps someone can point me at an example for configuring a nested menu 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:15:34+00:00Added an answer on May 22, 2026 at 5:15 pm

    My opinion is that the plugin.xml implementation is the way to go.

    My main two reasons for using this method:

    • It’s really easy to reconfigure and reorganize the menus and buttons without writing java code.
    • Very clear hierarchical visualization of the menu trees.

    Here is a code snippet that implements menus and submenus. In this example, they are added to the main menu.

    You can paste this into your plugin.xml:

    <extension
             name="Main Menu Contributions"
             point="org.eclipse.ui.menus">
     <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="fileMenu"
               label="File">
            <command
                  commandId="org.eclipse.ui.file.exit"
                  label="Exit"
                  style="push">
            </command>
         </menu>
         <menu
               label="Edit">
            <command
                  commandId="org.eclipse.ui.edit.selectAll"
                  label="Select All"
                  style="push">
            </command>
            <menu
                  label="Submenu">
               <command
                     commandId="org.eclipse.ui.edit.selectAll"
                     label="Select All Submenu"
                     style="push">
               </command>
               <command
                     commandId="org.eclipse.ui.edit.delete"
                     label="Delete submenu"
                     style="push">
               </command>
            </menu>
         </menu>
      </menuContribution>
    </extension>
    

    For activating/deactivating a menu, you have to use Core Expressions to enable/disable command handlers. If a command doesn’t have any active handlers attached, it will be disabled. So, the menu item that calls that command will also be disabled.

    The following code snippets show how to create a button on the toolbar of a view and have it be enabled/disabled depending of a variable’s value. Bare in mind that you will have to change some things in this code to make it work. Most of the changes are for reference names and class implementation.

    Create the button in the toolbar (plugin.xml):

       <extension
             name="View Toolbar Contributions"
             point="org.eclipse.ui.menus">
          <menuContribution
                allPopups="false"
                locationURI="toolbar:myapp.views.MyView">
           <command
                 commandId="myapp.commands.PauseSound"
                 icon=""
                 label="Pause Playback Sound"
                 style="push"
                 tooltip="Pause">
           </command>
         </menuContribution>
    </extension>
    

    Create the command (plugin.xml):

    <extension
             id="myapp.commands.PauseSound"
             name="Pause sound command"
             point="org.eclipse.ui.commands">
          <command
                id="myapp.commands.PauseSound"
                name="Pause Sound">
          </command>
    </extension> 
    

    Create the command handler (plugin.xml):

    <extension
             point="org.eclipse.ui.handlers">
          <handler
                commandId="myapp.commands.PauseSound">
             <activeWhen>
                <with
                      variable="myapp.commands.sourceprovider.active">
                   <or>
                      <equals
                            value="PLAYING">
                      </equals>
                      <equals
                            value="PAUSED">
                      </equals>
                   </or>
                </with>
             </activeWhen>
             <class
                   class="myapp.rcp.commands.toolbar.PausePlayback">
             </class>
          </handler>
    </extension> 
    

    Create the state variable for the command (plugin.xml):

       <extension
             point="org.eclipse.ui.services">
          <sourceProvider
                provider="myapp.commands.sourceprovider.CommandState">
             <variable
                   name="myapp.commands.sourceprovider.active"
                   priorityLevel="workbench">
             </variable>
          </sourceProvider>
       </extension>
    

    Implement the class that changes the variable’s state:

    public class CommandState extends AbstractSourceProvider {
        public final static String STATE = "myapp.commands.sourceprovider.active";
        public final static String STOPPED = "STOPPED";
        public final static String PLAYING = "PLAYING";
        public final static String PAUSED = "PAUSED";
        public final static String NOT_LOADED = "NOT_LOADED";
    
    enum State {
            NOT_LOADED, PLAYING, PAUSED, STOPPED
        };
        private State curState = State.NOT_LOADED;
    
        @Override
        public void dispose() {
        }
    
        @Override
        public String[] getProvidedSourceNames() {
            return new String[] { STATE };
        }
    
        // You cannot return NULL
        @SuppressWarnings("unchecked")
        @Override
        public Map getCurrentState() {
            Map map = new HashMap(1);
            if (curState == State.PLAYING)
                map.put(STATE, PLAYING);
            else if (curState == State.STOPPED)
                map.put(STATE, STOPPED);
            else if (curState == State.PAUSED)
                map.put(STATE, PAUSED);
    
            return map;
        }
    
        public void setPlaying() {
            fireSourceChanged(ISources.WORKBENCH, STATE, PLAYING);
        }
    
        public void setPaused() {
            fireSourceChanged(ISources.WORKBENCH, STATE, PAUSED);
        }
    
        public void setStopped() {
            fireSourceChanged(ISources.WORKBENCH, STATE, STOPPED);
        }
    
        public void setNotLoaded() {
            fireSourceChanged(ISources.WORKBENCH, STATE, NOT_LOADED);
        }
    
    }
    

    More details on how to implement these features can be found at these locations:

    • Eclipse Commands Tutorial
    • Limiting Visibility of Commands
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more a general question but my particular case involves a ruby/rails app
This is a general question of sorts, but do you think that it's important
This is a general question, but I'll explain my specific need at the moment:
This is a general question about MVC as a pattern, but in this case
I'm working on a RoR app, but this is a general question of strategy
I know this SO question, but it deals with the subject in more general
So, this is a rails app but really more of a general ruby question:
This is a more general question, but which has wider implications for a data
Yesterday I asked this general question about decimals and their internal precisions. Here is
This is a general question concerning technology decisions for a product development. My aim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.