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.StringUtils;
25 import org.glom.web.client.Utils;
26 import org.glom.web.client.event.LocaleChangeEvent;
27 import org.glom.web.client.event.LocaleChangeEventHandler;
28 import org.glom.web.client.event.QuickFindChangeEvent;
29 import org.glom.web.client.event.QuickFindChangeEventHandler;
30 import org.glom.web.client.event.TableChangeEvent;
31 import org.glom.web.client.event.TableChangeEventHandler;
32 import org.glom.web.client.place.DocumentSelectionPlace;
33 import org.glom.web.client.place.HasRecordsPlace;
34 import org.glom.web.client.place.ListPlace;
35 import org.glom.web.client.ui.ListView;
36 import org.glom.web.shared.libglom.layout.LayoutGroup;
38 import com.google.gwt.core.client.GWT;
39 import com.google.gwt.event.dom.client.ClickEvent;
40 import com.google.gwt.event.dom.client.ClickHandler;
41 import com.google.gwt.event.shared.EventBus;
42 import com.google.gwt.user.client.rpc.AsyncCallback;
43 import com.google.gwt.user.client.ui.AcceptsOneWidget;
45 public class ListActivity extends HasTableActivity {
47 private final String quickFind;
48 private final ListView listView;
50 public ListActivity(final HasRecordsPlace place, final ClientFactory clientFactory) {
51 super(place, clientFactory);
52 this.quickFind = place.getQuickFind();
53 this.listView = clientFactory.getListView();
57 public void start(final AcceptsOneWidget panel, final EventBus eventBus) {
58 if (StringUtils.isEmpty(documentID))
59 goTo(new DocumentSelectionPlace());
61 // register this class as the presenter
62 listView.setPresenter(this);
64 // TODO this should really be it's own Place/Activity
65 // check if the authentication info has been set for the document
66 final AsyncCallback<Boolean> isAuthCallback = new AsyncCallback<Boolean>() {
68 public void onFailure(final Throwable caught) {
69 // TODO: create a way to notify users of asynchronous callback failures
70 GWT.log("AsyncCallback Failed: OnlineGlomService.isAuthenticated()");
74 public void onSuccess(final Boolean result) {
76 setUpAuthClickHandler(eventBus);
77 authenticationPopup.center();
81 OnlineGlomServiceAsync.Util.getInstance().isAuthenticated(documentID, isAuthCallback);
83 // set the change handler for the table selection widget
84 eventBus.addHandler(TableChangeEvent.TYPE, new TableChangeEventHandler() {
86 public void onTableChange(final TableChangeEvent event) {
87 goTo(new ListPlace(documentID, event.getNewTableName(), ""));
91 // populate the cell table with data
92 final AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
94 public void onFailure(final Throwable caught) {
95 // TODO: create a way to notify users of asynchronous callback failures
96 GWT.log("AsyncCallback Failed: OnlineGlomService.getListViewLayout()");
100 public void onSuccess(final LayoutGroup result) {
101 // TODO check if result.getTableName() is the same as the tableName field. Update it if it's not the
103 listView.setCellTable(documentID, tableName, result, quickFind);
107 final String localeID = Utils.getCurrentLocaleID();
108 OnlineGlomServiceAsync.Util.getInstance().getListViewLayout(documentID, tableName, localeID, callback);
110 // TODO: Avoid the code duplication with DetailsActivity.
111 // set the change handler for the quickfind text widget
112 eventBus.addHandler(QuickFindChangeEvent.TYPE, new QuickFindChangeEventHandler() {
114 public void onQuickFindChange(final QuickFindChangeEvent event) {
115 // We switch to the List view, to show search results.
116 // TODO: Show the details view if there is only one result.
117 goTo(new ListPlace(documentID, tableName, event.getNewQuickFindText()));
121 // Set the change handler for the table selection widget
122 eventBus.addHandler(LocaleChangeEvent.TYPE, new LocaleChangeEventHandler() {
124 public void onLocaleChange(final LocaleChangeEvent event) {
125 // note the empty primary key item
126 goTo(new ListPlace(documentID, tableName, quickFind));
130 // indicate that the view is ready to be displayed
131 panel.setWidget(listView.asWidget());
134 private void setUpAuthClickHandler(final EventBus eventBus) {
135 authenticationPopup.setClickOkHandler(new ClickHandler() {
137 public void onClick(final ClickEvent event) {
138 authenticationPopup.setTextFieldsEnabled(false);
139 final AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
141 public void onFailure(final Throwable caught) {
142 // TODO: create a way to notify users of asynchronous callback failures
143 GWT.log("AsyncCallback Failed: OnlineGlomService.checkAuthentication()");
147 public void onSuccess(final Boolean result) {
149 authenticationPopup.hide();
150 eventBus.fireEvent(new TableChangeEvent(clientFactory.getTableSelectionView()
151 .getSelectedTableName()));
153 authenticationPopup.setTextFieldsEnabled(true);
154 authenticationPopup.setError();
158 OnlineGlomServiceAsync.Util.getInstance().checkAuthentication(documentID,
159 authenticationPopup.getUsername(), authenticationPopup.getPassword(), callback);
165 private void clearView() {
166 authenticationPopup.hide();
167 authenticationPopup.clear();
174 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
177 public void onCancel() {
184 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
187 public void onStop() {