* merge branches/adempiere341 revision 6285 changes

This commit is contained in:
Heng Sin Low 2008-08-30 05:29:39 +00:00
parent ff4df8636d
commit 5f6dc1ef0f
1 changed files with 77 additions and 1 deletions

View File

@ -1,7 +1,20 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.webui.component;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import org.compiere.model.DataStatusEvent;
import org.compiere.model.DataStatusListener;
@ -17,14 +30,23 @@ import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.AbstractListModel;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelExt;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemComparator;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.ListitemRendererExt;
import org.zkoss.zul.event.ListDataEvent;
public class GridTableListModel extends AbstractListModel implements ListitemRenderer, ListitemRendererExt, DataStatusListener {
/**
*
* @author Low Heng Sin
*
*/
public class GridTableListModel extends AbstractListModel implements ListitemRenderer,
ListitemRendererExt, DataStatusListener, ListModelExt {
private GridTable tableModel;
private GridField[] gridField;
@ -33,6 +55,11 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
private int pageSize = -1;
private int pageNo = 0;
/**
*
* @param tableModel
* @param windowNo
*/
public GridTableListModel(GridTable tableModel, int windowNo) {
this.tableModel = tableModel;
this.windowNo = windowNo;
@ -40,6 +67,10 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
tableModel.addDataStatusListener(this);
}
/**
* @param rowIndex
* @see ListModel#getElementAt(int)
*/
public Object getElementAt(int rowIndex) {
int columnCount = tableModel.getColumnCount();
Object[] values = new Object[columnCount];
@ -79,14 +110,27 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
return pageNo;
}
/**
* Set number of rows per page
* @param pgSize
*/
public void setPageSize(int pgSize) {
pageSize = pgSize;
}
/**
* Get number of rows per page
* @return pageSize
*/
public int getPageSize() {
return pageSize;
}
/**
* Get total number of rows
* @return int
* @see ListModel#getSize()
*/
public int getSize() {
int total = tableModel.getRowCount();
if (pageSize < 0)
@ -103,6 +147,11 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
}
}
/**
* @param listitem
* @param data
* @see ListitemRenderer#render(Listitem, Object)
*/
public void render(Listitem listitem, Object data) throws Exception {
Object[] values = (Object[])data;
int columnCount = tableModel.getColumnCount();
@ -180,10 +229,17 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
return obj.toString();
}
/**
* @see ListitemRendererExt#getControls()
*/
public int getControls() {
return DETACH_ON_RENDER;
}
/**
* @param item
* @see ListitemRendererExt#newListcell(Listitem)
*/
public Listcell newListcell(Listitem item) {
ListCell listCell = new ListCell();
listCell.applyProperties();
@ -191,12 +247,20 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
return listCell;
}
/**
* @param listbox
* @see ListitemRendererExt#newListitem(Listbox)
*/
public Listitem newListitem(Listbox listbox) {
ListItem item = new ListItem();
item.applyProperties();
return item;
}
/**
* @param e
* @see DataStatusListener#dataStatusChanged(DataStatusEvent)
*/
public void dataStatusChanged(DataStatusEvent e) {
if (Executions.getCurrent() != null) {
fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
@ -204,4 +268,16 @@ public class GridTableListModel extends AbstractListModel implements ListitemRen
}
/**
* @param cmpr
* @param ascending
* @see ListModelExt#sort(Comparator, boolean)
*/
public void sort(Comparator cmpr, boolean ascending) {
//use default zk comparator
ListitemComparator lic = (ListitemComparator) cmpr;
tableModel.sort(lic.getListheader().getColumnIndex(), ascending);
fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
}
}