As a prominent example for the use of actions,
we will illustrate their connection to a UI component using a context menu.
For this purpose, we will create a context menu
and ensure that it is connected with the desired UI component (for example,
Model Viewer).
Default Path Provider
As a plug-in developer you generally do not
have to concern yourself directly with the path provider, since you can use a
default implementation, the default path provider. By using the default path provider you can also ensure that the
display information of an action category is processed consistently by the
context menu.
However, if you want to implement your own
versions of the context menu display, you must also implement your own path
provider and add it to the provider manager.
![]()
Note
that the default path provider only returns categories with display information
- that is, of the type IDisplayableCategory.
Dynamic and Static Context Menus
The framework allows you to use different types
of context menus.
Dynamic context menu
|
|
|
|
For dynamic context menus, menu data is
created at runtime using the action provider manager. These context menus are created using the
class com.tssap.util.ui.menu.context.DynamicContextMenu. |
Static context menu
|
|
|
|
Static context menus are used for UI
components that have fixed functions and do not permit the integration of
additional functions. The menu data is predefined and cannot be
extended. These context menus are created using the
class com.tssap.util.ui.menu.context.StaticContextMenu. |
Mixed context menu
|
|
|
|
A mixed menu is used if the UI component
already has default functions and also allows you to add additional
functions. In the case of mixed context menus, the menu
data is both static and dynamic. These context menus are created using the
class com.tssap.util.ui.menu.context.MixedContextMenu. |
Package com.tssap.util.ui.menu.
IMenuFactory
|
|
|
|
This interface defines methods for creating
menus from a predefined context. |
MenuFactory
|
|
|
|
The factory class implements the interface IMenuFactory and provides method
implementations for creating menus. These create methods return the relevant
menu references from the given context. If, as a tool developer, you want to create dynamic
context menus, you need to specify the path provider explicitly at runtime.
To obtain a path provider you first need access to the path provider manager.
For this purpose, the MenuFactory class provides the
following get method: |
|
public IPathProviderManager
getPathProviderManager() Returns a path provider manager reference to
the menu. The path provider manager can make a query to all providers and
assign selected path providers at runtime. |
|
Package com.tssap.util.ui.menu.context
IContextMenu
|
|
|
|
This interface defines methods for converting
context data to a visual display. Method: |
|
void show(Control parent, IContext context) Displays a context menu on a control. |
|
IContextMenuParticipant
|
|
|
|
This interface defines convenience methods for
linking context menus with UI components. As a tool developer, you will normally use
predefined participants (such as the Model Viewer, SAP Tree Viewer, or SAP
Table Viewer), which already implement this interface. Methods: |
|
IContextMenu getContextMenu() Returns a context menu. |
|
|
void setContextMenu(IContextMenu
contextMenu) Assigns a context menu to the UI component. |
|
ContextMenu
|
|
|
|
This abstract class serves as a basis class
for the implementation of specific context menus (dynamic, static, or mixed).
ContextMenu provides two static methods
that are used to link context menus with SWT components: |
|
public static void setContextMenuToStructuredViewer( StructuredViewer viewer, IContextMenu contextMenu) Assigns a context menu to a structure-oriented
SWT/JFace viewer (tree viewer, table viewer, list). Only a viewer
instance and the context menu are passed as parameters. |
|
|
public static void setContextMenuToControl(Control
control, IContextMenu contextMenu , IContext context) Assigns a context menu to an SWT/JFace
control, such as a button or a text field. As well as the control instance
and a context menu, the relevant context must also be passed. The reason for
this is that, unlike a structure-oriented viewer, the selection context is
not automatically known to controls. |
|
DynamicContextMenu
|
|
|
|
Inherits from the basis class ContextMenu and instantiates a dynamic
context menu as a specific version of context menu. Unlike a static context
menu, you must assign a path provider at runtime when creating dynamic
context menus. |
Package com.tssap.util.action.path
IPathProvider
|
|
|
|
The interface requires a method for
ascertaining the path information. IPath getPath(ICategory category,
IContext context) Returns a path for category and a context that is used to identify the UI elements. |
IPathProviderManager
|
|
|
|
Interface
for defining a path provider manager. A path provider manager manages all
path providers and can add providers or remove them. |
|
void addPathProvider(IPathProvider pathProvider) Adds a
path provider. |
|
|
void removePathProvider(IPathProvider pathProvider) Removes
a path provider. |
|
|
IPathProvider[] getPathProviders() Returns
a list of all providers in the container. |
|
PathProviderManager
|
|
|
|
Class
that implements the path provider manager. |
DefaultPathProvider
|
|
|
|
The default implementation of the path
provider that provides the relevant path information from a given category. |
Different viewer implementations, including the
SAP Viewer classes SAPTreeViewer, SAPTable Viewer,
or the GenericDataModelTreeViewer, implement the interface IContextMenuParticipant.
