Dynamic generation of context menus

The Conigma Repository Browser allows you to generate parts of the context menu dynamically using ABAP coding. This is useful in the following scenarios:

  • The creation of all context menu entries via Customizing is not possible due to the number of entries required

  • Checking the precondition using expressions would lead to performance problems

  • The descriptions of the context menu items are to be generated dynamically

Relevant Classes and Interfaces 

The following table shows the classes and interfaces that are relevant in this context:

Name

Type

Description

/GAL/CCM_IF_GUI_ACTION_TRIGGER

Interface

Interface for a GUI element that supports triggering an action. This interface does not have to be implemented directly, since it is contained in the interface for menu items.


/GAL/CCM_IF_GUI_MENU_ITEM

Interface

All instances returned as menu items by a menu item provider must implement this interface. It enables the definition of the display functions for a context menu item and the implementation of the action to be triggered by the menu item.

/GAL/CCM_IF_GUI_MENU_ITEM_PROV

Interface

Classes that implement this interface can be used as providers for menu items (or subitems). If it is a top-level provider, the interface /GAL/CCM_IF_GUI_MENU_ITEM can also be implemented, otherwise the information from the definition of the object action is copied. Menu items that also act as providers for submenu items must implement both the interface /GAL/CCM_IF_GUI_MENU_ITEM and the interface /GAL/CCM_IF_GUI_MENU_ITEM_PROV.

/GAL/CCM_GUI_MENU_ADAPTER

Class

This class acts as an interface between the classic object actions and the new dynamically generated context menus. It creates the instance of the context menu provider and queries the context menu items to be generated. From this information, a table with temporary object actions is created at runtime and inserted into the table of classic object actions. If one of these temporary object actions is selected, the system determines the object that represents the corresponding menu option and triggers the action processing implemented there.

/GAL/CCM_GUI_MENU_BUILDER_IMP

Class

Menu item provider for the step-by-step execution of an import with system filters. This class can be used as an example for your own implementations of dynamic context menus.

/GAL/CCM_GUI_MENU_ITEM_IMP

Class

Menu item for the step-by-step execution of an import with system filters. This class can be used as an example for your own implementations of dynamic context menus.

/GAL/CCM_GUI_MENU_SEPARATOR

Class

Special implementation of the interface /GAL/CCM_IF_GUI_MENU_ITEM, which creates a separator line in the context menu. If required, you can also use this class in your own implementations of dynamic context menus.

Implementation of a provider for a dynamic context menu 

The first step is to create a new class that serves as the menu item provider for the dynamic context menu. This class must implement the interface /GAL/CCM_IF_GUI_MENU_ITEM_PROV and optionally the interface /GAL/CCM_IF_GUI_MENU_ITEM.

The interface /GAL/CCM_IF_GUI_MENU_ITEM_PROV contains only one method with the name GET_MENU_ITEMS. This must return a list of object instances that implement the interface /GAL/CCM_IF_GUI_MENU_ITEM and represent the individual menu items. Sub menus can be created by implementing the interface /GAL/CCM_IF_GUI_MENU_ITEM_PROV with individual menu items.

The interface /GAL/CCM_IF_GUI_MENU_ITEM contains the following methods:

Name

Description

GET_ICON

Returns an icon representing the menu item. If this is not desired, the constant ICON_SPACE can be returned from the type group ICON.

The SAPgui does not currently support the display of icons in context menus. However, if the actions are displayed in the form of a button in a toolbar (in split screen mode), the icons are used there.

GET_STATUS

This method returns status information about the menu item:

IS_ENABLED: Menu item is active
IS_SEPARATOR: Menu item is displayed as dividing line
IS_VISIBLE: Menu item is visible

GET_TEXT

This method returns the text for the menu item.

TRIGGER_ACTION

This method contains the implementation of the actual action, which is to be executed after selecting the menu item. No actions can be performed on menu items with sub menus and separators.

The code for executing the action may have to check whether its execution is still meaningful/relevant, since there may be a longer period of time between the possible actions being called and the actual execution of an action.

As with classic actions, dynamic actions can also return an impact value that specifies the scope of the repository objects to be updated in the tree view. The corresponding definition is made by calling the static method SET_IMPACT in the class /GAL/CCM_GUI_MENU_ADAPTER. If this call is omitted, there are no explicit updates in the tree view of the repository browser.

Customizing for the use of dynamic context menus 

As a placeholder for a dynamic context menu, an object action of the type "Provider for dynamic menu structure" must be customized in the corresponding object type. A description and a precondition can be stored as usual. In this case, however, the actual expression does not contain the action to be executed in the case of selection, but an expression that returns the desired menu item provider. This could, for example, look like this:


Everything else is done automatically by the adapter for dynamic context menus when the context menu is created.