Package com.hybris.cockpitng.engine
Interface WidgetInstanceManager
-
- All Known Implementing Classes:
DefaultWidgetInstanceManager
public interface WidgetInstanceManagerProvides widget framework related functionality. Allows you to send data to output sockets, access the widget settings and the widget model to store view related data in the session scope. To use it you need to implement theWidgetInstanceManagerAwareinterface in your widget controller (ideally you extend theDefaultWidgetController) or in your MVVM view model.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCNG_TITLE_CHANGE_LISTENER
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <CONFIG> ConfigContextbuildConfigurationContext(ConfigContext additionalContext, java.lang.Class<CONFIG> configurationType)Builds cockpit configuration context for this widget.voidexecuteOperation(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)Executes anOperationin a separate thread.default voidexecuteOperationInParallel(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent)Executes anOperationin a separate thread regardless is there is already running another operation for the widget.java.lang.StringgetLabel(java.lang.String key)Returns a localized label in the current locale.java.lang.StringgetLabel(java.lang.String key, java.lang.Object[] args)Returns a localized label in the current locale and formats it with the given arguments.WidgetModelgetModel()Returns the widget view model as specified in the definition.xml of the widget.java.lang.StringgetTitle()Returns the current widget title.TypedSettingsMapgetWidgetSettings()Returns the widget settings map.WidgetslotgetWidgetslot()Returns the widget slot the widget related to this manager is placed in.voidinitWidgetSetting(java.lang.String key, java.lang.Object initialValue)Initializes a widget setting and sets an initial value if there is none, i.e.<CONFIG> CONFIGloadConfiguration(ConfigContext context, java.lang.Class<CONFIG> configurationType)Delegate to cockpitConfigurationService.default voidregisterAfterEditorCallback(CallbackOperation callback)Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener.default voidregisterBeforeEditorCallback(CallbackOperation callback)Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener.default EditorListenerregisterEditorListener(EditorContext context, EditorListener listener)Whenever an editor is created in the context of a widget it may be needed to inform the parent widget that the editor wants to interact with its model.voidsendOutput(java.lang.String socketId, java.lang.Object data)Sends data to the output socked with the given ID.voidsendOutputAfterOperation(java.lang.String id, Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)Executes anOperationin a separate thread and sends an output event to the output socket with the given id after the operation has been finished.voidsetTitle(java.lang.String title)Changes the title of the widget dynamically.<CONFIG> voidstoreConfiguration(ConfigContext context, CONFIG configuration)Delegate to cockpitConfigurationService.
-
-
-
Field Detail
-
CNG_TITLE_CHANGE_LISTENER
static final java.lang.String CNG_TITLE_CHANGE_LISTENER
- See Also:
- Constant Field Values
-
-
Method Detail
-
sendOutput
void sendOutput(java.lang.String socketId, java.lang.Object data)Sends data to the output socked with the given ID.- Parameters:
socketId- output socket ID to sent the data todata- the data to be sent
-
getWidgetSettings
TypedSettingsMap getWidgetSettings()
Returns the widget settings map.- Returns:
- widget settings map
-
getModel
WidgetModel getModel()
Returns the widget view model as specified in the definition.xml of the widget. The widget view model has a scope of a session, use it to store the view state data.- Returns:
- the widget view model
-
getWidgetslot
Widgetslot getWidgetslot()
Returns the widget slot the widget related to this manager is placed in.- Returns:
- the widget slot the widget is placed in
-
initWidgetSetting
void initWidgetSetting(java.lang.String key, java.lang.Object initialValue)Initializes a widget setting and sets an initial value if there is none, i.e. this method does nothing if there is already a value set for the given key.- Parameters:
key-initialValue-
-
sendOutputAfterOperation
void sendOutputAfterOperation(java.lang.String id, Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)Executes anOperationin a separate thread and sends an output event to the output socket with the given id after the operation has been finished.- Parameters:
id- The output socket id.operation- The operation to execute.callbackEvent- An optional callback event listener that is invoked after the output event has been sent.busyMessage- A busy message that should be displayed while the operation is executed.
-
executeOperation
void executeOperation(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)
Executes anOperationin a separate thread.- Parameters:
operation- The operation to execute.callbackEvent- An optional callback event listener that is invoked after the operation has been finished.busyMessage- A busy message that should be displayed while the operation is executed.
-
executeOperationInParallel
default void executeOperationInParallel(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent)
Executes anOperationin a separate thread regardless is there is already running another operation for the widget.- Parameters:
operation- The operation to execute.callbackEvent- An optional callback event listener that is invoked after the operation has been finished.
-
getLabel
java.lang.String getLabel(java.lang.String key)
Returns a localized label in the current locale.- Parameters:
key- localization key as specified in the locales_*.properties in your widget definition.- Returns:
- localized label in the current locale
-
getLabel
java.lang.String getLabel(java.lang.String key, java.lang.Object[] args)Returns a localized label in the current locale and formats it with the given arguments. The formatting is done by the use ofMessageFormat.- Parameters:
key- localization key as specified in the locales_*.properties in your widget definition.args- list of arguments for the formating- Returns:
- localized label in the current locale formatted with the given arguments
-
getTitle
java.lang.String getTitle()
Returns the current widget title.- Returns:
- current widget title
-
setTitle
void setTitle(java.lang.String title)
Changes the title of the widget dynamically.- Parameters:
title- the new title
-
buildConfigurationContext
<CONFIG> ConfigContext buildConfigurationContext(ConfigContext additionalContext, java.lang.Class<CONFIG> configurationType)
Builds cockpit configuration context for this widget. It takes context parameters from the widget settings and possibly from other sources eg. user role from the session information (see the spring beanwidgetConfigurationContextDecoratorListfor list of installedWidgetConfigurationContextDecorators).- Parameters:
additionalContext- additional configuration context for the widget, this can contain dynamic context parameters as "type" or similarconfigurationType- type of the configuration this context is to be built for. This might influence the logic inWidgetConfigurationContextDecorators.- Returns:
- a configuration context containing all widget related parameters as well as those included in the given additionalContext
-
loadConfiguration
<CONFIG> CONFIG loadConfiguration(ConfigContext context, java.lang.Class<CONFIG> configurationType) throws CockpitConfigurationException
Delegate to cockpitConfigurationService. Always use this method to load the configuration as it will automatically add all necessary context parameters from the environment - like configuration parameters from widget settings, current user/role from the session etc. Loads a single piece of cockpit configuration according to context provided.- Parameters:
context- the context to be used to look for the configurationconfigurationType- desired configuration type- Returns:
- single piece of cockpit configuration according to context provided
- Throws:
CockpitConfigurationException- if configuration could not be found or some error occured during loading- See Also:
CockpitConfigurationService.loadConfiguration(ConfigContext, Class)
-
storeConfiguration
<CONFIG> void storeConfiguration(ConfigContext context, CONFIG configuration) throws CockpitConfigurationException
Delegate to cockpitConfigurationService. Always use this method to load the configuration as it will automatically add all necessary context parameters from the environment - like configuration parameters from widget settings, current user/role from the session etc. Stores a single piece of cockpit configuration according to context provided.- Parameters:
context- the context to be used to store the configurationconfiguration- the configuration to be stored- Throws:
CockpitConfigurationException- if configuration could not be stored for some reason- See Also:
CockpitConfigurationService.storeConfiguration(ConfigContext, Object)
-
registerEditorListener
default EditorListener registerEditorListener(EditorContext context, EditorListener listener)
Whenever an editor is created in the context of a widget it may be needed to inform the parent widget that the editor wants to interact with its model. In this case this method may come handy to wrap the original listener with a proxy that does some additional - widget related - work.- Parameters:
context- editor contextlistener- original editor listener @return wrapped listener (by default it returns the original listener,
-
registerBeforeEditorCallback
default void registerBeforeEditorCallback(CallbackOperation callback)
Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener. Appropriate implementation should notify all the registered callbacks on listener notifications. Default implementation does nothing.- Parameters:
callback- the callback to be invoked
-
registerAfterEditorCallback
default void registerAfterEditorCallback(CallbackOperation callback)
Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener. Appropriate implementation should notify all the registered callbacks on listener notifications. Default implementation does nothing.- Parameters:
callback- the callback to be invoked
-
-