1 package org.glom.web.client;
3 import java.util.ArrayList;
5 import org.glom.web.shared.GlomDocument;
6 import org.glom.web.shared.LayoutListTable;
8 import com.google.gwt.event.dom.client.ChangeEvent;
9 import com.google.gwt.event.dom.client.ChangeHandler;
10 import com.google.gwt.user.client.Window;
11 import com.google.gwt.user.client.rpc.AsyncCallback;
12 import com.google.gwt.user.client.ui.Composite;
13 import com.google.gwt.user.client.ui.HorizontalPanel;
14 import com.google.gwt.user.client.ui.IsWidget;
15 import com.google.gwt.user.client.ui.Label;
16 import com.google.gwt.user.client.ui.ListBox;
17 import com.google.gwt.user.client.ui.RootPanel;
18 import com.google.gwt.user.client.ui.VerticalPanel;
20 public class OnlineGlomView extends Composite implements IsWidget {
22 private final VerticalPanel mainVPanel = new VerticalPanel();
23 private final HorizontalPanel hPanel = new HorizontalPanel();
24 private static ListBox dropBox = new ListBox();
25 private LayoutListView table = null;
26 private String documentName = "";
28 public OnlineGlomView() {
29 dropBox.addChangeHandler(new ChangeHandler() {
30 public void onChange(ChangeEvent event) {
35 hPanel.add(new Label("Table:"));
38 mainVPanel.add(hPanel);
40 // associate the main panel with the HTML host page
41 RootPanel.get().add(mainVPanel);
43 // set up the callback object.
44 AsyncCallback<GlomDocument> callback = new AsyncCallback<GlomDocument>() {
45 public void onFailure(Throwable caught) {
46 // FIXME: need to deal with failure
47 System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()");
50 public void onSuccess(GlomDocument result) {
51 ArrayList<String> tableNames = result.getTableNames();
52 ArrayList<String> tableTitles = result.getTableTitles();
53 for (int i = 0; i < tableNames.size(); i++) {
54 dropBox.addItem(tableTitles.get(i), tableNames.get(i));
56 dropBox.setSelectedIndex(result.getDefaultTableIndex());
57 documentName = result.getTitle();
62 // make the call to get the filled in GlomDocument
63 OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(callback);
66 private void updateTable() {
68 // set up the callback object.
69 AsyncCallback<LayoutListTable> callback = new AsyncCallback<LayoutListTable>() {
70 public void onFailure(Throwable caught) {
71 // FIXME: need to deal with failure
72 System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()");
75 public void onSuccess(LayoutListTable result) {
77 mainVPanel.remove(table);
78 table = new LayoutListView(result.getColumns(), result.getNumRows());
79 mainVPanel.add(table);
80 Window.setTitle("OnlineGlom - " + documentName + ": " + dropBox.getItemText(dropBox.getSelectedIndex()));
84 String selectedTable = dropBox.getValue(dropBox.getSelectedIndex());
85 OnlineGlomServiceAsync.Util.getInstance().getLayoutListTable(selectedTable, callback);
89 // FIXME find a better way to do this
90 public static String getCurrentTableName() {
91 return dropBox.getValue(dropBox.getSelectedIndex());