Revision: 8558
Author: [email protected]
Date: Tue Aug 17 11:40:14 2010
Log: Allows subclasses to take control of exit points in
AbstractRecordListActivity and AbstractRecordEditActivity
https://jira.springsource.org/browse/ROO-1225
https://jira.springsource.org/browse/ROO-1226
https://jira.springsource.org/browse/ROO-1227
Review at http://gwt-code-reviews.appspot.com/771802
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8558
Modified:
/trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
/trunk/user/src/com/google/gwt/app/place/AbstractRecordListActivity.java
=======================================
---
/trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
Mon Aug 16 20:22:31 2010
+++
/trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
Tue Aug 17 11:40:14 2010
@@ -70,16 +70,16 @@
if ((unsavedChangesWarning == null)
|| Window.confirm(unsavedChangesWarning)) {
if (requestObject != null) {
- requestObject.reset(); // silence the next mayStop() call when
place
- }
- // changes
- if (creating) {
- display.showActivityWidget(null);
- } else {
- exit();
- }
+ // silence the next mayStop() call when place changes
+ requestObject.reset();
+ }
+ exit(false);
}
}
+
+ public R getRecord() {
+ return record;
+ }
public String mayStop() {
if (requestObject != null && requestObject.isChanged()) {
@@ -113,10 +113,10 @@
return;
}
boolean hasViolations = false;
-
- // TODO(amit) at the moment we only get one response, and futures
are buggy.
- // So forcing the issue for now, but the more code involved may
have to come back
- // when bugs are fixed
+
+ // TODO(amit) at the moment we only get one response, and futures
are
+ // buggy. So forcing the issue for now, but the more involved code
may
+ // have to come back when bugs are fixed
assert response.size() == 1;
SyncResult syncResult = response.iterator().next();
record = cast(syncResult.getRecord());
@@ -124,25 +124,25 @@
hasViolations = true;
view.showErrors(syncResult.getViolations());
}
-// for (SyncResult syncResult : response) {
-// Record syncRecord = syncResult.getRecord();
-// if (creating) {
-// if (futureId == null |
| !futureId.equals(syncResult.getFutureId())) {
-// continue;
-// }
-// record = cast(syncRecord);
-// } else {
-// if (!syncRecord.getId().equals(record.getId())) {
-// continue;
-// }
-// }
-// if (syncResult.hasViolations()) {
-// hasViolations = true;
-// view.showErrors(syncResult.getViolations());
-// }
-// }
+ // for (SyncResult syncResult : response) {
+ // Record syncRecord = syncResult.getRecord();
+ // if (creating) {
+ // if (futureId == null |
| !futureId.equals(syncResult.getFutureId())) {
+ // continue;
+ // }
+ // record = cast(syncRecord);
+ // } else {
+ // if (!syncRecord.getId().equals(record.getId())) {
+ // continue;
+ // }
+ // }
+ // if (syncResult.hasViolations()) {
+ // hasViolations = true;
+ // view.showErrors(syncResult.getViolations());
+ // }
+ // }
if (!hasViolations) {
- exit();
+ exit(true);
} else {
requestObject = toCommit;
requestObject.clearUsed();
@@ -165,7 +165,7 @@
futureId = tempRecord.getId();
doStart(display, tempRecord);
} else {
- fireFindRequest(Value.of(record.getId()), new Receiver<R>() {
+ fireFindRequest(Value.of(getRecord().getId()), new Receiver<R>() {
public void onSuccess(R record, Set<SyncResult> syncResults) {
if (AbstractRecordEditActivity.this.display != null) {
doStart(AbstractRecordEditActivity.this.display, record);
@@ -174,6 +174,24 @@
});
}
}
+
+ /**
+ * Called when the user cancels or has successfully saved. This default
+ * implementation tells the {...@link PlaceController} to show the details
of the
+ * edited record, or clears the display if a creation was canceled.
+ * <p>
+ * If we're creating, a call to getRecord() from here will return a
record
+ * with the correct id. However, other properties may be stale or unset.
+ *
+ * @param saved true if changes were comitted
+ */
+ protected void exit(boolean saved) {
+ if (!saved && creating) {
+ display.showActivityWidget(null);
+ } else {
+ placeController.goTo(new ProxyPlace(getRecord(), Operation.DETAILS));
+ }
+ }
/**
* Called to fetch the details of the edited record.
@@ -195,11 +213,4 @@
view.showErrors(null);
display.showActivityWidget(view);
}
-
- /**
- * Called when the user has clicked Cancel or has successfully saved.
- */
- private void exit() {
- placeController.goTo(new ProxyPlace(record, Operation.DETAILS));
- }
-}
+}
=======================================
---
/trunk/user/src/com/google/gwt/app/place/AbstractRecordListActivity.java
Tue Aug 17 10:14:36 2010
+++
/trunk/user/src/com/google/gwt/app/place/AbstractRecordListActivity.java
Tue Aug 17 11:40:14 2010
@@ -1,12 +1,12 @@
/*
* 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
@@ -47,19 +47,19 @@
* Abstract activity for requesting and displaying a list of {...@link
Record}.
* <p>
* Subclasses must:
- *
+ *
* <ul>
* <li>implement methods to provide a full count, and request a specific
* <li>provide a {...@link RecordListView}
* <li>respond to "show details" commands
* </ul>
- *
+ *
* Only the properties required by the view will be requested.
- *
+ *
* @param <R> the type of {...@link Record} listed
*/
-public abstract class AbstractRecordListActivity<R extends Record>
- implements Activity, RecordListView.Delegate<R> {
+public abstract class AbstractRecordListActivity<R extends Record>
implements
+ Activity, RecordListView.Delegate<R> {
/**
* Used by the table and its selection model, to define record equality
via
* id.
@@ -101,12 +101,11 @@
view.setDelegate(this);
final HasData<R> hasData = view.asHasData();
- rangeChangeHandler = hasData.addRangeChangeHandler(
- new RangeChangeEvent.Handler() {
- public void onRangeChange(RangeChangeEvent event) {
- AbstractRecordListActivity.this.onRangeChanged(hasData);
- }
- });
+ rangeChangeHandler = hasData.addRangeChangeHandler(new
RangeChangeEvent.Handler() {
+ public void onRangeChange(RangeChangeEvent event) {
+ AbstractRecordListActivity.this.onRangeChanged(hasData);
+ }
+ });
selectionModel = new SingleSelectionModel<R>();
selectionModel.setKeyProvider(keyProvider);
@@ -223,6 +222,16 @@
protected abstract RecordListRequest<R> createRangeRequest(Range range);
protected abstract void fireCountRequest(Receiver<Long> callback);
+
+ /**
+ * Called when the user chooses a record to view. This default
implementation
+ * sends the {...@link PlaceController} to an appropriate {...@link
ProxyPlace}.
+ *
+ * @param record the chosen record
+ */
+ protected void showDetails(R record) {
+ placeController.goTo(new ProxyPlace(record, Operation.DETAILS));
+ }
private void getLastPage() {
fireCountRequest(new Receiver<Long>() {
@@ -255,10 +264,6 @@
private void selectCoerced(Place newPlace) {
select((R) ((ProxyPlace) newPlace).getProxy());
}
-
- private void showDetails(R record) {
- placeController.goTo(new ProxyPlace(record, Operation.DETAILS));
- }
private void update(R record) {
Integer row = recordToRow.get(record.getId());
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors