Package com.hybris.cockpitng.engine.impl
Class DefaultWidgetInstanceManager
- java.lang.Object
-
- com.hybris.cockpitng.engine.impl.DefaultWidgetInstanceManager
-
- All Implemented Interfaces:
WidgetInstanceManager
public class DefaultWidgetInstanceManager extends java.lang.Object implements WidgetInstanceManager
Provides access to the widget instance from within a controller.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCNG_CURRENT_TITLEstatic java.lang.StringWIM_FAILURE_NOTIFICATION_TYPE-
Fields inherited from interface com.hybris.cockpitng.engine.WidgetInstanceManager
CNG_TITLE_CHANGE_LISTENER
-
-
Constructor Summary
Constructors Constructor Description DefaultWidgetInstanceManager(Widgetslot widgetslot, CockpitWidgetEngine cockpitWidgetEngine, WidgetUtils widgetUtils, CockpitThreadContextCreator ctxCreator, java.util.Map<java.lang.String,java.lang.Object> labels, java.util.List<WidgetConfigurationContextDecorator> contextDecorators, CockpitConfigurationService cockpitConfigurationService, LabelService labelService, NotificationService notificationService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <CONFIG> ConfigContextbuildConfigurationContext(ConfigContext additionalContext, java.lang.Class<CONFIG> configurationType)Builds cockpit configuration context for this widget.protected org.zkoss.zk.ui.ComponentcreateNotificationComponent()Creates component on which long operation notification will be displayed.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.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.CockpitComponentDefinitionServicegetComponentDefinitionService()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.LabelServicegetLabelService()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.protected booleanlockOperationIfPossible(java.lang.String operationIdentityValue, java.lang.Object operationId)Checks whether widgetSlot has an attribute with given operationId.protected voidonBackgroundOperationError(java.lang.Exception e)protected voidonBackgroundOperationFinished(Operation operation, boolean parallel, java.lang.String operationId, LongOperationNotifier longOperationNotifier)protected voidonBackgroundOperationSuccess(java.lang.String socketId, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String operationId, java.lang.Object result)protected CockpitNGBackgroundOperationprepareLongOperation(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, LongOperationNotifier longOperationNotifier, boolean parallel, java.lang.String operationId, java.lang.String socketId)voidregisterAfterEditorCallback(CallbackOperation callback)Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener.voidregisterBeforeEditorCallback(CallbackOperation callback)Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener.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 socketId, 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.protected voidunlockOperation(java.lang.String operationIdentityValue, java.lang.Object operationId)Removed widget slot's information for given operation id.
-
-
-
Field Detail
-
CNG_CURRENT_TITLE
public static final java.lang.String CNG_CURRENT_TITLE
- See Also:
- Constant Field Values
-
WIM_FAILURE_NOTIFICATION_TYPE
public static final java.lang.String WIM_FAILURE_NOTIFICATION_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultWidgetInstanceManager
public DefaultWidgetInstanceManager(Widgetslot widgetslot, CockpitWidgetEngine cockpitWidgetEngine, WidgetUtils widgetUtils, CockpitThreadContextCreator ctxCreator, java.util.Map<java.lang.String,java.lang.Object> labels, java.util.List<WidgetConfigurationContextDecorator> contextDecorators, CockpitConfigurationService cockpitConfigurationService, LabelService labelService, NotificationService notificationService)
-
-
Method Detail
-
sendOutput
public void sendOutput(java.lang.String socketId, java.lang.Object data)Description copied from interface:WidgetInstanceManagerSends data to the output socked with the given ID.- Specified by:
sendOutputin interfaceWidgetInstanceManager- Parameters:
socketId- output socket ID to sent the data todata- the data to be sent
-
getWidgetSettings
public TypedSettingsMap getWidgetSettings()
Description copied from interface:WidgetInstanceManagerReturns the widget settings map.- Specified by:
getWidgetSettingsin interfaceWidgetInstanceManager- Returns:
- widget settings map
-
getModel
public WidgetModel getModel()
Description copied from interface:WidgetInstanceManagerReturns 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.- Specified by:
getModelin interfaceWidgetInstanceManager- Returns:
- the widget view model
-
getWidgetslot
public Widgetslot getWidgetslot()
Description copied from interface:WidgetInstanceManagerReturns the widget slot the widget related to this manager is placed in.- Specified by:
getWidgetslotin interfaceWidgetInstanceManager- Returns:
- the widget slot the widget is placed in
-
getComponentDefinitionService
public CockpitComponentDefinitionService getComponentDefinitionService()
-
initWidgetSetting
public 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.- Specified by:
initWidgetSettingin interfaceWidgetInstanceManager
-
sendOutputAfterOperation
public final void sendOutputAfterOperation(java.lang.String socketId, Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)Description copied from interface:WidgetInstanceManagerExecutes anOperationin a separate thread and sends an output event to the output socket with the given id after the operation has been finished.- Specified by:
sendOutputAfterOperationin interfaceWidgetInstanceManager- Parameters:
socketId- 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
public void executeOperation(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)
Description copied from interface:WidgetInstanceManagerExecutes anOperationin a separate thread.- Specified by:
executeOperationin interfaceWidgetInstanceManager- 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
public void executeOperationInParallel(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent)
Description copied from interface:WidgetInstanceManagerExecutes anOperationin a separate thread regardless is there is already running another operation for the widget.- Specified by:
executeOperationInParallelin interfaceWidgetInstanceManager- Parameters:
operation- The operation to execute.callbackEvent- An optional callback event listener that is invoked after the operation has been finished.
-
getLabel
public java.lang.String getLabel(java.lang.String key)
Description copied from interface:WidgetInstanceManagerReturns a localized label in the current locale.- Specified by:
getLabelin interfaceWidgetInstanceManager- Parameters:
key- localization key as specified in the locales_*.properties in your widget definition.- Returns:
- localized label in the current locale
-
getLabel
public java.lang.String getLabel(java.lang.String key, java.lang.Object[] args)Description copied from interface:WidgetInstanceManagerReturns a localized label in the current locale and formats it with the given arguments. The formatting is done by the use ofMessageFormat.- Specified by:
getLabelin interfaceWidgetInstanceManager- 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
-
prepareLongOperation
protected CockpitNGBackgroundOperation prepareLongOperation(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, LongOperationNotifier longOperationNotifier, boolean parallel, java.lang.String operationId, java.lang.String socketId)
-
onBackgroundOperationFinished
protected void onBackgroundOperationFinished(Operation operation, boolean parallel, java.lang.String operationId, LongOperationNotifier longOperationNotifier)
-
onBackgroundOperationError
protected void onBackgroundOperationError(java.lang.Exception e)
-
onBackgroundOperationSuccess
protected void onBackgroundOperationSuccess(java.lang.String socketId, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String operationId, java.lang.Object result)
-
createNotificationComponent
protected org.zkoss.zk.ui.Component createNotificationComponent()
Creates component on which long operation notification will be displayed. The component will be detached after long operation.- Returns:
- a component to render a notification.
-
lockOperationIfPossible
protected boolean lockOperationIfPossible(java.lang.String operationIdentityValue, java.lang.Object operationId)Checks whether widgetSlot has an attribute with given operationId. If there is not such attribute it will be added so other operation with the same id won't be executed at the same time.- Parameters:
operationIdentityValue- operation identity value.operationId- result ofOperation.getId()- Returns:
- true if there was not attribute with given id.
-
unlockOperation
protected void unlockOperation(java.lang.String operationIdentityValue, java.lang.Object operationId)Removed widget slot's information for given operation id.- Parameters:
operationIdentityValue- operation identity value.operationId- result ofOperation.getId()
-
getTitle
public java.lang.String getTitle()
Description copied from interface:WidgetInstanceManagerReturns the current widget title.- Specified by:
getTitlein interfaceWidgetInstanceManager- Returns:
- current widget title
-
setTitle
public void setTitle(java.lang.String title)
Description copied from interface:WidgetInstanceManagerChanges the title of the widget dynamically.- Specified by:
setTitlein interfaceWidgetInstanceManager- Parameters:
title- the new title
-
buildConfigurationContext
public <CONFIG> ConfigContext buildConfigurationContext(ConfigContext additionalContext, java.lang.Class<CONFIG> configurationType)
Description copied from interface:WidgetInstanceManagerBuilds 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).- Specified by:
buildConfigurationContextin interfaceWidgetInstanceManager- 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
public <CONFIG> CONFIG loadConfiguration(ConfigContext context, java.lang.Class<CONFIG> configurationType) throws CockpitConfigurationException
Description copied from interface:WidgetInstanceManagerDelegate 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.- Specified by:
loadConfigurationin interfaceWidgetInstanceManager- 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
public <CONFIG> void storeConfiguration(ConfigContext context, CONFIG configuration) throws CockpitConfigurationException
Description copied from interface:WidgetInstanceManagerDelegate 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.- Specified by:
storeConfigurationin interfaceWidgetInstanceManager- 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
public EditorListener registerEditorListener(EditorContext context, EditorListener listener)
Description copied from interface:WidgetInstanceManagerWhenever 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.- Specified by:
registerEditorListenerin interfaceWidgetInstanceManager- Parameters:
context- editor contextlistener- original editor listener @return wrapped listener (by default it returns the original listener,
-
registerBeforeEditorCallback
public void registerBeforeEditorCallback(CallbackOperation callback)
Description copied from interface:WidgetInstanceManagerMethod complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener. Appropriate implementation should notify all the registered callbacks on listener notifications. Default implementation does nothing.- Specified by:
registerBeforeEditorCallbackin interfaceWidgetInstanceManager- Parameters:
callback- the callback to be invoked
-
registerAfterEditorCallback
public void registerAfterEditorCallback(CallbackOperation callback)
Description copied from interface:WidgetInstanceManagerMethod complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener. Appropriate implementation should notify all the registered callbacks on listener notifications. Default implementation does nothing.- Specified by:
registerAfterEditorCallbackin interfaceWidgetInstanceManager- Parameters:
callback- the callback to be invoked
-
getLabelService
public LabelService getLabelService()
-
-