Class CollectionPreviewController

  • All Implemented Interfaces:
    WidgetController, WidgetDragAndDropAware, WidgetInstanceManagerAware, java.io.Serializable, org.zkoss.zk.ui.event.EventListener, org.zkoss.zk.ui.event.SerializableEventListener, org.zkoss.zk.ui.util.ComponentActivationListener, org.zkoss.zk.ui.util.ComponentCloneListener, org.zkoss.zk.ui.util.Composer<org.zkoss.zk.ui.Component>, org.zkoss.zk.ui.util.ComposerExt<org.zkoss.zk.ui.Component>

    public class CollectionPreviewController
    extends DefaultWidgetController
    Controller of the collection preview widget - responsible for rendering a preview for each item from a passed Pageable pageable

    . In order to setPage a comprehensive item representation controller relies on Base configuration where one can specified its name, description and a graphical representation.

    See Also:
    Serialized Form
    • Field Detail

      • SOCKET_IN_PAGEABLE

        public static final java.lang.String SOCKET_IN_PAGEABLE
        See Also:
        Constant Field Values
      • SOCKET_SELECTED_ITEM

        public static final java.lang.String SOCKET_SELECTED_ITEM
        See Also:
        Constant Field Values
      • WIDGET_SETTING_CONFIG_CONTEXT

        public static final java.lang.String WIDGET_SETTING_CONFIG_CONTEXT
        See Also:
        Constant Field Values
      • WIDGET_SETTING_ASYNC

        public static final java.lang.String WIDGET_SETTING_ASYNC
        See Also:
        Constant Field Values
      • ENTRY_IMG_FALLBACK

        protected static final java.lang.String ENTRY_IMG_FALLBACK
        See Also:
        Constant Field Values
      • YW_COLLECTION_PREVIEW_EMPTY_LIST

        protected static final java.lang.String YW_COLLECTION_PREVIEW_EMPTY_LIST
        See Also:
        Constant Field Values
      • COMP_ID_ITEMLIST

        protected static final java.lang.String COMP_ID_ITEMLIST
        See Also:
        Constant Field Values
      • MODEL_PAGEABLE_LIST

        protected static final java.lang.String MODEL_PAGEABLE_LIST
        See Also:
        Constant Field Values
      • MODEL_ITEM_SELECTED_INDEX

        protected static final java.lang.String MODEL_ITEM_SELECTED_INDEX
        See Also:
        Constant Field Values
    • Constructor Detail

      • CollectionPreviewController

        public CollectionPreviewController()
    • Method Detail

      • setPageable

        public void setPageable​(Pageable<?> pageable)
        Called whenever a socket event is sent to the "pageable" socket. Renders the entries in the pageable object (if any)

        Thread-safety is provided
        Parameters:
        pageable - the pageable object to setPage
      • setPageable

        protected void setPageable​(Pageable<?> pageable,
                                   boolean synch)
        Renders the entries in the pageable object (if any)

        Thread-safety is provided
        Parameters:
        pageable - the pageable object to setPage
        synch - when true renders entries synchronously
      • selectEntry

        public void selectEntry​(org.zkoss.zk.ui.event.SelectEvent<org.zkoss.zk.ui.Component,​?> event)
        Call back method for select events. Resolves the selected object and sends it out on the outgoing socket called "selectedItem".
        Parameters:
        event - the select event
      • setSelectedItem

        public void setSelectedItem​(java.lang.Object itemToSelect)
      • render

        protected void render​(Pageable<?> pageable,
                              java.util.List<?> genericObjectList)
        Renders the provided entries as a list - each item is represented by base configuration where one can configure name, description and an image representation.

        Parameters:
        pageable - used to resolve the relevant type code (if any) and other paging information
        genericObjectList - the objects to be rendered
      • handleObjectUpdatedEvent

        public void handleObjectUpdatedEvent​(CockpitEvent event)
      • handleObjectDeletedEvent

        public void handleObjectDeletedEvent​(CockpitEvent event)
      • updatePreviewCollection

        protected void updatePreviewCollection​(CockpitEvent event)
      • updatePreviewCollection

        protected void updatePreviewCollection​(Pageable pageable,
                                               CockpitEvent event,
                                               java.lang.Object updatedObject)
      • getIndexToSelectAfterRemoval

        protected int getIndexToSelectAfterRemoval​(int currentIndex,
                                                   int removedIndex)
        Returns new index of item to select based on currently selected and removed items or -1 if currently selected item has been removed
        Parameters:
        currentIndex - index of currently selected item
        removedIndex - index of removed item
        Returns:
        new index of item to select
      • setResultList

        protected void setResultList​(java.util.List<?> allResults,
                                     java.lang.Integer indexToSelect)
        Changes current MODEL_PAGEABLE to its copy with passed as an argument collection of available elements and selects an element with provided index
        Parameters:
        allResults - collection of available elements to be set on the MODEL_PAGEABLE.
        indexToSelect - index of an element to be selected
      • setResultList

        protected void setResultList​(java.util.List<?> allResults,
                                     java.lang.Integer indexToSelect,
                                     boolean synch)
        Changes current MODEL_PAGEABLE to its copy with passed as an argument collection of available elements and selects an element with provided index
        Parameters:
        allResults - collection of available elements to be set on the MODEL_PAGEABLE.
        indexToSelect - index of an element to be selected
        synch - when true renders entries synchronously
      • getPageableCopyWithResultList

        protected <T> Pageable<T> getPageableCopyWithResultList​(java.util.List<T> allResults)
      • createPageableInstance

        protected <T> Pageable<T> createPageableInstance​(java.util.List<T> allResults,
                                                         int pageSize,
                                                         java.lang.String typeCode)
        Creates new instance of Pageable
        Parameters:
        allResults - collection of all elements available in the preview. The collection is exposed through Pageable.getAllResults()
        pageSize -
        typeCode -
        Returns:
        new instance of Pageable with provided parameters
      • getWidgetResourcePath

        protected java.lang.String getWidgetResourcePath()
      • createEntry

        protected org.zkoss.zk.ui.Component createEntry​(java.lang.Object entry,
                                                        Base config)
      • loadConfiguration

        protected Base loadConfiguration​(java.lang.String typeCode)
        Loads the UI configuration for component with code "configContext" and for the specified type, typeCode.
        Parameters:
        typeCode - the type code for which the configuration should be loaded
        Returns:
        the configuration object if found, null otherwise
      • getRendererProps

        protected java.util.Map<java.lang.String,​java.lang.Object> getRendererProps​(java.lang.Object entry,
                                                                                          Base baseConfig)
        Returns a map with all the key/value pairs which should be passed to the zul template used for rendering.
        Parameters:
        entry - the object to be rendered
        baseConfig - the UI configuration to be used when rendering
        Returns:
        map with renderer properties, which are accessible in the zul template (using ${args.<KEY_NAME>} )
      • selectItem

        protected void selectItem​(java.lang.Integer position)
      • convertAllPagesIntoSingleList

        protected <T> java.util.List<T> convertAllPagesIntoSingleList​(Pageable<T> pageable)
      • getTypeFacade

        public TypeFacade getTypeFacade()
      • getItemList

        public org.zkoss.zul.Listbox getItemList()