Message and action
Message/action is a way to support communication between widget to widget, widget to framework, and framework to widget. Widget/framework can publish a message, and they can listen to a message as well.
A message is identified by MessageType
, which is defined by the jimu framework. There are some message types defined in jimu, such as ExtentChange
and DataRecordsSelectionChange
.
Publishing a message
A widget calls MessageManager.getInstance().publishMessage(message)
to publish a message. For example, the List
widget publishes the DataRecordsSelectionChange
message when a list item is
clicked or a Map
widget publishes the ExtentChange
message when the view is changed, which updates the List
widget content. The following MessageTypes
are supported:
StringSelectionChange
ExtentChange
DataRecordsSelectionChange
DataRecordSetChange
Each message has a class to define it. For example, the ExtentChange
message is defined by ExtentChangeMessage
class, this class defines the extent
property, which is the message payload.
To publish a message, a widget should declare the published messages in the manifest.json
file.
Creating a message action
To create a message action, you will need to extend AbstractMessageAction
class. There are several methods and functions that help with developing message actions.
The filterMessageType
method is used to filter the available actions.
filterMessage
method is used to filter messages in message manager.
The getSettingComponentUri
component can be used to configure the action based on the message.
onExecute
method handles the logic for what you would like to happen for your message type. In the snippet below, it basically selects the action based on the message type and sends it from the application to the store using getAppStore()
function using the dispatch
property. This dispatches the redux action
and allows the state to be updated. Learn more about redux actions and using the store in Redux.
In the manifest.json
there is a messageActions property that provides the location and information for the message action extension.
i18n support
The support for languages in your message action follows the same pattern as a widget with one key difference. A message action has a Select an action
panel that allows users to select an action. Therefore you will need to have a file called default.ts
in the runtime/translations folder with the property names of your actions.
The framework handles the translations of the action label in this panel. As a result, the property of the label needs to have this naming convention _action_<actionName>_label
.