2 * Copyright (C) 2012 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.place.HasTablePlace;
26 import org.glom.web.client.ui.AuthenticationPopup;
27 import org.glom.web.client.ui.View;
29 import com.google.gwt.activity.shared.AbstractActivity;
30 import com.google.gwt.core.client.GWT;
31 import com.google.gwt.event.dom.client.ClickEvent;
32 import com.google.gwt.event.dom.client.ClickHandler;
33 import com.google.gwt.event.shared.EventBus;
34 import com.google.gwt.place.shared.Place;
35 import com.google.gwt.user.client.rpc.AsyncCallback;
38 * @author Ben Konrath <ben@bagu.org>
41 public abstract class HasTableActivity extends AbstractActivity implements View.Presenter {
43 protected final ClientFactory clientFactory;
44 protected final String documentID;
45 protected final String tableName;
46 protected final AuthenticationPopup authenticationPopup;
51 public HasTableActivity(final HasTablePlace place, final ClientFactory clientFactory) {
53 this.documentID = place.getDocumentID(); // TODO: Just store the place?
54 this.tableName = place.getTableName();
55 this.clientFactory = clientFactory;
56 this.authenticationPopup = clientFactory.getAuthenticationPopup();
62 * @see org.glom.web.client.ui.View.Presenter#goTo(com.google.gwt.place.shared.Place)
65 public void goTo(final Place place) {
66 clientFactory.getPlaceController().goTo(place);
72 protected void checkAuthentication(final EventBus eventBus) {
73 // TODO this should really be it's own Place/Activity
74 // check if the authentication info has been set for the document
75 final AsyncCallback<Boolean> isAuthCallback = new AsyncCallback<Boolean>() {
77 public void onFailure(final Throwable caught) {
78 // TODO: create a way to notify users of asynchronous callback failures
79 GWT.log("AsyncCallback Failed: OnlineGlomService.isAuthenticated(): " + caught.getMessage());
83 public void onSuccess(final Boolean result) {
85 setUpAuthClickHandler(eventBus);
86 authenticationPopup.center();
90 OnlineGlomServiceAsync.Util.getInstance().isAuthenticated(documentID, isAuthCallback);
93 private void setUpAuthClickHandler(final EventBus eventBus) {
94 authenticationPopup.setClickOkHandler(new ClickHandler() {
96 public void onClick(final ClickEvent event) {
97 authenticationPopup.setTextFieldsEnabled(false);
99 final AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
101 public void onFailure(final Throwable caught) {
102 // TODO: create a way to notify users of asynchronous callback failures
103 GWT.log("AsyncCallback Failed: OnlineGlomService.checkAuthentication(): " + caught.getMessage());
107 public void onSuccess(final Boolean result) {
109 // If authentication succeeded, take us to the requested table:
110 authenticationPopup.hide();
111 eventBus.fireEvent(new TableChangeEvent(clientFactory.getTableSelectionView()
112 .getSelectedTableName()));
114 // If authentication failed, tell the user:
115 authenticationPopup.setTextFieldsEnabled(true);
116 authenticationPopup.setError();
120 OnlineGlomServiceAsync.Util.getInstance().checkAuthentication(documentID,
121 authenticationPopup.getUsername(), authenticationPopup.getPassword(), callback);