Adempiere 3.5.2a

org.adempiere.webui.component
Class WListbox

java.lang.Object
  extended by org.zkoss.zk.ui.AbstractComponent
      extended by org.zkoss.zk.ui.HtmlBasedComponent
          extended by org.zkoss.zul.impl.XulElement
              extended by org.zkoss.zul.Listbox
                  extended by org.adempiere.webui.component.Listbox
                      extended by org.adempiere.webui.component.WListbox
All Implemented Interfaces:
Serializable, Cloneable, TableValueChangeListener, WTableModelListener, Component, EventListener, ComponentCtrl

public class WListbox
extends Listbox
implements TableValueChangeListener, WTableModelListener

Replacement for the Swing client minigrid component ZK Listbox extension for Adempiere Web UI. The listbox contains a model and a renderer. The model holds the underlying data objects, while the renderer deals with displaying the data objects. The renderer will render data objects using a variety of components. These components can then be edited if they are not readonly.

Author:
Andrew Kimball, Sendy Yagambrum
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.zkoss.zul.Listbox
Listbox.ExtraCtrl
 
Field Summary
protected  int m_keyColumnIndex
          Model Index of Key Column.
 
Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent
RS_NO_DISPLAY, RS_NO_HEIGHT, RS_NO_WIDTH
 
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
 
Constructor Summary
WListbox()
          Default constructor.
 
Method Summary
 void addColumn(Class classType, boolean readOnly, String header)
          Set the attributes of the column.
 void addColumn(String header)
          Add Table Column and specify the column header.
 void clear()
          Clear the table components.
 void clearTable()
          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.
 ColumnInfo[] getLayout()
          Get the table layout.
 ColumnInfo[] getLayoutInfo()
          Get Layout.
 ListModelTable getModel()
          Return the ListModelTable associated with this table.
 int getRowCount()
          Get the number of rows in this table's model.
 int getSelectedRow()
          Returns the index of the first selected row, -1 if no row is selected.
 Integer getSelectedRowKey()
          Get the key of currently selected row based on layout defined in prepareTable(ColumnInfo[], String, String, boolean, String).
 Object getValueAt(int row, int column)
          Returns the cell value at row and column.
 boolean isCellEditable(int row, int column)
          Is the cell at the specified row and column editable?
 boolean isMultiSelection()
          Query whether multiple rows can be selected in the table.
 void loadTable(PO[] pos)
          Load Table from Object Array.
 void loadTable(ResultSet rs)
          Load Table from ResultSet - The ResultSet is not closed.
 String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName)
          Prepare Table and return SQL required to get resultset to populate table.
 String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName, boolean addAccessSQL)
          Prepare Table and return SQL required to get resultset to populate table
 void repaint()
          Repaint the Table.
 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 attributes of the column.
 void setColumnClass(int index, Class classType, boolean readOnly, String header)
          Set the attributes 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, Vector<? extends String> columnNames)
          Set the data model and column header names for the Listbox.
 void setModel(ListModel model)
           
 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 setValueAt(Object value, int row, int column)
          Set the cell value at row and column.
 void tableChanged(WTableModelEvent event)
          Respond to a change in the table's model.
 void tableValueChange(TableValueChangeEvent event)
          Respond to a TableValueChangeEvent event Notifies this listener that an event has occurred.
 
Methods inherited from class org.adempiere.webui.component.Listbox
addDoubleClickListener, addOnDropListener, addPropertyChangeListener, appendItem, appendItem, getItemAtIndex, getItems, getListHead, getSelectedIndices, getSelectedItem, insertBefore, isEnabled, isItemDraggable, onEvent, setEnabled, setItemDraggable, setSelectedIndices, setValue
 
Methods inherited from class org.zkoss.zul.Listbox
addItemToSelection, afterInsert, beforeRemove, clearSelection, clone, getActivePage, getHeads, getIndexOfItem, getInnerBottom, getInnerHeight, getInnerTop, getInnerWidth, getItemCount, getItemRenderer, getListfoot, getListhead, getMaxlength, getName, getOddRowSclass, getOuterAttrs, getPageCount, getPageSize, getPaginal, getPaging, getPagingPosition, getPreloadSize, getRows, getSelectedCount, getSelectedIndex, getSelectedItems, getSeltype, getTabindex, getVisibleBegin, getVisibleEnd, isCheckmark, isDisabled, isFixedLayout, isMultiple, isVflex, newExtraCtrl, onChildAdded, onChildRemoved, onInitRender, removeChild, removeItemAt, removeItemFromSelection, renderAll, renderItem, renderItems, selectAll, selectItem, setActivePage, setActivePage, setCheckmark, setDisabled, setFixedLayout, setInnerBottom, setInnerHeight, setInnerTop, setInnerWidth, setItemRenderer, setItemRenderer, setMaxlength, setMold, setMultiple, setName, setOddRowSclass, setPageSize, setPaginal, setPagingPosition, setPreloadSize, setRows, setSelectedIndex, setSelectedItem, setSeltype, setTabindex, setVflex, smartUpdate, toggleItemSelection
 
Methods inherited from class org.zkoss.zul.impl.XulElement
getAction, getActionAttrs, getAllOnClickAttrs, getContext, getCtrlKeys, getInnerAttrs, getPopup, getTooltip, setAction, setContext, setContext, setCtrlKeys, setPopup, setPopup, setTooltip, setTooltip
 
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
focus, getAllOnClickAttrs, getDraggable, getDroppable, getHeight, getLeft, getRealSclass, getRealStyle, getRealStyleFlags, getSclass, getStyle, getTooltiptext, getTop, getWidth, getZIndex, setClass, setDraggable, setDroppable, setFocus, setHeight, setLeft, setSclass, setStyle, setTooltiptext, setTop, setWidth, setZIndex
 
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addAnnotation, addEventHandler, addEventListener, addForward, addForward, addForward, addForward, addMoved, addSharedAnnotationMap, addSharedEventHandlerMap, appendAsapAttr, appendAsapAttr, appendChild, applyProperties, containsVariable, detach, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttributes, getAttributes, getChildren, getCommand, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getExtraCtrl, getFellow, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getMoldURI, getNamespace, getNextSibling, getPage, getParent, getPreviousSibling, getPropagatee, getRoot, getSpaceOwner, getUuid, getVariable, invalidate, isAsapRequired, isChildable, isInvalidated, isListenerAvailable, isVisible, onDrawNewChild, onPageAttached, onPageDetached, onWrongValue, redraw, removeAttribute, removeAttribute, removeEventListener, removeForward, removeForward, response, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setComponentDefinition, setId, setPage, setPageBefore, setParent, setVariable, setVisible, smartUpdate, smartUpdate, smartUpdateDeferred, smartUpdateValues, toString, unsetVariable
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_keyColumnIndex

protected int m_keyColumnIndex
Model Index of Key Column.

Constructor Detail

WListbox

public WListbox()
Default constructor. Sets a row renderer and an empty model

Method Detail

setData

public void setData(ListModelTable model,
                    Vector<? 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 - The names of the table columns

setModel

public void setModel(ListModel model)
Overrides:
setModel in class Listbox

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Is the cell at the specified row and column editable?

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.

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 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.

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.

Parameters:
viewColumnIndex - the index of the column in the view
Returns:
the index of the corresponding column in the model
See Also:
#convertColumnIndexToVi

setColumnReadOnly

public void setColumnReadOnly(int index,
                              boolean readOnly)
Set Column at the specified index to read-only or read/write.

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.

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 required 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)
Add Table Column and specify the column header.

Parameters:
header - name of column header

setColumnClass

public void setColumnClass(int index,
                           Class classType,
                           boolean readOnly,
                           String header)
Set the attributes of the column.

Parameters:
index - The index of the column to be modified
classType - The class of data that the column will contain
readOnly - Whether the data in the column is read only
header - The header text for the column
See Also:
setColumnClass(int, Class, boolean)

setColumnClass

public void setColumnClass(int index,
                           Class classType,
                           boolean readOnly)
Set the attributes of the column.

Parameters:
index - The index of the column to be modified
classType - The class of data that the column will contain
readOnly - Whether the data in the column is read only
See Also:
setColumnClass(int, Class, boolean, String)

addColumn

public void addColumn(Class classType,
                      boolean readOnly,
                      String header)
Set the attributes of the column.

Parameters:
classType - The class of data that the column will contain
readOnly - Whether the data in the column is read only
header - The header text for the column
See Also:
setColumnClass(int, Class, boolean), addColumn(String)

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)
Load Table from ResultSet - The ResultSet is not closed.

Parameters:
rs - ResultSet containing data t enter int the table. The contents must conform to the column layout defined in prepareTable(ColumnInfo[], String, String, boolean, String)

loadTable

public void loadTable(PO[] pos)
Load Table from Object Array.

Parameters:
pos - array of Persistent Objects

clear

public void clear()
Clear the table components.


getSelectedRowKey

public Integer getSelectedRowKey()
Get the key of currently selected row based on layout defined in prepareTable(ColumnInfo[], String, String, boolean, String).

Returns:
ID if key

getSelectedRow

public int getSelectedRow()
Returns the index of the first selected row, -1 if no row is selected.

Returns:
the index of the first selected row

setRowCount

public void setRowCount(int rowCount)
Set the size of the underlying data model.

Parameters:
rowCount - number of rows

getLayoutInfo

public ColumnInfo[] getLayoutInfo()
Get Layout.

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.

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.

Parameters:
multiSelection - are multiple selections allowed

isMultiSelection

public boolean isMultiSelection()
Query whether multiple rows can be selected in the table.

Returns:
true if multiple rows can be selected

setColorCompare

public void setColorCompare(Object dataCompare)
Set ColorColumn comparison criteria.

Parameters:
dataCompare - object encapsualating comparison criteria

getColorCode

public int getColorCode(int row)
Get ColorCode for Row.
        If numerical value in compare column is
                negative = -1,
      positive = 1,
      otherwise = 0
  If Timestamp
  

Parameters:
row - row
Returns:
color code

tableValueChange

public void tableValueChange(TableValueChangeEvent event)
Description copied from interface: TableValueChangeListener
Respond to a TableValueChangeEvent event Notifies this listener that an event has occurred. To get the event, you have to register it first by use of WListItemRenderer.addTableValueChangeListener(TableValueChangeListener)

Specified by:
tableValueChange in interface TableValueChangeListener
Parameters:
event - The event that has occurred

repaint

public void repaint()
Repaint the Table.


getLayout

public ColumnInfo[] getLayout()
Get the table layout.

Returns:
the 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

Adempiere 3.5.2a

Adempiere® is a registered trademark of ADempiere Business Inc. ©2004-2008 HumanFlash.com All rights reserved.