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.layout.LayoutGroup;
29 import org.glom.web.shared.layout.LayoutItem;
30 import org.glom.web.shared.layout.LayoutItemField;
32 import com.google.gwt.activity.shared.AbstractActivity;
33 import com.google.gwt.event.shared.EventBus;
34 import com.google.gwt.place.shared.Place;
35 import com.google.gwt.user.client.rpc.AsyncCallback;
36 import com.google.gwt.user.client.ui.AcceptsOneWidget;
39 * @author Ben Konrath <ben@bagu.org>
41 public class DetailsActivity extends AbstractActivity implements DetailsView.Presenter {
42 private final String documentTitle;
43 private final ClientFactory clientFactory;
44 private final DetailsView detailsView;
46 public DetailsActivity(DetailsPlace place, ClientFactory clientFactory) {
47 this.documentTitle = place.getDocumentTitle();
48 this.clientFactory = clientFactory;
49 detailsView = clientFactory.getDetailsView();
55 * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget,
56 * com.google.gwt.event.shared.EventBus)
59 public void start(AcceptsOneWidget panel, EventBus eventBus) {
60 // register this class as the presenter
61 detailsView.setPresenter(this);
63 // get the layout for the DetailsView
64 final String selectedTable = clientFactory.getTableSelectionView().getSelectedTable();
65 if (!selectedTable.isEmpty()) {
66 // The table name has been set so we can use the selected table name to populate the cell table.
67 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
68 public void onFailure(Throwable caught) {
69 // FIXME: need to deal with failure
70 System.out.println("AsyncCallback Failed: OnlineGlomService.getDetailsLayout()");
74 public void onSuccess(LayoutGroup result) {
75 setDetailsLayout(result);
78 OnlineGlomServiceAsync.Util.getInstance().getDetailsLayoutGroup(documentTitle, selectedTable, callback);
80 // The table name has not been set so we need to fill in the details layout using the default table for the
82 // The table name has been set so we can use the selected table name to populate the cell table.
83 AsyncCallback<LayoutGroup> callback = new AsyncCallback<LayoutGroup>() {
84 public void onFailure(Throwable caught) {
85 // FIXME: need to deal with failure
86 System.out.println("AsyncCallback Failed: OnlineGlomService.getDetailsLayout()");
90 public void onSuccess(LayoutGroup result) {
91 setDetailsLayout(result);
94 OnlineGlomServiceAsync.Util.getInstance().getDefaultDetailsLayoutGroup(documentTitle, callback);
97 // indicate that the view is ready to be displayed
98 panel.setWidget(detailsView.asWidget());
101 private void setDetailsLayout(LayoutGroup layoutGroup) {
102 ArrayList<LayoutItem> items = layoutGroup.getItems();
103 for (LayoutItem layoutItem : items) {
104 if (layoutItem instanceof LayoutGroup) {
105 detailsView.addLayoutGroup((LayoutGroup) layoutItem);
106 } else if (layoutItem instanceof LayoutItemField) {
107 detailsView.addLayoutField((LayoutItemField) layoutItem);
115 * @see com.google.gwt.activity.shared.Activity#onCancel()
118 public void onCancel() {
125 * @see com.google.gwt.activity.shared.Activity#onStop()
128 public void onStop() {
135 * @see org.glom.web.client.ui.DetailsView.Presenter#goTo(com.google.gwt.place.shared.Place)
138 public void goTo(Place place) {
139 clientFactory.getPlaceController().goTo(place);