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.ListPlace;
26 import org.glom.web.client.ui.TableSelectionView;
27 import org.glom.web.shared.GlomDocument;
29 import com.google.gwt.activity.shared.AbstractActivity;
30 import com.google.gwt.event.dom.client.ChangeEvent;
31 import com.google.gwt.event.dom.client.ChangeHandler;
32 import com.google.gwt.event.dom.client.HasChangeHandlers;
33 import com.google.gwt.event.shared.EventBus;
34 import com.google.gwt.event.shared.HandlerRegistration;
35 import com.google.gwt.user.client.Window;
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>
43 public class TableSelectionActivity extends AbstractActivity {
44 private final ClientFactory clientFactory;
45 private String documentTitle;
46 private HandlerRegistration changeHandlerRegistration = null;
48 public TableSelectionActivity(ListPlace place, ClientFactory clientFactory) {
49 this.documentTitle = place.getDocumentTitle();
50 this.clientFactory = clientFactory;
54 * Invoked by the ActivityManager to start a new Activity
57 public void start(AcceptsOneWidget containerWidget, final EventBus eventBus) {
58 Window.setTitle("Online Glom - " + documentTitle);
60 final TableSelectionView tableSelectionView = clientFactory.getTableSelectionView();
62 HasChangeHandlers tableSelector = tableSelectionView.getTableSelector();
64 changeHandlerRegistration = tableSelector.addChangeHandler(new ChangeHandler() {
66 public void onChange(ChangeEvent event) {
67 eventBus.fireEvent(new TableChangeEvent(tableSelectionView.getSelectedTable()));
71 // get the table names, table titles and default table index for the current document
72 AsyncCallback<GlomDocument> callback = new AsyncCallback<GlomDocument>() {
73 public void onFailure(Throwable caught) {
74 // FIXME: need to deal with failure
75 System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()");
78 public void onSuccess(GlomDocument result) {
79 tableSelectionView.setTableSelection(result.getTableNames(), result.getTableTitles());
80 tableSelectionView.setTableSelectedIndex(result.getDefaultTableIndex());
83 OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(documentTitle, callback);
85 // we're done, set the widget
86 containerWidget.setWidget(tableSelectionView.asWidget());
89 private void shutdown() {
90 clientFactory.getTableSelectionView().clear();
91 if (changeHandlerRegistration != null) {
92 changeHandlerRegistration.removeHandler();
93 changeHandlerRegistration = null;
100 * @see com.google.gwt.activity.shared.AbstractActivity#onCancel()
103 public void onCancel() {
110 * @see com.google.gwt.activity.shared.AbstractActivity#onStop()
113 public void onStop() {