Author: konstantin.mishin
Date: 2010-03-11 13:00:35 -0500 (Thu, 11 Mar 2010)
New Revision: 16561
Added:
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIDataTableBaseTest.java
Modified:
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/ArrangeableModelTest.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java
Log:
RF-8118 RF-8119
Modified:
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/ArrangeableModelTest.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/ArrangeableModelTest.java 2010-03-11
16:41:22 UTC (rev 16560)
+++
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/ArrangeableModelTest.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -73,6 +73,7 @@
}
}
+ private static final int ROWS = 2;
private static final int ROW_KEY = 4;
private static final List<Integer> FILTERD_AND_SORTED_ROW_KEYS =
Arrays.asList(5, 3, 2, 0);
@@ -163,6 +164,7 @@
Assert.assertNull(extendedDataModel.getRowKey());
arrangeableModel.setRowKey(ROW_KEY);
Assert.assertEquals(ROW_KEY, extendedDataModel.getRowKey());
+ Assert.assertEquals(ROW_KEY, arrangeableModel.getRowKey());
arrangeableModel.setRowKey(extendedDataModel.getRowCount());
Assert.assertEquals(extendedDataModel.getRowCount(),
extendedDataModel.getRowKey());
}
@@ -173,9 +175,8 @@
*/
@Test
public void testWalk() {
-
final List<Object> rowKeys = new ArrayList<Object>();
- arrangeableModel.walk(facesContext, new DataVisitor() {
+ DataVisitor visitor = new DataVisitor() {
@Override
public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
arrangeableModel.setRowKey(rowKey);
@@ -184,8 +185,12 @@
}
return DataVisitResult.CONTINUE;
}
- }, new SequenceRange(0, -1), null);
+ };
+ arrangeableModel.walk(facesContext, visitor, new SequenceRange(0, -1), null);
Assert.assertEquals(FILTERD_AND_SORTED_ROW_KEYS, rowKeys);
+ rowKeys.clear();
+ arrangeableModel.walk(facesContext, visitor, new SequenceRange(0, ROWS), null);
+ Assert.assertEquals(FILTERD_AND_SORTED_ROW_KEYS.subList(0, ROWS), rowKeys);
}
/**
@@ -205,6 +210,7 @@
};
arrangeableModel.addDataModelListener(listener);
Assert.assertSame(listener, extendedDataModel.getDataModelListeners()[0]);
+ Assert.assertSame(listener, arrangeableModel.getDataModelListeners()[0]);
arrangeableModel.removeDataModelListener(listener);
Assert.assertEquals(0, extendedDataModel.getDataModelListeners().length);
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java 2010-03-11
16:41:22 UTC (rev 16560)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -23,7 +23,6 @@
package org.richfaces.component;
import java.util.Comparator;
-import java.util.Map;
import javax.el.ValueExpression;
import javax.swing.SortOrder;
@@ -32,27 +31,49 @@
import org.richfaces.model.FilterField;
import org.richfaces.model.SortField;
-public abstract class UIColumn extends javax.faces.component.UIColumn implements Column
{
+public class UIColumn extends javax.faces.component.UIColumn implements Column {
- public abstract int getRowspan();
+ protected enum PropertyKeys {
+ filter, filterValue, comparator, sortOrder
+ }
+ public void setSortOrder(SortOrder sortOrder) {
+ getStateHelper().put(PropertyKeys.sortOrder, sortOrder);
+ }
- public abstract int getColspan();
+ public SortOrder getSortOrder() {
+ return (SortOrder) getStateHelper().get(PropertyKeys.sortOrder);
+ }
- public abstract boolean isBreakBefore();
+ public void setFilter(Filter<?> filter) {
+ getStateHelper().put(PropertyKeys.filter, filter);
+ }
- public abstract boolean isSelfSorted();
+ public Filter<?> getFilter() {
+ return (Filter<?>) getStateHelper().get(PropertyKeys.filter);
+ }
- public abstract void setSortOrder(SortOrder sortOrder);
+ public void setFilterValue(Object filterValue) {
+ getStateHelper().put(PropertyKeys.filterValue, filterValue);
+ }
- public abstract SortOrder getSortOrder();
+ public Object getFilterValue() {
+ return getStateHelper().get(PropertyKeys.filterValue);
+ }
+ public void setComparator(Comparator<?> comparator) {
+ getStateHelper().put(PropertyKeys.comparator, comparator);
+ }
+
+ public Comparator<?> getComparator() {
+ return (Comparator<?>) getStateHelper().get(PropertyKeys.comparator);
+ }
+
public FilterField getFilterField() {
FilterField field = null;
- Map<String, Object> attributes = getAttributes();
- Filter<?> filter = (Filter<?>) attributes.get("filter");
+ Filter<?> filter = getFilter();
ValueExpression filterExpression =
getValueExpression("filterExpression");
if (filter != null || filterExpression != null) {
- field = new FilterField(filterExpression, filter,
attributes.get("filterValue"));
+ field = new FilterField(filterExpression, filter, getFilterValue());
}
return field;
}
@@ -61,7 +82,7 @@
SortField field = null;
SortOrder sortOrder = getSortOrder();
if (sortOrder != null && !SortOrder.UNSORTED.equals(sortOrder)) {
- Comparator<?> comparator = (Comparator<?>)
getAttributes().get("comparator");
+ Comparator<?> comparator = getComparator();
ValueExpression sortBy = getValueExpression("sortBy");
if (comparator != null || sortBy != null) {
field = new SortField(sortBy, comparator, sortOrder);
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java 2010-03-11
16:41:22 UTC (rev 16560)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumn.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -22,23 +22,20 @@
package org.richfaces.component.html;
-import javax.swing.SortOrder;
-
import org.richfaces.component.UIColumn;
public class HtmlColumn extends UIColumn {
enum PropertyKeys {
- breakBefore, rowspan, colspan, sortOrder, selfSorted, sortBy
+ breakBefore, rowspan, colspan, selfSorted, sortBy
}
public static final String COMPONENT_TYPE = "org.richfaces.Column";
-
+
public static final String COMPONENT_FAMILY = "org.richfaces.Column";
-
public int getColspan() {
- return (Integer) getStateHelper().eval(PropertyKeys.colspan,
Integer.MIN_VALUE);
+ return (Integer) getStateHelper().eval(PropertyKeys.colspan, Integer.MIN_VALUE);
}
public void setColspan(int colspan) {
@@ -53,20 +50,10 @@
getStateHelper().put(PropertyKeys.rowspan, Integer.valueOf(rowspan));
}
- @Override
- public SortOrder getSortOrder() {
- return (SortOrder)
getStateHelper().eval(PropertyKeys.sortOrder,SortOrder.UNSORTED);
- }
-
- @Override
- public void setSortOrder(SortOrder sortOrder) {
- getStateHelper().put(PropertyKeys.sortOrder, sortOrder);
- }
-
public boolean isSelfSorted() {
- return (Boolean)getStateHelper().eval(PropertyKeys.selfSorted, true);
+ return (Boolean) getStateHelper().eval(PropertyKeys.selfSorted, true);
}
-
+
public void setSelfSorted(boolean selfSorted) {
getStateHelper().put(PropertyKeys.selfSorted, selfSorted);
}
@@ -79,11 +66,10 @@
getStateHelper().put(PropertyKeys.sortBy, sortBy);
}
- @Override
public boolean isBreakBefore() {
- return (Boolean)getStateHelper().eval(PropertyKeys.breakBefore, false);
+ return (Boolean) getStateHelper().eval(PropertyKeys.breakBefore, false);
}
-
+
public void setBreakBefore(boolean breakBefore) {
getStateHelper().put(PropertyKeys.breakBefore, breakBefore);
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-03-11
16:41:22 UTC (rev 16560)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.util.Iterator;
+import java.util.Map;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
@@ -92,15 +93,15 @@
}
currentLength = 0;
} else if (component instanceof org.richfaces.component.UIColumn) {
- org.richfaces.component.UIColumn column =
(org.richfaces.component.UIColumn) component;
// For new row, save length of previsous.
- if (column.isBreakBefore()) {
+ Map<String, Object> attributes = component.getAttributes();
+ if ((Boolean)attributes.get("breakBefore")) {
if (currentLength > count) {
count = currentLength;
}
currentLength = 0;
}
- Integer colspan = (Integer)
component.getAttributes().get("colspan");
+ Integer colspan = (Integer) attributes.get("colspan");
// Append colspan of this column
if (null != colspan && colspan.intValue() !=
Integer.MIN_VALUE) {
currentLength += colspan.intValue();
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java 2010-03-11
16:41:22 UTC (rev 16560)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRenderer.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -192,12 +192,12 @@
boolean sortableColumn = isSortable(column);
- if (sortableColumn && column.isSelfSorted()) {
+// if (sortableColumn && column.isSelfSorted()) {
// FormUtil.throwEnclFormReqExceptionIfNeed(context, column.getParent());
// TODO: anton - add "selfSorted = true" behavior;
// writer.writeAttribute(HTML.ONCLICK_ATTRIBUTE, createFunction(context,
col) , null);
// writer.writeAttribute(HTML.STYLE_ATTRIBUTE, "cursor:
pointer;", null);
- }
+// }
// writer.startElement(HTML.DIV_ELEM, column);
// writer.writeAttribute(HTML.ID_ATTRIBUTE, clientId + SORT_DIV, null);
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java 2010-03-11
16:41:22 UTC (rev 16560)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -1,6 +1,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Map;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
@@ -26,9 +27,9 @@
String parentId = holder.getDataTableId();
if (component instanceof org.richfaces.component.UIColumn) {
- org.richfaces.component.UIColumn column = (org.richfaces.component.UIColumn)
component;
- if (column.isBreakBefore() && holder.getProcessCell() != 0) {
- encodeRowEnd(writer, context, column);
+ Map<String, Object> attributes = component.getAttributes();
+ if ((Boolean)attributes.get("breakBefore") &&
holder.getProcessCell() != 0) {
+ encodeRowEnd(writer, context, component);
holder.nextRow();
holder.setRowStart(true);
}
@@ -66,14 +67,14 @@
encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, cellClass);
if (component instanceof org.richfaces.component.UIColumn) {
- org.richfaces.component.UIColumn column = (org.richfaces.component.UIColumn)
component;
+ Map<String, Object> attributes = component.getAttributes();
- int rowspan = column.getRowspan();
+ int rowspan = (Integer) attributes.get("rowspan");
if (rowspan != Integer.MIN_VALUE) {
writer.writeAttribute("rowspan", Integer.valueOf(rowspan),
null);
}
- int colspan = column.getColspan();
+ int colspan = (Integer) attributes.get("colspan");
if (colspan != Integer.MIN_VALUE) {
writer.writeAttribute("colspan", Integer.valueOf(colspan),
null);
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIDataTableBaseTest.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIDataTableBaseTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIDataTableBaseTest.java 2010-03-11
18:00:35 UTC (rev 16561)
@@ -0,0 +1,258 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.swing.SortOrder;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.jboss.test.faces.AbstractFacesTest;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.model.Arrangeable;
+import org.richfaces.model.ArrangeableState;
+import org.richfaces.model.FilterField;
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortMode;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class UIDataTableBaseTest extends AbstractFacesTest {
+
+ private class MockArrangeableModel extends ExtendedDataModel<Object> implements
Arrangeable {
+
+ private ArrangeableState state;
+ @Override
+ public Object getRowKey() {
+ return null;
+ }
+
+ @Override
+ public void setRowKey(Object key) {
+ }
+
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) {
+ }
+
+ @Override
+ public int getRowCount() {
+ return 0;
+ }
+
+ @Override
+ public Object getRowData() {
+ return null;
+ }
+
+ @Override
+ public int getRowIndex() {
+ return 0;
+ }
+
+ @Override
+ public Object getWrappedData() {
+ return null;
+ }
+
+ @Override
+ public boolean isRowAvailable() {
+ return false;
+ }
+
+ @Override
+ public void setRowIndex(int rowIndex) {
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ }
+
+ @Override
+ public void arrange(FacesContext context, ArrangeableState state) {
+ this.state = state;
+ }
+
+ public ArrangeableState getState() {
+ return state;
+ }
+
+ }
+ private UIDataTableBase table = null;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ table = new UIDataTableBase();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ table = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.component.UIDataTableBase#getRendersChildren()}.
+ */
+ @Test
+ public void testGetRendersChildren() {
+ Assert.assertTrue(table.getRendersChildren());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#dataChildren()}.
+ */
+ @Test
+ public void testDataChildren() {
+ Assert.assertTrue(table.dataChildren() instanceof DataIterator);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#fixedChildren()}.
+ */
+ @Test
+ public void testFixedChildren() {
+ Assert.assertTrue(table.fixedChildren() instanceof FixedChildrenIterator);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.component.UIDataTableBase#createExtendedDataModel()}.
+ */
+ @Test
+ public void testCreateExtendedDataModel() {
+ Assert.assertFalse(table.createExtendedDataModel() instanceof Arrangeable);
+ List<String> sortPriority = Arrays.asList("id2", "id0",
"id1");
+ List<UIComponent> children = table.getChildren();
+ ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
+ ELContext elContext = facesContext.getELContext();
+ UIColumn column = new UIColumn();
+ column.setRendered(false);
+ children.add(column);
+ for (int i = 0; i < sortPriority.size(); i++) {
+ UIColumn child = new UIColumn();
+ child.setId("id" + i);
+ child.setValueExpression("filterExpression", expressionFactory
+ .createValueExpression(elContext, "#{'id" + i +
"'}", Object.class));
+ child.setValueExpression("sortBy", expressionFactory
+ .createValueExpression(elContext, "#{'id" + i +
"'}", Object.class));
+ child.setSortOrder(SortOrder.ASCENDING);
+ children.add(child);
+ }
+ Assert.assertTrue(table.createExtendedDataModel() instanceof Arrangeable);
+ MockArrangeableModel model = new MockArrangeableModel();
+ table.setValue(model);
+ table.setSortPriority(sortPriority);
+ Assert.assertSame(model, table.createExtendedDataModel());
+ ArrangeableState state = model.getState();
+ List<FilterField> filterFields = state.getFilterFields();
+ for (int i = 0; i < sortPriority.size(); i++) {
+ Assert.assertEquals("id" + i ,
filterFields.get(i).getFilterExpression().getValue(elContext));
+ }
+ List<SortField> sortFields = state.getSortFields();
+ for (int i = 0; i < sortPriority.size(); i++) {
+ Assert.assertEquals(sortPriority.get(i),
sortFields.get(i).getSortBy().getValue(elContext));
+ }
+ Assert.assertEquals(facesContext.getViewRoot().getLocale(), state.getLocale());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#columns()}.
+ */
+ @Test
+ public void testColumns() {
+ Assert.assertTrue(table.columns() instanceof ColumnsIterator);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#getHeader()}.
+ */
+ @Test
+ public void testGetHeader() {
+ UIOutput component = new UIOutput();
+ table.getFacets().put("header", component);
+ Assert.assertSame(component, table.getHeader());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#getFooter()}.
+ */
+ @Test
+ public void testGetFooter() {
+ UIOutput component = new UIOutput();
+ table.getFacets().put("footer", component);
+ Assert.assertSame(component, table.getFooter());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#getFilterVar()}
and
+ * {@link org.richfaces.component.UIDataTableBase#setFilterVar(java.lang.String)}.
+ */
+ @Test
+ public void testFilterVar() {
+ String string = "fv";
+ table.setFilterVar(string);
+ Assert.assertSame(string, table.getFilterVar());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#getSortPriority()}
and
+ * {@link
org.richfaces.component.UIDataTableBase#setSortPriority(java.util.Collection)}.
+ */
+ @Test
+ public void testSortPriority() {
+ table.setSortPriority(Collections.EMPTY_LIST);
+ Assert.assertSame(Collections.EMPTY_LIST, table.getSortPriority());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIDataTableBase#getSortMode()} and
+ * {@link
org.richfaces.component.UIDataTableBase#setSortMode(org.richfaces.model.SortMode)}.
+ */
+ @Test
+ public void testSortMode() {
+ table.setSortMode(SortMode.multi);
+ Assert.assertSame(SortMode.multi, table.getSortMode());
+ }
+}