| 1 |
/* |
| 2 |
* Copyright (C) 2010, 2011 Openismus GmbH |
| 3 |
* |
| 4 |
* This file is part of GWT-Glom. |
| 5 |
* |
| 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. |
| 10 |
* |
| 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 |
| 14 |
* for more details. |
| 15 |
* |
| 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/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
package org.glom.web.client.ui; |
| 21 |
|
| 22 |
import org.glom.web.client.place.DetailsPlace; |
| 23 |
import org.glom.web.client.ui.cell.NavigationButtonCell; |
| 24 |
import org.glom.web.client.ui.list.ListViewTable; |
| 25 |
import org.glom.web.shared.TypedDataItem; |
| 26 |
import org.glom.web.shared.layout.LayoutGroup; |
| 27 |
|
| 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; |
| 33 |
|
| 34 |
public class ListViewImpl extends Composite implements ListView { |
| 35 |
|
| 36 |
/* |
| 37 |
* Cell renderer for Details open buttons. |
| 38 |
*/ |
| 39 |
private class ListViewNavigationButtonCell extends NavigationButtonCell { |
| 40 |
private final String documentID; |
| 41 |
private final String tableName; |
| 42 |
|
| 43 |
public ListViewNavigationButtonCell(final String documentID, final String tableName) { |
| 44 |
this.documentID = documentID; |
| 45 |
this.tableName = tableName; |
| 46 |
} |
| 47 |
|
| 48 |
/* |
| 49 |
* (non-Javadoc) |
| 50 |
* |
| 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) |
| 54 |
*/ |
| 55 |
@Override |
| 56 |
protected void onEnterKeyDown(final Context context, final Element parent, final String value, |
| 57 |
final NativeEvent event, final ValueUpdater<String> valueUpdater) { |
| 58 |
presenter.goTo(new DetailsPlace(documentID, tableName, (TypedDataItem) context.getKey())); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
final private FlowPanel mainPanel = new FlowPanel(); |
| 64 |
private Presenter presenter; |
| 65 |
|
| 66 |
public ListViewImpl() { |
| 67 |
initWidget(mainPanel); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void setPresenter(final Presenter presenter) { |
| 72 |
this.presenter = presenter; |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public void setCellTable(final String documentID, final LayoutGroup layoutGroup, |
| 77 |
final String quickFind) { |
| 78 |
// This is not really in the MVP style because we're creating a new ListTable (really just a configured |
| 79 |
// CellTable) for every document and table name change. The issue with creating a re-usable CellTable with |
| 80 |
// methods like setColumnTitles() and setNumRows() is that the column objects (new Column<DataItem[], |
| 81 |
// DataItem>(new GlomTextCell())) aren't destroyed when the column is removed from the CellTable and |
| 82 |
// IndexOutOfBounds exceptions are encountered with invalid array indexes trying access the data in this line: |
| 83 |
// return object[j]. There's probably a workaround that could be done to fix this but I'm leaving it until |
| 84 |
// there's a reason to fix it (performance, ease of testing, alternate implementation or otherwise). |
| 85 |
// Note: This comment refers to code that is now in the ListTable class. |
| 86 |
|
| 87 |
mainPanel.clear(); |
| 88 |
|
| 89 |
final ListViewTable listViewTable = new ListViewTable(documentID, layoutGroup, |
| 90 |
new ListViewNavigationButtonCell(documentID, layoutGroup.getTableName()), quickFind); |
| 91 |
|
| 92 |
if (layoutGroup.getExpectedResultSize() <= listViewTable.getMinNumVisibleRows()) { |
| 93 |
// Set the table row count to the minimum row count if the data row count is less than or equal to |
| 94 |
// the minimum row count. This ensures that data with fewer rows than the minimum will not create |
| 95 |
// indexes in the underlying CellTable that will override the rendering of the empty rows. |
| 96 |
listViewTable.setRowCount(listViewTable.getMinNumVisibleRows()); |
| 97 |
} else { |
| 98 |
// Set the table row count to the data row count if it's larger than the minimum number of rows |
| 99 |
// visible. |
| 100 |
listViewTable.setRowCount(layoutGroup.getExpectedResultSize()); |
| 101 |
} |
| 102 |
|
| 103 |
mainPanel.add(listViewTable); |
| 104 |
} |
| 105 |
|
| 106 |
/* |
| 107 |
* (non-Javadoc) |
| 108 |
* |
| 109 |
* @see org.glom.web.client.ui.ListView#clear() |
| 110 |
*/ |
| 111 |
@Override |
| 112 |
public void clear() { |
| 113 |
mainPanel.clear(); |
| 114 |
} |
| 115 |
|
| 116 |
} |