Revision: 7721
Author: rj...@google.com
Date: Fri Mar 12 09:35:24 2010
Log: Start of sending an update request. Checking in mid-way to allow some
renaming work before Amit finishes it.
Review at http://gwt-code-reviews.appspot.com/192801
Review by: amitman...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=7721
Added:
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java
Modified:
/trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.ui.xml
/trunk/bikeshed/src/com/google/gwt/sample/expenses/client/ValuesImpl.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRequests.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
/trunk/bikeshed/src/com/google/gwt/valuestore/shared/Values.java
=======================================
--- /dev/null
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java
Fri Mar 12 09:35:24 2010
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.sample.expenses.shared;
+
+/**
+ * Request to commit CRUD operations accumulated in a DeltaValueStore.
+ */
+public interface SyncRequest {
+ void fire();
+}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java
Wed Mar 10 14:02:29 2010
+++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java
Fri Mar 12 09:35:24 2010
@@ -21,6 +21,10 @@
import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
import com.google.gwt.sample.expenses.shared.Report;
import com.google.gwt.user.client.ui.RootLayoutPanel;
+import com.google.gwt.valuestore.shared.Values;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@@ -46,6 +50,17 @@
final EmployeeList employees = new EmployeeList(shell.users);
root.add(shell);
+
+ shell.setListener(new Shell.Listener() {
+ public void setFirstPurpose(String purpose) {
+ ValuesImpl<Report> reportValues = (ValuesImpl<Report>
)shell.getValues().get(0);
+ reportValues.setString(Report.PURPOSE, purpose);
+ List<Values<Report>> deltaValueStore = new
ArrayList<Values<Report>>();
+ deltaValueStore.add(reportValues);
+
+ requestFactory.syncRequest(deltaValueStore).fire();
+ }
+ });
employees.setListener(new EmployeeList.Listener() {
public void onEmployeeSelected(Employee e) {
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java
Wed Mar 10 14:02:29 2010
+++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java
Fri Mar 12 09:35:24 2010
@@ -22,13 +22,18 @@
import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.dom.client.TableElement;
import com.google.gwt.dom.client.TableRowElement;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.sample.expenses.shared.Report;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValueList;
import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.shared.Values;
@@ -41,9 +46,14 @@
* refactored into proper MVP pieces.
*/
public class Shell extends Composite implements
HasValueList<Values<Report>> {
-
- interface ShellUiBinder extends UiBinder<Widget, Shell> {
- }
+ interface Listener {
+ void setFirstPurpose(String purpose);
+ }
+
+ interface ShellUiBinder extends UiBinder<Widget, Shell> {
+ }
+
+ private Listener listener;
private static ShellUiBinder uiBinder = GWT.create(ShellUiBinder.class);
@UiField
@@ -54,6 +64,11 @@
TableRowElement header;
@UiField
ListBox users;
+ @UiField
+ TextBox purpose;
+ @UiField
+ Button save;
+ private List<Values<Report>> values;
public Shell() {
initWidget(uiBinder.createAndBindUi(this));
@@ -64,12 +79,38 @@
throw new UnsupportedOperationException();
}
+ public List<Values<Report>> getValues() {
+ return values;
+ }
+
+ @UiHandler("purpose")
+ public void onPurposeChange(ValueChangeEvent<String> e) {
+ listener.setFirstPurpose(e.getValue());
+ }
+
+ @UiHandler("save")
+ public void onSaveClick(ClickEvent e) {
+ listener.setFirstPurpose(purpose.getValue());
+ }
+
+ public void setListener(Listener listener) {
+ this.listener = listener;
+ }
+
public void setValueList(List<Values<Report>> newValues) {
+ this.values = newValues;
int r = 1; // skip header
NodeList<TableRowElement> tableRows = table.getRows();
+ purpose.setText("");
+ boolean enabled = newValues.size() > 0;
+ purpose.setEnabled(enabled);
+ save.setEnabled(enabled);
for (int i = 0; i < newValues.size(); i++) {
Values<Report> valueRow = newValues.get(i);
+ if (i == 0) {
+ purpose.setText(valueRow.get(Report.PURPOSE));
+ }
if (r < tableRows.getLength()) {
reuseRow(r, tableRows, valueRow);
} else {
@@ -101,7 +142,7 @@
}
private <T> String renderDate(Values<T> values, Property<T, Date>
property) {
- return
DateTimeFormat.getShortDateTimeFormat().format(values.get(property));
+ return
DateTimeFormat.getShortDateFormat().format(values.get(property));
}
/**
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.ui.xml
Wed Mar 10 14:02:29 2010
+++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.ui.xml
Fri Mar 12 09:35:24 2010
@@ -1,31 +1,29 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
-<ui:UiBinder
- xmlns:ui='urn:ui:com.google.gwt.uibinder'
- xmlns:g='urn:import:com.google.gwt.user.client.ui'
- xmlns:e='urn:import:com.google.gwt.sample.expenses.client'>
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:e='urn:import:com.google.gwt.sample.expenses.client'>
<ui:style>
.disabled {
- color: gray;
- }
-
+ color: gray;
+ }
+
table.reports td {
- border-width: 1px;
- padding: 1px;
- border-style: solid;
- background-color: white;
+ border-width: 1px;
+ padding: 1px;
+ border-style: solid;
+ background-color: white;
}
.error {
- position: absolute;
- width: 100%;
- text-align: center;
- background-color: red;
+ position: absolute;
+ width: 100%;
+ text-align: center;
+ background-color: red;
}
.users {
- position: absolute;
- right: 0;
+ position: absolute;
+ right: 0;
}
</ui:style>
@@ -57,6 +55,12 @@
<th align='left'>Purpose</th>
</tr>
</table>
+
+ <div>
+ Edit purpose of first report:
+ <g:TextBox ui:field='purpose' enabled='false'/>
+ <g:Button ui:field='save' enabled='false'>Save</g:Button>
+ </div>
</g:HTMLPanel>
</g:center>
</g:DockLayoutPanel>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/client/ValuesImpl.java
Wed Mar 10 14:23:14 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/client/ValuesImpl.java
Fri Mar 12 09:35:24 2010
@@ -60,6 +60,10 @@
return nativeGet(property);
}
+ public native void setString(Property<T, String> property, String value)
/*-{
+ this[proper...@com.google.gwt.valuestore.shared.property::getName()()]
= value;
+ }-*/;
+
public native T getPropertyHolder() /*-{
return this.propertyHolder;
}-*/;
@@ -84,4 +88,17 @@
private native <V, P extends Property<T, V>> V nativeGet(P property) /*-{
return
this[proper...@com.google.gwt.valuestore.shared.property::getName()()];
}-*/;
-}
+
+ /**
+ * @return
+ */
+ public native String toJson() /*-{
+ var output = "";
+ for (property in this) {
+ if (property != 'propertyHolder') {
+ output += '"' + property + '": ' + '"' + this[property] + '"'
+ '; ';
+ }
+ }
+ return output;
+ }-*/;
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRequests.java
Thu Mar 11 09:45:33 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRequests.java
Fri Mar 12 09:35:24 2010
@@ -60,6 +60,8 @@
if (200 == response.getStatusCode()) {
String text = response.getText();
JsArray<ValuesImpl<Employee>> valueArray =
ValuesImpl.arrayFromJson(text);
+ // Handy for FireBug snooping
+// Document.get().getBody().setPropertyJSO("foo", valueArray);
List<Values<Employee>> valueList = new
ArrayList<Values<Employee>>(
valueArray.length());
for (int i = 0; i < valueArray.length(); i++) {
@@ -85,7 +87,7 @@
// values.subscribe(watcher, future, properties);
}
-
+
public EntityListRequest<Employee> forProperty(
Property<Employee, ?> property) {
return this;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
Wed Mar 10 14:02:29 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
Fri Mar 12 09:35:24 2010
@@ -15,6 +15,12 @@
*/
package com.google.gwt.sample.expenses.shared;
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.sample.expenses.client.ValuesImpl;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasValueList;
import com.google.gwt.valuestore.shared.DeltaValueStore;
@@ -22,10 +28,12 @@
import com.google.gwt.valuestore.shared.ValueStore;
import com.google.gwt.valuestore.shared.Values;
+import java.util.List;
import java.util.Set;
/**
- * "Generated" factory for requests against
com.google.gwt.sample.expenses.domain.
+ * "Generated" factory for requests against
+ * com.google.gwt.sample.expenses.domain.
* <p>
* IRL would be an interface that was generated by a JPA-savvy script, and
the
* following implementation would in turn be generated by a call to
@@ -42,6 +50,7 @@
// TODO Auto-generated method stub
return null;
}
+
public <T, V> void subscribe(HasValue<V> watcher, T propertyOwner,
Property<T, V> property) {
// TODO Auto-generated method stub
@@ -49,32 +58,90 @@
public <T, V> void subscribe(HasValueList<Values<T>> watcher,
T propertyOwner, Set<Property<T, ?>> properties) {
- // TODO Auto-generated method stub
- }
-
+ // TODO Auto-generated method stub
+ }
+
};
public EmployeeRequests employeeRequest() {
return new EmployeeRequests(values);
}
-
+
public EmployeeRequests employeeRequest(DeltaValueStore deltas) {
return new EmployeeRequests(deltas);
}
-
+
public ValueStore getValueStore() {
return values;
}
-
+
public DeltaValueStore newDeltaStore() {
return values.edit();
}
-
+
public ReportRequests reportRequest() {
return new ReportRequests(values);
}
-
+
public ReportRequests reportRequest(DeltaValueStore deltas) {
return new ReportRequests(deltas);
}
-}
+
+ /**
+ * @param deltaValueStore
+ * @return
+ */
+ public SyncRequest syncRequest(final List<Values<Report>>
deltaValueStore) {
+ return new SyncRequest() {
+
+ public void fire() {
+
+ // TODO: need someway to track that this request has been issued
so that
+ // we don't issue another request that arrives while we are
waiting for
+ // the response.
+ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
+ "/expenses/data?methodName=" + MethodName.SYNC.name());
+
+ StringBuilder requestData = new StringBuilder("{");
+ boolean first = true;
+ for (Values<Report> values : deltaValueStore) {
+ ValuesImpl<Report> impl = (ValuesImpl<Report>)values;
+ if (first) {
+ first = false;
+ } else {
+ requestData.append(",");
+ }
+ requestData.append(impl.toJson());
+ }
+ requestData.append("}");
+
+ builder.setRequestData(requestData.toString());
+ builder.setCallback(new RequestCallback() {
+
+ public void onError(Request request, Throwable exception) {
+ // shell.error.setInnerText(SERVER_ERROR);
+ }
+
+ public void onResponseReceived(Request request, Response
response) {
+ if (200 == response.getStatusCode()) {
+ String text = response.getText();
+ } else {
+ // shell.error.setInnerText(SERVER_ERROR + " ("
+ // + response.getStatusText() + ")");
+ }
+ }
+ });
+
+ try {
+ builder.send();
+ } catch (RequestException e) {
+ // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
+ // ")");
+ }
+
+ // values.subscribe(watcher, future, properties);
+ }
+
+ };
+ }
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
Wed Mar 10 14:02:29 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
Fri Mar 12 09:35:24 2010
@@ -19,5 +19,5 @@
* Represents the MethodName.
*/
public enum MethodName {
- FIND_ALL_EMPLOYEES, FIND_EMPLOYEE, FIND_REPORTS_BY_EMPLOYEE,
-}
+ FIND_ALL_EMPLOYEES, FIND_EMPLOYEE, FIND_REPORTS_BY_EMPLOYEE, SYNC,
+}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/valuestore/shared/Values.java Thu
Mar 4 14:11:39 2010
+++ /trunk/bikeshed/src/com/google/gwt/valuestore/shared/Values.java Fri
Mar 12 09:35:24 2010
@@ -15,6 +15,7 @@
*/
package com.google.gwt.valuestore.shared;
+
/**
* Provides access to the values of an object managed by the {...@link
ValueStore}.
*
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors