Author: abelevich
Date: 2010-03-17 11:47:54 -0400 (Wed, 17 Mar 2010)
New Revision: 16588
Modified:
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/renderkit/DataScrollerBaseRenderer.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js
Log:
add initial data scroll support
Modified:
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 2010-03-17
15:42:23 UTC (rev 16587)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-03-17
15:47:54 UTC (rev 16588)
@@ -1,5 +1,7 @@
package org.richfaces.component;
+import java.util.Collection;
+import java.util.LinkedHashSet;
import java.util.Map;
import javax.el.ELException;
@@ -39,20 +41,28 @@
style, styleClass, stepControls
}
- protected enum Facets {
- first, last, fastforward, fastrewind, first_disabled, last_disabled,
fastforward_disabled, fastrewind_disabled
- }
-
protected enum PageMode {
full, part //part - prev short
}
+ public static final String FIRST_FACET_NAME = "first";
+ public static final String LAST_FACET_NAME = "last";
+
+ 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";
+
+
+
//TODO: anton - fix
private Integer page;
-
public void addScrollerListener(DataScrollerListener listener) {
addFacesListener(listener);
}
@@ -68,23 +78,25 @@
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 =
(MethodExpression)getAttributes().get(PropertyKeys.scrollerListener);
//getScrollerListener();
+
+ MethodExpression scrollerListener =
(MethodExpression)getStateHelper().eval(PropertyKeys.scrollerListener);
if (scrollerListener != null) {
scrollerListener.invoke(context.getELContext(), new Object[]{event});
}
+
+ context.getPartialViewContext().getRenderIds().add(dataScrollerEvent.getComponent().getClientId(context));
+
context.getPartialViewContext().getRenderIds().add(getDataTable().getClientId(context));
}
}
-
-
- /**
+ /**
* Finds the dataTable which id is mapped to the "for" property
*
* @return the dataTable component
@@ -123,8 +135,7 @@
}
private int getFastStepOrDefault() {
- int step = (Integer)getStateHelper().get(PropertyKeys.fastStep);
- return step <= 0 ? 1 : step;
+ return (Integer)getStateHelper().eval(PropertyKeys.fastStep,1);
}
public int getPageForFacet(String facetName) {
@@ -135,19 +146,22 @@
int newPage = 1;
int pageCount = getPageCount();
- switch (Facets.valueOf(facetName)) {
- case first : newPage = 1; break;
- case last : newPage = pageCount > 0 ? pageCount : 1; break;
- case fastforward : newPage = getPage() + getFastStepOrDefault(); break;
- case fastrewind : newPage = getPage() - getFastStepOrDefault(); break;
- default:
- try {
- newPage = Integer.parseInt(facetName.toString());
- } catch (NumberFormatException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- }
- break;
- }
+
+ if (FIRST_FACET_NAME.equals(facetName)) {
+ newPage = 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;
@@ -216,22 +230,22 @@
// facet getter methods
public UIComponent getFirst() {
- return getFacet(Facets.first.toString());
+ return getFacet(FIRST_FACET_NAME);
}
public UIComponent getLast() {
- return getFacetByKey(Facets.last);
+ return getFacetByKey(LAST_FACET_NAME);
}
public UIComponent getFastForward() {
- return getFacetByKey(Facets.fastforward);
+ return getFacetByKey(FAST_FORWARD_FACET_NAME);
}
public UIComponent getFastRewind() {
- return getFacetByKey(Facets.fastrewind);
+ return getFacetByKey(FAST_REWIND_FACET_NAME);
}
- private UIComponent getFacetByKey(Object key) {
+ private UIComponent getFacetByKey(String key) {
return getFacet(key.toString());
}
Modified:
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 2010-03-17
15:42:23 UTC (rev 16587)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-17
15:47:54 UTC (rev 16588)
@@ -32,7 +32,6 @@
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
@@ -40,6 +39,7 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIDataScroller;
import org.richfaces.event.DataScrollerEvent;
@@ -53,13 +53,13 @@
@ResourceDependency(name = "css/datascroller.css")
})
-public class DataScrollerBaseRenderer extends Renderer {
+public class DataScrollerBaseRenderer extends RendererBase {
public void doDecode(FacesContext context, UIComponent component) {
Map <String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
String clientId = component.getClientId(context);
- String param = (String) paramMap.get(clientId);
+ String param = (String) paramMap.get(clientId + ":page");
if (param != null) {
@@ -72,12 +72,7 @@
}
}
}
- @Override
- public void decode(FacesContext context, UIComponent component) {
- Map <String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
-
- }
public ControlsState getControlsState(FacesContext context, UIComponent component) {
@@ -119,7 +114,6 @@
boolean isAuto;
String boundaryControls =
(String)component.getAttributes().get("boundaryControls");
- String stepControls =
(String)component.getAttributes().get("stepControls");
String fastControls =
(String)component.getAttributes().get("fastControls");
if ((isAuto = "auto".equals(boundaryControls)) ||
"show".equals(
@@ -136,20 +130,6 @@
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) {
@@ -230,14 +210,6 @@
out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital ds_current
"+styleClass, null);
} else {
out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital
"+styleClass, null);
- /*
- out.writeAttribute(HTML.ONMOUSEOVER_ATTRIBUTE,
"this.className='ds_digital ds_over'", null);
- out.writeAttribute(HTML.ONMOUSEOUT_ATTRIBUTE,
"this.className='ds_digital'", null);
- out.writeAttribute(HTML.ONMOUSEUP_ATTRIBUTE,
"this.className='ds_digital ds_over'", null);
- out.writeAttribute(HTML.ONMOUSEDOWN_ATTRIBUTE,
"this.className='ds_digital ds_press'", null);
-
- out.writeAttribute(HTML.ONCLICK_ATTRIBUTE, getOnClick(context, component,
Integer.toString(i + 1)), null);
- */
}
if (null != style) {
@@ -257,7 +229,7 @@
}
public Map<String, Map<String,String>> getControls(FacesContext context,
UIComponent component, ControlsState controlsState) {
- //will be refactored
+
Map<String, Map<String, String>> controls = new HashMap<String,
Map<String,String>>();
Map<String, String> right = new HashMap<String, String>();
Map<String, String> left = new HashMap<String, String>();
@@ -265,20 +237,19 @@
String clientId = component.getClientId(context);
if(controlsState.getFirstRendered() && controlsState.getFirstEnabled())
{
-
- left.put(clientId + "_ds_f", "first");
+ left.put(clientId + "_ds_f", UIDataScroller.FIRST_FACET_NAME);
}
if(controlsState.getFastRewindRendered()&&
controlsState.getFastRewindEnabled()) {
- left.put(clientId + "_ds_fr", "fastRewind");
+ left.put(clientId + "_ds_fr",
UIDataScroller.FAST_REWIND_FACET_NAME);
}
if(controlsState.getFastForwardRendered()&&
controlsState.getFastForwardEnabled()) {
- right.put(clientId + "_ds_ff", "fastForward");
+ right.put(clientId + "_ds_ff",
UIDataScroller.FAST_FORWARD_FACET_NAME);
}
if(controlsState.getLastRendered()&& controlsState.getLastEnabled()) {
- right.put(clientId + "_ds_l", "last");
+ right.put(clientId + "_ds_l", UIDataScroller.LAST_FACET_NAME);
}
if(!left.isEmpty()) {
@@ -299,6 +270,7 @@
Map<String, Object> options = new HashMap<String, Object>();
options.put("buttons", buttons);
options.put("digitals", digitals);
+ options.put("currentPage",
(Integer)component.getAttributes().get("page"));
function.addParameter(getSubmitFunction(context, component));
function.addParameter(options);
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js 2010-03-17
15:42:23 UTC (rev 16587)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/resources/META-INF/resources/script/datascroller.js 2010-03-17
15:47:54 UTC (rev 16588)
@@ -7,7 +7,8 @@
$super.constructor.call(this,id);
this.options = options;
-
+ this.currentPage = options.currentPage;
+
var buttons = options.buttons;
var digitals = options.digitals;
@@ -63,7 +64,7 @@
var processStyles = function(event) {
var data = event.data;
- if(data) {
+ if(data && (data.page != this.currentPage)) {
var element = data.element;
var css = data.css;