Author: nbelaevski
Date: 2010-12-28 09:49:14 -0500 (Tue, 28 Dec 2010)
New Revision: 20827
Added:
trunk/ui/iteration/api/src/main/java/org/richfaces/component/DataScrollerControlsMode.java
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
Log:
https://issues.jboss.org/browse/RF-10098
Added:
trunk/ui/iteration/api/src/main/java/org/richfaces/component/DataScrollerControlsMode.java
===================================================================
---
trunk/ui/iteration/api/src/main/java/org/richfaces/component/DataScrollerControlsMode.java
(rev 0)
+++
trunk/ui/iteration/api/src/main/java/org/richfaces/component/DataScrollerControlsMode.java 2010-12-28
14:49:14 UTC (rev 20827)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public enum DataScrollerControlsMode {
+
+ show, auto, hide;
+
+ public static final DataScrollerControlsMode DEFAULT = show;
+
+}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java 2010-12-28
14:27:29 UTC (rev 20826)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java 2010-12-28
14:49:14 UTC (rev 20827)
@@ -91,21 +91,38 @@
@Attribute
public abstract String getLastPageMode();
- @Attribute(defaultValue="10")
+ @Attribute
public abstract int getMaxPages();
- @Attribute(defaultValue="show")
- public abstract String getBoundaryControls();
+ public int getMaxPagesOrDefault() {
+ int maxPages = getMaxPages();
+ if (maxPages <= 0) {
+ maxPages = 10;
+ }
+
+ return maxPages;
+ }
- @Attribute(defaultValue="show")
- public abstract String getFastControls();
+ @Attribute
+ public abstract DataScrollerControlsMode getBoundaryControls();
+
+ @Attribute
+ public abstract DataScrollerControlsMode getFastControls();
- @Attribute(defaultValue="show")
- public abstract String getStepControls();
+ @Attribute
+ public abstract DataScrollerControlsMode getStepControls();
- @Attribute(defaultValue="1")
+ @Attribute
public abstract int getFastStep();
+ public int getFastStepOrDefault() {
+ int fastStep = getFastStep();
+ if (fastStep <= 0) {
+ fastStep = 1;
+ }
+ return fastStep;
+ }
+
@Attribute
public String getFor() {
return (String)getStateHelper().eval("for");
@@ -191,9 +208,9 @@
} else if (NEXT_FACET_NAME.equals(facetName)) {
newPage = getPage() + 1;
} else if (FAST_FORWARD_FACET_NAME.equals(facetName)) {
- newPage = getPage() + getFastStep();
+ newPage = getPage() + getFastStepOrDefault();
} else if (FAST_REWIND_FACET_NAME.equals(facetName)) {
- newPage = getPage() - getFastStep();
+ newPage = getPage() - getFastStepOrDefault();
} else {
try {
newPage = Integer.parseInt(facetName.toString());
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-12-28
14:27:29 UTC (rev 20826)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-12-28
14:49:14 UTC (rev 20827)
@@ -23,6 +23,9 @@
package org.richfaces.renderkit;
+import static org.richfaces.component.DataScrollerControlsMode.auto;
+import static org.richfaces.component.DataScrollerControlsMode.show;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +41,7 @@
import org.ajax4jsf.javascript.JSLiteral;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.component.AbstractDataScroller;
+import org.richfaces.component.DataScrollerControlsMode;
import org.richfaces.event.DataScrollerEvent;
import org.richfaces.renderkit.util.AjaxRendererUtils;
@@ -69,19 +73,23 @@
}
}
+ private DataScrollerControlsMode getModeOrDefault(UIComponent component, String
attributeName) {
+ DataScrollerControlsMode mode = (DataScrollerControlsMode)
component.getAttributes().get(attributeName);
+ if (mode == null) {
+ mode = DataScrollerControlsMode.DEFAULT;
+ }
+ return mode;
+ }
+
public ControlsState getControlsState(FacesContext context, UIComponent component) {
- int fastStep = (Integer) component.getAttributes().get("fastStep");
+ int fastStep = (Integer)
component.getAttributes().get("fastStepOrDefault");
int pageIndex = (Integer) component.getAttributes().get("page");
int pageCount = (Integer) component.getAttributes().get("pageCount");
int minPageIdx = 1;
int maxPageIdx = pageCount;
- if (fastStep <= 1) {
- fastStep = 1;
- }
-
boolean useFirst = true;
boolean useLast = true;
@@ -106,12 +114,12 @@
useForwFast = false;
}
- String boundaryControls = (String)
component.getAttributes().get("boundaryControls");
- String stepControls = (String)
component.getAttributes().get("stepControls");
- String fastControls = (String)
component.getAttributes().get("fastControls");
+ DataScrollerControlsMode boundaryControls = getModeOrDefault(component,
"boundaryControls");
+ DataScrollerControlsMode stepControls = getModeOrDefault(component,
"stepControls");
+ DataScrollerControlsMode fastControls = getModeOrDefault(component,
"fastControls");
- boolean isAuto = "auto".equals(boundaryControls);
- if (isAuto || "show".equals(boundaryControls)) {
+ boolean isAuto = auto.equals(boundaryControls);
+ if (isAuto || show.equals(boundaryControls)) {
if (isAuto) {
controlsState.setFirstRendered(useFirst);
controlsState.setLastRendered(useLast);
@@ -124,8 +132,8 @@
controlsState.setLastRendered(false);
}
- isAuto = "auto".equals(stepControls);
- if (isAuto || "show".equals(stepControls)) {
+ isAuto = auto.equals(stepControls);
+ if (isAuto || show.equals(stepControls)) {
if (isAuto) {
controlsState.setPreviousRendered(useFirst);
controlsState.setNextRendered(useLast);
@@ -138,8 +146,8 @@
controlsState.setNextRendered(false);
}
- isAuto = "auto".equals(fastControls);
- if (isAuto || "show".equals(fastControls)) {
+ isAuto = auto.equals(fastControls);
+ if (isAuto || show.equals(fastControls)) {
if (isAuto) {
controlsState.setFastForwardRendered(useForwFast);
controlsState.setFastRewindRendered(useBackFast);
@@ -164,7 +172,7 @@
throws IOException {
int currentPage = (Integer) component.getAttributes().get("page");
- int maxPages = (Integer) component.getAttributes().get("maxPages");
+ int maxPages = (Integer)
component.getAttributes().get("maxPagesOrDefault");
int pageCount = (Integer) component.getAttributes().get("pageCount");
Map<String, String> digital = new HashMap<String, String>();
@@ -173,10 +181,6 @@
return digital;
}
- if (maxPages <= 1) {
- maxPages = 1;
- }
-
int delta = maxPages / 2;
int pages;