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 8812791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:41:07+00:00 2026-06-14T03:41:07+00:00

I am working on a Desktop app with the Netbeans RCP. I have a

  • 0

I am working on a Desktop app with the Netbeans RCP. I have a number of menu items that are beeing added to the menu through annotations in the TopComponents.
I would like to be able to disable several of these menu items, depending on the access rights of the logged user.

  • 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-06-14T03:41:08+00:00Added an answer on June 14, 2026 at 3:41 am

    One way to do this in the NetBeans Platform is to register a Presenter.Menu in the menu:

    @ActionID(id = "com.company.MyPresenter", category = "Edit")
    @ActionRegistration(displayName = "com.company.Bundle#CTL_MyPresenter")
    @ActionReference(path = "Menu/Edit", position = 1)
    public class MyPresenter implements Presenter.Menu {
    
        @Override
        public JMenuItem getMenuPresenter() {
            // return menu item from your ACL'd registry
        }
    }
    

    When you register a Presenter.Menu in the menu the getMenuPresenter() method is called by the platform to get the actual JMenuItem that is added to the menu.

    Normally you would just construct a JMenuItem here but since you need to be able to get a hold of it in other parts of the application you’ll need to keep some kind of registry of your menu items so that you’ll be retrieving the same instance.

    One way to do this is to register all of your ACL’d menu items as a ServiceProvider. In this way you can Lookup all of them when you need to enable/disable them.

    A ServiceProvider interface:

    public interface ControllableMenuItem {
    
        void setEnabled(boolean enabled);
    
        JMenuItem getMenuItem();
    }
    

    A ControllableMenuItem implementation registered as a ServiceProvider:

    @ServiceProvider(service = ControllableMenuItem.class)
    public class MyMenuItem implements ControllableMenuItem {
    
        private JMenuItem menuItem;
    
        @Override
        public void setEnabled(boolean enabled) {
            getMenuItem().setEnabled(enabled);
        }
    
        @Override
        public JMenuItem getMenuItem() {
            if (menuItem == null) {
                menuItem = new JMenuItem(new MyAction());
            }
            return menuItem;
        }
    }
    

    Now you can Lookup all of the ControllableMenuItems when you need to enable/disable them:

    Collection<? extends ControllableMenuItem> menuItems = 
        Lookup.getDefault().lookupAll(ControllableMenuItem.class);
    for (ControllableMenuItem item : menuItems) {
        item.setEnabled(isAuthorized());
    }
    

    However there’s one more piece for this to work properly. You need a way to guarantee that the Presenter.Menu is getting the same instance that the Lookup is getting. One way to do this – admittedly not very elegant – is to register the MenuItem as a @ServiceProvider for itself and look this up in getMenuPresenter():

    // replaces the above annotation of MyMenuItem
    @ServiceProviders(value = {
        @ServiceProvider(service = ControllableMenuItem.class),
        @ServiceProvider(service = MyMenuItem.class)
    })
    public class MyMenuItem implements ControllableMenuItem {...}
    

    public class MyPresenter implements Presenter.Menu {
    
        @Override
        public JMenuItem getMenuPresenter() {
            MyMenuItem myMenuItem = Lookup.getDefault().lookup(MyMenuItem.class);
            return myMenuItem.getMenuItem();
        }
    }
    

    In this way you are guaranteed to get the same instance whenever you Lookup your ControllableMenuItems.

    This is only one way of doing this. The point here is that you need to have a mechanism in place to get the same instances of all of your ACL’d menu items when you need to disable them.

    Another approach to controlling what menu items actually make it into the menu system is to create separate modules for each level of access and simply disable modules when users aren’t authorized for a particular group of functionality. This is beneficial in many respects and is one of the strengths of using a modular system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a desktop app in Java that connects to a MySql database through
I am working on my first desktop app that queries LDAP. I'm working in
I am working on a Mono GTK# desktop app written in C#. I have
I have an .NET 4 .exe (Winform Desktop app) to which I have added
We already have Facebook working on our main desktop app without an issue. When
I am working on a desktop app in Qt that would work on Windows
I have wrote a desktop app, that holds FB applications data and lists test
I have a Java rich client desktop app. that I want to distribute on
I'm working on desktop application (Extract Transform Load type of app) that requires uploading
I'm working on a desktop application that will produce several in-memory datasets as an

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.