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