Menu

How menus work

Mirco Gatz

[Home] : [Documentation]

How menus work

Interfaces

org.e1.ui_base_plugin.ui.menu.Menu Interface
All menus have to implement this interface. It provides all required methods.
The methods are:

  • set/getID() - Every menu has a unique id which could be set and retrieved via its setter and getter method.
  • addMenuEntry(parent, entry) - Adds a new entry to the menu. Pass a parent entry if the new entry is not in root layer or null if the new entry is a root layer one.
  • removeMenuEntry(entry) - Removes the passed entry from the menu not regarding its layer.
  • getMenuEntries() - Returns a list of all the root entries.

org.e1.ui_base_plugin.ui.menu.MenuEntry Interface
All menus consist of elements implementing the MenuEntry interface. Entries could host other entries or could be standalone.
The methods are:

  • set/getID() - Every menu item has a unique id which could be set and retrieved via its setter and getter method. The ids must be globally unique.
  • set/getDisplayTextKey() - Could be used to pass a localization key that will be used to determine the display text. If this property is set the DisplayText property will be ignored.
  • set/getDisplayText() - Sets and gets the display text of the menu entry that will be used if there is no DisplayTextKey present.
  • set/getURL() - The link url that will be used.
  • set/getPriority() - This Integer value is used to allow ordering of menu entries. Every call to get the list of menu entries (e.g. from the menu) will use this property to sort the them.
  • set/getMenuEntries() - Allows getting or direct setting of this entries sub entries. Direct setting of sub entries is considered as not recommended.
  • hasMenuEntries() - Returns true if this entry host sub entries.
  • add/removeMenuEntry() - Allows to add or remove direct sub entries.
  • set/getParent() - Sets or gets this entries parent entry. Could be null if the element is a root entry.
  • hasParent() - Return true if this entry is not a root entry.

Default Implementation for the Main Menu

The main menu implementation consists of the classes DefaultMainMenu and DefaultMainMenuEntry both to be found in the namespace org.e1.ui_base_plugin.ui.menu of the ui-base-plugin.

Using Spring and beans

Every menu and every menu entry is a bean which needs to be defined inside one of the applicationContext files.
The main menu entries are defined inside the applicationContext-ui_base_plugin.xml file.

The menu itself uses a flow to be managed. The flow can be found in the same context file named CreateMainMenuFlow.
To add the default menu entries and to create the main menu itself there is a flow step called AddMainMenuBaseEntriesStep.

Using flow steps to create a menu is recommended because they allow some logic to be executed before, during and after the managing of the entries.
Keep in mind that the flow engine has a caching algorithm build in if it is extended from the AbstractCachedFlow class.


Related

Wiki: Documentation
Wiki: Home
Wiki: How to add entries to a menu