Creates and initializes a new CommandExecution.
The CommandExecution registers a shortcut when it is added to the dependent aggregation of a control. The shortcut information is retrieved from the owner components manifest (/sap.ui5/commands/<command>
).
You can use a CommandExecution instead of an event handler in XMLViews by using cmd:
plus the command name.
Example for sap.m.Button
:
<Button press="cmd:MyCommand" />
When the press event is fired, the CommandExecution will be triggered and the execute
event is fired.
When using commands, the component will create a model named $cmd
. The model data provides the enabled and visible state of all CommandExecutions. With that, action-triggering controls (e.g. a button) can be bound to the enable/visible property of the CommandExecution to centrally control their state.
Note: The usage of the $cmd
model is restricted to sap.suite.ui.generic
When binding a button's enabled state to this model, it follows the enabled state of the CommandExecution. The binding path must be relative like myCommand/enabled
:
<Button press="cmd:MyCommand" enabled="$cmd>MyCommand/enabled" />
A CommandExecution can have three states:
Accepts an object literal mSettings
that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject#constructor for a general description of the syntax of the settings object.
new sap.ui.core.CommandExecution()
Name | Type | Default Value | Description |
---|---|---|---|
command | string | The command's name, that has to be defined in the manifest. This property can only be applied initially. Visibility: public |
|
enabled | boolean | true | Whether the CommandExecution is enabled or not. By default, it is enabled. If the CommandExecution is disabled, the CommandExecution processes the event, but the event handler for it will not be called. Therefore, also no event handler configured on CommandExecutions on ancestors is called. Visibility: public |
visible | boolean | true | Whether the CommandExecution is visible, or not. By default, it is visible. If not visible, the CommandExecution won't process the event, and the event handler for it will not be called, regardless of the enabled state. Therefore, the configured event handler on the next CommandExecution in the ancestor chain or, if no ancestor in the ancestor chain has any CommandExecutions configured for this shortcut, the event handler of the browser is called. Visibility: public |
Name | Cardinality | Type | Description |
---|---|---|---|
customData | 0..n | sap.ui.core.CustomData |
Custom Data, a data structure like a map containing arbitrary key value pairs. |
dependents | 0..n | sap.ui.core.Element |
Dependents are not rendered, but their databinding context and lifecycle are bound to the aggregating Element. |
dragDropConfig | 0..n | sap.ui.core.dnd.DragDropBase |
Defines the drag-and-drop configuration. Note: This configuration might be ignored due to control metadata restrictions. |
layoutData | 0..1 | sap.ui.core.LayoutData |
Defines the layout constraints for this control when it is used inside a Layout. LayoutData classes are typed classes and must match the embedding Layout. See VariantLayoutData for aggregating multiple alternative LayoutData instances to a single Element. |
tooltip | 0..1 | sap.ui.core.TooltipBase |
The tooltip that should be shown for this Element. In the most simple case, a tooltip is a string that will be rendered by the control and displayed by the browser when the mouse pointer hovers over the control's DOM. In this variant, Controls need to explicitly support this kind of tooltip as they have to render it, but most controls do. Exceptions will be documented for the corresponding controls (e.g. Alternatively, UI5 currently does not provide a recommended implementation of See the section Using Tooltips
|
Event | Description |
---|---|
execute |
Execute will be fired when the CommandExecution will be triggered. |
Method | Description |
---|---|
attachExecute |
Attaches event handler When called, the context of the event handler (its Execute will be fired when the CommandExecution will be triggered. |
detachExecute |
Detaches event handler The passed function and listener object must match the ones used for event registration. |
sap.ui.core.CommandExecution.extend |
Creates a new subclass of class sap.ui.core.CommandExecution with name
|
fireExecute |
Fires event execute to attached listeners. |
getCommand |
Gets current value of property command. The command's name, that has to be defined in the manifest. This property can only be applied initially. |
getEnabled |
Gets current value of property enabled. Whether the CommandExecution is enabled or not. By default, it is enabled. If the CommandExecution is disabled, the CommandExecution processes the event, but the event handler for it will not be called. Therefore, also no event handler configured on CommandExecutions on ancestors is called. Default value is |
sap.ui.core.CommandExecution.getMetadata |
Returns a metadata object for class sap.ui.core.CommandExecution. |
getVisible |
Gets current value of property visible. Whether the CommandExecution is visible, or not. By default, it is visible. If not visible, the CommandExecution won't process the event, and the event handler for it will not be called, regardless of the enabled state. Therefore, the configured event handler on the next CommandExecution in the ancestor chain or, if no ancestor in the ancestor chain has any CommandExecutions configured for this shortcut, the event handler of the browser is called. Default value is |
setEnabled |
Sets whether the |
setVisible |
Sets whether the |
trigger |
Fires the execute event and triggers the attached handler. If the CommandExecution is disabled, the handler will not be triggered. |
Attaches event handler fnFunction
to the execute event of this sap.ui.core.CommandExecution
.
When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.ui.core.CommandExecution
itself.
Execute will be fired when the CommandExecution will be triggered.
Param | Type | DefaultValue | Description |
---|---|---|---|
oData | object |
An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
|
fnFunction | function(sap.ui.base.Event) : void |
The function to be called when the event occurs |
|
oListener | object |
Context object to call the event handler with. Defaults to this |
Detaches event handler fnFunction
from the execute event of this sap.ui.core.CommandExecution
.
The passed function and listener object must match the ones used for event registration.
Param | Type | DefaultValue | Description |
---|---|---|---|
fnFunction | function(sap.ui.base.Event) : void |
The function to be called, when the event occurs |
|
oListener | object |
Context object on which the given function had to be called |
Creates a new subclass of class sap.ui.core.CommandExecution with name sClassName
and enriches it with the information contained in oClassInfo
.
oClassInfo
might contain the same kind of information as described in sap.ui.core.Element.extend.
Param | Type | DefaultValue | Description |
---|---|---|---|
sClassName | string |
Name of the class being created |
|
oClassInfo | object |
Object literal with information about the class |
|
FNMetaImpl | function |
Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class |
Fires event execute to attached listeners.
Param | Type | DefaultValue | Description |
---|---|---|---|
mParameters | object |
Parameters to pass along with the event |
Gets current value of property command.
The command's name, that has to be defined in the manifest. This property can only be applied initially.
Gets current value of property enabled.
Whether the CommandExecution is enabled or not. By default, it is enabled. If the CommandExecution is disabled, the CommandExecution processes the event, but the event handler for it will not be called. Therefore, also no event handler configured on CommandExecutions on ancestors is called.
Default value is true
.
Returns a metadata object for class sap.ui.core.CommandExecution.
Gets current value of property visible.
Whether the CommandExecution is visible, or not. By default, it is visible. If not visible, the CommandExecution won't process the event, and the event handler for it will not be called, regardless of the enabled state. Therefore, the configured event handler on the next CommandExecution in the ancestor chain or, if no ancestor in the ancestor chain has any CommandExecutions configured for this shortcut, the event handler of the browser is called.
Default value is true
.
Sets whether the CommandExecution
is enabled, or not. If set to false, the CommandExecution
will still register the shortcut. This will block any configured CommandExecutions on any ancestors for that shortcut.
Param | Type | DefaultValue | Description |
---|---|---|---|
bValue | boolean |
Whether the CommandExecution is enabled, or not. |
Sets whether the CommandExecution
is visible, or not. If set to false, the CommandExecution
will unregister the shortcut. If not visible, the CommandExecution will not be triggered even if it is enabled.
Param | Type | DefaultValue | Description |
---|---|---|---|
bValue | boolean |
Whether the CommandExecution is visible, or not. |