Class MenuResourceListener

java.lang.Object
com.onenetwork.platform.common.menu.MenuResourceListener

public abstract class MenuResourceListener
extends java.lang.Object
Clients can subclass to modify Menu contents at runtime. #onMenu() is called on each user login, and the MenuDefinition passed can be mutated by this listener. The menuDefinition passed will correspond to the UI Meta Model definition (coming from the module or dataset), but can be further manipulated by this class. Available operations include:
  • Adding menu actions
  • Removing menu actions
  • Adding menu folders.
  • Removing menu folders.
  • Reassigning menu actions to different folders.
  • Adding or removing home action
  • Adding or removing menu actions in the quick launch actions list.

The code sample below shows how to extend MenuResourceListener (and register it in ModuleContextListener.moduleInitialized method).

public class ModuleContextListener implements com.onenetwork.platform.env.module.ModuleContextListener {

  public void moduleInitialized(Module module) throws Exception {
    Services.get(MenuService.class).registerListener(new MyCustomMenuResourceListener());
  }
  
}

public class MyCustomMenuResourceListener extends MenuResourceListener {
  
  public void onMenu(MenuDefinition menuDefinition, PlatformUserContext userContext) {
    if(!userContext.getUserName().equals("MyCustomUser")) { //Only applies to specific user.
      return;
    }
    
    MenuService menuService = Services.get(MenuService.class);
    List items = menuDefinition.getMenuElements();
    
    MenuAction homeAction = menuDefinition.getHomeAction();  
    homeAction.setURL("/oms/apps/MyApp/newHome");
    
    items.get(0).setName("Renamed Item");
    items.get(0).setURL("/oms/apps/MyApp/someNewURL");
    
    MenuFolder menuFolder = menuService.newMenuFolder("Menu Group Added By MenuResourceListener");
    List list = menuFolder.getMenuElements();
    MenuAction menuAction = menuService.newMenuAction("Action #1 Added By MenuResourceListener(Singleton)");
    menuAction.setURL("http://www.onenetwork.com");
    menuAction.setSingleton(true);
    list.add(menuAction);
    MenuElement menuDivider = menuService.newMenuDivider();
    list.add(menuDivider); //Menu divider/seperator
    menuDefinition.getMenuElements().add(menuFolder);
  }

}
  • Constructor Summary

    Constructors 
    Constructor Description
    MenuResourceListener()  
  • Method Summary

    Modifier and Type Method Description
    abstract void onMenu​(MenuDefinition menuDefinition, PlatformUserContext userContext)
    Modify MenuDefinition by using PlatformUserContext.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait