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 java.util.ArrayList;
24 import org.glom.web.client.ClientFactory;
25 import org.glom.web.client.OnlineGlomServiceAsync;
26 import org.glom.web.client.event.TableChangeEvent;
27 import org.glom.web.client.event.TableChangeEventHandler;
28 import org.glom.web.client.place.DetailsPlace;
29 import org.glom.web.client.ui.DetailsView;
30 import org.glom.web.shared.GlomField;
31 import org.glom.web.shared.layout.LayoutGroup;
33 import com.google.gwt.activity.shared.AbstractActivity;
34 import com.google.gwt.event.shared.EventBus;
35 import com.google.gwt.place.shared.Place;
36 import com.google.gwt.user.client.rpc.AsyncCallback;
37 import com.google.gwt.user.client.ui.AcceptsOneWidget;
40 * @author Ben Konrath <ben@bagu.org>
42 public class DetailsActivity extends AbstractActivity implements DetailsView.Presenter {
43 private final String documentID;
44 private final String tableName;
45 private final String primaryKey;
46 private final ClientFactory clientFactory;
47 private final DetailsView detailsView;
49 public DetailsActivity(DetailsPlace place, ClientFactory clientFactory) {
50 this.documentID = place.getDocumentID();
51 this.tableName = place.getTableName();
52 this.primaryKey = place.getPrimaryKeyValue();
53 this.clientFactory = clientFactory;
54 detailsView = clientFactory.getDetailsView();
60 * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget,
61 * com.google.gwt.event.shared.EventBus)
64 public void start(AcceptsOneWidget panel, EventBus eventBus) {
65 // register this class as the presenter
66 detailsView.setPresenter(this);
68 // TODO here's where we should check for database authentication - see ListActivity.start() for how to do this
70 // set the change handler for the table selection widget
71 eventBus.addHandler(TableChangeEvent.TYPE, new TableChangeEventHandler() {
73 public void onTableChange(final TableChangeEvent event) {
74 goTo(new DetailsPlace(documentID, event.getTableName(), ""));
78 // get the layout for the DetailsView
79 AsyncCallback<ArrayList<LayoutGroup>> layoutCallback = new AsyncCallback<ArrayList<LayoutGroup>>() {
80 public void onFailure(Throwable caught) {
81 // FIXME: need to deal with failure
82 System.out.println("AsyncCallback Failed: OnlineGlomService.getDetailsLayout()");
86 public void onSuccess(ArrayList<LayoutGroup> result) {
87 for (LayoutGroup layoutGroup : result) {
88 detailsView.addLayoutGroup(layoutGroup);
92 OnlineGlomServiceAsync.Util.getInstance().getDetailsLayout(documentID, tableName, layoutCallback);
94 // get the data from the server
95 AsyncCallback<GlomField[]> callback = new AsyncCallback<GlomField[]>() {
96 public void onFailure(Throwable caught) {
97 // FIXME: need to deal with failure
98 System.out.println("AsyncCallback Failed: OnlineGlomService.getDetailsData()");
102 public void onSuccess(GlomField[] result) {
103 // FIXME there's no guarantee that the layout will be ready for this
104 detailsView.setData(result);
107 OnlineGlomServiceAsync.Util.getInstance().getDetailsData(documentID, tableName, primaryKey, callback);
109 // indicate that the view is ready to be displayed
110 panel.setWidget(detailsView.asWidget());
116 * @see com.google.gwt.activity.shared.Activity#onCancel()
119 public void onCancel() {
126 * @see com.google.gwt.activity.shared.Activity#onStop()
129 public void onStop() {
136 * @see org.glom.web.client.ui.DetailsView.Presenter#goTo(com.google.gwt.place.shared.Place)
139 public void goTo(Place place) {
140 clientFactory.getPlaceController().goTo(place);