Change 'Demo' naming convention to 'Document'.
[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 java.util.ArrayList;
23
24 import org.glom.web.client.ClientFactory;
25 import org.glom.web.client.OnlineGlomServiceAsync;
26 import org.glom.web.client.place.OnlineGlomPlace;
27 import org.glom.web.client.ui.DocumentSelectionView;
28
29 import com.google.gwt.activity.shared.AbstractActivity;
30 import com.google.gwt.event.shared.EventBus;
31 import com.google.gwt.user.client.Window;
32 import com.google.gwt.user.client.rpc.AsyncCallback;
33 import com.google.gwt.user.client.ui.AcceptsOneWidget;
34
35 public class DocumentSelectionActivity extends AbstractActivity {
36
37         // TODO inject with GIN
38         private final ClientFactory clientFactory;
39         private final ArrayList<OnlineGlomPlace> documentPlaces = new ArrayList<OnlineGlomPlace>();
40
41         public DocumentSelectionActivity(ClientFactory clientFactory) {
42                 this.clientFactory = clientFactory;
43         }
44
45         @Override
46         public void start(AcceptsOneWidget panel, EventBus eventBus) {
47                 Window.setTitle("Online Glom");
48                 final DocumentSelectionView documentSelectionView = clientFactory.getDocumentSelectionView();
49
50                 AsyncCallback<ArrayList<String>> callback = new AsyncCallback<ArrayList<String>>() {
51                         public void onFailure(Throwable caught) {
52                                 // FIXME: need to deal with failure
53                                 System.out.println("AsyncCallback Failed: OnlineGlomService.getDocumentTitles()");
54                         }
55
56                         public void onSuccess(ArrayList<String> documentTitles) {
57                                 documentSelectionView.clearHyperLinks();
58                                 if (!documentTitles.isEmpty()) {
59                                         for (String documentTitle : documentTitles) {
60                                                 OnlineGlomPlace place = new OnlineGlomPlace(documentTitle);
61                                                 documentPlaces.add(place);
62                                                 documentSelectionView.addHyperLink(documentTitle,
63                                                                 clientFactory.getHistoryMapper().getToken(place));
64                                         }
65                                 } else {
66                                         documentSelectionView
67                                                         .setErrorMessage("Could not find any Glom documents to load. Check the error log for more information.");
68                                 }
69                         }
70                 };
71                 OnlineGlomServiceAsync.Util.getInstance().getDocumentTitles(callback);
72
73                 panel.setWidget(documentSelectionView.asWidget());
74         }
75 }