Revision: 8136
Author: [email protected]
Date: Thu May 13 12:50:46 2010
Log: Introduces RequestEvent, useful for busy indicators
Review at http://gwt-code-reviews.appspot.com/527801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8136
Added:
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/shared/RequestEvent.java
Modified:
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/Scaffold.java
=======================================
--- /dev/null
+++
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/shared/RequestEvent.java
Thu May 13 12:50:46 2010
@@ -0,0 +1,57 @@
+/*
+ * 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.requestfactory.shared;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * An event posted whenever an RPC request is sent or its response is
received.
+ */
+public class RequestEvent extends GwtEvent<RequestEvent.Handler> {
+ /**
+ * Implemented by handlers of this type of event.
+ */
+ public interface Handler extends EventHandler {
+ void onRequestEvent(RequestEvent requestEvent);
+ }
+
+ public enum State {
+ SENT, RECEIVED
+ }
+
+ private final State state;
+
+ public static final Type<Handler> TYPE = new Type<Handler>();
+
+ public RequestEvent(State state) {
+ this.state = state;
+ }
+
+ @Override
+ public GwtEvent.Type<Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ @Override
+ protected void dispatch(Handler handler) {
+ handler.onRequestEvent(this);
+ }
+}
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Tue May 11 18:52:23 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Thu May 13 12:50:46 2010
@@ -23,9 +23,11 @@
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.requestfactory.shared.Receiver;
+import com.google.gwt.requestfactory.shared.RequestEvent;
import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.requestfactory.shared.SyncRequest;
import com.google.gwt.requestfactory.shared.SyncResult;
+import com.google.gwt.requestfactory.shared.RequestEvent.State;
import com.google.gwt.requestfactory.shared.impl.RequestDataManager;
import com.google.gwt.valuestore.client.DeltaValueStoreJsonImpl;
import com.google.gwt.valuestore.client.ValueStoreJsonImpl;
@@ -39,12 +41,14 @@
public abstract class RequestFactoryJsonImpl implements RequestFactory {
private ValueStoreJsonImpl valueStore;
+ private HandlerManager handlerManager;
/**
* @param handlerManager
*/
protected void init(HandlerManager handlerManager, RecordToTypeMap map) {
this.valueStore = new ValueStoreJsonImpl(handlerManager, map);
+ this.handlerManager = handlerManager;
}
public void fire(final RequestObject<?> requestObject) {
@@ -54,6 +58,7 @@
builder.setCallback(new RequestCallback() {
public void onError(Request request, Throwable exception) {
+ postRequestEvent(State.RECEIVED);
// shell.error.setInnerText(SERVER_ERROR);
}
@@ -65,12 +70,14 @@
// shell.error.setInnerText(SERVER_ERROR + " ("
// + response.getStatusText() + ")");
}
+ postRequestEvent(State.RECEIVED);
}
});
try {
builder.send();
+ postRequestEvent(State.SENT);
} catch (RequestException e) {
// shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage() +
// ")");
@@ -99,6 +106,7 @@
builder.setCallback(new RequestCallback() {
public void onError(Request request, Throwable exception) {
+ postRequestEvent(State.RECEIVED);
// shell.error.setInnerText(SERVER_ERROR);
}
@@ -110,11 +118,13 @@
// shell.error.setInnerText(SERVER_ERROR + " ("
// + response.getStatusText() + ")");
}
+ postRequestEvent(State.RECEIVED);
}
});
try {
builder.send();
+ postRequestEvent(State.SENT);
} catch (RequestException e) {
// shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
// ")");
@@ -127,4 +137,8 @@
}
};
}
-}
+
+ private void postRequestEvent(State received) {
+ handlerManager.fireEvent(new RequestEvent(received));
+ }
+}
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/Scaffold.java
Tue May 4 17:35:40 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/Scaffold.java
Thu May 13 12:50:46 2010
@@ -25,6 +25,8 @@
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.shared.HandlerManager;
+import com.google.gwt.requestfactory.shared.RequestEvent;
+import com.google.gwt.requestfactory.shared.RequestEvent.State;
import com.google.gwt.sample.expenses.gwt.client.place.ListScaffoldPlace;
import com.google.gwt.sample.expenses.gwt.client.place.ScaffoldPlace;
import
com.google.gwt.sample.expenses.gwt.request.ExpensesEntityTypesProcessor;
@@ -38,11 +40,11 @@
import java.util.Collections;
import java.util.List;
+
/**
* Application for browsing the entities of the Expenses app.
*/
public class Scaffold implements EntryPoint {
-
public void onModuleLoad() {
/* App controllers and services */
@@ -53,6 +55,16 @@
final PlaceController<ScaffoldPlace> placeController = new
PlaceController<ScaffoldPlace>(
eventBus);
+ eventBus.addHandler(RequestEvent.TYPE, new RequestEvent.Handler() {
+ public void onRequestEvent(RequestEvent requestEvent) {
+ if (requestEvent.getState() == State.SENT) {
+ // TODO jaimeyap
+ } else {
+ // TODO jaimeyap
+ }
+ }
+ });
+
/* Top level UI */
final ScaffoldShell shell = new ScaffoldShell();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors