Revision: 8090
Author: j...@google.com
Date: Tue May 11 07:01:15 2010
Log: Adds the ability to create new expenses within a report.
http://code.google.com/p/google-web-toolkit/source/detail?r=8090
Modified:
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpensesMobileShell.java
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseEntry.java
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseList.java
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpensesMobileShell.java
Mon May 10 10:53:16 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpensesMobileShell.java
Tue May 11 07:01:15 2010
@@ -123,6 +123,10 @@
private void showExpenseList(ReportRecord report) {
if (expenseList == null) {
expenseList = new MobileExpenseList(new MobileExpenseList.Listener()
{
+ public void onCreateExpense(String reportId) {
+ showNewExpenseEntry(reportId);
+ }
+
public void onExpenseSelected(ExpenseRecord expense) {
showExpenseDetails(expense);
}
@@ -132,6 +136,19 @@
expenseList.show(report);
pushPage(expenseList);
}
+
+ private void showNewExpenseEntry(String reportId) {
+ if (expenseEntry == null) {
+ expenseEntry = new MobileExpenseEntry(new
MobileExpenseEntry.Listener() {
+ public void onExpenseUpdated() {
+ popPage();
+ }
+ }, requestFactory);
+ }
+
+ expenseEntry.create(reportId);
+ pushPage(expenseEntry);
+ }
private void showPage(MobilePage page) {
Widget oldPage = container.getWidget();
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseEntry.java
Mon May 10 10:53:16 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseEntry.java
Tue May 11 07:01:15 2010
@@ -54,6 +54,7 @@
private ExpenseRecord expense;
private final ExpensesRequestFactory requestFactory;
private final Listener listener;
+ private DeltaValueStore deltas;
public MobileExpenseEntry(Listener listener,
ExpensesRequestFactory requestFactory) {
@@ -69,6 +70,14 @@
public Widget asWidget() {
return this;
}
+
+ public void create(String reportId) {
+ deltas = requestFactory.getValueStore().spawnDeltaView();
+
+ expense = (ExpenseRecord) deltas.create(ExpenseRecord.TOKEN);
+ deltas.set(ExpenseRecord.reportId, expense, reportId);
+ displayExpense();
+ }
public String getPageTitle() {
return expense != null ? expense.getDescription() : "";
@@ -90,16 +99,13 @@
}
public void onCustom() {
- // Create a delta and sync with the value store.
- DeltaValueStore deltas =
requestFactory.getValueStore().spawnDeltaView();
deltas.set(ExpenseRecord.description, expense, nameText.getText());
deltas.set(ExpenseRecord.category, expense, categoryText.getText());
- // TODO: validate amount, store amount
- // (currently writing doubles seems to be unimplemented)
-// String amountText = priceText.getText();
-// double amount = Double.parseDouble(amountText);
-// deltas.set(ExpenseRecord.amount, expense, amount);
+ // TODO(jgw): validate amount (in dollars -- database is in pennies)
+ String amountText = priceText.getText();
+ double amount = Double.parseDouble(amountText);
+ deltas.set(ExpenseRecord.amount, expense, amount * 100);
// TODO(jgw): Use non-deprecated date methods for this.
Date date = new Date(
@@ -131,8 +137,12 @@
}
public void show(ExpenseRecord expense) {
+ deltas = requestFactory.getValueStore().spawnDeltaView();
this.expense = expense;
-
+ displayExpense();
+ }
+
+ private void displayExpense() {
nameText.setText(expense.getDescription());
categoryText.setText(expense.getCategory());
priceText.setText(ExpensesMobile.formatCurrency(expense.getAmount().intValue()));
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseList.java
Mon May 10 10:53:16 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseList.java
Tue May 11 07:01:15 2010
@@ -44,6 +44,7 @@
*/
public interface Listener {
void onExpenseSelected(ExpenseRecord expense);
+ void onCreateExpense(String reportId);
}
private final ExpensesRequestFactory requestFactory;
@@ -51,9 +52,11 @@
private final ListViewAdapter<ExpenseRecord> expenseAdapter;
private final SingleSelectionModel<ExpenseRecord> expenseSelection;
private ReportRecord report;
+ private final Listener listener;
public MobileExpenseList(final Listener listener,
final ExpensesRequestFactory requestFactory) {
+ this.listener = listener;
this.requestFactory = requestFactory;
expenseAdapter = new ListViewAdapter<ExpenseRecord>();
@@ -101,7 +104,7 @@
}
public void onAdd() {
- // TODO Auto-generated method stub
+ listener.onCreateExpense(report.getId());
}
public void onCustom() {
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors