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.ListPlace;
27 import org.glom.web.client.ui.TableSelectionView;
28 import org.glom.web.shared.GlomDocument;
30 import com.google.gwt.activity.shared.AbstractActivity;
31 import com.google.gwt.event.dom.client.ChangeEvent;
32 import com.google.gwt.event.dom.client.ChangeHandler;
33 import com.google.gwt.event.dom.client.HasChangeHandlers;
34 import com.google.gwt.event.shared.EventBus;
35 import com.google.gwt.event.shared.HandlerRegistration;
36 import com.google.gwt.user.client.Window;
37 import com.google.gwt.user.client.rpc.AsyncCallback;
38 import com.google.gwt.user.client.ui.AcceptsOneWidget;
41 * @author Ben Konrath <ben@bagu.org>
44 public class TableSelectionActivity extends AbstractActivity {
45 private final ClientFactory clientFactory;
46 private String documentTitle;
47 private HandlerRegistration changeHandlerRegistration = null;
49 public TableSelectionActivity(ListPlace place, ClientFactory clientFactory) {
50 this.documentTitle = place.getDocumentTitle();
51 this.clientFactory = clientFactory;
54 public TableSelectionActivity(DetailsPlace place, ClientFactory clientFactory) {
55 this.documentTitle = place.getDocumentTitle();
56 this.clientFactory = clientFactory;
60 * Invoked by the ActivityManager to start a new Activity
63 public void start(AcceptsOneWidget containerWidget, final EventBus eventBus) {
64 Window.setTitle("Online Glom - " + documentTitle);
66 final TableSelectionView tableSelectionView = clientFactory.getTableSelectionView();
68 HasChangeHandlers tableSelector = tableSelectionView.getTableSelector();
70 changeHandlerRegistration = tableSelector.addChangeHandler(new ChangeHandler() {
72 public void onChange(ChangeEvent event) {
73 eventBus.fireEvent(new TableChangeEvent(tableSelectionView.getSelectedTable()));
77 // get the table names, table titles and default table index for the current document
78 AsyncCallback<GlomDocument> callback = new AsyncCallback<GlomDocument>() {
79 public void onFailure(Throwable caught) {
80 // FIXME: need to deal with failure
81 System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()");
84 public void onSuccess(GlomDocument result) {
85 tableSelectionView.setTableSelection(result.getTableNames(), result.getTableTitles());
86 tableSelectionView.setTableSelectedIndex(result.getDefaultTableIndex());
89 OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(documentTitle, callback);
91 // we're done, set the widget
92 containerWidget.setWidget(tableSelectionView.asWidget());
95 private void clearView() {
96 clientFactory.getTableSelectionView().clear();
97 if (changeHandlerRegistration != null) {
98 changeHandlerRegistration.removeHandler();
99 changeHandlerRegistration = null;
106 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
109 public void onCancel() {
116 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
119 public void onStop() {