Class 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 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
    • Method Detail

      • sendOutput

        public void sendOutput​(java.lang.String socketId,
                               java.lang.Object data)
        Description copied from interface: WidgetInstanceManager
        Sends data to the output socked with the given ID.
        Specified by:
        sendOutput in interface WidgetInstanceManager
        Parameters:
        socketId - output socket ID to sent the data to
        data - the data to be sent
      • getModel

        public WidgetModel getModel()
        Description copied from interface: WidgetInstanceManager
        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.
        Specified by:
        getModel in interface WidgetInstanceManager
        Returns:
        the widget view model
      • 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:
        initWidgetSetting in interface WidgetInstanceManager
      • 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: WidgetInstanceManager
        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.
        Specified by:
        sendOutputAfterOperation in interface WidgetInstanceManager
        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: WidgetInstanceManager
        Executes an Operation in a separate thread.
        Specified by:
        executeOperation in interface WidgetInstanceManager
        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: WidgetInstanceManager
        Executes an Operation in a separate thread regardless is there is already running another operation for the widget.
        Specified by:
        executeOperationInParallel in interface WidgetInstanceManager
        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: WidgetInstanceManager
        Returns a localized label in the current locale.
        Specified by:
        getLabel in interface WidgetInstanceManager
        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: WidgetInstanceManager
        Returns a localized label in the current locale and formats it with the given arguments. The formatting is done by the use of MessageFormat.
        Specified by:
        getLabel in interface WidgetInstanceManager
        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 of Operation.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 of Operation.getId()
      • setTitle

        public void setTitle​(java.lang.String title)
        Description copied from interface: WidgetInstanceManager
        Changes the title of the widget dynamically.
        Specified by:
        setTitle in interface WidgetInstanceManager
        Parameters:
        title - the new title
      • buildConfigurationContext

        public <CONFIG> ConfigContext buildConfigurationContext​(ConfigContext additionalContext,
                                                                java.lang.Class<CONFIG> configurationType)
        Description copied from interface: WidgetInstanceManager
        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).
        Specified by:
        buildConfigurationContext in interface WidgetInstanceManager
        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

        public <CONFIG> CONFIG loadConfiguration​(ConfigContext context,
                                                 java.lang.Class<CONFIG> configurationType)
                                          throws CockpitConfigurationException
        Description copied from interface: WidgetInstanceManager
        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.
        Specified by:
        loadConfiguration in interface WidgetInstanceManager
        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)
      • registerEditorListener

        public EditorListener registerEditorListener​(EditorContext context,
                                                     EditorListener listener)
        Description copied from interface: WidgetInstanceManager
        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.
        Specified by:
        registerEditorListener in interface WidgetInstanceManager
        Parameters:
        context - editor context
        listener - original editor listener @return wrapped listener (by default it returns the original listener,
      • registerBeforeEditorCallback

        public void registerBeforeEditorCallback​(CallbackOperation callback)
        Description copied from interface: WidgetInstanceManager
        Method 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:
        registerBeforeEditorCallback in interface WidgetInstanceManager
        Parameters:
        callback - the callback to be invoked
      • registerAfterEditorCallback

        public void registerAfterEditorCallback​(CallbackOperation callback)
        Description copied from interface: WidgetInstanceManager
        Method 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:
        registerAfterEditorCallback in interface WidgetInstanceManager
        Parameters:
        callback - the callback to be invoked