Author: abelevich
Date: 2010-04-30 12:20:42 -0400 (Fri, 30 Apr 2010)
New Revision: 16852
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java
Log:
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableColumnsIterator.java 2010-04-30
16:20:42 UTC (rev 16852)
@@ -0,0 +1,56 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.Column;
+
+/**
+ * Iterator for all children table columns.
+ *
+ * @author asmirnov
+ *
+ */
+class DataTableColumnsIterator extends DataTableIteratorBase<UIComponent> {
+
+ protected Iterator<UIComponent> childrenIterator;
+
+ public DataTableColumnsIterator(UIComponent dataTable) {
+ this.childrenIterator = dataTable.getChildren().iterator();
+ }
+
+ protected UIComponent nextItem() {
+ while (childrenIterator != null && childrenIterator.hasNext()) {
+ UIComponent child = childrenIterator.next();
+ if (child instanceof javax.faces.component.UIColumn || child instanceof
Column) {
+ return child;
+ }
+ }
+
+ // TODO nick - free childrenIterator field
+
+ return null;
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableDataIterator.java 2010-04-30
16:20:42 UTC (rev 16852)
@@ -0,0 +1,82 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.Column;
+
+class DataTableDataIterator extends DataTableIteratorBase<UIComponent> {
+
+ private Iterator<UIComponent> facetsIterator;
+
+ private Iterator<UIComponent> childrenIterator;
+
+ public DataTableDataIterator(UIDataTableBase dataTable) {
+ this.childrenIterator = dataTable.getChildren().iterator();
+ this.facetsIterator = dataTable.getFacets().values().iterator();
+ }
+
+ protected UIComponent nextItem() {
+
+ UIComponent nextColumn = null;
+ while (nextColumn == null && childrenIterator.hasNext()) {
+ UIComponent child = childrenIterator.next();
+ // TODO nick - why non-rendered children are filtered?
+ // TODO nick - should be (child instanceof UIColumn || child instanceof
Column)?
+ if ((child instanceof UIColumn) || (child instanceof Column)) {
+ nextColumn = child;
+ } else if (checkAjaxComponent(child)) {
+ nextColumn = child;
+ }
+ }
+
+ // TODO nick - free childrenIterator
+
+ // ???
+ while (nextColumn == null && facetsIterator.hasNext()) {
+ UIComponent component = facetsIterator.next();
+ if (checkAjaxComponent(component)) {
+ nextColumn = component;
+ }
+ }
+
+ // TODO nick - free facetsIterator
+
+ return nextColumn;
+ }
+
+ protected Iterator<UIComponent> getFacetsIterator() {
+ return this.facetsIterator;
+ }
+
+ protected Iterator<UIComponent> getChildrenIterator() {
+ return this.childrenIterator;
+ }
+
+ // TODO nick - what's this for?
+ protected boolean checkAjaxComponent(UIComponent child) {
+ return false;
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableFixedChildrenIterator.java 2010-04-30
16:20:42 UTC (rev 16852)
@@ -0,0 +1,83 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+
+class DataTableFixedChildrenIterator extends DataTableDataIterator {
+
+ private Iterator<UIComponent> currentColumnIterator;
+
+ public DataTableFixedChildrenIterator(UIDataTableBase dataTable) {
+ super(dataTable);
+ }
+
+ @Override
+ protected UIComponent nextItem() {
+ UIComponent next = null;
+
+ if (currentColumnIterator != null && currentColumnIterator.hasNext()) {
+ next = currentColumnIterator.next();
+ checkColumnIterator();
+ }
+
+ if (next == null) {
+ Iterator<UIComponent> childrenIterator = getChildrenIterator();
+ while (next == null && childrenIterator.hasNext()) {
+ UIComponent child = childrenIterator.next();
+ if ((child instanceof UIColumn) && child.isRendered()) {
+ currentColumnIterator = getChildFacetIterator(child);
+ next = nextItem();
+ } else if (checkAjaxComponent(child)) {
+ next = child;
+ }
+ }
+ }
+
+ if (next == null) {
+ next = getNextFacet();
+ }
+ return next;
+ }
+
+ protected UIComponent getNextFacet() {
+ Iterator<UIComponent> facetsIterator = getFacetsIterator();
+ // TODO nick - while -> if
+ while (facetsIterator.hasNext()) {
+ return facetsIterator.next();
+ }
+ return null;
+ }
+
+ protected void checkColumnIterator() {
+ if (!currentColumnIterator.hasNext()) {
+ currentColumnIterator = null;
+ }
+ }
+
+ protected Iterator<UIComponent> getChildFacetIterator(UIComponent component) {
+ return component.getFacets().values().iterator();
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/DataTableIteratorBase.java 2010-04-30
16:20:42 UTC (rev 16852)
@@ -0,0 +1,52 @@
+package org.richfaces.component;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * @author Anton Belevich
+ * @author Nick Belaevski
+ */
+// TODO nick - rename this class
+public abstract class DataTableIteratorBase<E> implements Iterator<E> {
+
+ private boolean isCompleted = false;
+
+ private E next = null;
+
+ private void setupNext() {
+ if (!isCompleted) {
+ if (next == null) {
+ next = nextItem();
+
+ if (next == null) {
+ isCompleted = true;
+ }
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ setupNext();
+
+ return next != null;
+ }
+
+ public E next() {
+ setupNext();
+
+ if (next == null) {
+ throw new NoSuchElementException();
+ }
+
+ E result = next;
+ next = null;
+ return result;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("Iterator is read-only");
+ }
+
+ protected abstract E nextItem();
+}
Show replies by date