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.place.DetailsPlace;
27 import org.glom.web.client.ui.DetailsView;
28 import org.glom.web.shared.GlomField;
29 import org.glom.web.shared.layout.LayoutGroup;
30 import org.glom.web.shared.layout.LayoutItem;
31 import org.glom.web.shared.layout.LayoutItemField;
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 documentTitle;
44 private final ClientFactory clientFactory;
45 private final DetailsView detailsView;
47 public DetailsActivity(DetailsPlace place, ClientFactory clientFactory) {
48 this.documentTitle = place.getDocumentTitle();
49 this.clientFactory = clientFactory;
50 detailsView = clientFactory.getDetailsView();
56 * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget,
57 * com.google.gwt.event.shared.EventBus)
60 public void start(AcceptsOneWidget panel, EventBus eventBus) {
61 // register this class as the presenter
62 detailsView.setPresenter(this);
64 // get the layout for the DetailsView
65 final String selectedTable = clientFactory.getTableSelectionView().getSelectedTable();
66 if (!selectedTable.isEmpty()) {
67 // The table name has been set so we can use the selected table name to populate the cell table.
68 AsyncCallback<ArrayList<LayoutGroup>> callback = new AsyncCallback<ArrayList<LayoutGroup>>() {
69 public void onFailure(Throwable caught) {
70 // FIXME: need to deal with failure
71 System.out.println("AsyncCallback Failed: OnlineGlomService.getDetailsLayout()");
75 public void onSuccess(ArrayList<LayoutGroup> result) {
76 addLayoutGroups(result);
79 OnlineGlomServiceAsync.Util.getInstance().getDetailsLayout(documentTitle, selectedTable, callback);
81 // The table name has not been set so we need to fill in the details layout using the default table for the
83 AsyncCallback<ArrayList<LayoutGroup>> callback = new AsyncCallback<ArrayList<LayoutGroup>>() {
84 public void onFailure(Throwable caught) {
85 // FIXME: need to deal with failure
86 System.out.println("AsyncCallback Failed: OnlineGlomService.getDefaultDetailsLayout()");
90 public void onSuccess(ArrayList<LayoutGroup> result) {
91 addLayoutGroups(result);
94 OnlineGlomServiceAsync.Util.getInstance().getDefaultDetailsLayout(documentTitle, callback);
97 // get the data from the server
98 AsyncCallback<GlomField[]> callback = new AsyncCallback<GlomField[]>() {
99 public void onFailure(Throwable caught) {
100 // FIXME: need to deal with failure
101 System.out.println("AsyncCallback Failed: OnlineGlomService.getDetailsData()");
105 public void onSuccess(GlomField[] result) {
106 // FIXME there's no guarantee that the layout will be ready for this
107 detailsView.setData(result);
110 OnlineGlomServiceAsync.Util.getInstance().getDetailsData(documentTitle, selectedTable, "0", callback);
112 // indicate that the view is ready to be displayed
113 panel.setWidget(detailsView.asWidget());
116 private void addLayoutGroups(ArrayList<LayoutGroup> layoutGroups) {
117 for (LayoutGroup layoutGroup : layoutGroups) {
118 addLayoutGroup(layoutGroup, "");
123 * This is just a temporary method for creating a basic indented layout without the flowtable/spreadtable that Glom
126 private void addLayoutGroup(LayoutGroup layoutGroup, String indent) {
127 if (layoutGroup == null)
130 // look at each child item
131 ArrayList<LayoutItem> layoutItems = layoutGroup.getItems();
132 for (LayoutItem layoutItem : layoutItems) {
134 if (layoutItem == null)
137 String title = layoutItem.getTitle();
138 if (layoutItem instanceof LayoutItemField)
139 detailsView.addLayoutField(indent + title);
140 else if (!title.isEmpty())
141 detailsView.addLayoutGroup(indent + title);
143 // recurse into child groups
144 if (layoutItem instanceof LayoutGroup)
145 addLayoutGroup((LayoutGroup) layoutItem, indent + "-- ");
152 * @see com.google.gwt.activity.shared.Activity#onCancel()
155 public void onCancel() {
162 * @see com.google.gwt.activity.shared.Activity#onStop()
165 public void onStop() {
172 * @see org.glom.web.client.ui.DetailsView.Presenter#goTo(com.google.gwt.place.shared.Place)
175 public void goTo(Place place) {
176 clientFactory.getPlaceController().goTo(place);