package welcome.client.ui.store;
import java.util.Iterator;
import welcome.client.GreetingService;
import welcome.client.GreetingServiceAsync;
import welcome.client.ui.Content;
import welcome.shared.store.Store;
import welcome.shared.store.Article;
import com.google.gwt.user.client.Window;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Label;
public class StoreForm extends Content {
/**
* Create a remote service proxy to talk to the server-side Greeting
* service.
*/
private final GreetingServiceAsync storeService = GWT
.create(GreetingService.class);
private FlexTable articleTable = new FlexTable();
public StoreForm() {
//
this.storeService.getStore(new AsyncCallback<Store>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Faillure");
}
@Override
public void onSuccess(Store result) {
articleTable.setText(0, 0, "Name");
articleTable.setText(0, 1, "Amount");
articleTable.setText(0, 2, "Order Amount");
articleTable.setText(0, 3, "Order");
Label nameLabel;
Label amountLabel;
IntegerBox amountTB;
Button orderBt;
Iterator<Article> it = result.iterator();
Article currentArticle;
// construct a new Grid with correct size (we can t add a row
// dynamically...
for (int i = 0; it.hasNext(); i++) {
currentArticle = it.next();
nameLabel = new Label(currentArticle.getName());
amountLabel = new Label(String.valueOf(currentArticle
.getAmount()));
amountTB = new IntegerBox();
amountTB.setValue(0);
orderBt = new Button("Order");
articleTable.setWidget(i, 0, nameLabel);
articleTable.setWidget(i, 1, amountLabel);
articleTable.setWidget(i, 2, amountTB);
articleTable.setWidget(i, 3, orderBt);
}
}
});
initWidget(articleTable);
}
}