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.ui;
22 import org.glom.web.client.place.DetailsPlace;
23 import org.glom.web.client.ui.cell.OpenButtonCell;
24 import org.glom.web.client.ui.list.ListViewTable;
25 import org.glom.web.shared.TypedDataItem;
26 import org.glom.web.shared.layout.LayoutGroup;
28 import com.google.gwt.cell.client.ValueUpdater;
29 import com.google.gwt.dom.client.Element;
30 import com.google.gwt.dom.client.NativeEvent;
31 import com.google.gwt.user.client.ui.Composite;
32 import com.google.gwt.user.client.ui.FlowPanel;
34 public class ListViewImpl extends Composite implements ListView {
37 * Cell renderer for Details open buttons.
39 private class DetailsButtonCell extends OpenButtonCell {
40 private String documentID;
41 private String tableName;
43 public DetailsButtonCell(String documentID, String tableName) {
44 this.documentID = documentID;
45 this.tableName = tableName;
51 * @see com.google.gwt.cell.client.ButtonCell#onEnterKeyDown(com.google.gwt.cell.client.Cell.Context,
52 * com.google.gwt.dom.client.Element, java.lang.String, com.google.gwt.dom.client.NativeEvent,
53 * com.google.gwt.cell.client.ValueUpdater)
56 protected void onEnterKeyDown(Context context, Element parent, String value, NativeEvent event,
57 ValueUpdater<String> valueUpdater) {
58 presenter.goTo(new DetailsPlace(documentID, tableName, (TypedDataItem) context.getKey()));
63 final private FlowPanel mainPanel = new FlowPanel();
64 private Presenter presenter;
66 public ListViewImpl() {
67 initWidget(mainPanel);
71 public void setPresenter(Presenter presenter) {
72 this.presenter = presenter;
76 public void setCellTable(final String documentID, LayoutGroup layoutGroup) {
77 // This is not really in the MVP style because we're creating a new ListTable (really just a configured
78 // CellTable) for every document and table name change. The issue with creating a re-usable CellTable with
79 // methods like setColumnTitles() and setNumRows() is that the column objects (new Column<DataItem[],
80 // DataItem>(new GlomTextCell())) aren't destroyed when the column is removed from the CellTable and
81 // IndexOutOfBounds exceptions are encountered with invalid array indexes trying access the data in this line:
82 // return object[j]. There's probably a workaround that could be done to fix this but I'm leaving it until
83 // there's a reason to fix it (performance, ease of testing, alternate implementation or otherwise).
84 // Note: This comment refers to code that is now in the ListTable class.
88 ListViewTable listViewTable = new ListViewTable(documentID, layoutGroup, "Details", new DetailsButtonCell(
89 documentID, layoutGroup.getTableName()));
91 if (layoutGroup.getExpectedResultSize() <= listViewTable.getMinNumVisibleRows()) {
92 // Set the table row count to the minimum row count if the data row count is less than or equal to
93 // the minimum row count. This ensures that data with fewer rows than the minimum will not create
94 // indexes in the underlying CellTable that will override the rendering of the empty rows.
95 listViewTable.setRowCount(listViewTable.getMinNumVisibleRows());
97 // Set the table row count to the data row count if it's larger than the minimum number of rows
99 listViewTable.setRowCount(layoutGroup.getExpectedResultSize());
102 mainPanel.add(listViewTable);
108 * @see org.glom.web.client.ui.ListView#clear()
111 public void clear() {