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 org.glom.web.client.ClientFactory;
23 import org.glom.web.client.OnlineGlomServiceAsync;
24 import org.glom.web.client.event.TableChangeEvent;
25 import org.glom.web.client.place.DetailsPlace;
26 import org.glom.web.client.place.HasSelectableTablePlace;
27 import org.glom.web.client.place.ListPlace;
28 import org.glom.web.client.ui.TableSelectionView;
29 import org.glom.web.shared.GlomDocument;
31 import com.google.gwt.activity.shared.AbstractActivity;
32 import com.google.gwt.event.dom.client.ChangeEvent;
33 import com.google.gwt.event.dom.client.ChangeHandler;
34 import com.google.gwt.event.dom.client.HasChangeHandlers;
35 import com.google.gwt.event.shared.EventBus;
36 import com.google.gwt.event.shared.HandlerRegistration;
37 import com.google.gwt.place.shared.Place;
38 import com.google.gwt.user.client.rpc.AsyncCallback;
39 import com.google.gwt.user.client.ui.AcceptsOneWidget;
42 * @author Ben Konrath <ben@bagu.org>
45 public class TableSelectionActivity extends AbstractActivity implements TableSelectionView.Presenter {
46 private final ClientFactory clientFactory;
47 private String documentID;
48 private HandlerRegistration changeHandlerRegistration = null;
50 // This activity isn't properly configured until the List or Details Place is set with the appropriate methods
51 public TableSelectionActivity(ClientFactory clientFactory) {
52 this.clientFactory = clientFactory;
56 * Invoked by the ActivityManager to start a new Activity
59 public void start(AcceptsOneWidget containerWidget, final EventBus eventBus) {
60 // FIXME set the window title with the title from the glom document
61 // Window.setTitle("Online Glom - " + documentTitle);
63 final TableSelectionView tableSelectionView = clientFactory.getTableSelectionView();
64 tableSelectionView.setPresenter(this);
66 HasChangeHandlers tableSelector = tableSelectionView.getTableSelector();
68 changeHandlerRegistration = tableSelector.addChangeHandler(new ChangeHandler() {
70 public void onChange(ChangeEvent event) {
71 eventBus.fireEvent(new TableChangeEvent(tableSelectionView.getSelectedTable()));
75 // get the table names, table titles and default table index for the current document
76 AsyncCallback<GlomDocument> callback = new AsyncCallback<GlomDocument>() {
77 public void onFailure(Throwable caught) {
78 // FIXME: need to deal with failure
79 System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()");
82 public void onSuccess(GlomDocument result) {
83 tableSelectionView.setTableSelection(result.getTableNames(), result.getTableTitles());
84 tableSelectionView.setTableSelectedIndex(result.getDefaultTableIndex());
87 OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(documentID, callback);
89 // we're done, set the widget
90 containerWidget.setWidget(tableSelectionView.asWidget());
93 public void setPlace(HasSelectableTablePlace place) {
94 this.documentID = place.getDocumentID();
95 TableSelectionView tableSelectionView = clientFactory.getTableSelectionView();
97 // show the 'back to list' link if we're at a DetailsPlace, hide it otherwise
98 if (place instanceof DetailsPlace) {
99 tableSelectionView.setBackLinkVisible(true);
100 tableSelectionView.setBackLink(documentID);
101 } else if (place instanceof ListPlace) {
102 tableSelectionView.setBackLinkVisible(false);
106 private void clearView() {
107 clientFactory.getTableSelectionView().clear();
108 if (changeHandlerRegistration != null) {
109 changeHandlerRegistration.removeHandler();
110 changeHandlerRegistration = null;
117 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
120 public void onCancel() {
127 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
130 public void onStop() {
137 * @see org.glom.web.client.ui.TableSelectionView.Presenter#goTo(com.google.gwt.place.shared.Place)
140 public void goTo(Place place) {
141 clientFactory.getPlaceController().goTo(place);