Author: maksimkaszynski
Date: 2007-06-08 07:06:13 -0400 (Fri, 08 Jun 2007)
New Revision: 1095
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnIterator.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Log:
added column iterator
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnIterator.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnIterator.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnIterator.java 2007-06-08
11:06:13 UTC (rev 1095)
@@ -0,0 +1,81 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.richfaces.component.UIScrollableGrid;
+import org.richfaces.component.UIScrollableGridColumn;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ColumnIterator implements Iterator {
+
+
+ public static ColumnIterator frozen(UIScrollableGrid grid, GridRendererState state) {
+ return new ColumnIterator(0, GridUtils.getFrozenColumnsCount(grid), grid, state) {
+ public Object next() {
+ this.state.setFrozenPart(true);
+ return super.next();
+ }
+ };
+ }
+
+ public static ColumnIterator normal(UIScrollableGrid grid, GridRendererState state) {
+ return new ColumnIterator(GridUtils.getFrozenColumnsCount(grid), grid.getChildCount(),
grid, state) {
+ public Object next() {
+ this.state.setFrozenPart(false);
+ return super.next();
+ }
+ };
+ }
+
+ public static ColumnIterator all(UIScrollableGrid grid, GridRendererState state) {
+ return new ColumnIterator(0, grid.getChildCount(), grid, state);
+ }
+
+ GridRendererState state;
+ private int index = 0;
+ private int start;
+ private int end;
+ private List kids;
+
+ private ColumnIterator(int start, int end, UIScrollableGrid grid, GridRendererState
state) {
+ this.start = start;
+ this.end = end;
+ this.state = state;
+ this.kids = grid.getChildren();
+ rewind();
+ }
+
+ public boolean hasNext() {
+ return index < end;
+ }
+
+ public Object next() {
+ state.setCellIndex(index);
+ Object o = kids.get(index);
+
+ index++;
+
+ return o;
+ }
+
+ public UIScrollableGridColumn nextColumn() {
+ return (UIScrollableGridColumn) next();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("remove");
+ }
+
+ public void rewind() {
+ index = start;
+ state.setCellIndex(index);
+ }
+
+}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java 2007-06-08
11:06:13 UTC (rev 1095)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import org.richfaces.component.UIScrollableGrid;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class GridUtils {
+
+ public static final String FROZEN_COL_COUNT_ATTR = "frozenColCount";
+
+ public static int getFrozenColumnsCount(UIScrollableGrid grid) {
+ return ((Integer)grid.getAttributes().get(FROZEN_COL_COUNT_ATTR)).intValue();
+ }
+
+}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-08
10:28:09 UTC (rev 1094)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-08
11:06:13 UTC (rev 1095)
@@ -41,7 +41,6 @@
public abstract class ScrollableGridBaseRenderer extends CompositeRenderer {
-
private final String FOOTER_PART = "footer";
private final String HEADER_PART = "header";
@@ -202,7 +201,7 @@
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HTML.TR_ELEMENT, grid);
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
getUtils().writeAttribute(writer, "id",row_id);
getUtils().writeAttribute(writer, "class","ClientUI_Grid_BR");
@@ -238,7 +237,7 @@
Collection collection = grid.getResponseData();
grid.setRowKey(rowKey);
ResponseWriter writer = context.getResponseWriter();
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
String row_id = null;
/*
@@ -297,6 +296,7 @@
}
};
+
public ScrollableGridBaseRenderer() {
addContributor(new SelectionRendererContributor());
}
@@ -362,7 +362,7 @@
System.out.println("ScrollableGridBaseRenderer.renderGridBody()");
System.out.println("");
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
state.setFrozenPart(isFrozen);
state.setClientId(grid.getClientId(context));
grid.walk(context, rowsRenderer, state);
@@ -382,7 +382,7 @@
state.setClientId(grid.getClientId(context));
state.setPart(HEADER_PART);
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
state.setFrozenPart(isFrozen);
state.setClientId(grid.getClientId(context));
state.setSepOffset(new Integer(0));
@@ -401,7 +401,7 @@
}
state.setClientId(grid.getClientId(context));
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
state.setFrozenPart(isFrozen);
ColumnWalker.iterateOverColumns(context, grid, colsRenderer, writer, state);
}
@@ -419,7 +419,7 @@
}
state.setClientId(grid.getClientId(context));
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
state.setFrozenPart(isFrozen);
int colsCount = ColumnWalker.iterateOverColumns(context, grid, footerCellRenderer,
writer, state);
int rowsCount = grid.getRowCount();
@@ -653,7 +653,7 @@
public void setUpColumnsWidth(FacesContext context, UIScrollableGrid grid) throws
IOException{
GridRendererState state = GridRendererState.getRendererState(context);
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+ state.setFrozenColumnCount(GridUtils.getFrozenColumnsCount(grid));
ColumnWalker.iterateOverColumns(context, grid, columnsWidthCounter, null, state);
ComponentVariables variables = ComponentsVariableResolver.getVariables(this, grid);
int sumWidth = state.getSumWidth() + 20;