Class WListbox

java.lang.Object
org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.HtmlBasedComponent
org.zkoss.zul.impl.XulElement
org.zkoss.zul.impl.MeshElement
org.zkoss.zul.Listbox
org.adempiere.webui.component.Listbox
org.adempiere.webui.component.WListbox
All Implemented Interfaces:
Serializable, Cloneable, TableValueChangeListener, WTableModelListener, IMiniTable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.EventListener<org.zkoss.zk.ui.event.Event>, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl, org.zkoss.zul.ext.Paginated

public class WListbox extends Listbox implements IMiniTable, TableValueChangeListener, WTableModelListener
IMiniTable implementation for Zk.
Author:
Andrew Kimball, Sendy Yagambrum
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.zkoss.zul.Listbox

    org.zkoss.zul.Listbox.Children, org.zkoss.zul.Listbox.ExtraCtrl

    Nested classes/interfaces inherited from class org.zkoss.zul.impl.MeshElement

    org.zkoss.zul.impl.MeshElement.InternalPaging

    Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

    org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Model Index of Key Column.

    Fields inherited from class org.zkoss.zul.Listbox

    LOADING_MODEL, SYNCING_MODEL

    Fields inherited from class org.zkoss.zul.impl.MeshElement

    CSS_FLEX_AUTO_DISABLED_COUNT

    Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    _zclass

    Fields inherited from interface org.zkoss.zk.ui.Component

    APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE

    Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

    AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addColumn(Class<?> classType, boolean readOnly, String header)
    Add column
    void
    addColumn(String header)
    add column with header
    void
    addColumn(String header, String description)
    Add column
    void
    addColumn(String header, String description, int AD_Reference_ID)
    Add Table Column and specify the column header.
    void
    Add new row for column totals
    void
    Deprecated.
    void
    Clear the table components.
    void
    Removes all data stored in the underlying model.
    int
    convertColumnIndexToModel(int viewColumnIndex)
    Convert the index for a column from the display index to the corresponding index in the underlying model.
    int
    getColorCode(int row)
    Get ColorCode for Row.
    int
    Get number of columns
    <T extends Serializable>
    T
    Get key of first row
    int
     
    Get columns layout.
    Get Columns Layout.
    Return the ListModelTable associated with this table.
    int
    Get the number of rows in this table's model.
    <T extends Serializable>
    T
    getRowKeyAt(int index)
    IDEMPIERE-1334 get key of record at index
    int
    Get index of the first selected row, -1 if no row is selected.
    <T extends Serializable>
    T
    Get the key of currently selected row based on layout defined in prepareTable(ColumnInfo[], String, String, boolean, String).
    boolean
    Is show total
    getValueAt(int row, int column)
    Returns the cell value at row and column.
    Get the name of the wListbox
    void
    Create ListHead and render list box header by calling WListItemRenderer.renderListHead(ListHead).
    Throw ApplicationException if renderer of list box is not WListItemRenderer.
    boolean
     
    boolean
    isCellEditable(int row, int column)
    Is the cell at the specified row and column editable?
    boolean
    Query whether multiple rows can be selected in the table.
    void
    Populate Table from ResultSet, note that ResultSet is not closed at the end of this method.
    void
    loadTable(PO[] pos)
    Populate Table from PO Array.
    prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName)
    Prepare Table and return SQL required to get resultset to populate table.
    prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName, boolean addAccessSQL)
    Prepare Table and return SQL to get ResultSet to populate table
    void
    Render the header of the WListbox with saved column width
    void
    Repaint the Table.
    void
    Save the width of all the columns to MWlistboxCustomization
    void
    setAllowIDColumnForReadWrite(boolean allowIDColumnForReadWrite)
    Set whether ID column is editable
    void
    setColorColumn(int modelIndex)
    Set the Column to determine the color of the row (based on model index).
    void
    setColorCompare(Object dataCompare)
    Set ColorColumn comparison criteria.
    void
    setColumnClass(int index, Class<?> classType, boolean readOnly)
    Set the type of the column.
    void
    setColumnClass(int index, Class<?> classType, boolean readOnly, String header)
    Set the type of the column.
    void
    setColumnReadOnly(int index, boolean readOnly)
    Set Column at the specified index to read-only or read/write.
    void
    setData(ListModelTable model, List<? extends String> columnNames)
    Set the data model and column header names for the Listbox.
    void
    setModel(org.zkoss.zul.ListModel<?> model)
    Set ListModel
    void
    setMultiSelection(boolean multiSelection)
    Set whether or not multiple rows can be selected.
    void
    setRowCount(int rowCount)
    Set the size of the underlying data model.
    void
    IDEMPIERE-1334.
    De-select all current select, set all record with key in lsKey as selected.
    If table has no key column, just return.
    void
    setShowTotals(boolean show)
    Set if Totals is Show
    void
    setValueAt(Object value, int row, int column)
    Set the cell value at row and column.
    void
    setwListBoxName(String wListBoxName)
    Set the name of the wListbox.
    void
    Respond to a change in the table's model.
    void
    Respond to a TableValueChangeEvent event.
    To listen to the event, you have to register it first by calling WListItemRenderer.addTableValueChangeListener(TableValueChangeListener)

    Methods inherited from class org.zkoss.zul.Listbox

    addItemToSelection, beforeChildAdded, beforeRemove, clearSelection, clone, getChildren, getEmptyMessage, getExtraCtrl, getFrozen, getGroupCount, getGroups, getGroupsModel, getHeads, getIndexOfItem, getInnerWidth, getItemCount, getItemRenderer, getItems, getListfoot, getListhead, getListModel, getMaxlength, getName, getNonselectableTags, getPaginal, getPagingChild, getPropertyAccess, getRows, getSelectedCount, getSelectedIndex, getSelectedItems, getSeltype, getVisibleItemCount, getZclass, hasGroup, isAutohidePaging, isCheckmark, isDisabled, isMultiple, isSelectOnHighlightDisabled, isVflex, onAfterRender, onInitRender, onPageAttached, onPageDetached, onPagingInitRender, pgi, removeItemAt, removeItemFromSelection, renderAll, renderItem, renderItems, renderProperties, scrollToIndex, selectAll, selectItem, service, sessionDidActivate, sessionWillPassivate, setActivePage, setActivePage, setCheckmark, setDisabled, setEmptyMessage, setHeight, setInnerWidth, setItemRenderer, setItemRenderer, setMaxlength, setModel, setMold, setMultiple, setName, setNonselectableTags, setPageSize, setPaginal, setRows, setSelectedIndex, setSelectedItem, setSelectedItems, setSeltype, setVflex, setVflex, shallUpdateScrollPos, toggleItemSelection

    Methods inherited from class org.zkoss.zul.impl.MeshElement

    checkBeforeSetRows, evalCSSFlex, getActivePage, getPageCount, getPageSize, getPagingPosition, getSpan, isAutopaging, isPagingDisabled, isSizedByContent, isSpan, setAutopaging, setPagingDisabled, setPagingPosition, setSizedByContent, setSpan, setSpan

    Methods inherited from class org.zkoss.zul.impl.XulElement

    getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes

    Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    addSclass, focus, getAction, getClientAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly

    Methods inherited from class org.zkoss.zk.ui.AbstractComponent

    addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, invalidate, isChildable, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • m_keyColumnIndex

      protected int m_keyColumnIndex
      Model Index of Key Column.
  • Constructor Details

    • WListbox

      public WListbox()
      Default constructor.
      Set empty model and WListItemRenderer as renderer.
  • Method Details

    • setData

      public void setData(ListModelTable model, List<? extends String> columnNames)
      Set the data model and column header names for the Listbox.
      Parameters:
      model - The data model to assign to the table
      columnNames - Header names of the table columns
    • setModel

      public void setModel(org.zkoss.zul.ListModel<?> model)
      Set ListModel
      Overrides:
      setModel in class org.zkoss.zul.Listbox
    • initialiseHeader

      public void initialiseHeader()
      Create ListHead and render list box header by calling WListItemRenderer.renderListHead(ListHead).
      Throw ApplicationException if renderer of list box is not WListItemRenderer.
    • isCellEditable

      public boolean isCellEditable(int row, int column)
      Is the cell at the specified row and column editable?
      Specified by:
      isCellEditable in interface IMiniTable
      Parameters:
      row - row index of cell
      column - column index of cell
      Returns:
      true if cell is editable, false otherwise
    • getValueAt

      public Object getValueAt(int row, int column)
      Returns the cell value at row and column.

      Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

      Specified by:
      getValueAt in interface IMiniTable
      Parameters:
      row - the index of the row whose value is to be queried
      column - the index of the column whose value is to be queried
      Returns:
      the Object at the specified cell
    • getModel

      public ListModelTable getModel()
      Return the ListModelTable associated with this table.
      Overrides:
      getModel in class org.zkoss.zul.Listbox
      Returns:
      The ListModelTable associated with this table.
    • setValueAt

      public void setValueAt(Object value, int row, int column)
      Set the cell value at row and column.
      Specified by:
      setValueAt in interface IMiniTable
      Parameters:
      value - The value to set
      row - the index of the row whose value is to be set
      column - the index of the column whose value is to be set
    • convertColumnIndexToModel

      public int convertColumnIndexToModel(int viewColumnIndex)
      Convert the index for a column from the display index to the corresponding index in the underlying model.

      This is unused for this implementation because the column ordering cannot be dynamically changed.

      Specified by:
      convertColumnIndexToModel in interface IMiniTable
      Parameters:
      viewColumnIndex - the index of the column in the view
      Returns:
      the index of the corresponding column in the model
    • setColumnReadOnly

      public void setColumnReadOnly(int index, boolean readOnly)
      Set Column at the specified index to read-only or read/write.
      Specified by:
      setColumnReadOnly in interface IMiniTable
      Parameters:
      index - index of column to set as read-only (or not)
      readOnly - Read only value. If true column is read only, if false column is read-write
    • prepareTable

      public String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName)
      Prepare Table and return SQL required to get resultset to populate table.
      Specified by:
      prepareTable in interface IMiniTable
      Parameters:
      layout - array of column info
      from - SQL FROM content
      where - SQL WHERE content
      multiSelection - multiple selections
      tableName - table name
      Returns:
      SQL statement to use to get resultset to populate table
    • prepareTable

      public String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName, boolean addAccessSQL)
      Prepare Table and return SQL to get ResultSet to populate table
      Parameters:
      layout - array of column info
      from - SQL FROM content
      where - SQL WHERE content
      multiSelection - multiple selections
      tableName - multiple selections
      addAccessSQL - specifies whether to addAcessSQL
      Returns:
      SQL statement to use to get resultset to populate table
    • addColumn

      public void addColumn(String header)
      Description copied from interface: IMiniTable
      add column with header
      Specified by:
      addColumn in interface IMiniTable
      Parameters:
      header -
    • addColumn

      public void addColumn(String header, String description)
      Add column
      Parameters:
      header -
      description -
    • addColumn

      public void addColumn(String header, String description, int AD_Reference_ID)
      Add Table Column and specify the column header.
      Parameters:
      header - name of column header
      description -
      AD_Reference_ID -
    • setColumnClass

      public void setColumnClass(int index, Class<?> classType, boolean readOnly, String header)
      Set the type of the column.
      Specified by:
      setColumnClass in interface IMiniTable
      Parameters:
      index - The index of the column to be modified
      classType - The class of data that the column will contain
      readOnly - Whether the column is read only
      header - The header text for the column
      See Also:
    • setColumnClass

      public void setColumnClass(int index, Class<?> classType, boolean readOnly)
      Set the type of the column.
      Specified by:
      setColumnClass in interface IMiniTable
      Parameters:
      index - The index of the column to be modified
      classType - The class of data that the column will contain
      readOnly - Whether column is read only
      See Also:
    • addColumn

      public void addColumn(Class<?> classType, boolean readOnly, String header)
      Add column
      Parameters:
      classType - The class of data that the column will contain
      readOnly - Whether the column is read only
      header - The header text for the column
      See Also:
    • setColorColumn

      public void setColorColumn(int modelIndex)
      Set the Column to determine the color of the row (based on model index).
      Parameters:
      modelIndex - the index of the column used to decide the colour
    • loadTable

      public void loadTable(ResultSet rs)
      Populate Table from ResultSet, note that ResultSet is not closed at the end of this method.
      Specified by:
      loadTable in interface IMiniTable
      Parameters:
      rs - ResultSet containing data to enter into the table.
      The contents must conform to the column layout defined in prepareTable(ColumnInfo[], String, String, boolean, String)
    • loadTable

      public void loadTable(PO[] pos)
      Populate Table from PO Array.
      Specified by:
      loadTable in interface IMiniTable
      Parameters:
      pos - array of Persistent Objects
    • clear

      public void clear()
      Clear the table components.
    • getSelectedRowKey

      public <T extends Serializable> T getSelectedRowKey()
      Get the key of currently selected row based on layout defined in prepareTable(ColumnInfo[], String, String, boolean, String).
      Specified by:
      getSelectedRowKey in interface IMiniTable
      Returns:
      ID (int) or UUID (String) - if key
    • getRowKeyAt

      public <T extends Serializable> T getRowKeyAt(int index)
      IDEMPIERE-1334 get key of record at index
      Parameters:
      index -
      Returns:
      ID (int) or UUID (String)
    • setSelectedByKeys

      public void setSelectedByKeys(List<Integer> lsKey)
      IDEMPIERE-1334.
      De-select all current select, set all record with key in lsKey as selected.
      If table has no key column, just return.
      Parameters:
      lsKey -
    • getFirstRowKey

      public <T extends Serializable> T getFirstRowKey()
      Get key of first row
      Returns:
      key for first row (row 0). null if table is empty.
    • getSelectedRow

      public int getSelectedRow()
      Get index of the first selected row, -1 if no row is selected.
      Specified by:
      getSelectedRow in interface IMiniTable
      Returns:
      the index of the first selected row
    • setRowCount

      public void setRowCount(int rowCount)
      Set the size of the underlying data model.
      Specified by:
      setRowCount in interface IMiniTable
      Parameters:
      rowCount - number of rows
    • setwListBoxName

      public void setwListBoxName(String wListBoxName)
      Set the name of the wListbox. This is use to save the width of columns into ad_wlistbox_customization.
    • getwListBoxName

      public String getwListBoxName()
      Get the name of the wListbox
    • getLayoutInfo

      public ColumnInfo[] getLayoutInfo()
      Get Columns Layout.
      Specified by:
      getLayoutInfo in interface IMiniTable
      Returns:
      Array of ColumnInfo
    • clearTable

      public void clearTable()
      Removes all data stored in the underlying model.
    • getRowCount

      public int getRowCount()
      Get the number of rows in this table's model.
      Specified by:
      getRowCount in interface IMiniTable
      Returns:
      the number of rows in this table's model
    • setMultiSelection

      public void setMultiSelection(boolean multiSelection)
      Set whether or not multiple rows can be selected.
      Specified by:
      setMultiSelection in interface IMiniTable
      Parameters:
      multiSelection - are multiple selections allowed
    • isMultiSelection

      public boolean isMultiSelection()
      Query whether multiple rows can be selected in the table.
      Specified by:
      isMultiSelection in interface IMiniTable
      Returns:
      true if multiple rows can be selected
    • setShowTotals

      public void setShowTotals(boolean show)
      Set if Totals is Show
      Specified by:
      setShowTotals in interface IMiniTable
      Parameters:
      show -
    • getShowTotals

      public boolean getShowTotals()
      Is show total
      Returns:
      true if Totals is Show
    • setColorCompare

      public void setColorCompare(Object dataCompare)
      Set ColorColumn comparison criteria.
      Specified by:
      setColorCompare in interface IMiniTable
      Parameters:
      dataCompare - object encapsulating comparison criteria
    • getColorCode

      public int getColorCode(int row)
      Get ColorCode for Row.
      If numerical value in color column (m_colorColumnIndex) compare to m_colorDataCompare is
    • negative = -1
    • positive = 1
    • otherwise = 0

    • If Timestamp, same as above for before, after and equal for comparison to m_colorDataCompare or today (if m_colorDataCompare is null).
      Specified by:
      getColorCode in interface IMiniTable
      Parameters:
      row - row
      Returns:
      color code
    • tableValueChange

      public void tableValueChange(TableValueChangeEvent event)
      Description copied from interface: TableValueChangeListener
      Respond to a TableValueChangeEvent event.
      To listen to the event, you have to register it first by calling WListItemRenderer.addTableValueChangeListener(TableValueChangeListener)
      Specified by:
      tableValueChange in interface TableValueChangeListener
      Parameters:
      event - The event that has occurred
    • repaint

      public void repaint()
      Repaint the Table.
      Specified by:
      repaint in interface IMiniTable
    • getLayout

      public ColumnInfo[] getLayout()
      Get columns layout.
      Returns:
      ColumnInfo[], the columns layout of the table
      See Also:
      • setLayout(ColumnInfo[])
    • tableChanged

      public void tableChanged(WTableModelEvent event)
      Respond to a change in the table's model.
      If the event indicates that the entire table has changed, the table is repainted.
      Specified by:
      tableChanged in interface WTableModelListener
      Parameters:
      event - The event fired to indicate a change in the table's model
    • autoSize

      @Deprecated public void autoSize()
      Deprecated.
      no op, to ease porting of swing form
      Specified by:
      autoSize in interface IMiniTable
    • getColumnCount

      public int getColumnCount()
      Description copied from interface: IMiniTable
      Get number of columns
      Specified by:
      getColumnCount in interface IMiniTable
      Returns:
      number of columns
    • getKeyColumnIndex

      public int getKeyColumnIndex()
      Returns:
      key column index
    • addTotals

      public void addTotals(ColumnInfo[] layout)
      Add new row for column totals
      Parameters:
      layout - ColumnInfo[]
    • isAllowIDColumnForReadWrite

      public boolean isAllowIDColumnForReadWrite()
      Returns:
      true if ID column is editable
    • setAllowIDColumnForReadWrite

      public void setAllowIDColumnForReadWrite(boolean allowIDColumnForReadWrite)
      Set whether ID column is editable
      Parameters:
      allowIDColumnForReadWrite -
    • renderCustomHeaderWidth

      public void renderCustomHeaderWidth()
      Render the header of the WListbox with saved column width
    • saveColumnWidth

      public void saveColumnWidth()
      Save the width of all the columns to MWlistboxCustomization