Replace standard application menu

Information about development with ProjX.

Replace standard application menu

Postby Development@SIB » Fri Nov 27, 2015 9:43 pm

The standard menu creates and configures the menu and toolbar automatically. It adds default menus like File, Edit, Help and default menu items like Login/Logout, Exit, About. All application work-screens will be added by the application to the menu. Every work-screen has its own menu item and/or toolbar button.

The menu forwards most actions to the application because the application is responsible for the security and work-screen management.

If you don't like the standard menu handling or layout, it's very easy to replace the standard menu with your own implementation.


Extending the Menu

The Menu class defines default methods which are used by the application. So it's important to extend the class. The class has a constructor with the application as parameter. The constructor delegates the configuration to the method

Code: Select all
protected void configureApplication()

Override this method if your application should get a custom style. The default implementation sets an UIBorderLayout for the Application Pane and adds the Content Pane to the Application Pane with CENTER constraint.

It's possible to add the Content Pane to your hierarchy (e.g. a Tabset) and use a different layout for the Application Pane. Ther aren't any limits.

The Menu class will be created by ProjX via

Code: Select all
protected Menu createMenu() throws Throwable

This method checks the Menu class parameter (see Customize an Application without derivation) and creates a default Menu instance if no user-defined class was set.


Useful methods

The menu has some relevant methods

Code: Select all
public void createStandardMenu()
public void addItem(String pId, String pAction, ...)

The createStandardMenu method will be called by the application after Menu creation. It re-creates the whole menu and adds only standard items. It doesn't add any work-screens. The standard menu contains File, Edit and About menus and toolbar buttons. The standard toolbar contains Exit, Login/Logout and Save, Reload (if connected).

The method delegates the creation of the menubar to the method

Code: Select all
protected void createStandardMenuBar()

and toolbar creation to

Code: Select all
protected void createStandardToolBar()

Simply override createStandardToolBar and don't call the parent method to hide the toolbar.


The work-screen items will be added by the application, after successful login. The method

Code: Select all
public void addItem(String pId,...)

will be called for every work-screen. It delegates item creation to

Code: Select all
protected IMenuItem addMenuItem(String pId, String pGroupId, ...)

and

Code: Select all
protected IButton addToolBarButton(String pId, ...)


But there are more useful methods for you. All methods that start with create, are helper methods e.g.

Code: Select all
public UIMenuItem createMenuItem(String pAction, ...)
public UIButton createToolBarButton(String pAction, ...)
public UIToggleButton createToolBarToggleButton(String pAction, ...)

and there are also some configure methods

Code: Select all
protected <T extends AbstractUIMenuItem<?>> T configureMenuItem(...)
protected <T extends AbstractUIButton<?>> T configureToolBarButton

Sometimes it's enough to override the configure methods instead of create methods because every create method calls a configure method.


Access with ID

Every item should have an id because the item access is managed with ids. There are a lot of default ids, e.g. Menu.FILE, Menu.FILE_LOGIN.

If you need access to an item, simply use

Code: Select all
public IComponent[] get(String pId)

The method returns all mapped items for the given id. Sometimes an ID mapps multiple items because one item is the menu item and another one is the toolbar button.

If you add custom items to the menu, simply map them with

Code: Select all
public IComponent[] put(String pId, IComponent... pComponent)


The Menu class has methods for item control

Code: Select all
public void removeItem(String pId)
public void setItemVisible(String pId, boolean pVisible)
public void setItemEnabled(String pId, boolean pEnable)
public boolean isSelected(String pId)
User avatar
Development@SIB
 
Posts: 311
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation