}
};
}
public Owners() {
final ClinicAsync clinic = ClinicAsync.Util.getInstance();
FlowPanel searchPanel = new FlowPanel();
final Grid grid = new Grid();
final VerticalPanel layout = new VerticalPanel();
final TextBox searchBox = new TextBox();
searchPanel.add(searchBox);
searchPanel.add(new Button("find", new ClickListener() {
public void onClick(Widget widget) {
if (searchBox.getText().length() > 0) {
clinic.findOwners(searchBox.getText(), new AsyncCallback<Collection<Owner>>() {
public void onSuccess(Collection<Owner> collection) {
if (collection.size() == 0) {
grid.resize(1, 1);
grid.setWidget(0, 0, new Label("No owners of last name '" + searchBox.getText() + "' were found."));
}
else {
grid.resize(collection.size() + 1, 4);
grid.setWidget(0, 0, new Label("name"));
grid.setWidget(0, 1, new Label("phone"));
grid.setWidget(0, 2, new Label("address"));
grid.setWidget(0, 3, new Label("city"));
grid.getCellFormatter().setWidth(0, 1, "12em");
grid.getCellFormatter().setHorizontalAlignment(0, 0, HasAlignment.ALIGN_CENTER);
grid.getCellFormatter().setHorizontalAlignment(0, 1, HasAlignment.ALIGN_CENTER);
grid.getCellFormatter().setHorizontalAlignment(0, 2, HasAlignment.ALIGN_CENTER);
grid.getCellFormatter().setHorizontalAlignment(0, 3, HasAlignment.ALIGN_CENTER);
grid.getRowFormatter().setStyleName(0, "clinic-tables-header");
int row = 1;
Iterator<Owner> it = collection.iterator();
while (it.hasNext()) {
final Owner owner = it.next();
final Label nameLabel = new Label(owner.getFirstName() + " " + owner.getLastName());
nameLabel.addStyleName("clinic-clickable");
nameLabel.addClickListener(new ClickListener() {
public void onClick(Widget widget) {
final DialogBox detailsPanel = new DialogBox(true);
final VerticalPanel petList = new VerticalPanel();
petList.add(new Label("Pets of " + nameLabel.getText() + ":"));
detailsPanel.setWidget(petList);
detailsPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
detailsPanel.setPopupPosition(nameLabel.getAbsoluteLeft(), nameLabel.getAbsoluteTop());
}
});
Iterator petsIt = owner.getPetIds().iterator();
while (petsIt.hasNext()) {
final Integer petId = (Integer) petsIt.next();
clinic.loadPet(petId.intValue(), new AsyncCallback<Pet>() {
public void onSuccess(Pet response) {
petList.add(new Label("A " + response.getType().getName() + " named " + response.getName() + "."));
}
public void onFailure(Throwable throwable) {