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.getItems(),
86 result.getExpectedResultSize());
89 OnlineGlomServiceAsync.Util.getInstance().getListLayout(documentTitle, event.getTableName(), callback);
93 // populate the cell table with data
94 final String selectedTable = clientFactory.getTableSelectionView().getSelectedTable();
95 if (!selectedTable.isEmpty()) {
96 // The table name has been set so we can use the selected table name to populate the cell table.
97 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
98 public void onFailure(Throwable caught) {
99 // FIXME: need to deal with failure
100 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
103 public void onSuccess(LayoutGroup result) {
104 listView.setCellTable(documentTitle, selectedTable, result.getItems(),
105 result.getExpectedResultSize());
108 OnlineGlomServiceAsync.Util.getInstance().getListLayout(documentTitle, selectedTable, callback);
110 // The table name has not been set so we need to fill in the cell table using the default table for the glom
112 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
113 public void onFailure(Throwable caught) {
114 // FIXME: need to deal with failure
115 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
118 public void onSuccess(LayoutGroup result) {
119 listView.setCellTable(documentTitle, result.getDefaultTableName(), result.getItems(),
120 result.getExpectedResultSize());
123 OnlineGlomServiceAsync.Util.getInstance().getDefaultListLayout(documentTitle, callback);
126 // indicate that the view is ready to be displayed
127 panel.setWidget(listView.asWidget());
130 private void setUpAuthClickHandler(final EventBus eventBus) {
131 authenticationPopup.setClickOkHandler(new ClickHandler() {
133 public void onClick(ClickEvent event) {
134 authenticationPopup.setTextFieldsEnabled(false);
135 AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
137 public void onFailure(Throwable caught) {
138 // FIXME: need to deal with failure
139 System.out.println("AsyncCallback Failed: OnlineGlomService.checkAuthentication()");
143 public void onSuccess(Boolean result) {
145 authenticationPopup.hide();
146 eventBus.fireEvent(new TableChangeEvent(clientFactory.getTableSelectionView()
147 .getSelectedTable()));
149 authenticationPopup.setTextFieldsEnabled(true);
150 authenticationPopup.setError();
154 OnlineGlomServiceAsync.Util.getInstance().checkAuthentication(documentTitle,
155 authenticationPopup.getUsername(), authenticationPopup.getPassword(), callback);
161 private void clearView() {
162 authenticationPopup.hide();
163 authenticationPopup.clear();
170 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
173 public void onCancel() {
180 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
183 public void onStop() {
190 * @see org.glom.web.client.ui.ListView.Presenter#goTo(com.google.gwt.place.shared.Place)
192 public void goTo(Place place) {
193 clientFactory.getPlaceController().goTo(place);