package com.ebpm.webdemo.zk;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Iterator;
import org.zkoss.zk.ui.Path;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Label;
import org.zkoss.zul.Radiogroup;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
import com.ebpm.webdemo.common.PersonBean;
import com.ebpm.webdemo.common.PersonDAO;
/**
* SimpleWindow.java
* @author Daniel Seiler
* Copyright © 2007 EBPM AG. All rights reserved
*
*/
public class SimpleWindow extends Window {
/**
*
*/
private static final long serialVersionUID = -8425760717953829365L;
public static SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
public void onCreate() {
createPersonsGrid();
}
public void addPerson() {
// extracting the person data
Textbox firstName = (Textbox) Path.getComponent("/simpleWindow/firstname");
Textbox lastName = (Textbox) Path.getComponent("/simpleWindow/lastname");
Textbox address = (Textbox) Path.getComponent("/simpleWindow/address");
Textbox weight = (Textbox) Path.getComponent("/simpleWindow/weight");
Datebox birthdate = (Datebox) Path.getComponent("/simpleWindow/birthdate");
Combobox color = (Combobox) Path.getComponent("/simpleWindow/color");
Checkbox married = (Checkbox) Path.getComponent("/simpleWindow/married");
Radiogroup rating = (Radiogroup) Path.getComponent("/simpleWindow/rating");
PersonBean personBean = new PersonBean();
personBean.setFirstname(firstName.getValue());
personBean.setLastname(lastName.getValue());
personBean.setAddress(address.getValue());
personBean.setWeight(new Float(weight.getValue()).floatValue());
personBean.setBirthdate(birthdate.getValue());
personBean.setColor(color.getValue());
personBean.setMarried(married.isChecked());
personBean.setRating(rating.getSelectedItem().getValue());
PersonDAO.getInstance().addPerson(personBean);
Grid personsGrid = (Grid)org.zkoss.zk.ui.Path.getComponent("/simpleWindow/personsGrid");
Rows rows = personsGrid.getRows();
addRow(personBean,rows);
}
@SuppressWarnings("unchecked")
private void addRow(PersonBean personBean, Rows rows) {
Row row = new Row();
rows.appendChild(row);
row.getChildren().add(new Label(personBean.getFirstname()));
row.getChildren().add(new Label(personBean.getLastname()));
row.getChildren().add(new Label(personBean.getAddress()));
row.getChildren().add(new Label(Float.toString(personBean.getWeight())));
row.getChildren().add(new Label(sdf.format(personBean.getBirthdate())));
row.getChildren().add(new Label(personBean.getColor()));
Checkbox cb = new Checkbox();
cb.setChecked(personBean.isMarried());
cb.setDisabled(true);
row.getChildren().add(cb);
row.getChildren().add(new Label(personBean.getRating()));
}
@SuppressWarnings("unchecked")
private void createPersonsGrid() {
Grid personsGrid = (Grid)Path.getComponent("/simpleWindow/personsGrid");
// add all the personsBeans
Collection personBeans = PersonDAO.getInstance().getAllPersons();
for (Iterator it = personBeans.iterator(); it.hasNext();) {
PersonBean personBean = (PersonBean) it.next();
addRow(personBean, personsGrid.getRows());
}
}
}
|