2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.client.activity;
22 import org.glom.web.client.ClientFactory;
23 import org.glom.web.client.OnlineGlomServiceAsync;
24 import org.glom.web.client.event.TableChangeEvent;
25 import org.glom.web.client.event.TableChangeEventHandler;
26 import org.glom.web.client.place.ListPlace;
27 import org.glom.web.client.ui.AuthenticationPopup;
28 import org.glom.web.client.ui.ListView;
29 import org.glom.web.shared.layout.LayoutGroup;
31 import com.google.gwt.activity.shared.AbstractActivity;
32 import com.google.gwt.core.client.GWT;
33 import com.google.gwt.event.dom.client.ClickEvent;
34 import com.google.gwt.event.dom.client.ClickHandler;
35 import com.google.gwt.event.shared.EventBus;
36 import com.google.gwt.place.shared.Place;
37 import com.google.gwt.user.client.rpc.AsyncCallback;
38 import com.google.gwt.user.client.ui.AcceptsOneWidget;
40 public class ListActivity extends AbstractActivity implements ListView.Presenter {
42 private final String documentID;
43 private final String tableName;
44 private final ClientFactory clientFactory;
45 private final ListView listView;
46 private final AuthenticationPopup authenticationPopup;
48 public ListActivity(ListPlace place, ClientFactory clientFactory) {
49 this.documentID = place.getDocumentID();
50 this.tableName = place.getTableName();
51 this.clientFactory = clientFactory;
52 listView = clientFactory.getListView();
53 authenticationPopup = clientFactory.getAuthenticationPopup();
57 public void start(AcceptsOneWidget panel, final EventBus eventBus) {
58 // register this class as the presenter
59 listView.setPresenter(this);
61 // TODO this should really be it's own Place/Activity
62 // check if the authentication info has been set for the document
63 AsyncCallback<Boolean> isAuthCallback = new AsyncCallback<Boolean>() {
64 public void onFailure(Throwable caught) {
65 // TODO: create a way to notify users of asynchronous callback failures
66 GWT.log("AsyncCallback Failed: OnlineGlomService.isAuthenticated()");
69 public void onSuccess(Boolean result) {
71 setUpAuthClickHandler(eventBus);
72 authenticationPopup.center();
76 OnlineGlomServiceAsync.Util.getInstance().isAuthenticated(documentID, isAuthCallback);
78 // set the change handler for the table selection widget
79 eventBus.addHandler(TableChangeEvent.TYPE, new TableChangeEventHandler() {
81 public void onTableChange(final TableChangeEvent event) {
82 goTo(new ListPlace(documentID, event.getNewTableName()));
86 // populate the cell table with data
87 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
88 public void onFailure(Throwable caught) {
89 // TODO: create a way to notify users of asynchronous callback failures
90 GWT.log("AsyncCallback Failed: OnlineGlomService.getListViewLayout()");
93 public void onSuccess(LayoutGroup result) {
94 // TODO check if result.getTableName() is the same as the tableName field. Update it if it's not the
96 listView.setCellTable(documentID, result);
99 OnlineGlomServiceAsync.Util.getInstance().getListViewLayout(documentID, tableName, callback);
101 // indicate that the view is ready to be displayed
102 panel.setWidget(listView.asWidget());
105 private void setUpAuthClickHandler(final EventBus eventBus) {
106 authenticationPopup.setClickOkHandler(new ClickHandler() {
108 public void onClick(ClickEvent event) {
109 authenticationPopup.setTextFieldsEnabled(false);
110 AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
112 public void onFailure(Throwable caught) {
113 // TODO: create a way to notify users of asynchronous callback failures
114 GWT.log("AsyncCallback Failed: OnlineGlomService.checkAuthentication()");
118 public void onSuccess(Boolean result) {
120 authenticationPopup.hide();
121 eventBus.fireEvent(new TableChangeEvent(clientFactory.getTableSelectionView()
122 .getSelectedTableName()));
124 authenticationPopup.setTextFieldsEnabled(true);
125 authenticationPopup.setError();
129 OnlineGlomServiceAsync.Util.getInstance().checkAuthentication(documentID,
130 authenticationPopup.getUsername(), authenticationPopup.getPassword(), callback);
136 private void clearView() {
137 authenticationPopup.hide();
138 authenticationPopup.clear();
145 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
148 public void onCancel() {
155 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
158 public void onStop() {
165 * @see org.glom.web.client.ui.ListView.Presenter#goTo(com.google.gwt.place.shared.Place)
167 public void goTo(Place place) {
168 clientFactory.getPlaceController().goTo(place);