Hide/Show Menu of NetBeans RCP when Login/Logout

Leave a comment

December 26, 2012 by huionn

There are a few ways to dynamically control (show, hide, add, remove) NetBeans platform application. For my simple use case: to show or hide menu when user login or logout, I find that Repository.LayerProvider is the simplest to implement.

@ServiceProviders({
     @ServiceProvider(service=LoginProvider.class),
     @ServiceProvider(service=LayerProvider.class)
 })
 public final class LoginProvider extends LayerProvider {
     private boolean showMenu;
 
     @Override
     public void registerLayers(Collection context) {
         if (!showMenu) {
             context.add(LoginProvider.class.getResource("hiddenMenu.xml"));
         }
     }
 
     public static void showMenu() {
         LoginProvider lp = Lookup.getDefault().lookup(LoginProvider.class);
         lp.showMenu = true;
         lp.refresh();
     }
     
     public static void hideMenu() {
         LoginProvider lp = Lookup.getDefault().lookup(LoginProvider.class);
         lp.showMenu = false;
         lp.refresh();
     }
 }

hiddenMenu.xml  file

<?xml version="1.0" encoding="UTF-8"?>

<filesystem>
    <file name="Menu_hidden" />
</filesystem>

As a side note, it may requires clean & build for this to take effect.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: