Package org.adempiere.webui.component
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
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
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_keyColumnIndex
Model Index of Key Column.
-
Constructor Summary
Constructors Constructor Description WListbox()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(Class<?> classType, boolean readOnly, String header)
Set the attributes of the column.void
addColumn(String header)
void
addColumn(String header, String description)
void
addColumn(String header, String description, int AD_Reference_ID)
Add Table Column and specify the column header.void
addTotals(ColumnInfo[] layout)
Adding a new row with the totalsvoid
autoSize()
no op, to ease porting of swing formvoid
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.int
getColumnCount()
TODO:in theory column of model maybe not map with column of view in case set other data model this function always return number of column of model, maybe not equal with number of column of view so it should is m_layout.lengthInteger
getFirstRowKey()
int
getKeyColumnIndex()
ColumnInfo[]
getLayout()
Get the table layout.ColumnInfo[]
getLayoutInfo()
Get Layout.ListModelTable
getModel()
Return theListModelTable
associated with this table.int
getRowCount()
Get the number of rows in this table's model.Integer
getRowKeyAt(int index)
IDEMPIERE-1334 get key of record at indexint
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 inprepareTable(ColumnInfo[], String, String, boolean, String)
.boolean
getShowTotals()
get if Totals is ShowObject
getValueAt(int row, int column)
Returns the cell value atrow
andcolumn
.String
getwListBoxName()
void
initialiseHeader()
Create the listbox header by fetching it from the renderer and adding it to the Listbox.boolean
isAllowIDColumnForReadWrite()
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(ResultSet rs)
Load Table from ResultSet - The ResultSet is not closed.void
loadTable(PO[] pos)
Load Table from Object Array.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 tablevoid
renderCustomHeaderWidth()
Render the header of the WListbox with the columns width of the saved column widthvoid
repaint()
Repaint the Table.void
saveColumnWidth()
Save the width of all the columns in the WLsitboxvoid
setAllowIDColumnForReadWrite(boolean allowIDColumnForReadWrite)
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 specifiedindex
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)
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
setSelectedByKeys(List<Integer> lsKey)
IDEMPIERE-1334 deselect all current select, set all record have key in lsKey is selected when non key column just returnvoid
setShowTotals(boolean show)
Set if Totals is Showvoid
setValueAt(Object value, int row, int column)
Set the cell value atrow
andcolumn
.void
setwListBoxName(String wListBoxName)
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
addActionListener, addDoubleClickListener, addItem, addItem, addOnDropListener, afterInsert, appendItem, appendItem, getItemAtIndex, getListHead, getOddRowSclass, getSelectedIndices, getSelectedItem, getValue, insertBefore, isEnabled, isItemDraggable, onEvent, removeActionListener, removeAllItems, removeChild, setEnabled, setItemDraggable, setOddRowSclass, setSelectedIndices, setSelectedKeyNamePair, setSelectedValueNamePair, setValue, toString
-
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, getPreloadSize, getRows, getSelectedCount, getSelectedIndex, getSelectedItems, getSeltype, getVisibleItemCount, getZclass, hasGroup, isAutohidePaging, isCheckmark, isDisabled, isFixedLayout, 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, setFixedLayout, setHeight, setInnerWidth, setItemRenderer, setItemRenderer, setMaxlength, setModel, setMold, setMultiple, setName, setNonselectableTags, setPageSize, setPaginal, setPreloadSize, 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, getPropertyAccess, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
-
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, focus, getAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, 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, addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildRemoved, beforeParentChanged, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, enableBindingAnnotation, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, 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, getId, getLastChild, getListenerIterator, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttribute, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, invalidate, invalidatePartial, isChildable, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, replace, response, response, response, service, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetAttribute, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
-
-
-
Method Detail
-
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 tablecolumnNames
- The names of the table columns
-
setModel
public void setModel(org.zkoss.zul.ListModel<?> model)
- Overrides:
setModel
in classorg.zkoss.zul.Listbox
-
initialiseHeader
public void initialiseHeader()
Create the listbox header by fetching it from the renderer and adding it to the Listbox.
-
isCellEditable
public boolean isCellEditable(int row, int column)
Is the cell at the specified row and column editable?- Specified by:
isCellEditable
in interfaceIMiniTable
- Parameters:
row
- row index of cellcolumn
- column index of cell- Returns:
- true if cell is editable, false otherwise
-
getValueAt
public Object getValueAt(int row, int column)
Returns the cell value atrow
andcolumn
.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 interfaceIMiniTable
- Parameters:
row
- the index of the row whose value is to be queriedcolumn
- the index of the column whose value is to be queried- Returns:
- the Object at the specified cell
-
getModel
public ListModelTable getModel()
Return theListModelTable
associated with this table.- Overrides:
getModel
in classorg.zkoss.zul.Listbox
- Returns:
- The
ListModelTable
associated with this table.
-
setValueAt
public void setValueAt(Object value, int row, int column)
Set the cell value atrow
andcolumn
.- Specified by:
setValueAt
in interfaceIMiniTable
- Parameters:
value
- The value to setrow
- the index of the row whose value is to be setcolumn
- 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 interfaceIMiniTable
- 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 specifiedindex
to read-only or read/write.- Specified by:
setColumnReadOnly
in interfaceIMiniTable
- Parameters:
index
- index of column to set as read-only (or not)readOnly
- Read only value. Iftrue
column is read only, iffalse
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 interfaceIMiniTable
- Parameters:
layout
- array of column infofrom
- SQL FROM contentwhere
- SQL WHERE contentmultiSelection
- multiple selectionstableName
- 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 infofrom
- SQL FROM contentwhere
- SQL WHERE contentmultiSelection
- multiple selectionstableName
- multiple selectionsaddAccessSQL
- specifies whether to addAcessSQL- Returns:
- SQL statement to use to get resultset to populate table
-
addColumn
public void addColumn(String header)
- Specified by:
addColumn
in interfaceIMiniTable
- Parameters:
header
-
-
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 headerdescription
-
-
setColumnClass
public void setColumnClass(int index, Class<?> classType, boolean readOnly, String header)
Set the attributes of the column.- Specified by:
setColumnClass
in interfaceIMiniTable
- Parameters:
index
- The index of the column to be modifiedclassType
- The class of data that the column will containreadOnly
- Whether the data in the column is read onlyheader
- 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.- Specified by:
setColumnClass
in interfaceIMiniTable
- Parameters:
index
- The index of the column to be modifiedclassType
- The class of data that the column will containreadOnly
- 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 containreadOnly
- Whether the data in the column is read onlyheader
- 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.- Specified by:
loadTable
in interfaceIMiniTable
- Parameters:
rs
- ResultSet containing data t enter int the table. The contents must conform to the column layout defined inprepareTable(ColumnInfo[], String, String, boolean, String)
-
loadTable
public void loadTable(PO[] pos)
Load Table from Object Array.- Specified by:
loadTable
in interfaceIMiniTable
- 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 inprepareTable(ColumnInfo[], String, String, boolean, String)
.- Specified by:
getSelectedRowKey
in interfaceIMiniTable
- Returns:
- ID if key
-
getRowKeyAt
public Integer getRowKeyAt(int index)
IDEMPIERE-1334 get key of record at index- Parameters:
index
-- Returns:
-
setSelectedByKeys
public void setSelectedByKeys(List<Integer> lsKey)
IDEMPIERE-1334 deselect all current select, set all record have key in lsKey is selected when non key column just return- Parameters:
lsKey
-
-
getFirstRowKey
public Integer getFirstRowKey()
-
getSelectedRow
public int getSelectedRow()
Returns the index of the first selected row, -1 if no row is selected.- Specified by:
getSelectedRow
in interfaceIMiniTable
- 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 interfaceIMiniTable
- Parameters:
rowCount
- number of rows
-
setwListBoxName
public void setwListBoxName(String wListBoxName)
-
getwListBoxName
public String getwListBoxName()
-
getLayoutInfo
public ColumnInfo[] getLayoutInfo()
Get Layout.- Specified by:
getLayoutInfo
in interfaceIMiniTable
- 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 interfaceIMiniTable
- 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 interfaceIMiniTable
- Parameters:
multiSelection
- are multiple selections allowed
-
isMultiSelection
public boolean isMultiSelection()
Query whether multiple rows can be selected in the table.- Specified by:
isMultiSelection
in interfaceIMiniTable
- Returns:
- true if multiple rows can be selected
-
setShowTotals
public void setShowTotals(boolean show)
Set if Totals is Show- Specified by:
setShowTotals
in interfaceIMiniTable
- Parameters:
show
-
-
getShowTotals
public boolean getShowTotals()
get if Totals is Show
-
setColorCompare
public void setColorCompare(Object dataCompare)
Set ColorColumn comparison criteria.- Specified by:
setColorCompare
in interfaceIMiniTable
- 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
- Specified by:
getColorCode
in interfaceIMiniTable
- 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 ofWListItemRenderer.addTableValueChangeListener(TableValueChangeListener)
- Specified by:
tableValueChange
in interfaceTableValueChangeListener
- Parameters:
event
- The event that has occurred
-
repaint
public void repaint()
Repaint the Table.- Specified by:
repaint
in interfaceIMiniTable
-
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 interfaceWTableModelListener
- Parameters:
event
- The event fired to indicate a change in the table's model
-
autoSize
public void autoSize()
no op, to ease porting of swing form- Specified by:
autoSize
in interfaceIMiniTable
-
getColumnCount
public int getColumnCount()
TODO:in theory column of model maybe not map with column of view in case set other data model this function always return number of column of model, maybe not equal with number of column of view so it should is m_layout.length- Specified by:
getColumnCount
in interfaceIMiniTable
-
getKeyColumnIndex
public int getKeyColumnIndex()
-
addTotals
public void addTotals(ColumnInfo[] layout)
Adding a new row with the totals
-
isAllowIDColumnForReadWrite
public boolean isAllowIDColumnForReadWrite()
-
setAllowIDColumnForReadWrite
public void setAllowIDColumnForReadWrite(boolean allowIDColumnForReadWrite)
-
renderCustomHeaderWidth
public void renderCustomHeaderWidth()
Render the header of the WListbox with the columns width of the saved column width
-
saveColumnWidth
public void saveColumnWidth()
Save the width of all the columns in the WLsitbox
-
-