2 * Copyright (C) 2010, 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;
22 import java.util.ArrayList;
24 import org.glom.web.shared.GlomDocument;
25 import org.glom.web.shared.LayoutListTable;
27 import com.google.gwt.core.client.EntryPoint;
28 import com.google.gwt.event.dom.client.ChangeEvent;
29 import com.google.gwt.event.dom.client.ChangeHandler;
30 import com.google.gwt.user.client.Window;
31 import com.google.gwt.user.client.rpc.AsyncCallback;
32 import com.google.gwt.user.client.ui.HorizontalPanel;
33 import com.google.gwt.user.client.ui.Label;
34 import com.google.gwt.user.client.ui.ListBox;
35 import com.google.gwt.user.client.ui.RootPanel;
36 import com.google.gwt.user.client.ui.VerticalPanel;
39 * Entry point classes define <code>onModuleLoad()</code>.
41 public class OnlineGlom implements EntryPoint {
43 private VerticalPanel mainVPanel = new VerticalPanel();
44 private HorizontalPanel hPanel = new HorizontalPanel();
45 private static ListBox dropBox = new ListBox();
46 private LayoutListView table = null;
47 private String documentName = "";
49 public void onModuleLoad() {
50 dropBox.addChangeHandler(new ChangeHandler() {
51 public void onChange(ChangeEvent event) {
56 hPanel.add(new Label("Table:"));
59 mainVPanel.add(hPanel);
61 // associate the main panel with the HTML host page
62 RootPanel.get().add(mainVPanel);
64 // set up the callback object.
65 AsyncCallback<GlomDocument> callback = new AsyncCallback<GlomDocument>() {
66 public void onFailure(Throwable caught) {
67 // FIXME: need to deal with failure
68 System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()");
71 public void onSuccess(GlomDocument result) {
72 ArrayList<String> tableNames = result.getTableNames();
73 ArrayList<String> tableTitles = result.getTableTitles();
74 for (int i = 0; i < tableNames.size(); i++) {
75 dropBox.addItem(tableTitles.get(i), tableNames.get(i));
77 dropBox.setSelectedIndex(result.getDefaultTableIndex());
78 documentName = result.getTitle();
83 // make the call to get the filled in GlomDocument
84 OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(callback);
87 private void updateTable() {
89 // set up the callback object.
90 AsyncCallback<LayoutListTable> callback = new AsyncCallback<LayoutListTable>() {
91 public void onFailure(Throwable caught) {
92 // FIXME: need to deal with failure
93 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
96 public void onSuccess(LayoutListTable result) {
98 mainVPanel.remove(table);
99 table = new LayoutListView(result.getColumnTitles(), result.getNumRows());
100 mainVPanel.add(table);
101 Window.setTitle("OnlineGlom - " + documentName + ": " + dropBox.getItemText(dropBox.getSelectedIndex()));
105 String selectedTable = dropBox.getValue(dropBox.getSelectedIndex());
106 OnlineGlomServiceAsync.Util.getInstance().getLayoutListTable(selectedTable, callback);
110 // FIXME find a better way to do this
111 public static String getCurrentTableName() {
112 return dropBox.getValue(dropBox.getSelectedIndex());