Interface WidgetInstanceManager

  • All Known Implementing Classes:
    DefaultWidgetInstanceManager

    public interface WidgetInstanceManager
    Provides 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 the WidgetInstanceManagerAware interface in your widget controller (ideally you extend the DefaultWidgetController) or in your MVVM view model.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      <CONFIG> ConfigContext buildConfigurationContext​(ConfigContext additionalContext, java.lang.Class<CONFIG> configurationType)
      Builds cockpit configuration context for this widget.
      void executeOperation​(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent, java.lang.String busyMessage)
      Executes an Operation in a separate thread.
      default void executeOperationInParallel​(Operation operation, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event> callbackEvent)
      Executes an Operation in a separate thread regardless is there is already running another operation for the widget.
      java.lang.String getLabel​(java.lang.String key)
      Returns a localized label in the current locale.
      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.
      WidgetModel getModel()
      Returns the widget view model as specified in the definition.xml of the widget.
      java.lang.String getTitle()
      Returns the current widget title.
      TypedSettingsMap getWidgetSettings()
      Returns the widget settings map.
      Widgetslot getWidgetslot()
      Returns the widget slot the widget related to this manager is placed in.
      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.
      <CONFIG> CONFIG loadConfiguration​(ConfigContext context, java.lang.Class<CONFIG> configurationType)
      Delegate to cockpitConfigurationService.
      default void registerAfterEditorCallback​(CallbackOperation callback)
      Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#registerEditorListener.
      default void registerBeforeEditorCallback​(CallbackOperation callback)
      Method complementary to com.hybris.cockpitng.engine.WidgetInstanceManager#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.
      void sendOutput​(java.lang.String socketId, java.lang.Object data)
      Sends data to the output socked with the given ID.
      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 an Operation in a separate thread and sends an output event to the output socket with the given id after the operation has been finished.
      void setTitle​(java.lang.String title)
      Changes the title of the widget dynamically.
      <CONFIG> void storeConfiguration​(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 to
        data - 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 an Operation in 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 an Operation in 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 an Operation in 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 of MessageFormat.
        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 bean widgetConfigurationContextDecoratorList for list of installed WidgetConfigurationContextDecorators).
        Parameters:
        additionalContext - additional configuration context for the widget, this can contain dynamic context parameters as "type" or similar
        configurationType - type of the configuration this context is to be built for. This might influence the logic in WidgetConfigurationContextDecorators.
        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 configuration
        configurationType - 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 configuration
        configuration - 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 context
        listener - 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