try {
ResultSetMetaData rsmd = rs.getMetaData();
if (rsmd.getColumnCount() == 1) {
while (rs.next()) {
Item item = new Item(rs.getObject(1), rs.getObject(1));
((JComboBox)childComponent).addItem(item);
}
} else {
while (rs.next()) {
StringBuffer sb = new StringBuffer();
for (int i = 2; i < rsmd.getColumnCount(); i++)
sb.append(rs.getObject(i) + " | ");
sb.append(rs.getObject(rsmd.getColumnCount()));
Item item = new Item(rs.getObject(1), sb.toString());
((JComboBox)childComponent).addItem(item);
}
}
rs.close();
}
catch (SQLException sqle) {
}
Iterator componentIter = components.iterator();
while (componentIter.hasNext()) {
JComponent component = (JComponent)componentIter.next();
((JComboBox)component).addActionListener(
new ActionAdapter() {
public void actionPerformed(ActionEvent e) {
((JComboBox)childComponent).removeAllItems();
DAO dao = DAO.getInstance();
dao.query(sql);
for (int i = 1; i <= components.size(); i++) {
JComponent tempComponent = (JComponent)components.get(i - 1);
dao.setObject(i, ComponentManager.getValue(tempComponent));
}
ResultSet rs = dao.executeQuery();
try {
ResultSetMetaData rsmd = rs.getMetaData();
if (rsmd.getColumnCount() == 1) {
while (rs.next()) {
Item item = new Item(rs.getObject(1), rs.getObject(1));
((JComboBox)childComponent).addItem(item);
}
} else {
while (rs.next()) {
StringBuffer sb = new StringBuffer();
for (int i = 2; i < rsmd.getColumnCount(); i++)
sb.append(rs.getObject(i) + " | ");
sb.append(rs.getObject(rsmd.getColumnCount()));
Item item = new Item(rs.getObject(1), sb.toString());
((JComboBox)childComponent).addItem(item);
}
}
rs.close();