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.OnlineGlomLoginServiceAsync;
24 import org.glom.web.client.StringUtils;
25 import org.glom.web.client.place.DocumentLoginPlace;
26 import org.glom.web.client.place.HasDocumentPlace;
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.shared.EventBus;
32 import com.google.gwt.place.shared.Place;
33 import com.google.gwt.user.client.rpc.AsyncCallback;
36 * @author Ben Konrath <ben@bagu.org>
39 public abstract class HasDocumentActivity extends AbstractActivity implements View.Presenter {
41 protected final ClientFactory clientFactory;
42 protected final String documentID;
47 public HasDocumentActivity(final HasDocumentPlace place, final ClientFactory clientFactory) {
49 this.documentID = place.getDocumentID(); // TODO: Just store the place?
50 this.clientFactory = clientFactory;
54 public void goTo(final Place place) {
55 clientFactory.getPlaceController().goTo(place);
61 protected void checkAuthentication(final EventBus eventBus) {
62 if(StringUtils.isEmpty(documentID)) {
63 //TODO: Show that no document was chosen?
67 // check if the authentication info has been set for the document
68 final AsyncCallback<Boolean> isAuthCallback = new AsyncCallback<Boolean>() {
70 public void onFailure(final Throwable caught) {
71 // TODO: create a way to notify users of asynchronous callback failures
72 GWT.log("AsyncCallback Failed: OnlineGlomService.isAuthenticated(): " + caught.getMessage());
76 public void onSuccess(final Boolean result) {
78 //If the user/session is not authenticated,
79 //then go to the login page, so he can try:
80 goTo(new DocumentLoginPlace(documentID));
84 OnlineGlomLoginServiceAsync.Util.getInstance().isAuthenticated(documentID, isAuthCallback);
87 protected void clearView() {