Revision: 10185
Author: [email protected]
Date: Fri May 13 12:07:34 2011
Log: First example of a View that kicks off its own presenter as
needed. Part way toward separating presenters from activities, and
making all views self inject their presenters. When we're done, we'll
have proper MVP separation, but will be able to assemble widgets
directly without having to think about their presenters: presenter as
widget implementation detail, and still completely JRE safe.
Activities no longer know about PlaceController. Instead they post
events when they are done. Clearly we need to make it easier to
declare new types of events with less boilerplate.
Review at http://gwt-code-reviews.appspot.com/1446806
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=10185
Added:
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ProvidesPresenter.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/MainMenuItem.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/AddTaskEvent.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/EditingCanceledEvent.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/GoHomeEvent.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/ShowTaskEvent.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/TaskSavedEvent.java
Deleted:
/trunk/samples/mobilewebapp/war/WEB-INF/classes
Modified:
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/App.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImplMobile.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImplTablet.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskEditActivity.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskListActivity.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskListView.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/DesktopTaskListView.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/MobileWebAppShellDesktop.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/mobile/MobileTaskListView.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/mobile/MobileWebAppShellMobile.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/place/TaskEditPlace.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/place/TaskListPlace.java
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/tablet/MobileWebAppShellTablet.java
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ProvidesPresenter.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client;
+
+/**
+ * Provides the presenter to run a given view for a new session.
+ *
+ * @param <P> the presenter type
+ * @param <V> the view type
+ */
+public interface ProvidesPresenter<P, V> {
+ P getPresenter(V view);
+}
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/MainMenuItem.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client.desktop;
+
+import com.google.gwt.cell.client.AbstractCell;
+import com.google.gwt.place.shared.Place;
+import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
+
+/**
+ * An item in the main menu that maps to a specific place.
+ */
+ class MainMenuItem {
+ /**
+ * The cell used to render a {@link MainMenuItem}.
+ */
+ static class Cell extends AbstractCell<MainMenuItem> {
+
+ @Override
+ public void render(com.google.gwt.cell.client.Cell.Context context,
MainMenuItem value,
+ SafeHtmlBuilder sb) {
+ if (value == null) {
+ return;
+ }
+ sb.appendEscaped(value.getName());
+ }
+ }
+ private final String name;
+
+ private final Place place;
+
+ /**
+ * Construct a new {@link MainMenuItem}.
+ *
+ * @param name the display name
+ * @param place the place to open when selected
+ */
+ public MainMenuItem(String name, Place place) {
+ this.name = name;
+ this.place = place;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Place getPlace() {
+ return place;
+ }
+ /**
+ * Check whether or not this {@link MainMenuItem} maps to the specified
+ * place.
+ *
+ * @param p a {@link Place}
+ * @return true if this menu item maps to the place, false if not
+ */
+ public boolean mapsToPlace(Place p) {
+ return place == p;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/AddTaskEvent.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client.event;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * Fired when the user wants a new task.
+ */
+public class AddTaskEvent extends GwtEvent<AddTaskEvent.Handler> {
+
+ /**
+ * Implemented by objects that handle {@link AddTaskEvent}.
+ */
+ public interface Handler extends EventHandler {
+ void onAddTask(AddTaskEvent event);
+ }
+
+ /**
+ * The event type.
+ */
+ public static final Type<AddTaskEvent.Handler> TYPE = new
Type<AddTaskEvent.Handler>();
+
+ @Override
+ public final Type<AddTaskEvent.Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(AddTaskEvent.Handler handler) {
+ handler.onAddTask(this);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/EditingCanceledEvent.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client.event;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * Fired when the user abandons edits of a task.
+ */
+public class EditingCanceledEvent extends
GwtEvent<EditingCanceledEvent.Handler> {
+
+ /**
+ * Implemented by objects that handle {@link EditingCanceledEvent}.
+ */
+ public interface Handler extends EventHandler {
+ void onEditCanceled(EditingCanceledEvent event);
+ }
+
+ /**
+ * The event type.
+ */
+ public static final Type<EditingCanceledEvent.Handler> TYPE = new
Type<EditingCanceledEvent.Handler>();
+
+ @Override
+ public final Type<EditingCanceledEvent.Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(EditingCanceledEvent.Handler handler) {
+ handler.onEditCanceled(this);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/GoHomeEvent.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client.event;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * Fired when the user wants to return to the main screen of the app.
+ */
+public class GoHomeEvent extends GwtEvent<GoHomeEvent.Handler> {
+
+ /**
+ * Implemented by objects that handle {@link GoHomeEvent}.
+ */
+ public interface Handler extends EventHandler {
+ void onGoHome(GoHomeEvent event);
+ }
+
+ /**
+ * The event type.
+ */
+ public static final Type<GoHomeEvent.Handler> TYPE = new
Type<GoHomeEvent.Handler>();
+
+ @Override
+ public final Type<GoHomeEvent.Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(GoHomeEvent.Handler handler) {
+ handler.onGoHome(this);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/ShowTaskEvent.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client.event;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
+
+/**
+ * Fired when the user wants to see a task.
+ */
+public class ShowTaskEvent extends GwtEvent<ShowTaskEvent.Handler> {
+
+ /**
+ * Implemented by objects that handle {@link ShowTaskEvent}.
+ */
+ public interface Handler extends EventHandler {
+ void onShowTask(ShowTaskEvent event);
+ }
+
+ private final TaskProxy task;
+
+ /**
+ * The event type.
+ */
+ public static final Type<ShowTaskEvent.Handler> TYPE = new
Type<ShowTaskEvent.Handler>();
+
+ public ShowTaskEvent(TaskProxy task) {
+ this.task = task;
+ }
+
+ @Override
+ public final Type<ShowTaskEvent.Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ /**
+ * Get the task to edit.
+ *
+ * @return the task to edit, or null if not available
+ */
+ public TaskProxy getTask() {
+ return task;
+ }
+
+ @Override
+ protected void dispatch(ShowTaskEvent.Handler handler) {
+ handler.onShowTask(this);
+ }
+}
=======================================
--- /dev/null
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/event/TaskSavedEvent.java
Fri May 13 12:07:34 2011
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2011 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.mobilewebapp.client.event;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * Fired when the user has saved a task.
+ */
+public class TaskSavedEvent extends GwtEvent<TaskSavedEvent.Handler> {
+
+ /**
+ * Implemented by objects that handle {@link TaskSavedEvent}.
+ */
+ public interface Handler extends EventHandler {
+ void onTaskSaved(TaskSavedEvent event);
+ }
+
+ /**
+ * The event type.
+ */
+ public static final Type<TaskSavedEvent.Handler> TYPE = new
Type<TaskSavedEvent.Handler>();
+
+ @Override
+ public final Type<TaskSavedEvent.Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(TaskSavedEvent.Handler handler) {
+ handler.onTaskSaved(this);
+ }
+}
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/App.java
Mon May 9 10:55:18 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/App.java
Fri May 13 12:07:34 2011
@@ -23,8 +23,15 @@
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import
com.google.gwt.sample.gaerequest.client.ReloadOnAuthenticationFailure;
+import com.google.gwt.sample.mobilewebapp.client.event.AddTaskEvent;
+import
com.google.gwt.sample.mobilewebapp.client.event.EditingCanceledEvent;
+import com.google.gwt.sample.mobilewebapp.client.event.GoHomeEvent;
+import com.google.gwt.sample.mobilewebapp.client.event.ShowTaskEvent;
+import com.google.gwt.sample.mobilewebapp.client.event.TaskSavedEvent;
import
com.google.gwt.sample.mobilewebapp.client.place.AppPlaceHistoryMapper;
+import com.google.gwt.sample.mobilewebapp.client.place.TaskEditPlace;
import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
+import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import com.google.gwt.storage.client.Storage;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasWidgets;
@@ -81,11 +88,47 @@
public void run(HasWidgets.ForIsWidget parentView) {
parentView.add(shell);
+ eventBus.addHandler(AddTaskEvent.TYPE, new AddTaskEvent.Handler() {
+ @Override
+ public void onAddTask(AddTaskEvent event) {
+ placeController.goTo(TaskEditPlace.getTaskCreatePlace());
+ }
+ });
+
+ eventBus.addHandler(ShowTaskEvent.TYPE, new ShowTaskEvent.Handler() {
+ @Override
+ public void onShowTask(ShowTaskEvent event) {
+ TaskProxy task = event.getTask();
+
placeController.goTo(TaskEditPlace.createTaskEditPlace(task.getId(), task));
+ }
+ });
+
+ eventBus.addHandler(GoHomeEvent.TYPE, new GoHomeEvent.Handler() {
+ @Override
+ public void onGoHome(GoHomeEvent event) {
+ placeController.goTo(new TaskListPlace(false));
+ }
+ });
+
+ eventBus.addHandler(TaskSavedEvent.TYPE, new TaskSavedEvent.Handler() {
+ @Override
+ public void onTaskSaved(TaskSavedEvent event) {
+ placeController.goTo(new TaskListPlace(true));
+ }
+ });
+
+ eventBus.addHandler(EditingCanceledEvent.TYPE, new
EditingCanceledEvent.Handler() {
+ @Override
+ public void onEditCanceled(EditingCanceledEvent event) {
+ placeController.goTo(new TaskListPlace(false));
+ }
+ });
+
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void onUncaughtException(Throwable e) {
while (e instanceof UmbrellaException) {
- e = ((UmbrellaException)e).getCauses().iterator().next();
+ e = ((UmbrellaException) e).getCauses().iterator().next();
}
Window.alert("An unexpected error occurred: " + e.getMessage());
placeController.goTo(new TaskListPlace(false));
@@ -105,7 +148,7 @@
private void initBrowserHistory(final AppPlaceHistoryMapper
historyMapper,
PlaceHistoryHandler historyHandler, TaskListPlace defaultPlace) {
- Place savedPlace = defaultPlace;
+ Place savedPlace = null;
if (storage != null) {
try {
// wrap in try-catch in case stored value is invalid
@@ -114,6 +157,9 @@
// ignore error and use the default-default
}
}
+ if (savedPlace == null) {
+ savedPlace = defaultPlace;
+ }
historyHandler.register(placeController, eventBus, savedPlace);
/*
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImplMobile.java
Tue May 10 20:04:34 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImplMobile.java
Fri May 13 12:07:34 2011
@@ -16,7 +16,9 @@
package com.google.gwt.sample.mobilewebapp.client;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskEditView;
+import com.google.gwt.sample.mobilewebapp.client.activity.TaskListActivity;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
+import
com.google.gwt.sample.mobilewebapp.client.activity.TaskListView.Presenter;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskReadView;
import com.google.gwt.sample.mobilewebapp.client.mobile.MobileTaskEditView;
import com.google.gwt.sample.mobilewebapp.client.mobile.MobileTaskListView;
@@ -24,6 +26,8 @@
import
com.google.gwt.sample.mobilewebapp.client.mobile.MobileWebAppShellMobile;
import com.google.gwt.sample.mobilewebapp.client.ui.OrientationHelper;
import
com.google.gwt.sample.mobilewebapp.client.ui.WindowBasedOrientationHelper;
+import com.google.gwt.user.client.ui.AcceptsOneWidget;
+import com.google.gwt.user.client.ui.IsWidget;
/**
* Mobile version of {@link ClientFactory}.
@@ -34,7 +38,7 @@
@Override
protected MobileWebAppShell createShell() {
return new MobileWebAppShellMobile(orientationHelper,
getTaskListView(),
- getTaskEditView(), getTaskReadView(), getPlaceController());
+ getTaskEditView(), getTaskReadView(), getEventBus());
}
@Override
@@ -44,7 +48,21 @@
@Override
protected TaskListView createTaskListView() {
- return new MobileTaskListView();
+ ProvidesPresenter<TaskListView.Presenter, TaskListView> factory =
+ new ProvidesPresenter<TaskListView.Presenter, TaskListView>() {
+ @Override
+ public Presenter getPresenter(TaskListView view) {
+ TaskListActivity taskListActivity = new
TaskListActivity(ClientFactoryImplMobile.this, false);
+ taskListActivity.start(new AcceptsOneWidget() {
+ @Override
+ public void setWidget(IsWidget w) {
+ // No op until we separate presenter and activity
+ }
+ }, getEventBus());
+ return taskListActivity;
+ }
+ };
+ return new MobileTaskListView(factory);
}
@Override
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImplTablet.java
Mon May 9 10:25:15 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImplTablet.java
Fri May 13 12:07:34 2011
@@ -16,9 +16,7 @@
package com.google.gwt.sample.mobilewebapp.client;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskEditView;
-import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskReadView;
-import com.google.gwt.sample.mobilewebapp.client.mobile.MobileTaskListView;
import
com.google.gwt.sample.mobilewebapp.client.tablet.MobileWebAppShellTablet;
import com.google.gwt.sample.mobilewebapp.client.tablet.TabletTaskEditView;
import com.google.gwt.sample.mobilewebapp.client.tablet.TabletTaskReadView;
@@ -28,25 +26,18 @@
/**
* Tablet version of {@link ClientFactory}.
*/
-public class ClientFactoryImplTablet extends ClientFactoryImpl {
+public class ClientFactoryImplTablet extends ClientFactoryImplMobile {
private final OrientationHelper orientationHelper = new
WindowBasedOrientationHelper();
@Override
protected MobileWebAppShell createShell() {
- return new MobileWebAppShellTablet(getEventBus(), orientationHelper,
getPlaceController(),
- getTaskListActivityProvider(), getTaskListView());
+ return new MobileWebAppShellTablet(getEventBus(), orientationHelper,
getTaskListView());
}
@Override
protected TaskEditView createTaskEditView() {
return new TabletTaskEditView();
}
-
- @Override
- protected TaskListView createTaskListView() {
- // Use the mobile list view on tablets.
- return new MobileTaskListView();
- }
@Override
protected TaskReadView createTaskReadView() {
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskEditActivity.java
Tue May 10 20:04:34 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskEditActivity.java
Fri May 13 12:07:34 2011
@@ -18,8 +18,9 @@
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.sample.mobilewebapp.client.ClientFactory;
+import
com.google.gwt.sample.mobilewebapp.client.event.EditingCanceledEvent;
+import com.google.gwt.sample.mobilewebapp.client.event.TaskSavedEvent;
import com.google.gwt.sample.mobilewebapp.client.place.TaskEditPlace;
-import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
import com.google.gwt.sample.mobilewebapp.client.ui.SoundEffects;
import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import com.google.gwt.sample.mobilewebapp.shared.TaskRequest;
@@ -177,7 +178,7 @@
TaskEditActivity.this.notify("Task Saved");
// Return to the task list.
- clientFactory.getPlaceController().goTo(new TaskListPlace(true));
+ clientFactory.getEventBus().fireEvent(new TaskSavedEvent());
}
});
}
@@ -249,7 +250,7 @@
* Cancel the current task.
*/
private void doCancelTask() {
- clientFactory.getPlaceController().goTo(new TaskListPlace(false));
+ clientFactory.getEventBus().fireEvent(new EditingCanceledEvent());
}
/**
@@ -306,6 +307,6 @@
notify("Task Deleted");
// Return to the task list.
- clientFactory.getPlaceController().goTo(new TaskListPlace(true));
+ clientFactory.getEventBus().fireEvent(new TaskSavedEvent());
}
}
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskListActivity.java
Fri May 13 14:17:46 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskListActivity.java
Fri May 13 12:07:34 2011
@@ -22,7 +22,8 @@
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.sample.mobilewebapp.client.ClientFactory;
-import com.google.gwt.sample.mobilewebapp.client.place.TaskEditPlace;
+import com.google.gwt.sample.mobilewebapp.client.event.AddTaskEvent;
+import com.google.gwt.sample.mobilewebapp.client.event.ShowTaskEvent;
import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import com.google.gwt.user.client.Timer;
@@ -102,7 +103,7 @@
*/
private final ClickHandler addButtonHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
-
clientFactory.getPlaceController().goTo(TaskEditPlace.getTaskCreatePlace());
+ clientFactory.getEventBus().fireEvent(new AddTaskEvent());
}
};
@@ -125,6 +126,11 @@
*/
private Timer refreshTimer;
+ public TaskListActivity(ClientFactory clientFactory, boolean
clearTaskList) {
+ this.clientFactory = clientFactory;
+ this.clearTaskList = clearTaskList;
+ }
+
/**
* Construct a new {@link TaskListActivity}.
*
@@ -134,11 +140,6 @@
public TaskListActivity(ClientFactory clientFactory, TaskListPlace
place) {
this(clientFactory, place.isTaskListStale());
}
-
- public TaskListActivity(ClientFactory clientFactory, boolean
clearTaskList) {
- this.clientFactory = clientFactory;
- this.clearTaskList = clearTaskList;
- }
public ClickHandler getAddButtonHandler() {
return addButtonHandler;
@@ -156,8 +157,7 @@
public void selectTask(TaskProxy selected) {
// Go into edit mode when a task is selected.
- clientFactory.getPlaceController().goTo(
- TaskEditPlace.createTaskEditPlace(selected.getId(), selected));
+ clientFactory.getEventBus().fireEvent(new ShowTaskEvent(selected));
}
public void start(AcceptsOneWidget container, EventBus eventBus) {
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskListView.java
Tue May 3 10:43:13 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskListView.java
Fri May 13 12:07:34 2011
@@ -30,6 +30,11 @@
*/
public static interface Presenter {
+ /**
+ * View was told to stop. Don't really expect to submit this.
+ */
+ void onStop();
+
/**
* Select a task.
*
@@ -56,4 +61,14 @@
* @param tasks the list of tasks
*/
void setTasks(List<TaskProxy> tasks);
-}
+
+ /**
+ * Start a new session of this view.
+ */
+ void start();
+
+ /**
+ * Stop it!
+ */
+ void stop();
+}
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/DesktopTaskListView.java
Fri May 6 08:20:47 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/DesktopTaskListView.java
Fri May 13 12:07:34 2011
@@ -1,12 +1,12 @@
/*
* Copyright 2011 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
@@ -17,6 +17,8 @@
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
+import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
@@ -28,8 +30,6 @@
import com.google.gwt.view.client.NoSelectionModel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionModel;
-import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
-import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import java.util.Date;
import java.util.List;
@@ -42,14 +42,14 @@
/**
* The UiBinder interface.
*/
- interface DesktopTaskListViewUiBinder extends
- UiBinder<Widget, DesktopTaskListView> {
+ interface DesktopTaskListViewUiBinder extends UiBinder<Widget,
DesktopTaskListView> {
}
/**
* The UiBinder used to generate the view.
*/
- private static DesktopTaskListViewUiBinder uiBinder =
GWT.create(DesktopTaskListViewUiBinder.class);
+ private static DesktopTaskListViewUiBinder uiBinder =
+ GWT.create(DesktopTaskListViewUiBinder.class);
/**
* Displays the list of tasks.
@@ -66,6 +66,7 @@
* Construct a new {@link DesktopTaskListView}.
*/
public DesktopTaskListView() {
+
// Create the CellTable.
taskList = new CellTable<TaskProxy>();
taskList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
@@ -90,8 +91,7 @@
taskList.addColumn(notesColumn, "Description");
// Add the task due date column.
- Column<TaskProxy, Date> dateColumn = new Column<TaskProxy, Date>(
- new DateCell()) {
+ Column<TaskProxy, Date> dateColumn = new Column<TaskProxy, Date>(new
DateCell()) {
@Override
public Date getValue(TaskProxy object) {
return (object == null) ? null : object.getDueDate();
@@ -132,4 +132,16 @@
public void setTasks(List<TaskProxy> tasks) {
taskList.setRowData(tasks);
}
-}
+
+ @Override
+ public void start() {
+ //TODO
+ throw new UnsupportedOperationException("Auto-generated method stub");
+ }
+
+ @Override
+ public void stop() {
+ //TODO
+ throw new UnsupportedOperationException("Auto-generated method stub");
+ }
+}
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/MobileWebAppShellDesktop.java
Tue May 10 20:04:34 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/desktop/MobileWebAppShellDesktop.java
Fri May 13 12:07:34 2011
@@ -16,7 +16,6 @@
package com.google.gwt.sample.mobilewebapp.client.desktop;
import com.google.gwt.canvas.dom.client.CssColor;
-import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.VideoElement;
@@ -26,7 +25,6 @@
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceChangeEvent;
import com.google.gwt.place.shared.PlaceController;
-import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.sample.mobilewebapp.client.MobileWebAppShell;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskEditView;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskListActivity;
@@ -88,59 +86,6 @@
@Source({"MainMenuCellList.css", CellList.Style.DEFAULT_CSS})
MainMenuStyle cellListStyle();
}
-
- /**
- * An item in the main menu that maps to a specific place.
- */
- private static class MainMenuItem {
- private final String name;
- private final Place place;
-
- /**
- * Construct a new {@link MainMenuItem}.
- *
- * @param name the display name
- * @param place the place to open when selected
- */
- public MainMenuItem(String name, Place place) {
- this.name = name;
- this.place = place;
- }
-
- public String getName() {
- return name;
- }
-
- public Place getPlace() {
- return place;
- }
-
- /**
- * Check whether or not this {@link MainMenuItem} maps to the specified
- * place.
- *
- * @param p a {@link Place}
- * @return true if this menu item maps to the place, false if not
- */
- public boolean mapsToPlace(Place p) {
- return place == p;
- }
- }
-
- /**
- * The cell used to render a {@link MainMenuItem}.
- */
- private static class MainMenuItemCell extends AbstractCell<MainMenuItem>
{
-
- @Override
- public void render(com.google.gwt.cell.client.Cell.Context context,
MainMenuItem value,
- SafeHtmlBuilder sb) {
- if (value == null) {
- return;
- }
- sb.appendEscaped(value.getName());
- }
- }
/**
* The URL attribute that determines whether or not to include the pie
chart.
@@ -209,7 +154,7 @@
// Initialize the main menu.
Resources resources = GWT.create(Resources.class);
- mainMenu = new CellList<MainMenuItem>(new MainMenuItemCell(),
resources);
+ mainMenu = new CellList<MainMenuItem>(new MainMenuItem.Cell(),
resources);
mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// We don't expect to have more than 30 menu items.
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/mobile/MobileTaskListView.java
Fri May 6 08:20:47 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/mobile/MobileTaskListView.java
Fri May 13 12:07:34 2011
@@ -16,6 +16,9 @@
package com.google.gwt.sample.mobilewebapp.client.mobile;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.sample.mobilewebapp.client.ProvidesPresenter;
+import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
+import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellList;
@@ -25,8 +28,6 @@
import com.google.gwt.view.client.NoSelectionModel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionModel;
-import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
-import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
import java.util.List;
@@ -34,7 +35,6 @@
* View used to display the list of Tasks.
*/
public class MobileTaskListView extends Composite implements TaskListView {
-
/**
* Resources used by the mobile CellList.
*/
@@ -42,6 +42,7 @@
@Source({CellList.Style.DEFAULT_CSS, "MobileCellList.css"})
CellListStyle cellListStyle();
}
+
/**
* Styles used by the mobile CellList.
@@ -55,6 +56,11 @@
interface MobileTaskListViewUiBinder extends
UiBinder<Widget, MobileTaskListView> {
}
+
+ /**
+ * Provides a new presenter for each session with this view.
+ */
+ private final ProvidesPresenter<TaskListView.Presenter, TaskListView>
presenterFactory;
/**
* The UiBinder used to generate the view.
@@ -76,7 +82,9 @@
/**
* Construct a new {@link MobileTaskListView}.
*/
- public MobileTaskListView() {
+ public MobileTaskListView(ProvidesPresenter<TaskListView.Presenter,
TaskListView> presenterFactory) {
+ this.presenterFactory = presenterFactory;
+
// Create the CellList.
CellListResources cellListRes = GWT.create(CellListResources.class);
taskList = new CellList<TaskProxy>(new TaskProxyCell(), cellListRes);
@@ -118,4 +126,14 @@
public void setTasks(List<TaskProxy> tasks) {
taskList.setRowData(tasks);
}
-}
+
+ @Override
+ public void start() {
+ setPresenter(presenterFactory.getPresenter(this));
+ }
+
+ @Override
+ public void stop() {
+ presenter.onStop();
+ }
+}
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/mobile/MobileWebAppShellMobile.java
Tue May 10 20:04:34 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/mobile/MobileWebAppShellMobile.java
Fri May 13 12:07:34 2011
@@ -21,13 +21,13 @@
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.sample.mobilewebapp.client.MobileWebAppShell;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskEditView;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskReadView;
-import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
+import com.google.gwt.sample.mobilewebapp.client.event.GoHomeEvent;
import com.google.gwt.sample.mobilewebapp.client.ui.OrientationHelper;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
@@ -110,7 +110,7 @@
* Construct a new {@link MobileWebAppShellMobile}.
*/
public MobileWebAppShellMobile(OrientationHelper orientationHelper,
TaskListView taskListView,
- TaskEditView taskEditView, TaskReadView taskReadView, final
PlaceController placeController) {
+ TaskEditView taskEditView, TaskReadView taskReadView, final EventBus
eventBus) {
initWidget(uiBinder.createAndBindUi(this));
@@ -141,11 +141,11 @@
}
});
- // Return the the task list place when the title is clicked.
+ // Return to the task list when the title is clicked.
titleBar.addDomHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- placeController.goTo(new TaskListPlace(false));
+ eventBus.fireEvent(new GoHomeEvent());
}
}, ClickEvent.getType());
}
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/place/TaskEditPlace.java
Wed May 4 05:01:35 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/place/TaskEditPlace.java
Fri May 13 12:07:34 2011
@@ -17,6 +17,7 @@
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
+import com.google.gwt.place.shared.Prefix;
import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
/**
@@ -27,6 +28,7 @@
/**
* The tokenizer for this place.
*/
+ @Prefix("edit")
public static class Tokenizer implements PlaceTokenizer<TaskEditPlace> {
private static final String NO_ID = "create";
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/place/TaskListPlace.java
Tue May 3 10:43:13 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/place/TaskListPlace.java
Fri May 13 12:07:34 2011
@@ -17,6 +17,7 @@
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
+import com.google.gwt.place.shared.Prefix;
/**
* The place in the app that shows a list of tasks.
@@ -27,6 +28,7 @@
* The tokenizer for this place. TaskList doesn't have any state, so we
don't
* have anything to encode.
*/
+ @Prefix("tl")
public static class Tokenizer implements PlaceTokenizer<TaskListPlace> {
public TaskListPlace getPlace(String token) {
=======================================
---
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/tablet/MobileWebAppShellTablet.java
Tue May 10 20:04:34 2011
+++
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/tablet/MobileWebAppShellTablet.java
Fri May 13 12:07:34 2011
@@ -20,12 +20,11 @@
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.place.shared.PlaceController;
+import com.google.gwt.sample.mobilewebapp.client.ClientFactory;
import com.google.gwt.sample.mobilewebapp.client.MobileWebAppShell;
-import com.google.gwt.sample.mobilewebapp.client.Provider;
-import com.google.gwt.sample.mobilewebapp.client.activity.TaskListActivity;
import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
-import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
+import com.google.gwt.sample.mobilewebapp.client.event.AddTaskEvent;
+import com.google.gwt.sample.mobilewebapp.client.event.GoHomeEvent;
import com.google.gwt.sample.mobilewebapp.client.ui.OrientationHelper;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
@@ -41,6 +40,8 @@
/**
* Tablet version of the UI shell.
+ *
+ * TODO(rjrjr): this thing needs a presenter. Not an activity. A presenter.
*/
public class MobileWebAppShellTablet extends ResizeComposite implements
MobileWebAppShell {
@@ -101,32 +102,20 @@
*/
private boolean firstContentWidget = true;
- /**
- * The main task list, which is always visible.
- */
- private TaskListActivity taskListActivity;
-
- private final EventBus bus;
+ private final EventBus eventBus;
private final TaskListView taskListView;
- private final PlaceController placeController;
-
- private final Provider<TaskListActivity> taskListActivityProvider;
+ private boolean isShowingTaskList;
/**
* Construct a new {@link MobileWebAppShellTablet}.
*
* @param clientFactory the {@link ClientFactory} of shared resources
*/
- public MobileWebAppShellTablet(EventBus bus, OrientationHelper
orientationHelper,
- final PlaceController placeController, Provider<TaskListActivity>
taskListActivityProvider,
+ public MobileWebAppShellTablet(final EventBus eventBus,
OrientationHelper orientationHelper,
TaskListView taskListView) {
- this.bus = bus;
-
- this.placeController = placeController;
-
- this.taskListActivityProvider = taskListActivityProvider;
+ this.eventBus = eventBus;
this.taskListView = taskListView;
@@ -153,10 +142,10 @@
});
// Go to the task list place when the title is clicked.
- titleLabel.addClickHandler(new ClickHandler() {
+ titleLabel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- placeController.goTo(new TaskListPlace(false));
+ eventBus.fireEvent(new GoHomeEvent());
}
});
}
@@ -193,8 +182,13 @@
contentContainer.setWidget((content == null) ? contentEmptyMessage :
content);
// If the content is null and we are in landscape mode, show the add
button.
- if (content == null && taskListActivity != null) {
- setAddButtonHandler(taskListActivity.getAddButtonHandler());
+ if (content == null && isShowingTaskList) {
+ setAddButtonHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ eventBus.fireEvent(new AddTaskEvent());
+ }
+ });
}
// Do not animate the first time we show a widget.
@@ -209,12 +203,12 @@
splitPanel.setWidgetSize(taskListContainer,
LANDSCAPE_TASK_LIST_WIDTH_PCT);
// TODO(rjrjr) View managing activity is an abomination
- if (taskListActivity == null) {
- taskListActivity = taskListActivityProvider.get();
- taskListActivity.start(taskListContainer, bus);
-
+ if (!isShowingTaskList) {
+ taskListView.start();
+ taskListContainer.add(taskListView);
// DeckLayoutPanel sets the display to none, so we need to clear it.
taskListView.asWidget().getElement().getStyle().clearDisplay();
+ isShowingTaskList = true;
}
// Do not use animations when the task list is always visible.
@@ -228,9 +222,9 @@
private void onShiftToPortrait() {
// Hide the static task list view.
- if (taskListActivity != null) {
- taskListActivity.onStop();
- taskListActivity = null;
+ if (isShowingTaskList) {
+ taskListView.stop();
+ isShowingTaskList = false;
}
splitPanel.setWidgetSize(taskListContainer, 0);
@@ -247,9 +241,8 @@
// Ensure that something is displayed.
Widget curWidget = contentContainer.getVisibleWidget();
if (curWidget == null || curWidget == contentEmptyMessage) {
- placeController.goTo(new TaskListPlace(false));
+ eventBus.fireEvent(new GoHomeEvent());
contentContainer.animate(0);
}
}
-
-}
+}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors