use of org.compiere.minigrid.DeleteColumn in project adempiere by adempiere.
the class WPOSTable method loadTable.
/**
* Load Table from ResultSet - The ResultSet is not closed.
*
* @param rs ResultSet containing data t enter int the table.
* The contents must conform to the column layout defined in
* {@link #prepareTable(ColumnInfo[], String, String, boolean, String)}
*/
public void loadTable(ResultSet rs) {
int no = 0;
// model row
int row = 0;
// model column
int col = 0;
Object data = null;
// index into result set
int rsColIndex = 0;
// result set columns start with 1
int rsColOffset = 1;
// class of the column
Class columnClass;
if (getLayout() == null) {
throw new UnsupportedOperationException("Layout not defined");
}
clearTable();
try {
while (rs.next()) {
row = getItemCount();
setRowCount(row + 1);
rsColOffset = 1;
no++;
for (col = 0; col < m_layout.length; col++) {
//reset the data value
data = null;
columnClass = m_layout[col].getColClass();
rsColIndex = col + rsColOffset;
if (isColumnClassMismatch(col, columnClass)) {
throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
}
if (columnClass == IDColumn.class && !m_layout[col].getColSQL().equals("'Row' AS \"Row\"")) {
data = new IDColumn(rs.getInt(rsColIndex));
} else if (columnClass == IDColumn.class && m_layout[col].getColSQL().equals("'Row' AS \"Row\"")) {
data = new IDColumn(no);
} else if (columnClass == Boolean.class) {
data = rs.getString(rsColIndex) == null ? new Boolean(false) : new Boolean(rs.getString(rsColIndex).equals("Y"));
} else if (columnClass == Timestamp.class) {
data = rs.getTimestamp(rsColIndex);
} else if (columnClass == BigDecimal.class) {
data = rs.getBigDecimal(rsColIndex);
} else if (columnClass == Double.class) {
data = new Double(rs.getDouble(rsColIndex));
} else if (columnClass == Integer.class) {
data = new Integer(rs.getInt(rsColIndex));
} else if (columnClass == KeyNamePair.class) {
// TODO factor out this generation
String display = rs.getString(rsColIndex);
int key = rs.getInt(rsColIndex + 1);
data = new KeyNamePair(key, display);
rsColOffset++;
} else if (columnClass == DeleteColumn.class) {
// TODO factor out this generation
data = new DeleteColumn(rs.getInt(rsColIndex));
} else {
// TODO factor out this cleanup
String s = rs.getString(rsColIndex);
if (s != null) {
// problems with NCHAR
data = s.trim();
} else {
data = null;
}
}
// store in underlying model
getModel().setDataAt(data, row, col);
}
}
} catch (SQLException exception) {
logger.log(Level.SEVERE, "", exception);
}
autoSize();
if (getShowTotals())
addTotals(m_layout);
// repaint the table
this.repaint();
logger.config("Row(rs)=" + getRowCount());
return;
}
Aggregations