Use filename based unique document ID in URL and for RPC.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / client / activity / DocumentSelectionActivity.java
1 /*
2  * Copyright (C) 2011 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
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.
10  *
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
14  * for more details.
15  *
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/>.
18  */
19
20 package org.glom.web.client.activity;
21
22 import org.glom.web.client.ClientFactory;
23 import org.glom.web.client.OnlineGlomServiceAsync;
24 import org.glom.web.client.ui.DocumentSelectionView;
25 import org.glom.web.shared.Documents;
26
27 import com.google.gwt.activity.shared.AbstractActivity;
28 import com.google.gwt.event.shared.EventBus;
29 import com.google.gwt.place.shared.Place;
30 import com.google.gwt.user.client.Window;
31 import com.google.gwt.user.client.rpc.AsyncCallback;
32 import com.google.gwt.user.client.ui.AcceptsOneWidget;
33
34 public class DocumentSelectionActivity extends AbstractActivity implements DocumentSelectionView.Presenter {
35
36         // TODO inject with GIN
37         private final ClientFactory clientFactory;
38
39         public DocumentSelectionActivity(ClientFactory clientFactory) {
40                 this.clientFactory = clientFactory;
41         }
42
43         @Override
44         public void start(AcceptsOneWidget panel, EventBus eventBus) {
45                 Window.setTitle("Online Glom");
46                 final DocumentSelectionView documentSelectionView = clientFactory.getDocumentSelectionView();
47                 documentSelectionView.setPresenter(this);
48
49                 AsyncCallback<Documents> callback = new AsyncCallback<Documents>() {
50                         public void onFailure(Throwable caught) {
51                                 documentSelectionView
52                                                 .setErrorMessage("Unable to communicate with the server. Check the error log for more information.");
53                         }
54
55                         public void onSuccess(Documents documents) {
56                                 documentSelectionView.clearHyperLinks();
57                                 if (documents.getCount() > 0) {
58                                         for (int i = 0; i < documents.getCount(); i++) {
59                                                 documentSelectionView.addDocumentLink(documents.getDocumentID(i), documents.getTitle(i));
60                                         }
61                                 } else {
62                                         documentSelectionView
63                                                         .setErrorMessage("Could not find any Glom documents to load. Check the error log for more information.");
64                                 }
65                         }
66                 };
67                 OnlineGlomServiceAsync.Util.getInstance().getDocuments(callback);
68
69                 panel.setWidget(documentSelectionView.asWidget());
70         }
71
72         @Override
73         public void goTo(Place place) {
74                 clientFactory.getPlaceController().goTo(place);
75         }
76
77 }