From ccd7fd591c4a3446ad4202b8a910f5e09f0d13b5 Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Mon, 4 Apr 2011 08:25:53 +0200 Subject: [PATCH] Move View classes to their own package. This is the second commit of a refactor that will allow OnlineGlom to be used with multiple documents. --- ChangeLog | 11 + .../java/org/glom/web/client/LayoutListView.java | 239 -------------------- src/main/java/org/glom/web/client/OnlineGlom.java | 2 + .../java/org/glom/web/client/OnlineGlomView.java | 93 -------- .../org/glom/web/client/ui/LayoutListView.java | 240 +++++++++++++++++++++ .../org/glom/web/client/ui/OnlineGlomView.java | 94 ++++++++ 6 files changed, 347 insertions(+), 332 deletions(-) delete mode 100644 src/main/java/org/glom/web/client/LayoutListView.java delete mode 100644 src/main/java/org/glom/web/client/OnlineGlomView.java create mode 100644 src/main/java/org/glom/web/client/ui/LayoutListView.java create mode 100644 src/main/java/org/glom/web/client/ui/OnlineGlomView.java diff --git a/ChangeLog b/ChangeLog index db18d32..b270e7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-04-04 Ben Konrath + + Move View classes to their own package. + + This is the second commit of a refactor that will allow OnlineGlom to + be used with multiple documents. + + * src/main/java/org/glom/web/client/OnlineGlom.java: + * src/main/java/org/glom/web/client/ui/LayoutListView.java: + * src/main/java/org/glom/web/client/ui/OnlineGlomView.java: + 2011-04-02 Ben Konrath Move UI code from the main module to its own class. diff --git a/src/main/java/org/glom/web/client/LayoutListView.java b/src/main/java/org/glom/web/client/LayoutListView.java deleted file mode 100644 index e8a7a28..0000000 --- a/src/main/java/org/glom/web/client/LayoutListView.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (C) 2010, 2011 Openismus GmbH - * - * This file is part of GWT-Glom. - * - * GWT-Glom is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GWT-Glom. If not, see . - */ - -package org.glom.web.client; - -import java.util.ArrayList; - -import org.glom.web.shared.ColumnInfo; -import org.glom.web.shared.GlomField; - -import com.google.gwt.cell.client.AbstractCell; -import com.google.gwt.cell.client.ButtonCell; -import com.google.gwt.cell.client.CheckboxCell; -import com.google.gwt.cell.client.ValueUpdater; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.InputElement; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.safehtml.shared.SafeHtml; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; -import com.google.gwt.safehtml.shared.SafeHtmlUtils; -import com.google.gwt.user.cellview.client.CellTable; -import com.google.gwt.user.cellview.client.Column; -import com.google.gwt.user.cellview.client.ColumnSortEvent.AsyncHandler; -import com.google.gwt.user.cellview.client.ColumnSortList; -import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo; -import com.google.gwt.user.cellview.client.SafeHtmlHeader; -import com.google.gwt.user.cellview.client.SimplePager; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.view.client.AsyncDataProvider; -import com.google.gwt.view.client.HasData; -import com.google.gwt.view.client.Range; - -public class LayoutListView extends Composite { - - private class GlomTextCell extends AbstractCell { - - // The SafeHtml class is used to escape strings to avoid XSS attacks. This is not strictly - // necessary because the values aren't coming from a user but I'm using it anyway as a reminder. - @Override - public void render(Context context, GlomField value, SafeHtmlBuilder sb) { - if (value == null) { - return; - } - - // get the foreground and background colours if they're set - SafeHtml fgcolour = null, bgcolour = null; - String colour = value.getFGColour(); - if (colour == null) { - fgcolour = SafeHtmlUtils.fromSafeConstant(""); - } else { - fgcolour = SafeHtmlUtils.fromString("color:" + colour + ";"); - } - colour = value.getBGColour(); - if (colour == null) { - bgcolour = SafeHtmlUtils.fromSafeConstant(""); - } else { - bgcolour = SafeHtmlUtils.fromString("background-color:" + colour + ";"); - } - - // set the text and colours - sb.appendHtmlConstant("
"); - sb.append(SafeHtmlUtils.fromString(value.getText())); - sb.appendHtmlConstant("
"); - } - } - - public LayoutListView(ColumnInfo[] columns, int numRows) { - final CellTable table = new CellTable(20); - - AsyncDataProvider dataProvider = new AsyncDataProvider() { - @Override - @SuppressWarnings("unchecked") - protected void onRangeChanged(HasData display) { - // setup the callback object - final Range range = display.getVisibleRange(); - final int start = range.getStart(); - AsyncCallback> callback = new AsyncCallback>() { - public void onFailure(Throwable caught) { - // FIXME: need to deal with failure - System.out.println("AsyncCallback Failed: OnlineGlomService.getTableData()"); - } - - public void onSuccess(ArrayList result) { - updateRowData(start, result); - } - }; - - // get data from the server - ColumnSortList colSortList = table.getColumnSortList(); - if (colSortList.size() > 0) { - // ColumnSortEvent has been requested by the user - ColumnSortInfo info = colSortList.get(0); - OnlineGlomServiceAsync.Util.getInstance().getSortedTableData(OnlineGlomView.getCurrentTableName(), - start, range.getLength(), table.getColumnIndex((Column) info.getColumn()), - info.isAscending(), callback); - } else { - OnlineGlomServiceAsync.Util.getInstance().getTableData(OnlineGlomView.getCurrentTableName(), start, - range.getLength(), callback); - } - } - }; - - dataProvider.addDataDisplay(table); - - SimplePager pager = new SimplePager(SimplePager.TextLocation.CENTER); - pager.setDisplay(table); - - // a panel to hold our widgets - VerticalPanel panel = new VerticalPanel(); - panel.add(table); - panel.add(pager); - - // create instances of GlomFieldColumn to retrieve the GlomField objects - for (int i = 0; i < columns.length; i++) { - // create a new column - Column column = null; - final int j = new Integer(i); - - switch (columns[i].getType()) { - case TYPE_BOOLEAN: - // The onBrowserEvent method is overridden to ensure the user can't toggle the checkbox. We'll probably - // be able to use a CheckboxCell directly when we add support for editing. - column = new Column(new CheckboxCell(false, false) { - @Override - public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event, - ValueUpdater valueUpdater) { - String type = event.getType(); - - boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER; - if ("change".equals(type) || enterPressed) { - InputElement input = parent.getFirstChild().cast(); - input.setChecked(!input.isChecked()); - } - } - }) { - @Override - public Boolean getValue(GlomField[] object) { - return object[j].getBoolean(); - } - }; - // Make checkboxes centred in the column. - column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); - break; - default: - // use a text rendering cell for types we don't know about but log an error - // TODO log error here - case TYPE_DATE: - case TYPE_IMAGE: - case TYPE_INVALID: - case TYPE_NUMERIC: - case TYPE_TIME: - case TYPE_TEXT: - // All of these types are formatted as text in the servlet. - column = new Column(new GlomTextCell()) { - @Override - public GlomField getValue(GlomField[] object) { - return object[j]; - } - }; - - // Set the alignment of the text. - switch (columns[i].getAlignment()) { - case HORIZONTAL_ALIGNMENT_LEFT: - column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); - break; - case HORIZONTAL_ALIGNMENT_RIGHT: - column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); - break; - case HORIZONTAL_ALIGNMENT_AUTO: - default: - // TODO: log warning, this shouldn't happen - column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_DEFAULT); - break; - } - break; - } - - // set column properties and add to cell table - column.setSortable(true); - table.addColumn(column, new SafeHtmlHeader(SafeHtmlUtils.fromString(columns[i].getHeader()))); - } - - Column detailsColumn = new Column(new ButtonCell() { - @Override - public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { - // TODO Enable the Details button: remove disabled=\"disabled\", add - // onclick=\"window.location.href='#targetHistoryToken'\", figure out how to create a history token to - // uniquely identify the row. - // TODO change to custom css class - // We're using a button tag for the link. If this causes a problem we can use an anchor tag with css - // styling - // to make it look like a button. - sb.appendHtmlConstant(""); - } - }) { - @Override - public String getValue(GlomField[] object) { - return "Details"; - } - }; - - table.addColumn(detailsColumn, ""); - - // set row count which is needed for paging - table.setRowCount(numRows); - - // add an AsyncHandler to activate sorting for the AsyncDataProvider that was created above - table.addColumnSortHandler(new AsyncHandler(table)); - - // take care of the stuff required for composite widgets - initWidget(panel); - setStyleName("glom-LayoutListView"); - } - -} diff --git a/src/main/java/org/glom/web/client/OnlineGlom.java b/src/main/java/org/glom/web/client/OnlineGlom.java index 35fe1ab..34a84bc 100644 --- a/src/main/java/org/glom/web/client/OnlineGlom.java +++ b/src/main/java/org/glom/web/client/OnlineGlom.java @@ -19,6 +19,8 @@ package org.glom.web.client; +import org.glom.web.client.ui.OnlineGlomView; + import com.google.gwt.core.client.EntryPoint; /** diff --git a/src/main/java/org/glom/web/client/OnlineGlomView.java b/src/main/java/org/glom/web/client/OnlineGlomView.java deleted file mode 100644 index 8887081..0000000 --- a/src/main/java/org/glom/web/client/OnlineGlomView.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.glom.web.client; - -import java.util.ArrayList; - -import org.glom.web.shared.GlomDocument; -import org.glom.web.shared.LayoutListTable; - -import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.event.dom.client.ChangeHandler; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.IsWidget; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.ListBox; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.VerticalPanel; - -public class OnlineGlomView extends Composite implements IsWidget { - - private final VerticalPanel mainVPanel = new VerticalPanel(); - private final HorizontalPanel hPanel = new HorizontalPanel(); - private static ListBox dropBox = new ListBox(); - private LayoutListView table = null; - private String documentName = ""; - - public OnlineGlomView() { - dropBox.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - updateTable(); - } - }); - - hPanel.add(new Label("Table:")); - hPanel.add(dropBox); - - mainVPanel.add(hPanel); - - // associate the main panel with the HTML host page - RootPanel.get().add(mainVPanel); - - // set up the callback object. - AsyncCallback callback = new AsyncCallback() { - public void onFailure(Throwable caught) { - // FIXME: need to deal with failure - System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()"); - } - - public void onSuccess(GlomDocument result) { - ArrayList tableNames = result.getTableNames(); - ArrayList tableTitles = result.getTableTitles(); - for (int i = 0; i < tableNames.size(); i++) { - dropBox.addItem(tableTitles.get(i), tableNames.get(i)); - } - dropBox.setSelectedIndex(result.getDefaultTableIndex()); - documentName = result.getTitle(); - updateTable(); - } - }; - - // make the call to get the filled in GlomDocument - OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(callback); - } - - private void updateTable() { - - // set up the callback object. - AsyncCallback callback = new AsyncCallback() { - public void onFailure(Throwable caught) { - // FIXME: need to deal with failure - System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()"); - } - - public void onSuccess(LayoutListTable result) { - if (table != null) - mainVPanel.remove(table); - table = new LayoutListView(result.getColumns(), result.getNumRows()); - mainVPanel.add(table); - Window.setTitle("OnlineGlom - " + documentName + ": " + dropBox.getItemText(dropBox.getSelectedIndex())); - } - }; - - String selectedTable = dropBox.getValue(dropBox.getSelectedIndex()); - OnlineGlomServiceAsync.Util.getInstance().getLayoutListTable(selectedTable, callback); - - } - - // FIXME find a better way to do this - public static String getCurrentTableName() { - return dropBox.getValue(dropBox.getSelectedIndex()); - } -} diff --git a/src/main/java/org/glom/web/client/ui/LayoutListView.java b/src/main/java/org/glom/web/client/ui/LayoutListView.java new file mode 100644 index 0000000..2936505 --- /dev/null +++ b/src/main/java/org/glom/web/client/ui/LayoutListView.java @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2010, 2011 Openismus GmbH + * + * This file is part of GWT-Glom. + * + * GWT-Glom is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GWT-Glom. If not, see . + */ + +package org.glom.web.client.ui; + +import java.util.ArrayList; + +import org.glom.web.client.OnlineGlomServiceAsync; +import org.glom.web.shared.ColumnInfo; +import org.glom.web.shared.GlomField; + +import com.google.gwt.cell.client.AbstractCell; +import com.google.gwt.cell.client.ButtonCell; +import com.google.gwt.cell.client.CheckboxCell; +import com.google.gwt.cell.client.ValueUpdater; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.InputElement; +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.safehtml.shared.SafeHtmlUtils; +import com.google.gwt.user.cellview.client.CellTable; +import com.google.gwt.user.cellview.client.Column; +import com.google.gwt.user.cellview.client.ColumnSortEvent.AsyncHandler; +import com.google.gwt.user.cellview.client.ColumnSortList; +import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo; +import com.google.gwt.user.cellview.client.SafeHtmlHeader; +import com.google.gwt.user.cellview.client.SimplePager; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.view.client.AsyncDataProvider; +import com.google.gwt.view.client.HasData; +import com.google.gwt.view.client.Range; + +public class LayoutListView extends Composite { + + private class GlomTextCell extends AbstractCell { + + // The SafeHtml class is used to escape strings to avoid XSS attacks. This is not strictly + // necessary because the values aren't coming from a user but I'm using it anyway as a reminder. + @Override + public void render(Context context, GlomField value, SafeHtmlBuilder sb) { + if (value == null) { + return; + } + + // get the foreground and background colours if they're set + SafeHtml fgcolour = null, bgcolour = null; + String colour = value.getFGColour(); + if (colour == null) { + fgcolour = SafeHtmlUtils.fromSafeConstant(""); + } else { + fgcolour = SafeHtmlUtils.fromString("color:" + colour + ";"); + } + colour = value.getBGColour(); + if (colour == null) { + bgcolour = SafeHtmlUtils.fromSafeConstant(""); + } else { + bgcolour = SafeHtmlUtils.fromString("background-color:" + colour + ";"); + } + + // set the text and colours + sb.appendHtmlConstant("
"); + sb.append(SafeHtmlUtils.fromString(value.getText())); + sb.appendHtmlConstant("
"); + } + } + + public LayoutListView(ColumnInfo[] columns, int numRows) { + final CellTable table = new CellTable(20); + + AsyncDataProvider dataProvider = new AsyncDataProvider() { + @Override + @SuppressWarnings("unchecked") + protected void onRangeChanged(HasData display) { + // setup the callback object + final Range range = display.getVisibleRange(); + final int start = range.getStart(); + AsyncCallback> callback = new AsyncCallback>() { + public void onFailure(Throwable caught) { + // FIXME: need to deal with failure + System.out.println("AsyncCallback Failed: OnlineGlomService.getTableData()"); + } + + public void onSuccess(ArrayList result) { + updateRowData(start, result); + } + }; + + // get data from the server + ColumnSortList colSortList = table.getColumnSortList(); + if (colSortList.size() > 0) { + // ColumnSortEvent has been requested by the user + ColumnSortInfo info = colSortList.get(0); + OnlineGlomServiceAsync.Util.getInstance().getSortedTableData(OnlineGlomView.getCurrentTableName(), + start, range.getLength(), table.getColumnIndex((Column) info.getColumn()), + info.isAscending(), callback); + } else { + OnlineGlomServiceAsync.Util.getInstance().getTableData(OnlineGlomView.getCurrentTableName(), start, + range.getLength(), callback); + } + } + }; + + dataProvider.addDataDisplay(table); + + SimplePager pager = new SimplePager(SimplePager.TextLocation.CENTER); + pager.setDisplay(table); + + // a panel to hold our widgets + VerticalPanel panel = new VerticalPanel(); + panel.add(table); + panel.add(pager); + + // create instances of GlomFieldColumn to retrieve the GlomField objects + for (int i = 0; i < columns.length; i++) { + // create a new column + Column column = null; + final int j = new Integer(i); + + switch (columns[i].getType()) { + case TYPE_BOOLEAN: + // The onBrowserEvent method is overridden to ensure the user can't toggle the checkbox. We'll probably + // be able to use a CheckboxCell directly when we add support for editing. + column = new Column(new CheckboxCell(false, false) { + @Override + public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event, + ValueUpdater valueUpdater) { + String type = event.getType(); + + boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER; + if ("change".equals(type) || enterPressed) { + InputElement input = parent.getFirstChild().cast(); + input.setChecked(!input.isChecked()); + } + } + }) { + @Override + public Boolean getValue(GlomField[] object) { + return object[j].getBoolean(); + } + }; + // Make checkboxes centred in the column. + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); + break; + default: + // use a text rendering cell for types we don't know about but log an error + // TODO log error here + case TYPE_DATE: + case TYPE_IMAGE: + case TYPE_INVALID: + case TYPE_NUMERIC: + case TYPE_TIME: + case TYPE_TEXT: + // All of these types are formatted as text in the servlet. + column = new Column(new GlomTextCell()) { + @Override + public GlomField getValue(GlomField[] object) { + return object[j]; + } + }; + + // Set the alignment of the text. + switch (columns[i].getAlignment()) { + case HORIZONTAL_ALIGNMENT_LEFT: + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + break; + case HORIZONTAL_ALIGNMENT_RIGHT: + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); + break; + case HORIZONTAL_ALIGNMENT_AUTO: + default: + // TODO: log warning, this shouldn't happen + column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_DEFAULT); + break; + } + break; + } + + // set column properties and add to cell table + column.setSortable(true); + table.addColumn(column, new SafeHtmlHeader(SafeHtmlUtils.fromString(columns[i].getHeader()))); + } + + Column detailsColumn = new Column(new ButtonCell() { + @Override + public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { + // TODO Enable the Details button: remove disabled=\"disabled\", add + // onclick=\"window.location.href='#targetHistoryToken'\", figure out how to create a history token to + // uniquely identify the row. + // TODO change to custom css class + // We're using a button tag for the link. If this causes a problem we can use an anchor tag with css + // styling + // to make it look like a button. + sb.appendHtmlConstant(""); + } + }) { + @Override + public String getValue(GlomField[] object) { + return "Details"; + } + }; + + table.addColumn(detailsColumn, ""); + + // set row count which is needed for paging + table.setRowCount(numRows); + + // add an AsyncHandler to activate sorting for the AsyncDataProvider that was created above + table.addColumnSortHandler(new AsyncHandler(table)); + + // take care of the stuff required for composite widgets + initWidget(panel); + setStyleName("glom-LayoutListView"); + } + +} diff --git a/src/main/java/org/glom/web/client/ui/OnlineGlomView.java b/src/main/java/org/glom/web/client/ui/OnlineGlomView.java new file mode 100644 index 0000000..742d5ed --- /dev/null +++ b/src/main/java/org/glom/web/client/ui/OnlineGlomView.java @@ -0,0 +1,94 @@ +package org.glom.web.client.ui; + +import java.util.ArrayList; + +import org.glom.web.client.OnlineGlomServiceAsync; +import org.glom.web.shared.GlomDocument; +import org.glom.web.shared.LayoutListTable; + +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.IsWidget; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.ListBox; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.VerticalPanel; + +public class OnlineGlomView extends Composite implements IsWidget { + + private final VerticalPanel mainVPanel = new VerticalPanel(); + private final HorizontalPanel hPanel = new HorizontalPanel(); + private static ListBox dropBox = new ListBox(); + private LayoutListView table = null; + private String documentName = ""; + + public OnlineGlomView() { + dropBox.addChangeHandler(new ChangeHandler() { + public void onChange(ChangeEvent event) { + updateTable(); + } + }); + + hPanel.add(new Label("Table:")); + hPanel.add(dropBox); + + mainVPanel.add(hPanel); + + // associate the main panel with the HTML host page + RootPanel.get().add(mainVPanel); + + // set up the callback object. + AsyncCallback callback = new AsyncCallback() { + public void onFailure(Throwable caught) { + // FIXME: need to deal with failure + System.out.println("AsyncCallback Failed: OnlineGlomService.getGlomDocument()"); + } + + public void onSuccess(GlomDocument result) { + ArrayList tableNames = result.getTableNames(); + ArrayList tableTitles = result.getTableTitles(); + for (int i = 0; i < tableNames.size(); i++) { + dropBox.addItem(tableTitles.get(i), tableNames.get(i)); + } + dropBox.setSelectedIndex(result.getDefaultTableIndex()); + documentName = result.getTitle(); + updateTable(); + } + }; + + // make the call to get the filled in GlomDocument + OnlineGlomServiceAsync.Util.getInstance().getGlomDocument(callback); + } + + private void updateTable() { + + // set up the callback object. + AsyncCallback callback = new AsyncCallback() { + public void onFailure(Throwable caught) { + // FIXME: need to deal with failure + System.out.println("AsyncCallback Failed: OnlineGlomService.getLayoutListTable()"); + } + + public void onSuccess(LayoutListTable result) { + if (table != null) + mainVPanel.remove(table); + table = new LayoutListView(result.getColumns(), result.getNumRows()); + mainVPanel.add(table); + Window.setTitle("OnlineGlom - " + documentName + ": " + dropBox.getItemText(dropBox.getSelectedIndex())); + } + }; + + String selectedTable = dropBox.getValue(dropBox.getSelectedIndex()); + OnlineGlomServiceAsync.Util.getInstance().getLayoutListTable(selectedTable, callback); + + } + + // FIXME find a better way to do this + public static String getCurrentTableName() { + return dropBox.getValue(dropBox.getSelectedIndex()); + } +} -- 2.1.4