Author: abelevich
Date: 2010-03-02 13:51:43 -0500 (Tue, 02 Mar 2010)
New Revision: 16515
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml
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/HtmlDataScroller.java
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/DatascrollerTagHandler.java
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml
Log:
UIDatascroller isn't abstract class, extend template
Modified:
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 2010-03-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/faces-config.xml 2010-03-02
18:51:43 UTC (rev 16515)
@@ -33,13 +33,4 @@
<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
Modified:
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 2010-03-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java 2010-03-02
18:51:43 UTC (rev 16515)
@@ -99,9 +99,9 @@
if (component instanceof UIDataScroller && isRendered(state.components)) {
UIDataScroller datascroller = (UIDataScroller) component;
- UIData dataTable = datascroller.getDataTable();
+ //UIData dataTable = datascroller.getDataTable();
- state.connections.addConnection(dataTable, datascroller);
+ // state.connections.addConnection(dataTable, datascroller);
}
}
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-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-03-02
18:51:43 UTC (rev 16515)
@@ -1,5 +1,6 @@
package org.richfaces.component;
+import java.io.Serializable;
import java.util.Map;
import javax.el.ELException;
@@ -25,46 +26,34 @@
import org.slf4j.Logger;
-public abstract class UIDataScroller extends UIComponentBase implements
DataScrollerSource {
+public class UIDataScroller extends UIComponentBase implements DataScrollerSource {
public static final String COMPONENT_TYPE = "org.richfaces.DataScroller";
+ public static final String COMPONENT_FAMILY = "org.richfaces.DataScroller";
+
private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
-
+
+ protected enum PropertyKeys {
+ boundaryControls, data, fastControls, fastStep, forComponent, handleValue,
inactiveStyle, selectStyle,
+ inactiveStyleClass, selectStyleClass, scrollerListener, lastPageMode, maxPages,
pageIndexVar, pagesVar, renderIfSinglePage,
+ style, styleClass, stepControls
+ }
+
+ protected enum Facets {
+ first, last, fastforward, fastrewind, first_disabled, last_disabled,
fastforward_disabled, fastrewind_disabled
+ }
- public static final String LAST_PAGE_MODE_FULL = "full";
+ protected enum PageMode {
+ full, part //part - prev short
+ }
+
- 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";
-
-
+//TODO: anton - fix
private Integer page;
+
public void addScrollerListener(DataScrollerListener listener) {
addFacesListener(listener);
}
@@ -87,88 +76,32 @@
FacesContext context = getFacesContext();
- MethodExpression scrollerListener = getScrollerListener();
+ MethodExpression scrollerListener =
(MethodExpression)getAttributes().get(PropertyKeys.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();
+ public UIComponent getDataTable() {
+ String forAttribute = (String)getStateHelper().get(PropertyKeys.forComponent);
UIComponent forComp;
if (forAttribute == null) {
forComp = this;
while ((forComp = forComp.getParent()) != null) {
- if (forComp instanceof UIData) {
- setFor(forComp.getId());
- return (UIData) forComp;
+ if (forComp instanceof UIData || forComp instanceof UIDataAdaptor) {
+ getStateHelper().put(PropertyKeys.forComponent, forComp.getId());
+ return forComp;
}
}
throw new FacesException("could not find dataTable for datascroller " +
this.getId());
@@ -179,19 +112,19 @@
if (forComp == null) {
throw new IllegalArgumentException("could not find dataTable with id
'" + forAttribute + "'");
- } else if (!(forComp instanceof UIData)) {
+ } else if (!(forComp instanceof UIData) || !(forComp instanceof UIDataAdaptor)) {
throw new IllegalArgumentException( "component with id '" +
forAttribute
- + "' must be of type " + UIData.class.getName()
+ + "' must be of type " + UIData.class.getName() + " or " +
UIDataAdaptor.class
+ ", not type "
+ forComp.getClass().getName());
}
- return (UIData) forComp;
+ return forComp;
}
-
+
private int getFastStepOrDefault() {
- int step = getFastStep();
+ int step = (Integer)getStateHelper().get(PropertyKeys.fastStep);
return step <= 0 ? 1 : step;
}
@@ -202,25 +135,19 @@
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);
- }
+
+ 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 (newPage >= 1 && newPage <= pageCount) {
@@ -230,13 +157,13 @@
}
}
- public int getPageCount(UIData data) {
+ public int getPageCount(UIComponent data) {
int rowCount = getRowCount(data);
int rows = getRows(data);
return getPageCount(data, rowCount, rows);
}
- public int getPageCount(UIData data, int rowCount, int rows) {
+ public int getPageCount(UIComponent data, int rowCount, int rows) {
int pageCount;
if (rows > 0) {
pageCount = rows <= 0 ? 1 : rowCount / rows;
@@ -258,8 +185,8 @@
return getPageCount(getDataTable());
}
- public int getRowCount(UIData data) {
- int rowCount = data.getRowCount();
+ public int getRowCount(UIComponent data) {
+ int rowCount = (Integer)data.getAttributes().get("rowCount");
if (rowCount >= 0) {
return rowCount;
}
@@ -278,9 +205,9 @@
return getRowCount(getDataTable());
}
- public int getRows(UIData data) {
+ public int getRows(UIComponent data) {
int row = 0;
- row = data.getRows();
+ row = (Integer)data.getAttributes().get("rows");
if (row == 0) {
row = getRowCount(data);
}
@@ -290,45 +217,42 @@
// facet getter methods
public UIComponent getFirst() {
- return getFacet(FIRST_FACET_NAME);
+ return getFacet(Facets.first.toString());
}
public UIComponent getLast() {
- return getFacet(LAST_FACET_NAME);
+ return getFacetByKey(Facets.last);
}
- public UIComponent getNext() {
- return getFacet(NEXT_FACET_NAME);
- }
-
public UIComponent getFastForward() {
- return getFacet(FAST_FORWARD_FACET_NAME);
+ return getFacetByKey(Facets.fastforward);
}
public UIComponent getFastRewind() {
- return getFacet(FAST_REWIND_FACET_NAME);
+ return getFacetByKey(Facets.fastrewind);
}
- public UIComponent getPrevious() {
- return getFacet(PREVIOUS_FACET_NAME);
+ private UIComponent getFacetByKey(Object key) {
+ return getFacet(key.toString());
}
-
+
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();
+ UIComponent dataTable = getDataTable();
if (isRendered()) {
int rowCount = getRowCount(dataTable);
int rows = getRows(dataTable);
@@ -358,16 +282,15 @@
if (isRendered(dataTable)) {
int first;
- String lastPageMode = getLastPageMode();
+ String lastPageMode = (String)getStateHelper().get(PropertyKeys.lastPageMode);
+
if (lastPageMode == null) {
- lastPageMode = LAST_PAGE_MODE_SHORT;
- } else if (!LAST_PAGE_MODE_SHORT.equals(lastPageMode) &&
- !LAST_PAGE_MODE_FULL.equals(lastPageMode)) {
-
+ lastPageMode = PageMode.part.toString();
+ } else if (!PageMode.part.equals(lastPageMode) &&
!PageMode.full.equals(lastPageMode)) {
throw new IllegalArgumentException("Illegal value of 'lastPageMode'
attribute: '" + lastPageMode + "'");
}
- if (page != pageCount || LAST_PAGE_MODE_SHORT.equals(lastPageMode)) {
+ if (page != pageCount || PageMode.part.equals(lastPageMode)) {
first = (page - 1) * rows;
} else {
first = rowCount - rows;
@@ -376,7 +299,7 @@
}
}
- dataTable.setFirst(first);
+ dataTable.getAttributes().put("first", first);
}
}
}
@@ -415,10 +338,10 @@
}
private void updateModel(int newPage) {
- UIData dataTable = getDataTable();
+ UIComponent dataTable = getDataTable();
if (isRendered(dataTable)) {
- dataTable.setFirst((newPage - 1) * getRows(dataTable));
+ dataTable.getAttributes().put("first", (newPage - 1) *
getRows(dataTable));
}
Map<String, Object> attributes = dataTable.getAttributes();
@@ -474,14 +397,14 @@
static class BinarySearch {
- public static int search(UIData data) {
- int rowIndex = data.getRowIndex();
+ public static int search(UIComponent data) {
+ int rowIndex = (Integer)data.getAttributes().get("rowIndex");
try {
int n = 1;
int k = 2;
for (; ;) {
- data.setRowIndex(k - 1);
- if (data.isRowAvailable()) {
+ data.getAttributes().put("rowIndex", k-1);
+ if ((Boolean)data.getAttributes().get("rowAvailable")) {
n = k;
k = k * 2;
} else {
@@ -491,22 +414,22 @@
while (n < k) {
int kk = Math.round((n + k) / 2) + 1;
- data.setRowIndex(kk - 1);
- if (data.isRowAvailable()) {
+ data.getAttributes().put("rowIndex", kk-1);
+ if ((Boolean)data.getAttributes().get("rowAvailable")) {
n = kk;
} else {
k = kk - 1;
}
}
-
- data.setRowIndex(k - 1);
- if (data.isRowAvailable()) {
+
+ data.getAttributes().put("rowIndex", k-1);
+ if ((Boolean)data.getAttributes().get("rowAvailable")) {
return k;
} else {
return 0;
}
} finally {
- data.setRowIndex(rowIndex);
+ data.getAttributes().put("rowIndex",rowIndex);
}
}
}
@@ -536,4 +459,8 @@
page = null;
}
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
}
Modified:
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 2010-03-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java 2010-03-02
18:51:43 UTC (rev 16515)
@@ -6,157 +6,120 @@
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);
+ return (String)getStateHelper().eval(PropertyKeys.boundaryControls,
"show");
}
- @Override
public String getFastControls() {
- return (String)getStateHelper().eval(PropertyKeys.fastControls);
+ return (String)getStateHelper().eval(PropertyKeys.fastControls,
"show");
}
- @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;
+ public boolean isRenderIfSinglePage() {
+ return true;
}
}
Modified:
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 2010-03-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/ControlsState.java 2010-03-02
18:51:43 UTC (rev 16515)
@@ -32,13 +32,13 @@
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;
@@ -47,30 +47,33 @@
private boolean controlsSeparatorRendered = false;
- public boolean isFirstRendered() {
+
+ public boolean getFirstRendered() {
return firstRendered;
}
public void setFirstRendered(boolean firstRendered) {
this.firstRendered = firstRendered;
}
- public boolean isFirstEnabled() {
+ public boolean getFirstEnabled() {
return firstEnabled;
}
public void setFirstEnabled(boolean firstEnabled) {
this.firstEnabled = firstEnabled;
}
- public boolean isLastRendered() {
+ public boolean getLastRendered() {
return lastRendered;
}
public void setLastRendered(boolean lastRendered) {
this.lastRendered = lastRendered;
}
- public boolean isLastEnabled() {
+ public boolean getLastEnabled() {
return lastEnabled;
}
public void setLastEnabled(boolean lastEnabled) {
this.lastEnabled = lastEnabled;
}
+
+ /*
public boolean isPreviousRendered() {
return previousRendered;
}
@@ -94,26 +97,26 @@
}
public void setNextEnabled(boolean nextEnabled) {
this.nextEnabled = nextEnabled;
- }
- public boolean isFastRewindRendered() {
+ }*/
+ public boolean getFastRewindRendered() {
return fastRewindRendered;
}
public void setFastRewindRendered(boolean fastRewindRendered) {
this.fastRewindRendered = fastRewindRendered;
}
- public boolean isFastRewindEnabled() {
+ public boolean getFastRewindEnabled() {
return fastRewindEnabled;
}
public void setFastRewindEnabled(boolean fastRewindEnabled) {
this.fastRewindEnabled = fastRewindEnabled;
}
- public boolean isFastForwardRendered() {
+ public boolean getFastForwardRendered() {
return fastForwardRendered;
}
public void setFastForwardRendered(boolean fastForwardRendered) {
this.fastForwardRendered = fastForwardRendered;
}
- public boolean isFastForwardEnabled() {
+ public boolean getFastForwardEnabled() {
return fastForwardEnabled;
}
public void setFastForwardEnabled(boolean fastForwardEnabled) {
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-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-02
18:51:43 UTC (rev 16515)
@@ -23,54 +23,57 @@
import java.io.IOException;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
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.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIDataScroller;
import org.richfaces.event.DataScrollerEvent;
+@ResourceDependencies( {@ResourceDependency(library = "javax.faces", name =
"jsf-uncompressed.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name="richfaces-queue.js"),
+ @ResourceDependency(name = "script/datascroller.js"),
+ @ResourceDependency(name = "css/datascroller.css")})
public class DataScrollerBaseRenderer extends Renderer {
public void doDecode(FacesContext context, UIComponent component) {
- Map paramMap = getParamMap(context);
+ Map <String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
+
String clientId = component.getClientId(context);
String param = (String) paramMap.get(clientId);
+
if (param != null) {
- UIDataScroller scroller = (UIDataScroller) component;
+
+ 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();
-
+ new DataScrollerEvent(scroller,String.valueOf(page), param, newPage).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) {
+ public ControlsState getControlsState(FacesContext context, UIComponent component) {
+
+
+ int fastStep = (Integer)component.getAttributes().get("fastStep");
+ int pageIndex = (Integer)component.getAttributes().get("page");
+ int pageCount = (Integer)component.getAttributes().get("pageCount");
+
int minPageIdx = 1;
int maxPageIdx = pageCount;
- int fastStep = datascroller.getFastStep();
+
if (fastStep <= 1) {
fastStep = 1;
}
@@ -100,9 +103,10 @@
}
boolean isAuto;
- String boundaryControls = datascroller.getBoundaryControls();
- String stepControls = datascroller.getStepControls();
- String fastControls = datascroller.getFastControls();
+
+ 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(
boundaryControls)) {
@@ -118,8 +122,8 @@
controlsState.setLastRendered(false);
}
- if ((isAuto = "auto".equals(stepControls)) || "show".equals(
- stepControls)) {
+ /*
+ if ((isAuto = "auto".equals(stepControls)) ||
"show".equals(stepControls)) {
if (isAuto) {
controlsState.setPreviousRendered(useFirst);
controlsState.setNextRendered(useLast);
@@ -130,7 +134,7 @@
} else {
controlsState.setPreviousRendered(false);
controlsState.setNextRendered(false);
- }
+ }*/
if ((isAuto = "auto".equals(fastControls)) || "show".equals(
fastControls)) {
@@ -146,7 +150,7 @@
controlsState.setFastRewindRendered(false);
}
- UIComponent controlsSeparatorFacet =
datascroller.getFacet("controlsSeparator");
+ UIComponent controlsSeparatorFacet =
component.getFacet("controlsSeparator");
if (controlsSeparatorFacet != null &&
controlsSeparatorFacet.isRendered()) {
controlsState.setControlsSeparatorRendered(true);
}
@@ -154,22 +158,20 @@
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;
- }
+ public void renderPager(FacesContext context,ResponseWriter out, UIComponent
component) throws IOException {
- int pageCount = count;
+ int currentPage = (Integer)component.getAttributes().get("page");
+ int maxPages = (Integer)component.getAttributes().get("maxPages");
+ int pageCount = (Integer)component.getAttributes().get("pageCount");
+
if (pageCount <= 1) {
return;
}
-
+
+ if (maxPages <= 1) {
+ maxPages = 1;
+ }
+
int delta = maxPages / 2;
int pages;
@@ -191,127 +193,92 @@
String styleClass;
String style;
if (isCurrentPage) {
- styleClass = scroller.getSelectedStyleClass();
- style = scroller.getSelectedStyle();
+ styleClass =
(String)component.getAttributes().get("selectedStyleClass");
+ style = (String)component.getAttributes().get("selectedStyle");
} else {
- styleClass = scroller.getInactiveStyleClass();
- style = scroller.getInactiveStyle();
+ styleClass = (String)component.getAttributes().get("inactiveStyleClass");
+ style = (String)component.getAttributes().get("inactiveStyle");
}
if (styleClass==null){
styleClass="";
}
- out.startElement("td", component);
+ out.startElement(HTML.SPAN_ELEM, component);
if (isCurrentPage) {
- out.writeAttribute("class", "rich-datascr-act "+
- styleClass, null);
+ out.writeAttribute(HTML.CLASS_ATTRIBUTE, "ds_digital ds_current
"+styleClass, null);
} else {
- out.writeAttribute("class", "rich-datascr-inact "+
- styleClass, null);
- out.writeAttribute("onclick", getOnClick(Integer.toString(i +
1)), null);
+ 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(Integer.toString(i +
1)), null);
}
- if (null != style) out.writeAttribute("style", style, null);
+
+ if (null != style) {
+ out.writeAttribute(HTML.STYLE_ATTRIBUTE, style, null);
+ }
out.writeText(Integer.toString(i + 1), null);
- //renderChild(context, link);
- out.endElement("td");
+ out.endElement(HTML.SPAN_ELEM);
}
-
}
+
+
public Object getOnClick(String string) {
- return "Event.fire(this, 'rich:datascroller:onscroll', {'page':
'" + 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;
+ public void renderPages(FacesContext context, UIComponent component, int pageIndex,
int count) throws IOException {
int currentPage = pageIndex;
int pageCount = count;
if (pageCount <= 1) {
pageCount = 1;
}
- String varName = (String)
scroller.getAttributes().get("pageIndexVar");
+ String varName = (String)
component.getAttributes().get("pageIndexVar");
if (varName != null && varName.length() > 0) {
- context.getExternalContext()
- .getRequestMap().put(varName, new Integer(currentPage));
+ //TODO: anton - fix
+ context.getExternalContext().getRequestMap().put(varName, new
Integer(currentPage));
}
- varName = (String) scroller.getAttributes().get("pagesVar");
+ varName = (String) component.getAttributes().get("pagesVar");
if (varName != null && varName.length() > 0) {
- context.getExternalContext()
- .getRequestMap().put(varName, new Integer(pageCount));
+ //TODO: anton - fix
+ 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();
+ //get UIParameter's Map
+ protected Map <String, Object> getParameters(FacesContext context, UIComponent
component){
+ Map <String,Object> parameters = new HashMap<String, Object>();
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) {
+
+ UIDataScroller datascroller = (UIDataScroller)component;
+ List <UIComponent> children = datascroller.getChildren();
+
+ for (UIComponent child: children) {
+ 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());
+// TODO: anton - add
+ return null;
}
-
- return definition.toScript();
- }
- */
- /** Creates HtmlAjaxCommandLink sets its id, value and reRender and UIParameter */
public boolean getRendersChildren() {
return true;
}
Modified:
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 2010-03-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java 2010-03-02
18:51:43 UTC (rev 16515)
@@ -44,14 +44,14 @@
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;
- }
- }
-
+ 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 {
@@ -72,17 +72,17 @@
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);
+ Integer value = (Integer) ve.getValue(ctx.getFacesContext().getELContext());
+ datascroller.setPage(value);
} else {
- datascroller.setValueExpression("page", ve);
+ datascroller.setValueExpression("page", ve);
}
}
}
public DatascrollerTagHandler(ComponentConfig config) {
- super(config);
+ super(config);
}
protected MetaRuleset createMetaRuleset(Class type) {
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml 2010-03-01
18:30:39 UTC (rev 16514)
+++
root/ui-sandbox/trunk/components/datascroller/ui/src/main/templates/datascroller.template.xml 2010-03-02
18:51:43 UTC (rev 16515)
@@ -5,33 +5,80 @@
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
<cc:interface>
- <cdk:class>org.richfaces.renderkit.html.GenerateDataScrollerRenderer</cdk:class>
+ <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.GeneratedDataScroller</cdk:renderer-type>
+ <cdk:renderer-type>org.richfaces.DataScrollerRenderer</cdk:renderer-type>
</cc:interface>
<cc:implementation>
- <span id="" class="ds_container !ds_container_decor"><!--
Now decor is disabled !!! -->
+
+
+ <cdk:object type="org.richfaces.renderkit.ControlsState"
name="controlsState"
value="#{getControlsState(facesContext,component)}" />
+
+ <span id="#{clientId}" class="ds_container
!ds_container_decor"><!-- Now decor is disabled !!! -->
+ <c:if test="#{controlsState.firstRendered}">
+ <c:choose>
+ <c:when test="#{controlsState.firstEnabled}">
+ <span class="ds_button ds_left"
onmousedown="this.className='ds_button ds_left ds_over'"
onmouseup="this.className='ds_button ds_left'"
onmouseout="this.className='ds_button ds_left'"
onclick="#{getOnClick('first')}">
+ ««
+ </span>
+ </c:when>
+ <c:otherwise>
+ <span class="ds_button ds_left ds_disabled">
+ ««
+ </span>
+ </c:otherwise>
+ </c:choose>
+ </c:if>
- <span class="ds_button ds_left ds_disabled">
- ««
- </span>
- <span class="ds_button ds_left ds_disabled">
- «
- </span>
+ <c:if test="#{controlsState.fastRewindRendered}">
+ <c:choose>
+ <c:when test="#{controlsState.fastRewindEnabled}">
+ <span class="ds_button ds_left"
onmousedown="this.className='ds_button ds_left ds_over'"
onmouseup="this.className='ds_button ds_left'"
onmouseout="this.className='ds_button ds_left'"
onclick="#{getOnClick('fastRewind')}">
+ «
+ </span>
+ </c:when>
+ <c:otherwise>
+ <span class="ds_button ds_left ds_disabled">
+ «
+ </span>
+ </c:otherwise>
+ </c:choose>
+ </c:if>
+
+ <cdk:call expression="renderPager(facesContext, responseWriter,
component);"/>
- <span class="ds_digital" onmouseover="this.className='ds_digital
ds_over'" onmouseout="this.className='ds_digital'"
onmouseup="this.className='ds_digital ds_over'"
onmousedown="this.className='ds_digital ds_press'">
- </span>
+ <c:if test="#{controlsState.fastForwardRendered}">
+ <c:choose>
+ <c:when test="#{controlsState.fastForwardEnabled}">
+ <span class="ds_button ds_right"
onmousedown="this.className='ds_button ds_right ds_over'"
onmouseup="this.className='ds_button ds_right'"
onmouseout="this.className='ds_button ds_right'"
onclick="#{getOnClick('fastForward')}">
+ »
+ </span>
+ </c:when>
+ <c:otherwise>
+ <span class="ds_button ds_right ds_disabled">
+ »
+ </span>
+ </c:otherwise>
+ </c:choose>
+ </c:if>
- <span class="ds_button ds_right"
onmousedown="this.className='ds_button ds_right ds_over'"
onmouseup="this.className='ds_button ds_right'"
onmouseout="this.className='ds_button ds_right'">
- »
- </span>
-
- <span class="ds_button ds_right"
onmousedown="this.className='ds_button ds_right ds_over'"
onmouseup="this.className='ds_button ds_right'"
onmouseout="this.className='ds_button ds_right'">
- »»
+ <c:if test="#{controlsState.lastRendered}">
+ <c:choose>
+ <c:when test="#{controlsState.lastEnabled}">
+ <span class="ds_button ds_right"
onmousedown="this.className='ds_button ds_right ds_over'"
onmouseup="this.className='ds_button ds_right'"
onmouseout="this.className='ds_button ds_right'"
onclick="#{getOnClick('last')}">
+ »»
+ </span>
+ </c:when>
+ <c:otherwise>
+ <span class="ds_button ds_right ds_disabled">
+ »»
+ </span>
+ </c:otherwise>
+ </c:choose>
+ </c:if>
</span>
- </span>
</cc:implementation>
</cdk:root>
\ No newline at end of file