Author: abelevich
Date: 2010-02-24 14:35:07 -0500 (Wed, 24 Feb 2010)
New Revision: 16489
Added:
root/ui-sandbox/trunk/components/datascroller/api/
root/ui-sandbox/trunk/components/datascroller/api/pom.xml
root/ui-sandbox/trunk/components/datascroller/api/src/
root/ui-sandbox/trunk/components/datascroller/api/src/main/
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerEvent.java
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerListener.java
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerSource.java
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java
root/ui-sandbox/trunk/components/datascroller/pom.xml
root/ui-sandbox/trunk/components/datascroller/ui/
root/ui-sandbox/trunk/components/datascroller/ui/pom.xml
root/ui-sandbox/trunk/components/datascroller/ui/src/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/README
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/ControlsState.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/taglib/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/datascroller.taglib.xml
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/tempates/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/tempates/datascroller.template.xml
Log:
Added: root/ui-sandbox/trunk/components/datascroller/api/pom.xml
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/api/pom.xml (rev
0)
+++ root/ui-sandbox/trunk/components/datascroller/api/pom.xml 2010-02-24 19:35:07 UTC (rev
16489)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.richfaces.sandbox.ui.components</groupId>
+ <artifactId>datascroller</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>${parent.artifactId}-api</artifactId>
+ <name>richfaces datascroller api</name>
+
+ <dependencies>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added:
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerEvent.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerEvent.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Wesley Hales
+ */
+public class DataScrollerEvent extends ActionEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2657353903701932561L;
+ private String oldScrolVal;
+ private String newScrolVal;
+ private int page;
+
+ /**
+ * Creates a new ScrollerEvent.
+ *
+ * @param component the source of the event
+ * @param thisOldScrolVal the previously showing item identifier
+ * @param thisNewScrolVal the currently showing item identifier
+ */
+ public DataScrollerEvent(UIComponent component, String thisOldScrolVal, String
thisNewScrolVal, int page) {
+ super(component);
+ oldScrolVal = thisOldScrolVal;
+ newScrolVal = thisNewScrolVal;
+ this.page = page;
+ }
+
+ public String getOldScrolVal() {
+ return oldScrolVal;
+ }
+
+ public String getNewScrolVal() {
+ return newScrolVal;
+ }
+
+ /**
+ * @since 3.2
+ * @return new page or <code>-1</code> if not applicable
+ */
+ public int getPage() {
+ return page;
+ }
+
+ public boolean isAppropriateListener(FacesListener listener){
+ return super.isAppropriateListener(listener) || (listener instanceof
DataScrollerListener);
+ }
+
+ /**
+ * Delivers this event to the SliderListener.
+ *
+ * @param listener the slider listener
+ */
+ public void processListener(FacesListener listener){
+ if (listener instanceof DataScrollerListener) {
+ DataScrollerListener dataScrollerListener = (DataScrollerListener) listener;
+ dataScrollerListener.processScroller(this);
+ }
+
+ if (super.isAppropriateListener(listener)) {
+ super.processListener(listener);
+ }
+ }
+}
Added:
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerListener.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerListener.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,31 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.event;
+
+import javax.faces.event.FacesListener;
+
+
+public interface DataScrollerListener extends FacesListener {
+
+ public void processScroller(org.richfaces.event.DataScrollerEvent event);
+
+}
Added:
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerSource.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerSource.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/DataScrollerSource.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,47 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.event;
+
+public interface DataScrollerSource {
+
+ /**
+ * Adds a DataScrollerListener to this DataScrollerSource.
+ *
+ * @param listener the Scroler listener to be added
+ */
+ public void addScrollerListener(org.richfaces.event.DataScrollerListener listener);
+
+ /**
+ * Removes a DataFilterSliderListener from this DataScrollerSourceSource.
+ *
+ * @param listener the Scroler listener to be removed
+ */
+ public void removeScrollerListener(DataScrollerListener listener);
+
+ /**
+ * Returns all ScrollerListeners for this DataScrollerSource.
+ *
+ * @return the Scroler listener array
+ */
+ public DataScrollerListener[] getScrollerListeners();
+
+}
Added:
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,36 @@
+/**
+ * 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.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.PhaseEvent;
+
+public interface RenderPhaseComponentVisitor {
+
+ Object beforeRoot(PhaseEvent event);
+
+ void beforeComponent(UIComponent component, PhaseEvent event, Object state);
+
+ void afterComponent(UIComponent component, PhaseEvent event, Object state);
+
+ void afterRoot(PhaseEvent event, Object state);
+
+}
Added: root/ui-sandbox/trunk/components/datascroller/pom.xml
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/pom.xml (rev 0)
+++ root/ui-sandbox/trunk/components/datascroller/pom.xml 2010-02-24 19:35:07 UTC (rev
16489)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.richfaces.sandbox.ui</groupId>
+ <artifactId>components</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.sandbox.ui.components</groupId>
+ <artifactId>datascroller</artifactId>
+ <packaging>pom</packaging>
+
+ <name>richfaces datascroller</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <modules>
+ <module>api</module>
+ <module>ui</module>
+ </modules>
+
+</project>
\ No newline at end of file
Added: root/ui-sandbox/trunk/components/datascroller/ui/pom.xml
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/pom.xml (rev
0)
+++ root/ui-sandbox/trunk/components/datascroller/ui/pom.xml 2010-02-24 19:35:07 UTC (rev
16489)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.richfaces.sandbox.ui.components</groupId>
+ <artifactId>datascroller</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>${parent.artifactId}-ui</artifactId>
+ <name>richfaces datascroller ui</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <version>${project.version}</version>
+ <artifactId>${parent.artifactId}-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <version>${project.version}</version>
+ <artifactId>${parent.artifactId}-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-impl</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,45 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+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.
+-->
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
+ version="2.0">
+
+ <component>
+ <component-type>org.richfaces.DataScroller</component-type>
+ <component-class>org.richfaces.component.html.HtmlDataScroller</component-class>
+ <component-extension>
+ <cdk:generate
xmlns:cdk="http://richfaces.org/cdk/extensions">false</cd...
+ </component-extension>
+ </component>
+
+ <render-kit>
+ <render-kit-id>HTML_BASIC</render-kit-id>
+ <renderer>
+ <component-family>org.richfaces.DataScroller</component-family>
+ <renderer-type>org.richfaces.DataScrollerRenderer</renderer-type>
+ <renderer-class>org.richfaces.renderkit.html.DataScrollerRenderer</renderer-class>
+ </renderer>
+ </render-kit>
+</faces-config>
\ No newline at end of file
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/README
===================================================================
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,232 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.el.Expression;
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+
+import org.ajax4jsf.Messages;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.event.RenderPhaseComponentVisitor;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
+
+/**
+ * Created 08.03.2008
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class RenderPhaseDataScrollerVisitor implements RenderPhaseComponentVisitor {
+
+ private class State {
+
+ private ComponentConnections connections;
+ private LinkedList<UIComponent> components;
+
+ private State(LinkedList<UIComponent> components,
+ ComponentConnections connections) {
+ this.components = components;
+ this.connections = connections;
+ }
+ }
+
+ private static final class ComponentConnections {
+ private final Map<UIData, List<UIDataScroller>> map =
+ new HashMap<UIData, List<UIDataScroller>>();
+
+ public void addConnection(UIData one, UIDataScroller multi) {
+ List<UIDataScroller> list = map.get(one);
+ if (list == null) {
+ list = new ArrayList<UIDataScroller>(1);
+ map.put(one, list);
+ }
+
+ list.add(multi);
+ }
+
+ public Iterator<Entry<UIData, List<UIDataScroller>>> iterator() {
+ return map.entrySet().iterator();
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + ": " + map;
+ }
+ }
+
+ private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
+
+ public Object beforeRoot(PhaseEvent event) {
+ return new State(new LinkedList<UIComponent>(), new ComponentConnections());
+ }
+
+ public void beforeComponent(UIComponent component, PhaseEvent event, Object object) {
+ State state = (State) object;
+ state.components.addLast(component);
+
+ if (component instanceof UIDataScroller && isRendered(state.components)) {
+ UIDataScroller datascroller = (UIDataScroller) component;
+ UIData dataTable = datascroller.getDataTable();
+
+ state.connections.addConnection(dataTable, datascroller);
+ }
+ }
+
+ public void afterComponent(UIComponent component, PhaseEvent event, Object object) {
+ State state = (State) object;
+ state.components.removeLast();
+ }
+
+ public void afterRoot(PhaseEvent event, Object object) {
+ State state = (State) object;
+ FacesContext facesContext = event.getFacesContext();
+ Iterator<Entry<UIData, List<UIDataScroller>>> entries =
+ state.connections.iterator();
+
+ while (entries.hasNext()) {
+ Entry<UIData, List<UIDataScroller>> entry = entries.next();
+ List<UIDataScroller> scrollers = entry.getValue();
+ if (!scrollers.isEmpty()) {
+ List<Object> values = new ArrayList<Object>(scrollers.size());
+
+ UIData data = entry.getKey();
+ UIDataScroller activeComponent = null;
+
+ Map<String, Object> attributes = data.getAttributes();
+ Object pageValue = attributes.get(UIDataScroller.SCROLLER_STATE_ATTRIBUTE);
+
+ if (pageValue == null) {
+ boolean valid = true;
+
+ for (UIDataScroller datascroller : scrollers) {
+ Object nextPageValue = null;
+
+ if (datascroller.isLocalPageSet()) {
+ nextPageValue = datascroller.getPage();
+ attributes.put(UIDataScroller.SCROLLER_STATE_ATTRIBUTE, nextPageValue);
+ datascroller.resetLocalPage();
+ } else {
+ nextPageValue = datascroller.getValueExpression("page");
+ }
+
+ if (!values.isEmpty() && !same(values.get(values.size() - 1),
nextPageValue)) {
+ valid = false;
+ }
+
+ values.add(nextPageValue);
+
+ if (nextPageValue != null) {
+ activeComponent = datascroller;
+ pageValue = nextPageValue;
+ }
+ }
+
+ if (!valid) {
+ StringBuilder builder = new StringBuilder("\n[");
+ Iterator<UIDataScroller> scrollerItr = scrollers.iterator();
+ Iterator<Object> valueItr = values.iterator();
+
+ while (scrollerItr.hasNext()) {
+ UIDataScroller next = scrollerItr.next();
+ builder.append(MessageUtil.getLabel(facesContext, next));
+ builder.append(": ");
+
+ Object value = valueItr.next();
+ if (value instanceof Expression) {
+ builder.append(((Expression) value).getExpressionString());
+ } else {
+ builder.append(value);
+ }
+
+ builder.append(scrollerItr.hasNext() ? ",\n" : "]");
+ }
+
+ String formattedMessage =
Messages.getMessage(Messages.DATASCROLLER_PAGES_DIFFERENT,
+ new Object[] {MessageUtil.getLabel(facesContext, data), builder});
+
+
+ log.error(formattedMessage);
+ }
+
+ }
+
+ if (activeComponent == null) {
+ activeComponent = scrollers.get(scrollers.size() - 1);
+ }
+
+ if (pageValue != null) {
+ activeComponent.setupFirstRowValue();
+ }
+ }
+ }
+ }
+
+ private static boolean isRendered(List<UIComponent> components) {
+ boolean rendered;
+
+ for (UIComponent component : components) {
+ rendered = false;
+
+ try {
+ rendered = component.isRendered();
+ } catch (Exception e) {
+ //ignore that
+ if (log.isDebugEnabled()) {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ }
+
+ if (!rendered) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private static boolean same(Object o1, Object o2) {
+ if (o1 instanceof ValueExpression && o2 instanceof ValueExpression) {
+ ValueExpression ve1 = (ValueExpression) o1;
+ ValueExpression ve2 = (ValueExpression) o2;
+
+ if (same(ve1.getExpressionString(), ve2.getExpressionString()) &&
same(ve1.getExpectedType(), ve2.getExpectedType())) {
+ return true;
+ }
+ }
+
+ return (o1 != null && o1.equals(o2)) || (o1 == null && o2 == null);
+ }
+}
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,539 @@
+package org.richfaces.component;
+
+import java.util.Map;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIData;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.event.DataScrollerEvent;
+import org.richfaces.event.DataScrollerListener;
+import org.richfaces.event.DataScrollerSource;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
+
+public abstract class UIDataScroller extends UIComponentBase implements
DataScrollerSource {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.DataScroller";
+
+ private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
+
+
+ public static final String LAST_PAGE_MODE_FULL = "full";
+
+ public static final String LAST_PAGE_MODE_SHORT = "short";
+
+
+ public static final String FIRST_FACET_NAME = "first";
+
+ public static final String LAST_FACET_NAME = "last";
+
+ public static final String NEXT_FACET_NAME = "next";
+
+ public static final String PREVIOUS_FACET_NAME = "previous";
+
+ public static final String FAST_FORWARD_FACET_NAME = "fastforward";
+
+ public static final String FAST_REWIND_FACET_NAME = "fastrewind";
+
+ public static final String FIRST_DISABLED_FACET_NAME = "first_disabled";
+
+ public static final String LAST_DISABLED_FACET_NAME = "last_disabled";
+
+ public static final String NEXT_DISABLED_FACET_NAME = "next_disabled";
+
+ public static final String PREVIOUS_DISABLED_FACET_NAME =
"previous_disabled";
+
+ public static final String FAST_FORWARD_DISABLED_FACET_NAME =
"fastforward_disabled";
+
+ public static final String FAST_REWIND_DISABLED_FACET_NAME =
"fastrewind_disabled";
+
+
+ private Integer page;
+
+
+ public void addScrollerListener(DataScrollerListener listener) {
+ addFacesListener(listener);
+ }
+
+ public DataScrollerListener[] getScrollerListeners() {
+ return (DataScrollerListener[]) getFacesListeners(DataScrollerListener.class);
+ }
+
+ public void removeScrollerListener(DataScrollerListener listener) {
+ removeFacesListener(listener);
+ }
+
+
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+ if (event instanceof DataScrollerEvent) {
+ DataScrollerEvent dataScrollerEvent = (DataScrollerEvent) event;
+
+ updateModel(dataScrollerEvent.getPage());
+
+ FacesContext context = getFacesContext();
+
+ MethodExpression scrollerListener = getScrollerListener();
+ if (scrollerListener != null) {
+ scrollerListener.invoke(context.getELContext(), new Object[]{event});
+ }
+ }
+ }
+
+
+
+ public abstract MethodExpression getScrollerListener();
+
+ public abstract void setScrollerListener(MethodExpression scrollerListener);
+
+ public abstract void setFor(String f);
+
+ public abstract String getFor();
+
+ public abstract int getFastStep();
+
+ public abstract void setFastStep(int FastStep);
+
+ public abstract int getMaxPages();
+
+ public abstract void setMaxPages(int maxPages);
+
+ public abstract String getSelectedStyleClass();
+
+ public abstract void setSelectedStyleClass(String selectedStyleClass);
+
+ public abstract String getSelectedStyle();
+
+ public abstract void setSelectedStyle(String selectedStyle);
+
+ public abstract String getStyleClass();
+
+ public abstract void setStyleClass(String styleClass);
+
+ public abstract String getStyle();
+
+ public abstract void setStyle(String styleClass);
+
+ public abstract String getBoundaryControls();
+
+ public abstract void setBoundaryControls(String boundaryControls);
+
+ public abstract String getFastControls();
+
+ public abstract void setFastControls(String fastControls);
+
+ public abstract String getStepControls();
+
+ public abstract void setStepControls(String stepControls);
+
+ public abstract String getInactiveStyleClass();
+
+ public abstract void setInactiveStyleClass(String inactiveStyleClass);
+
+ public abstract String getInactiveStyle();
+
+ public abstract void setInactiveStyle(String inactiveStyle);
+
+ public abstract String getLastPageMode();
+
+ public abstract void setLastPageMode(String lastPageMode);
+
+ /**
+ * Finds the dataTable which id is mapped to the "for" property
+ *
+ * @return the dataTable component
+ */
+
+ public UIData getDataTable() {
+ String forAttribute = getFor();
+ UIComponent forComp;
+
+ if (forAttribute == null) {
+ forComp = this;
+
+ while ((forComp = forComp.getParent()) != null) {
+ if (forComp instanceof UIData) {
+ setFor(forComp.getId());
+ return (UIData) forComp;
+ }
+ }
+ throw new FacesException("could not find dataTable for datascroller " +
this.getId());
+
+ } else {
+ forComp = RendererUtils.getInstance().findComponentFor(this, forAttribute);
+ }
+
+ if (forComp == null) {
+ throw new IllegalArgumentException("could not find dataTable with id
'" + forAttribute + "'");
+ } else if (!(forComp instanceof UIData)) {
+
+ throw new IllegalArgumentException( "component with id '" +
forAttribute
+ + "' must be of type " + UIData.class.getName()
+ + ", not type "
+ + forComp.getClass().getName());
+ }
+
+ return (UIData) forComp;
+ }
+
+ private int getFastStepOrDefault() {
+ int step = getFastStep();
+ return step <= 0 ? 1 : step;
+ }
+
+ public int getPageForFacet(String facetName) {
+ if (facetName == null) {
+ throw new NullPointerException();
+ }
+
+ int newPage = 1;
+ int pageCount = getPageCount();
+
+ if (FIRST_FACET_NAME.equals(facetName)) {
+ newPage = 1;
+ } else if (PREVIOUS_FACET_NAME.equals(facetName)) {
+ newPage = getPage() - 1;
+ } else if (NEXT_FACET_NAME.equals(facetName)) {
+ newPage = getPage() + 1;
+ } else if (LAST_FACET_NAME.equals(facetName)) {
+ newPage = pageCount > 0 ? pageCount : 1;
+ } else if (FAST_FORWARD_FACET_NAME.equals(facetName)) {
+ newPage = getPage() + getFastStepOrDefault();
+ } else if (FAST_REWIND_FACET_NAME.equals(facetName)) {
+ newPage = getPage() - getFastStepOrDefault();
+ } else {
+ try {
+ newPage = Integer.parseInt(facetName.toString());
+ } catch (NumberFormatException e) {
+ throw new FacesException(e.getLocalizedMessage(), e);
+ }
+ }
+
+ if (newPage >= 1 && newPage <= pageCount) {
+ return newPage;
+ } else {
+ return 0;
+ }
+ }
+
+ public int getPageCount(UIData data) {
+ int rowCount = getRowCount(data);
+ int rows = getRows(data);
+ return getPageCount(data, rowCount, rows);
+ }
+
+ public int getPageCount(UIData data, int rowCount, int rows) {
+ int pageCount;
+ if (rows > 0) {
+ pageCount = rows <= 0 ? 1 : rowCount / rows;
+ if (rowCount % rows > 0) {
+ pageCount++;
+ }
+ if (pageCount == 0) {
+ pageCount = 1;
+ }
+ } else {
+ rows = 1;
+ pageCount = 1;
+ }
+ return pageCount;
+ }
+
+ /** @return the page count of the uidata */
+ public int getPageCount() {
+ return getPageCount(getDataTable());
+ }
+
+ public int getRowCount(UIData data) {
+ int rowCount = data.getRowCount();
+ if (rowCount >= 0) {
+ return rowCount;
+ }
+
+ return BinarySearch.search(data);
+ }
+
+ /** @return int */
+ public int getRowCount() {
+ //xxx nick -> alex - scrollable models can return -1 here
+ //let's implement "dychotomic" discovery
+ // setPage(1)... if isPageAvailable() setPage(2) then 4, 8, etc.
+ // setPage() { setRowIndex(pageIdx * rows); }
+ // isPageAvailable() { return isRowAvailable() }
+ //return getUIData().getRowCount();
+ return getRowCount(getDataTable());
+ }
+
+ public int getRows(UIData data) {
+ int row = 0;
+ row = data.getRows();
+ if (row == 0) {
+ row = getRowCount(data);
+ }
+
+ return row;
+ }
+
+ // facet getter methods
+ public UIComponent getFirst() {
+ return getFacet(FIRST_FACET_NAME);
+ }
+
+ public UIComponent getLast() {
+ return getFacet(LAST_FACET_NAME);
+ }
+
+ public UIComponent getNext() {
+ return getFacet(NEXT_FACET_NAME);
+ }
+
+ public UIComponent getFastForward() {
+ return getFacet(FAST_FORWARD_FACET_NAME);
+ }
+
+ public UIComponent getFastRewind() {
+ return getFacet(FAST_REWIND_FACET_NAME);
+ }
+
+ public UIComponent getPrevious() {
+ return getFacet(PREVIOUS_FACET_NAME);
+ }
+
+ private static boolean isRendered(UIComponent component) {
+ UIComponent c = component;
+ while (c != null) {
+ if (!c.isRendered()) {
+ return false;
+ }
+
+ c = c.getParent();
+ }
+
+ return true;
+ }
+
+
+ public void setupFirstRowValue() {
+ UIData dataTable = getDataTable();
+ if (isRendered()) {
+ int rowCount = getRowCount(dataTable);
+ int rows = getRows(dataTable);
+
+ Integer pageCount = getPageCount(dataTable, rowCount, rows);
+
+ int page = getPage();
+ int newPage = -1;
+ if (page < 1) {
+ newPage = 1;
+ } else if (page > pageCount) {
+ newPage = (pageCount != 0 ? pageCount : 1);
+ }
+
+ if (newPage != -1) {
+ FacesContext context = getFacesContext();
+ Object label = MessageUtil.getLabel(context, this);
+ String formattedMessage = Messages.getMessage(Messages.DATASCROLLER_PAGE_MISSING,
+ new Object[] {label, page, pageCount, newPage});
+
+ log.warn(formattedMessage);
+
+ page = newPage;
+ dataTable.getAttributes().put(SCROLLER_STATE_ATTRIBUTE, page);
+ }
+
+ if (isRendered(dataTable)) {
+ int first;
+
+ String lastPageMode = getLastPageMode();
+ if (lastPageMode == null) {
+ lastPageMode = LAST_PAGE_MODE_SHORT;
+ } else if (!LAST_PAGE_MODE_SHORT.equals(lastPageMode) &&
+ !LAST_PAGE_MODE_FULL.equals(lastPageMode)) {
+
+ throw new IllegalArgumentException("Illegal value of 'lastPageMode'
attribute: '" + lastPageMode + "'");
+ }
+
+ if (page != pageCount || LAST_PAGE_MODE_SHORT.equals(lastPageMode)) {
+ first = (page - 1) * rows;
+ } else {
+ first = rowCount - rows;
+ if (first < 0) {
+ first = 0;
+ }
+ }
+
+ dataTable.setFirst(first);
+ }
+ }
+ }
+
+ public void setPage(int newPage) {
+ this.page = newPage;
+ }
+
+ public int getPage() {
+ Map<String, Object> attributes = getDataTable().getAttributes();
+ Integer state = (Integer) attributes.get(SCROLLER_STATE_ATTRIBUTE);
+ if (state != null) {
+ return state;
+ }
+
+ if (this.page != null) {
+ return page;
+ }
+
+ ValueExpression ve = getValueExpression("page");
+ if (ve != null) {
+ try {
+ Integer pageObject = (Integer) ve.getValue(getFacesContext().getELContext());
+
+ if (pageObject != null) {
+ return pageObject;
+ } else {
+ return 1;
+ }
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ } else {
+ return 1;
+ }
+ }
+
+ private void updateModel(int newPage) {
+ UIData dataTable = getDataTable();
+
+ if (isRendered(dataTable)) {
+ dataTable.setFirst((newPage - 1) * getRows(dataTable));
+ }
+
+ Map<String, Object> attributes = dataTable.getAttributes();
+ attributes.put(SCROLLER_STATE_ATTRIBUTE, newPage);
+
+ FacesContext context = getFacesContext();
+ ValueExpression ve = getValueExpression("page");
+ if (ve != null) {
+ try {
+ ve.setValue(context.getELContext(), newPage);
+ attributes.remove(SCROLLER_STATE_ATTRIBUTE);
+ } catch (ELException e) {
+ String messageStr = e.getMessage();
+ Throwable result = e.getCause();
+ while (null != result &&
+ result.getClass().isAssignableFrom(ELException.class)) {
+ messageStr = result.getMessage();
+ result = result.getCause();
+ }
+ FacesMessage message;
+ if (null == messageStr) {
+ message =
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
+ new Object[] { MessageUtil.getLabel(
+ context, this) });
+ } else {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ messageStr,
+ messageStr);
+ }
+ context.getExternalContext().log(message.getSummary(), result);
+ context.addMessage(getClientId(context), message);
+ context.renderResponse();
+ } catch (IllegalArgumentException e) {
+ FacesMessage message =
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
+ new Object[] { MessageUtil.getLabel(
+ context, this) });
+ context.getExternalContext().log(message.getSummary(), e);
+ context.addMessage(getClientId(context), message);
+ context.renderResponse();
+ } catch (Exception e) {
+ FacesMessage message =
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
+ new Object[] { MessageUtil.getLabel(
+ context, this) });
+ context.getExternalContext().log(message.getSummary(), e);
+ context.addMessage(getClientId(context), message);
+ context.renderResponse();
+ }
+ }
+ }
+
+ static class BinarySearch {
+
+ public static int search(UIData data) {
+ int rowIndex = data.getRowIndex();
+ try {
+ int n = 1;
+ int k = 2;
+ for (; ;) {
+ data.setRowIndex(k - 1);
+ if (data.isRowAvailable()) {
+ n = k;
+ k = k * 2;
+ } else {
+ break;
+ }
+ }
+
+ while (n < k) {
+ int kk = Math.round((n + k) / 2) + 1;
+ data.setRowIndex(kk - 1);
+ if (data.isRowAvailable()) {
+ n = kk;
+ } else {
+ k = kk - 1;
+ }
+ }
+
+ data.setRowIndex(k - 1);
+ if (data.isRowAvailable()) {
+ return k;
+ } else {
+ return 0;
+ }
+ } finally {
+ data.setRowIndex(rowIndex);
+ }
+ }
+ }
+
+ public Object saveState(FacesContext context) {
+ return new Object[] {
+ super.saveState(context),
+ page
+ };
+
+ }
+
+ public void restoreState(FacesContext context, Object object) {
+ Object[] state = (Object[]) object;
+
+ super.restoreState(context, state[0]);
+ page = (Integer) state[1];
+ }
+
+ public static final String SCROLLER_STATE_ATTRIBUTE = COMPONENT_TYPE +
":page";
+
+ public boolean isLocalPageSet() {
+ return page != null;
+ }
+
+ public void resetLocalPage() {
+ page = null;
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,162 @@
+package org.richfaces.component.html;
+
+import javax.el.MethodExpression;
+
+import org.richfaces.component.UIDataScroller;
+
+public class HtmlDataScroller extends UIDataScroller{
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.DataScroller";
+
+ protected enum PropertyKeys {
+ boundaryControls, data, fastControls, fastStep, forComponent, handleValue,
inactiveStyle, selectStyle,
+ inactiveStyleClass, selectStyleClass, scrollerListener, lastPageMode, maxPages,
pageIndexVar, pagesVar, renderIfSinglePage,
+ style, styleClass, stepControls
+ }
+
+ @Override
+ public String getBoundaryControls() {
+ return (String)getStateHelper().eval(PropertyKeys.boundaryControls);
+ }
+
+ @Override
+ public String getFastControls() {
+ return (String)getStateHelper().eval(PropertyKeys.fastControls);
+ }
+
+ @Override
+ public int getFastStep() {
+ return (Integer)getStateHelper().eval(PropertyKeys.fastStep, 0);
+ }
+
+ @Override
+ public String getFor() {
+ return (String)getStateHelper().eval(PropertyKeys.forComponent);
+ }
+
+ @Override
+ public String getInactiveStyle() {
+ return (String)getStateHelper().eval(PropertyKeys.inactiveStyle);
+ }
+
+ @Override
+ public String getInactiveStyleClass() {
+ return (String)getStateHelper().eval(PropertyKeys.inactiveStyleClass);
+ }
+
+ @Override
+ public String getLastPageMode() {
+ return (String)getStateHelper().eval(PropertyKeys.lastPageMode);
+ }
+
+ @Override
+ public int getMaxPages() {
+ return (Integer)getStateHelper().eval(PropertyKeys.maxPages,0);
+ }
+
+ @Override
+ public String getSelectedStyle() {
+ return (String)getStateHelper().eval(PropertyKeys.selectStyle);
+ }
+
+ @Override
+ public String getSelectedStyleClass() {
+ return (String)getStateHelper().eval(PropertyKeys.selectStyleClass);
+ }
+
+ @Override
+ public String getStepControls() {
+ return (String)getStateHelper().eval(PropertyKeys.selectStyleClass);
+ }
+
+ @Override
+ public String getStyle() {
+ return (String)getStateHelper().eval(PropertyKeys.selectStyle);
+ }
+
+ @Override
+ public String getStyleClass() {
+ return (String)getStateHelper().eval(PropertyKeys.selectStyleClass);
+ }
+
+ @Override
+ public MethodExpression getScrollerListener() {
+ return (MethodExpression)getStateHelper().eval(PropertyKeys.scrollerListener);
+ }
+
+ @Override
+ public void setBoundaryControls(String boundaryControls) {
+ getStateHelper().put(PropertyKeys.boundaryControls, boundaryControls);
+ }
+
+ @Override
+ public void setFastControls(String fastControls) {
+ getStateHelper().put(PropertyKeys.fastControls, fastControls);
+ }
+
+ @Override
+ public void setFastStep(int fastStep) {
+ getStateHelper().put(PropertyKeys.fastStep, fastStep);
+ }
+
+ @Override
+ public void setFor(String f) {
+ getStateHelper().put(PropertyKeys.forComponent, f);
+ }
+
+ @Override
+ public void setInactiveStyle(String inactiveStyle) {
+ getStateHelper().put(PropertyKeys.inactiveStyle, inactiveStyle);
+ }
+
+ @Override
+ public void setInactiveStyleClass(String inactiveStyleClass) {
+ getStateHelper().put(PropertyKeys.inactiveStyleClass, inactiveStyleClass);
+ }
+
+ @Override
+ public void setLastPageMode(String lastPageMode) {
+ getStateHelper().put(PropertyKeys.inactiveStyle, lastPageMode);
+ }
+
+ @Override
+ public void setMaxPages(int maxPages) {
+ getStateHelper().put(PropertyKeys.maxPages, maxPages);
+ }
+
+ @Override
+ public void setSelectedStyle(String selectedStyle) {
+ getStateHelper().put(PropertyKeys.selectStyle, selectedStyle);
+ }
+
+ @Override
+ public void setSelectedStyleClass(String selectedStyleClass) {
+ getStateHelper().put(PropertyKeys.selectStyleClass, selectedStyleClass);
+ }
+
+ @Override
+ public void setStepControls(String stepControls) {
+ getStateHelper().put(PropertyKeys.stepControls, stepControls);
+ }
+
+ @Override
+ public void setStyle(String style) {
+ getStateHelper().put(PropertyKeys.style, style);
+ }
+
+ @Override
+ public void setStyleClass(String styleClass) {
+ getStateHelper().put(PropertyKeys.styleClass, styleClass);
+ }
+
+ @Override
+ public void setScrollerListener(MethodExpression scrollerListener) {
+ getStateHelper().put(PropertyKeys.scrollerListener, scrollerListener);
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+}
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/ControlsState.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/ControlsState.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/ControlsState.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,128 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.renderkit;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ *
+ */
+public class ControlsState {
+
+ private boolean firstRendered = true;
+ private boolean firstEnabled = true;
+
+ private boolean lastRendered = true;
+ private boolean lastEnabled = true;
+
+ private boolean previousRendered = true;
+ private boolean previousEnabled = true;
+
+ private boolean nextRendered = true;
+ private boolean nextEnabled = true;
+
+ private boolean fastRewindRendered = true;
+ private boolean fastRewindEnabled = true;
+
+ private boolean fastForwardRendered = true;
+ private boolean fastForwardEnabled = true;
+
+ private boolean controlsSeparatorRendered = false;
+
+ public boolean isFirstRendered() {
+ return firstRendered;
+ }
+ public void setFirstRendered(boolean firstRendered) {
+ this.firstRendered = firstRendered;
+ }
+ public boolean isFirstEnabled() {
+ return firstEnabled;
+ }
+ public void setFirstEnabled(boolean firstEnabled) {
+ this.firstEnabled = firstEnabled;
+ }
+ public boolean isLastRendered() {
+ return lastRendered;
+ }
+ public void setLastRendered(boolean lastRendered) {
+ this.lastRendered = lastRendered;
+ }
+ public boolean isLastEnabled() {
+ return lastEnabled;
+ }
+ public void setLastEnabled(boolean lastEnabled) {
+ this.lastEnabled = lastEnabled;
+ }
+ public boolean isPreviousRendered() {
+ return previousRendered;
+ }
+ public void setPreviousRendered(boolean previousRendered) {
+ this.previousRendered = previousRendered;
+ }
+ public boolean isPreviousEnabled() {
+ return previousEnabled;
+ }
+ public void setPreviousEnabled(boolean previousEnabled) {
+ this.previousEnabled = previousEnabled;
+ }
+ public boolean isNextRendered() {
+ return nextRendered;
+ }
+ public void setNextRendered(boolean nextRendered) {
+ this.nextRendered = nextRendered;
+ }
+ public boolean isNextEnabled() {
+ return nextEnabled;
+ }
+ public void setNextEnabled(boolean nextEnabled) {
+ this.nextEnabled = nextEnabled;
+ }
+ public boolean isFastRewindRendered() {
+ return fastRewindRendered;
+ }
+ public void setFastRewindRendered(boolean fastRewindRendered) {
+ this.fastRewindRendered = fastRewindRendered;
+ }
+ public boolean isFastRewindEnabled() {
+ return fastRewindEnabled;
+ }
+ public void setFastRewindEnabled(boolean fastRewindEnabled) {
+ this.fastRewindEnabled = fastRewindEnabled;
+ }
+ public boolean isFastForwardRendered() {
+ return fastForwardRendered;
+ }
+ public void setFastForwardRendered(boolean fastForwardRendered) {
+ this.fastForwardRendered = fastForwardRendered;
+ }
+ public boolean isFastForwardEnabled() {
+ return fastForwardEnabled;
+ }
+ public void setFastForwardEnabled(boolean fastForwardEnabled) {
+ this.fastForwardEnabled = fastForwardEnabled;
+ }
+ public boolean isControlsSeparatorRendered() {
+ return controlsSeparatorRendered;
+ }
+ public void setControlsSeparatorRendered(boolean controlsSeparatorRendered) {
+ this.controlsSeparatorRendered = controlsSeparatorRendered;
+ }
+}
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,318 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.renderkit;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIParameter;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.richfaces.component.UIDataScroller;
+import org.richfaces.event.DataScrollerEvent;
+
+
+public class DataScrollerBaseRenderer extends Renderer {
+
+ public void doDecode(FacesContext context, UIComponent component) {
+ Map paramMap = getParamMap(context);
+ String clientId = component.getClientId(context);
+ String param = (String) paramMap.get(clientId);
+ if (param != null) {
+ UIDataScroller scroller = (UIDataScroller) component;
+ int newPage = scroller.getPageForFacet(param);
+ int page = scroller.getPage();
+ if (newPage != 0 && newPage != page) {
+ DataScrollerEvent event = new DataScrollerEvent(scroller,
+ String.valueOf(page), param, newPage);
+ event.queue();
+
+ }
+
+ if (AjaxRendererUtils.isAjaxRequest(context)) {
+ AjaxContext.getCurrentInstance(context)
+ .addAreasToProcessFromComponent(context, component);
+ }
+
+ new AjaxEvent(component).queue();
+ }
+ }
+
+ public ControlsState getControlsState(FacesContext context,
+ UIDataScroller datascroller, int pageIndex, int pageCount) {
+ int minPageIdx = 1;
+ int maxPageIdx = pageCount;
+ int fastStep = datascroller.getFastStep();
+ if (fastStep <= 1) {
+ fastStep = 1;
+ }
+
+ boolean useFirst = true;
+ boolean useLast = true;
+
+ boolean useBackFast = true;
+ boolean useForwFast = true;
+
+ ControlsState controlsState = new ControlsState();
+
+ if (pageIndex <= minPageIdx) {
+ useFirst = false;
+ }
+
+ if (pageIndex >= maxPageIdx) {
+ useLast = false;
+ }
+
+ if (pageIndex - fastStep < minPageIdx) {
+ useBackFast = false;
+ }
+
+ if (pageIndex + fastStep > maxPageIdx) {
+ useForwFast = false;
+ }
+
+ boolean isAuto;
+ String boundaryControls = datascroller.getBoundaryControls();
+ String stepControls = datascroller.getStepControls();
+ String fastControls = datascroller.getFastControls();
+
+ if ((isAuto = "auto".equals(boundaryControls)) ||
"show".equals(
+ boundaryControls)) {
+ if (isAuto) {
+ controlsState.setFirstRendered(useFirst);
+ controlsState.setLastRendered(useLast);
+ }
+
+ controlsState.setFirstEnabled(useFirst);
+ controlsState.setLastEnabled(useLast);
+ } else {
+ controlsState.setFirstRendered(false);
+ controlsState.setLastRendered(false);
+ }
+
+ if ((isAuto = "auto".equals(stepControls)) || "show".equals(
+ stepControls)) {
+ if (isAuto) {
+ controlsState.setPreviousRendered(useFirst);
+ controlsState.setNextRendered(useLast);
+ }
+
+ controlsState.setPreviousEnabled(useFirst);
+ controlsState.setNextEnabled(useLast);
+ } else {
+ controlsState.setPreviousRendered(false);
+ controlsState.setNextRendered(false);
+ }
+
+ if ((isAuto = "auto".equals(fastControls)) || "show".equals(
+ fastControls)) {
+ if (isAuto) {
+ controlsState.setFastForwardRendered(useForwFast);
+ controlsState.setFastRewindRendered(useBackFast);
+ }
+
+ controlsState.setFastForwardEnabled(useForwFast);
+ controlsState.setFastRewindEnabled(useBackFast);
+ } else {
+ controlsState.setFastForwardRendered(false);
+ controlsState.setFastRewindRendered(false);
+ }
+
+ UIComponent controlsSeparatorFacet =
datascroller.getFacet("controlsSeparator");
+ if (controlsSeparatorFacet != null &&
controlsSeparatorFacet.isRendered()) {
+ controlsState.setControlsSeparatorRendered(true);
+ }
+
+ return controlsState;
+ }
+
+ public void renderPager(FacesContext context, UIComponent component, int pageIndex,
int count)
+ throws IOException {
+ ResponseWriter out = context.getResponseWriter();
+ UIDataScroller scroller = (UIDataScroller) component;
+ int currentPage = pageIndex;
+
+ int maxPages = scroller.getMaxPages();
+ if (maxPages <= 1) {
+ maxPages = 1;
+ }
+
+ int pageCount = count;
+ if (pageCount <= 1) {
+ return;
+ }
+
+ int delta = maxPages / 2;
+
+ int pages;
+ int start;
+ if (pageCount > maxPages && currentPage > delta) {
+ pages = maxPages;
+ start = currentPage - pages / 2 - 1;
+ if (start + pages > pageCount) {
+ start = pageCount - pages;
+ }
+ } else {
+ pages = pageCount < maxPages ? pageCount : maxPages;
+ start = 0;
+ }
+
+ for (int i = start, size = start + pages; i < size; i++) {
+
+ boolean isCurrentPage = (i + 1 == currentPage);
+ String styleClass;
+ String style;
+ if (isCurrentPage) {
+ styleClass = scroller.getSelectedStyleClass();
+ style = scroller.getSelectedStyle();
+ } else {
+ styleClass = scroller.getInactiveStyleClass();
+ style = scroller.getInactiveStyle();
+ }
+ if (styleClass==null){
+ styleClass="";
+ }
+
+ out.startElement("td", component);
+
+ if (isCurrentPage) {
+ out.writeAttribute("class", "rich-datascr-act "+
+ styleClass, null);
+ } else {
+ out.writeAttribute("class", "rich-datascr-inact "+
+ styleClass, null);
+ out.writeAttribute("onclick", getOnClick(Integer.toString(i +
1)), null);
+ }
+ if (null != style) out.writeAttribute("style", style, null);
+ out.writeText(Integer.toString(i + 1), null);
+ //renderChild(context, link);
+ out.endElement("td");
+ }
+
+ }
+
+ public Object getOnClick(String string) {
+ return "Event.fire(this, 'rich:datascroller:onscroll', {'page':
'" + string + "'});";
+ }
+
+ public void renderPages(FacesContext context, UIComponent component, int pageIndex,
int count)
+ throws IOException {
+ UIDataScroller scroller = (UIDataScroller) component;
+ int currentPage = pageIndex;
+
+ int pageCount = count;
+ if (pageCount <= 1) {
+ pageCount = 1;
+ }
+ String varName = (String)
scroller.getAttributes().get("pageIndexVar");
+ if (varName != null && varName.length() > 0) {
+ context.getExternalContext()
+ .getRequestMap().put(varName, new Integer(currentPage));
+ }
+ varName = (String) scroller.getAttributes().get("pagesVar");
+ if (varName != null && varName.length() > 0) {
+ context.getExternalContext()
+ .getRequestMap().put(varName, new Integer(pageCount));
+ }
+ }
+
+ private Map getParamMap(FacesContext context) {
+ return context.getExternalContext().getRequestParameterMap();
+ }
+
+ //get UIParameter's Map
+ protected Map getParameters(FacesContext context, UIComponent component){
+ Map parameters = new HashMap();
+
+ if(component instanceof UIDataScroller){
+ UIDataScroller datascroller = (UIDataScroller)component;
+ List children = datascroller.getChildren();
+ for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+ UIComponent child = (UIComponent) iterator.next();
+ if(child instanceof UIParameter) {
+ UIParameter param = (UIParameter)child;
+ String name = param.getName();
+ if (name != null) {
+ parameters.put(name, param.getValue());
+ }
+ }
+ }
+ }
+
+ return parameters;
+ }
+
+ /**
+ public String getSubmitFunction(FacesContext context, UIComponent component) {
+ JSFunctionDefinition definition = new JSFunctionDefinition("event");
+
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(component,
+ context);
+ Map eventOptions = AjaxRendererUtils.buildEventOptions(context,
+ component, true);
+ Map parameters = (Map) eventOptions.get("parameters");
+
+ Map params = getParameters(context,component);
+ if(!params.isEmpty()){
+ parameters.putAll(params);
+ }
+
+ parameters.put(component.getClientId(context), new
JSLiteral("event.memo.page"));
+
+ function.addParameter(eventOptions);
+ StringBuffer buffer = new StringBuffer();
+ function.appendScript(buffer);
+ buffer.append("; return false;");
+
+ String onPageChange = (String) component.getAttributes().get("onpagechange");
+ if (onPageChange != null && onPageChange.length() != 0) {
+ JSFunctionDefinition onPageChangeDef = new JSFunctionDefinition("event");
+ onPageChangeDef.addToBody(onPageChange);
+ onPageChangeDef.addToBody("; return true;");
+
+ definition.addToBody("if (");
+ definition.addToBody(onPageChangeDef.toScript());
+ definition.addToBody("(event)) {");
+ definition.addToBody(buffer.toString());
+ definition.addToBody("}");
+ } else {
+ definition.addToBody(buffer.toString());
+ }
+
+ return definition.toScript();
+ }
+ */
+
+ /** Creates HtmlAjaxCommandLink sets its id, value and reRender and UIParameter */
+ public boolean getRendersChildren() {
+ return true;
+ }
+}
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,93 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.taglib;
+
+import javax.el.ValueExpression;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.UIDataScroller;
+
+
+/**
+ * Created 11.03.2008
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class DatascrollerTagHandler extends ComponentHandler {
+
+ private static final MetaRule pageRule = new MetaRule() {
+
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
+ if ("page".equals(name)) {
+ return new PageMapper(attribute);
+ } else {
+ return null;
+ }
+ }
+
+ };
+
+ private static final class PageMapper extends Metadata {
+
+ private final TagAttribute page;
+
+ /**
+ * @param attribute
+ */
+ public PageMapper(TagAttribute attribute) {
+ page = attribute;
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.facelets.tag.Metadata#applyMetadata(com.sun.facelets.FaceletContext,
java.lang.Object)
+ */
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ UIDataScroller datascroller = (UIDataScroller) instance;
+ ValueExpression ve = page.getValueExpression(ctx, int.class);
+ if (ve.isLiteralText()) {
+ Integer value = (Integer) ve.getValue(ctx.getFacesContext().getELContext());
+ datascroller.setPage(value);
+ } else {
+ datascroller.setValueExpression("page", ve);
+ }
+ }
+
+ }
+
+ public DatascrollerTagHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset ruleset = super.createMetaRuleset(type);
+ ruleset.addRule(pageRule);
+ return ruleset;
+ }
+}
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/datascroller.taglib.xml
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/datascroller.taglib.xml
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/datascroller.taglib.xml 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<facelet-taglib version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee" id="a4j">
+ <
namespace>http://richfaces.org/datascroller</namespace>
+ <tag>
+ <tag-name>dataScroller</tag-name>
+ <component>
+ <component-type>org.richfaces.DataScroller</component-type>
+ <renderer-type>org.richfaces.DataScrollerRenderer</renderer-type>
+ </component>
+ </tag>
+</facelet-taglib>
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/tempates/datascroller.template.xml
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/tempates/datascroller.template.xml
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/tempates/datascroller.template.xml 2010-02-24
19:35:07 UTC (rev 16489)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.DataScrollerRenderer</cdk:class>
+ <cdk:superclass>org.richfaces.renderkit.DataScrollerBaseRenderer</cdk:superclass>
+ <cdk:component-family>org.richfaces.DataScroller</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.DataScroller</cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ <div id="#{clientId}"
class="#{component.attributes['styleClass']}"
style="#{component.attributes['style']}">
+ <table>
+ <tbody>
+ <tr>
+ <td>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </cc:implementation>
+</cdk:root>
\ No newline at end of file