class sap.ui.core.CommandExecution

Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/core/CommandExecution
Application Component: CA-UI5-COR

Constructor

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()

Properties

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

Borrowed Aggregations

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.

Since: 1.19.

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.

Since: 1.56.

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, tooltip behaves like a simple control property.

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. sap.ui.core.HTML does not support tooltips).

Alternatively, tooltip can act like a 0..1 aggregation and can be set to a tooltip control (an instance of a subclass of sap.ui.core.TooltipBase). In that case, the framework will take care of rendering the tooltip control in a popup-like manner. Such a tooltip control can display arbitrary content, not only a string.

UI5 currently does not provide a recommended implementation of TooltipBase as the use of content-rich tooltips is discouraged by the Fiori Design Guidelines. Existing subclasses of TooltipBase therefore have been deprecated. However, apps can still subclass from TooltipBase and create their own implementation when needed (potentially taking the deprecated implementations as a starting point).

See the section Using Tooltips in the Fiori Design Guideline.


Events Overview

Event Description
execute

Execute will be fired when the CommandExecution will be triggered.

execute

Execute will be fired when the CommandExecution will be triggered.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object

Methods Overview

Method Description
attachExecute

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.

detachExecute

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.

sap.ui.core.CommandExecution.extend

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.

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 true.

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 true.

setEnabled

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.

setVisible

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.

trigger

Fires the execute event and triggers the attached handler. If the CommandExecution is disabled, the handler will not be triggered.

attachExecute

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 sap.ui.core.CommandExecution itself

detachExecute

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

sap.ui.core.CommandExecution.extend

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

fireExecute

Fires event execute to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

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 true.

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 true.

setEnabled

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.

setVisible

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.

trigger

Fires the execute event and triggers the attached handler. If the CommandExecution is disabled, the handler will not be triggered.