You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/06/18 17:52:31 UTC
svn commit: r415150 - in /beehive/trunk/netui:
src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/
src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/
src/tags-databinding/org/apache/...
Author: ekoneil
Date: Sun Jun 18 08:52:31 2006
New Revision: 415150
URL: http://svn.apache.org/viewvc?rev=415150&view=rev
Log:
Checkpoint work on a variety of data grid pager features including:
- setting a maximum number of rows to render
- rendering 'partial' data sets; for example, this supports rendering a List of size 10 that actually contains rows 100-109 of a larger data set
- setting a size hint for the data set
This changes some APIs on the PagedDataSet class; this is only used as an internal class to the DataGrid. It should be possible to put them back, but I'd rather just remove them... Squawk if this is a problem.
Test: NetUI pass
Modified:
beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java
beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java
beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/SpanCellDecorator.java
beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/PagedDataSet.java
beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java
beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/DataGridTestUtil.java
Modified: beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java?rev=415150&r1=415149&r2=415150&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java (original)
+++ beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java Sun Jun 18 08:52:31 2006
@@ -74,8 +74,9 @@
}
/**
- * Format an {@link Object} value. This method can be called by subclasses or by {@link CellDecorator} instances
- * which need to format data before rendering.
+ * Format an {@link Object} value. This method is used to apply a chain of formatters to some
+ * value. It will return <code>null</code> if the provided value is null; in this case, it
+ * is up to the caller to provide an appropriate default value.
*
* @param value the {@link Object} to format
* @return If the <code>value</code> is null, return <code>null</code>. If there are no registered
@@ -101,7 +102,7 @@
formatted = formatter.format(formatted);
}
catch(JspException e) {
- /* todo: v1 -- error reporting */
+ /* todo: error reporting */
LOGGER.error(Bundle.getErrorString("CellModel_FormatterThrewException", new Object[]{formatter.getClass().getName(), e}), e);
}
}
Modified: beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java?rev=415150&r1=415149&r2=415150&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java (original)
+++ beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java Sun Jun 18 08:52:31 2006
@@ -212,7 +212,6 @@
public void setDataSet(PagedDataSet dataSet) {
/* todo: would be nice to address this side-effect outside of the setter */
_dataSet = dataSet;
- _dataGridState.getPagerModel().setDataSetSize(_dataSet.getSize());
}
/**
Modified: beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/SpanCellDecorator.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/SpanCellDecorator.java?rev=415150&r1=415149&r2=415150&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/SpanCellDecorator.java (original)
+++ beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/SpanCellDecorator.java Sun Jun 18 08:52:31 2006
@@ -27,6 +27,7 @@
import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
+import org.apache.beehive.netui.tags.rendering.ConstantRendering;
/**
*
@@ -35,7 +36,7 @@
extends CellDecorator {
public void decorate(JspContext jspContext, AbstractRenderAppender appender, CellModel cellModel)
- throws CellDecoratorException {
+ throws CellDecoratorException {
assert cellModel instanceof SpanCellModel;
SpanCellModel spanCellModel = (SpanCellModel)cellModel;
@@ -44,7 +45,9 @@
TagRenderingBase span = TagRenderingBase.Factory.getRendering(TagRenderingBase.SPAN_TAG, request);
String formatted = cellModel.formatText(spanCellModel.getValue());
-
+ if(formatted == null)
+ formatted = "";
+
span.doStartTag(appender, spanCellModel.getSpanState());
appender.append(formatted);
span.doEndTag(appender);
Modified: beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/PagedDataSet.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/PagedDataSet.java?rev=415150&r1=415149&r2=415150&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/PagedDataSet.java (original)
+++ beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/PagedDataSet.java Sun Jun 18 08:52:31 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,103 +17,158 @@
*/
package org.apache.beehive.netui.databinding.datagrid.runtime.util;
-import java.util.Iterator;
-import java.util.ArrayList;
import java.util.Collections;
-
-import org.apache.beehive.netui.util.logging.Logger;
+import java.util.Iterator;
+import java.util.LinkedList;
/**
- *
+ * This is an internal class used by the data grid to support paging through a data set.
*/
public final class PagedDataSet
implements Iterator {
- private static final Logger LOGGER = Logger.getInstance(PagedDataSet.class);
+ /*
+ todo: need to support the following features:
+ - rendering the entire data set
+ - rendering a "page size" number of items starting from zero
+ - putting a ceiling on the number of items to render
+
+ a paged data set should work by accepting the following parameters:
+ x (optional) lower window bound
+ x (optional) window size (ie page size)
+ x (optional) total size (to avoid processing an entire data set just to determine the size)
+ x (optional) max size (a ceiling on the number of rows to render)
+ */
+
+ private boolean _initialized = false;
+ private Integer _size;
+ private Integer _firstRow;
+ private Integer _lastRow;
+ private Integer _maxRow;
+ private Integer _offset;
+ private Integer _pageSize;
+ private int _currentRow = -1;
- private boolean _completedBootstrap = false;
- private int _dataSetSize = 0;
- private int _currentIndex = -1;
- private int _startWindow = -1;
- private int _endWindow = -1;
-
- private String _dataSource = null;
- private ArrayList _list = null;
- private Iterator _dataSetIterator = null;
private Object _currentItem = null;
+ private String _dataSource = null;
+ private Iterator _iterator = null;
public PagedDataSet(String dataSource, Iterator iterator) {
_dataSource = dataSource;
if(iterator == null)
- _dataSetIterator = Collections.EMPTY_LIST.iterator();
- else
- _dataSetIterator = iterator;
-
- LOGGER.debug("iterator type: " + _dataSetIterator.getClass().getName());
-
- /* todo: would be nice to have a limit here so that this isn't needed in order to find the end of the data set */
- _list = new ArrayList();
- while(_dataSetIterator.hasNext()) {
- _list.add(_dataSetIterator.next());
- _dataSetSize++;
- }
- _dataSetIterator = _list.iterator();
+ _iterator = Collections.EMPTY_LIST.iterator();
+ else _iterator = iterator;
}
- public void createWindow(int startWindow, int windowSize) {
- /* todo: error checking */
- _startWindow = startWindow;
- /* the size of the window is inclusive, so remove one from the total size */
- _endWindow = _startWindow + windowSize - 1;
+ public void setFirstRow(int firstRow) {
+ _firstRow = new Integer(firstRow);
}
- public boolean hasNext() {
- if(!_completedBootstrap && _startWindow > 0) {
+ public void setPageSize(int pageSize) {
+ _pageSize = new Integer(pageSize);
+ }
+
+ public void setOffset(int offset) {
+ _offset = new Integer(offset);
+ }
- while(_dataSetIterator.hasNext() && (_currentIndex+1) != _startWindow) {
- _dataSetIterator.next();
- _currentIndex++;
+ public void setSize(int size) {
+ _size = new Integer(size);
+ }
+
+ public void setMaxRow(int maxRow) {
+ _maxRow = new Integer(maxRow);
+ }
+
+ public int getSize() {
+ return _size != null ? _size.intValue() : 0;
+ }
+
+ /**
+ * Perform initializations on a PagedDataSet. This method must be called before starting to use the
+ * {@link Iterator} functionality of this class.
+ */
+ public void initialize() {
+
+ assert _firstRow != null;
+ assert _pageSize != null;
+
+ _lastRow = new Integer(_firstRow.intValue() + (_pageSize.intValue()-1));
+ if(_maxRow != null && (_maxRow.intValue() < _lastRow.intValue()))
+ _lastRow = _maxRow;
+
+ // calculate the total size of the data set
+ if(_size == null) {
+ int size = 0;
+ LinkedList list = new LinkedList();
+ while(_iterator.hasNext()) {
+ list.add(_iterator.next());
+ size++;
}
- _completedBootstrap = true;
- }
- else if(_endWindow > -1 && (_currentIndex >= _endWindow)) {
- LOGGER.debug("current index: " + _currentIndex + " _endRenderWindiw: " + _endWindow + " end data set: " + (_currentIndex >= _endWindow));
- return false;
+ _size = new Integer(size);
+ _iterator = list.iterator();
}
- boolean hasNext = _dataSetIterator.hasNext();
- if(!hasNext) {
- _currentIndex = -1;
- _currentItem = null;
+ // set the position of the first row in the interator
+ if((_offset != null && _firstRow.intValue() == 0) || (_firstRow.intValue() > 0)) {
+ while(_iterator.hasNext() && (_currentRow +1 != _firstRow.intValue())) {
+ _iterator.next();
+ _currentRow++;
+ }
}
- return hasNext;
- }
+ _initialized = true;
- public Object next() {
- _currentItem = _dataSetIterator.next();
- _currentIndex++;
- return _currentItem;
+ assert _size != null : "Failed to initialize the size";
}
- public void remove() {
- throw new UnsupportedOperationException();
- }
+ /* ---------------------------------------------------------------
+
+ org.apache.beehive.netui.script.IDataAccessProvider implementation
+
+ --------------------------------------------------------------- */
public String getDataSource() {
return _dataSource;
}
- public int getSize() {
- return _dataSetSize;
- }
-
public int getCurrentIndex() {
- return _currentIndex;
+ return _currentRow;
}
public Object getCurrentItem() {
return _currentItem;
}
-}
+
+ /* ---------------------------------------------------------------
+
+ java.util.Iterator implementation
+
+ --------------------------------------------------------------- */
+ public boolean hasNext() {
+ assert _initialized : "Iterating without having initialized";
+
+ // reached the end of the window to render
+ if(_lastRow != null && (_currentRow >= _lastRow.intValue()))
+ return false;
+
+ boolean hasNext = _iterator.hasNext();
+ if(!hasNext) {
+ _currentRow = -1;
+ _currentItem = null;
+ }
+
+ return hasNext;
+ }
+
+ public Object next() {
+ _currentItem = _iterator.next();
+ _currentRow++;
+ return _currentItem;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
\ No newline at end of file
Modified: beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java?rev=415150&r1=415149&r2=415150&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java (original)
+++ beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java Sun Jun 18 08:52:31 2006
@@ -826,9 +826,12 @@
/* todo: perf -- should you be able to turn this off for perf? */
fragment.invoke(sw);
- /* todo: this needs to move into the DataGridTagModel */
PagerModel pm = _dataGridTagModel.getState().getPagerModel();
- _dataGridTagModel.getDataSet().createWindow(pm.getRow(), pm.getPageSize());
+ PagedDataSet pagedDataSet = _dataGridTagModel.getDataSet();
+ pagedDataSet.setFirstRow(pm.getRow());
+ pagedDataSet.setPageSize(pm.getPageSize());
+ pagedDataSet.initialize();
+ _dataGridTagModel.getState().getPagerModel().setDataSetSize(pagedDataSet.getSize());
/* now that the model objects have been initialized, it's time to start rendering */
_dataGridTagModel.changeRenderState(DataGridTagModel.RENDER_STATE_START);
@@ -919,7 +922,7 @@
/**
* Get the index of the current item in the data set. This is a zero-based absolute
* index into the entire data set being rendered by the data grid. This value
- * should only be data bound inside of the {@link Rows}.
+ * should only be data bound inside of the {@link Rows} nested tag.
* @return the index of the current item
*/
public int getCurrentIndex() {
@@ -929,7 +932,7 @@
/**
* Get the current item in the data set. As the data grid iterates over the data set, this
* value will change to provide access to the current item in the data set. This value
- * should only be data bound inside of the {@link Rows}.
+ * should only be data bound inside of the {@link Rows} nested tag.
* @return the current item
*/
public Object getCurrentItem() {
Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/DataGridTestUtil.java
URL: http://svn.apache.org/viewvc/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/DataGridTestUtil.java?rev=415150&r1=415149&r2=415150&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/DataGridTestUtil.java (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/DataGridTestUtil.java Sun Jun 18 08:52:31 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,13 @@
import org.apache.beehive.netui.databinding.datagrid.api.pager.PagerModel;
import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
-import org.apache.beehive.netui.databinding.datagrid.api.*;
import org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridState;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridStateFactory;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridURLBuilder;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfigFactory;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridResourceProvider;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfig;
import org.apache.beehive.netui.databinding.datagrid.runtime.util.PagedDataSet;
import org.apache.beehive.netui.test.servlet.HttpServletRequestHandler;
@@ -43,7 +48,7 @@
private DataGridTestUtil() {
}
- static final void initQueryString(ServletRequest request, String queryString) {
+ static void initQueryString(ServletRequest request, String queryString) {
assert request != null : "Received null request!";
assert Proxy.getInvocationHandler(request) instanceof HttpServletRequestHandler;
@@ -55,27 +60,29 @@
return ((PageContext)jspContext).getRequest();
}
- static final void initQueryString(JspContext jspContext, String queryString) {
+ static void initQueryString(JspContext jspContext, String queryString) {
initQueryString(getRequest(jspContext), queryString);
}
- static final DataGridTagModel getDataGridTagModel(JspContext jspContext) {
+ static DataGridTagModel getDataGridTagModel(JspContext jspContext) {
return buildDataGridTagModel(jspContext, DEFAULT_DATA_GRID_NAME, getPagedDataSet());
}
- static final DataGridTagModel getDataGridTagModel(JspContext jspContext, String name) {
+ static DataGridTagModel getDataGridTagModel(JspContext jspContext, String name) {
return buildDataGridTagModel(jspContext, name, getPagedDataSet());
}
- static final DataGridTagModel getEmptyDataGridTagModel(JspContext jspContext) {
+ static DataGridTagModel getEmptyDataGridTagModel(JspContext jspContext) {
return buildDataGridTagModel(jspContext, DEFAULT_DATA_GRID_NAME, getEmptyPagedDataSet());
}
- static final PagedDataSet getEmptyPagedDataSet() {
- return new PagedDataSet("${actionForm.emptyDataSource}", Collections.EMPTY_LIST.iterator());
+ static PagedDataSet getEmptyPagedDataSet() {
+ PagedDataSet pagedDataSet = new PagedDataSet("${actionForm.emptyDataSource}", Collections.EMPTY_LIST.iterator());
+ pagedDataSet.setSize(0);
+ return pagedDataSet;
}
- static final PagedDataSet getPagedDataSet() {
+ static PagedDataSet getPagedDataSet() {
ArrayList/*<String>*/ list = new ArrayList/*<String>*/();
list.add("abc");
list.add("def");
@@ -89,47 +96,48 @@
list.add("123");
list.add("456");
list.add("789");
- return new PagedDataSet("${actionForm.dataSource}", list.iterator());
+ PagedDataSet pagedDataSet = new PagedDataSet("${actionForm.dataSource}", list.iterator());
+ pagedDataSet.setSize(list.size());
+ return pagedDataSet;
}
- private static final DataGridTagModel buildDataGridTagModel(JspContext jspContext, String name, PagedDataSet dataSet) {
- DataGridConfig config = getDataGridConfig();
- DataGridResourceProvider provider = getDataGridConfig().getDefaultResourceProvider();
- provider.setLocale(Locale.US);
- DataGridTagModel dgm = new DataGridTagModel(name, config, jspContext);
- dgm.setDataSet(dataSet);
- dgm.setResourceProvider(provider);
- dgm.getState().getPagerModel().setPageAction("fauxPageAction.do");
- return dgm;
- }
-
- static final PagerModel getPagerModel(DataGridTagModel dgm) {
+ static PagerModel getPagerModel(DataGridTagModel dgm) {
return dgm.getState().getPagerModel();
}
- static final DataGridConfig getDataGridConfig() {
+ static DataGridConfig getDataGridConfig() {
return DataGridConfigFactory.getInstance();
}
- static final DataGridState createDataGridState(ServletRequest request, String gridName) {
+ static DataGridState createDataGridState(ServletRequest request, String gridName) {
DataGridStateFactory factory = DataGridStateFactory.getInstance(request);
return factory.getDataGridState(gridName, getDataGridConfig());
}
- static final DataGridState createDataGridState(JspContext jspContext, String gridName) {
+ static DataGridState createDataGridState(JspContext jspContext, String gridName) {
DataGridStateFactory factory = DataGridStateFactory.getInstance(getRequest(jspContext));
return factory.getDataGridState(gridName, getDataGridConfig());
}
- static final DataGridURLBuilder createDataGridURLBuilder(ServletRequest request, String gridName) {
+ static DataGridURLBuilder createDataGridURLBuilder(ServletRequest request, String gridName) {
DataGridStateFactory factory = DataGridStateFactory.getInstance(request);
return factory.getDataGridURLBuilder(gridName, getDataGridConfig());
}
- static final SortModel createSortModel(ServletRequest request, String gridNamespace) {
+ static SortModel createSortModel(ServletRequest request, String gridNamespace) {
DataGridState state = DataGridTestUtil.createDataGridState(request, gridNamespace);
SortModel sortModel = state.getSortModel();
return sortModel;
}
+ private static DataGridTagModel buildDataGridTagModel(JspContext jspContext, String name, PagedDataSet dataSet) {
+ DataGridConfig config = getDataGridConfig();
+ DataGridResourceProvider provider = getDataGridConfig().getDefaultResourceProvider();
+ provider.setLocale(Locale.US);
+ DataGridTagModel dgm = new DataGridTagModel(name, config, jspContext);
+ dgm.setDataSet(dataSet);
+ dgm.setResourceProvider(provider);
+ dgm.getState().getPagerModel().setPageAction("fauxPageAction.do");
+ return dgm;
+ }
}