Use generated Util class to get the RPC Async interface.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / client / OnlineGlom.java
1 package org.glom.web.client;
2
3 import com.google.gwt.core.client.EntryPoint;
4 import com.google.gwt.event.dom.client.ChangeEvent;
5 import com.google.gwt.event.dom.client.ChangeHandler;
6 import com.google.gwt.user.client.Window;
7 import com.google.gwt.user.client.rpc.AsyncCallback;
8 import com.google.gwt.user.client.ui.HorizontalPanel;
9 import com.google.gwt.user.client.ui.Label;
10 import com.google.gwt.user.client.ui.ListBox;
11 import com.google.gwt.user.client.ui.RootPanel;
12 import com.google.gwt.user.client.ui.VerticalPanel;
13
14 /**
15  * Entry point classes define <code>onModuleLoad()</code>.
16  */
17 public class OnlineGlom implements EntryPoint {
18
19         private VerticalPanel mainVPanel = new VerticalPanel();
20         private HorizontalPanel hPanel = new HorizontalPanel();
21         private static ListBox dropBox = new ListBox();
22         private LayoutList table = null;
23         private String documentName = "";
24
25         public void onModuleLoad() {
26                 dropBox.addChangeHandler(new ChangeHandler() {
27                         public void onChange(ChangeEvent event) {
28                                 updateTable();
29                         }
30                 });
31
32                 hPanel.add(new Label("Table:"));
33                 hPanel.add(dropBox);
34
35                 mainVPanel.add(hPanel);
36
37                 // associate the main panel with the HTML host page
38                 RootPanel.get().add(mainVPanel);
39
40                 // set up the callback object.
41                 AsyncCallback<GlomDocument> callback = new AsyncCallback<GlomDocument>() {
42                         public void onFailure(Throwable caught) {
43                                 // FIXME: need to deal with failure
44                                 System.out.println("AsyncCallback Failed: LibGlomService");
45                         }
46
47                         public void onSuccess(GlomDocument result) {
48                                 GlomTable[] tables = result.getTables();
49                                 for (int i = 0; i < tables.length; i++) {
50                                         dropBox.addItem(tables[i].getTitle(), tables[i].getName());
51                                 }
52                                 dropBox.setSelectedIndex(result.getDefaultTableIndex());
53                                 documentName = result.getTitle();
54                                 updateTable();
55                         }
56                 };
57
58                 // make the call to get the filled in GlomDocument
59                 LibGlomServiceAsync.Util.getInstance().getGlomDocument(callback);
60         }
61
62         private void updateTable() {
63
64                 // set up the callback object.
65                 AsyncCallback<String[]> callback = new AsyncCallback<String[]>() {
66                         public void onFailure(Throwable caught) {
67                                 // FIXME: need to deal with failure
68                                 System.out.println("AsyncCallback Failed: LibGlomService.updateTable()");
69                         }
70
71                         public void onSuccess(String[] result) {
72                                 if (table != null)
73                                         mainVPanel.remove(table);
74                                 table = new LayoutList(result);
75                                 mainVPanel.add(table);
76                                 Window.setTitle("OnlineGlom - " + documentName + ": " + dropBox.getItemText(dropBox.getSelectedIndex()));
77                         }
78                 };
79
80                 String selectedTable = dropBox.getValue(dropBox.getSelectedIndex());
81                 LibGlomServiceAsync.Util.getInstance().getLayoutListHeaders(selectedTable, callback);
82
83         }
84
85         // FIXME find a better way to do this
86         public static String getCurrentTableName() {
87                 return dropBox.getValue(dropBox.getSelectedIndex());
88         }
89 }