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.event.dom.client.ClickEvent;
33 import com.google.gwt.event.dom.client.ClickHandler;
34 import com.google.gwt.event.shared.EventBus;
35 import com.google.gwt.place.shared.Place;
36 import com.google.gwt.user.client.rpc.AsyncCallback;
37 import com.google.gwt.user.client.ui.AcceptsOneWidget;
39 public class ListActivity extends AbstractActivity implements ListView.Presenter {
41 private final String documentTitle;
42 private final ClientFactory clientFactory;
43 private final ListView listView;
44 private final AuthenticationPopup authenticationPopup;
46 public ListActivity(ListPlace place, ClientFactory clientFactory) {
47 this.documentTitle = place.getDocumentTitle();
48 this.clientFactory = clientFactory;
49 listView = clientFactory.getListView();
50 authenticationPopup = clientFactory.getAuthenticationPopup();
54 public void start(AcceptsOneWidget panel, final EventBus eventBus) {
55 // register this class as the presenter
56 listView.setPresenter(this);
58 // check if the authentication info has been set for the document
59 AsyncCallback<Boolean> isAuthCallback = new AsyncCallback<Boolean>() {
60 public void onFailure(Throwable caught) {
61 // FIXME: need to deal with failure
62 System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()");
65 public void onSuccess(Boolean result) {
67 setUpAuthClickHandler(eventBus);
68 authenticationPopup.center();
72 OnlineGlomServiceAsync.Util.getInstance().isAuthenticated(documentTitle, isAuthCallback);
74 // set the change handler for the table selection widget
75 eventBus.addHandler(TableChangeEvent.TYPE, new TableChangeEventHandler() {
77 public void onTableChange(final TableChangeEvent event) {
78 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
79 public void onFailure(Throwable caught) {
80 // FIXME: need to deal with failure
81 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
84 public void onSuccess(LayoutGroup result) {
85 listView.setCellTable(documentTitle, event.getTableName(), result);
88 OnlineGlomServiceAsync.Util.getInstance().getListLayout(documentTitle, event.getTableName(), callback);
92 // populate the cell table with data
93 final String selectedTable = clientFactory.getTableSelectionView().getSelectedTable();
94 if (!selectedTable.isEmpty()) {
95 // The table name has been set so we can use the selected table name to populate the cell table.
96 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
97 public void onFailure(Throwable caught) {
98 // FIXME: need to deal with failure
99 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
102 public void onSuccess(LayoutGroup result) {
103 listView.setCellTable(documentTitle, selectedTable, result);
106 OnlineGlomServiceAsync.Util.getInstance().getListLayout(documentTitle, selectedTable, callback);
108 // The table name has not been set so we need to fill in the cell table using the default table for the glom
110 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
111 public void onFailure(Throwable caught) {
112 // FIXME: need to deal with failure
113 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
116 public void onSuccess(LayoutGroup result) {
117 listView.setCellTable(documentTitle, result.getDefaultTableName(), result);
120 OnlineGlomServiceAsync.Util.getInstance().getDefaultListLayout(documentTitle, callback);
123 // indicate that the view is ready to be displayed
124 panel.setWidget(listView.asWidget());
127 private void setUpAuthClickHandler(final EventBus eventBus) {
128 authenticationPopup.setClickOkHandler(new ClickHandler() {
130 public void onClick(ClickEvent event) {
131 authenticationPopup.setTextFieldsEnabled(false);
132 AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
134 public void onFailure(Throwable caught) {
135 // FIXME: need to deal with failure
136 System.out.println("AsyncCallback Failed: OnlineGlomService.checkAuthentication()");
140 public void onSuccess(Boolean result) {
142 authenticationPopup.hide();
143 eventBus.fireEvent(new TableChangeEvent(clientFactory.getTableSelectionView()
144 .getSelectedTable()));
146 authenticationPopup.setTextFieldsEnabled(true);
147 authenticationPopup.setError();
151 OnlineGlomServiceAsync.Util.getInstance().checkAuthentication(documentTitle,
152 authenticationPopup.getUsername(), authenticationPopup.getPassword(), callback);
158 private void clearView() {
159 authenticationPopup.hide();
160 authenticationPopup.clear();
167 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
170 public void onCancel() {
177 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
180 public void onStop() {
187 * @see org.glom.web.client.ui.ListView.Presenter#goTo(com.google.gwt.place.shared.Place)
189 public void goTo(Place place) {
190 clientFactory.getPlaceController().goTo(place);