[richfaces-svn-commits] JBoss Rich Faces SVN: r2103 - in trunk: framework/api/src/main/java/org/richfaces/event/scroll and 3 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Tue Aug 7 10:56:08 EDT 2007
Author: maksimkaszynski
Date: 2007-08-07 10:56:08 -0400 (Tue, 07 Aug 2007)
New Revision: 2103
Added:
trunk/framework/api/src/main/java/org/richfaces/event/AttributeHolder.java
trunk/framework/api/src/main/java/org/richfaces/event/AttributedEvent.java
trunk/framework/api/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java
trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollListener.java
Modified:
trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollEvent.java
trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java
trunk/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
trunk/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Log:
re-factored sort and scroll events allowing renderers to provide renderer-specific attributes upon broadcasting
Added: trunk/framework/api/src/main/java/org/richfaces/event/AttributeHolder.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/AttributeHolder.java (rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/event/AttributeHolder.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -0,0 +1,54 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - 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;
+
+/**
+ * Base interface holding attributes that can lately
+ * be applied on {@link UIComponent}
+ * @author Maksim Kaszynski
+ *
+ */
+public interface AttributeHolder {
+
+ /**
+ *
+ * @param name
+ * @param value
+ */
+ public abstract void setAttribute(String name, Object value);
+
+ /**
+ *
+ * @param name
+ * @return
+ */
+ public abstract Object getAttribute(String name);
+
+ /**
+ * Copy attributes from event map to component
+ * @param component
+ */
+ public abstract void applyAttributes(UIComponent component);
+
+}
\ No newline at end of file
Added: trunk/framework/api/src/main/java/org/richfaces/event/AttributedEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/AttributedEvent.java (rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/event/AttributedEvent.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -0,0 +1,95 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - 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 java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+
+/**
+ * Base class for events carrying component attributes.
+ * By using it, renderer-specific attributes can
+ * be applied when event is broadcast
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class AttributedEvent extends FacesEvent implements AttributeHolder{
+
+ private Map attributes = new HashMap();
+
+ public AttributedEvent(UIComponent component) {
+ super(component);
+ }
+
+ public AttributedEvent(UIComponent component, Map attributes) {
+ super(component);
+ this.attributes.putAll(attributes);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.event.AttributeHolder#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ attributes.put(name, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.event.AttributeHolder#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.event.AttributeHolder#applyAttributes(javax.faces.component.UIComponent)
+ */
+ public void applyAttributes(UIComponent component) {
+
+ Map attrs = component.getAttributes();
+
+ for(Iterator iterator = attributes.entrySet().iterator();
+ iterator.hasNext(); ) {
+
+ Map.Entry entry = (Map.Entry) iterator.next();
+
+ String key = entry.getKey().toString();
+ Object value = entry.getValue();
+
+ if (value == null) {
+ attrs.remove(key);
+ } else {
+ attrs.put(key, value);
+ }
+ }
+ }
+
+ /**
+ * copy attributes to event source
+ */
+ public void applyAttributes() {
+ applyAttributes(getComponent());
+ }
+
+}
Added: trunk/framework/api/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java (rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -0,0 +1,66 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - 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;
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class ScrollableGridViewEvent extends AttributedEvent {
+
+
+ /**
+ * number of rows to update
+ */
+ protected int rows;
+ /**
+ * start position of update
+ */
+ protected int first;
+
+
+ public ScrollableGridViewEvent(UIComponent component, int rows, int first) {
+ super(component);
+ this.rows = rows;
+ this.first = first;
+ }
+
+ public int getFirst() {
+ return first;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setFirst(int first) {
+ this.first = first;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
+}
\ No newline at end of file
Modified: trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollEvent.java 2007-08-07 14:25:43 UTC (rev 2102)
+++ trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollEvent.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -4,48 +4,31 @@
package org.richfaces.event.scroll;
import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
+import org.richfaces.event.ScrollableGridViewEvent;
+
+
/**
* @author Anton Belevich
*
*/
-public class ScrollEvent extends FacesEvent {
+public class ScrollEvent extends ScrollableGridViewEvent {
private static final long serialVersionUID = 3786221668771853810L;
- private int rows;
-
- private int first;
-
public ScrollEvent(UIComponent component, int rows, int first){
- super(component);
+ super(component, rows, first);
this.rows = rows;
this.first = first;
}
public boolean isAppropriateListener(FacesListener listener) {
- return false;
+ return listener instanceof ScrollListener;
}
public void processListener(FacesListener listener) {
+ ((ScrollListener) listener).processScroll(this);
}
- public int getFirst() {
- return first;
- }
-
- public void setFirst(int first) {
- this.first = first;
- }
-
- public int getRows() {
- return rows;
- }
-
- public void setRows(int rows) {
- this.rows = rows;
- }
-
}
Added: trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollListener.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollListener.java (rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/event/scroll/ScrollListener.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -0,0 +1,32 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - 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.scroll;
+
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface ScrollListener extends FacesListener {
+ public void processScroll(ScrollEvent event);
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java 2007-08-07 14:25:43 UTC (rev 2102)
+++ trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -11,35 +11,26 @@
package org.richfaces.event.sort;
import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
+import org.richfaces.event.AttributedEvent;
+import org.richfaces.event.ScrollableGridViewEvent;
+
/**
* @author Maksim Kaszynski
* @modified by Anton Belevich
*
*/
-public class SortEvent extends FacesEvent {
+public class SortEvent extends ScrollableGridViewEvent {
private static final long serialVersionUID = -1453867412542792281L;
private int sortColumn;
- private int startRow;
-
- private int dataIndex;
-
- private boolean asc;
-
-
- public SortEvent(
- UIComponent component, int sortColumn, int startRow, int dataIndex, boolean asc) {
+ public SortEvent(UIComponent component, int sortColumn, int rows, int first) {
- super(component);
- this.asc = asc;
+ super(component, rows, first);
this.sortColumn = sortColumn;
- this.startRow = startRow;
- this.dataIndex = dataIndex;
}
@@ -65,30 +56,6 @@
return "SortEvent: {sortColumn: " + sortColumn + "}";
}
- public boolean isAsc() {
- return asc;
- }
-
- public void setAsc(boolean asc) {
- this.asc = asc;
- }
-
- public int getDataIndex() {
- return dataIndex;
- }
-
- public void setDataIndex(int dataIndex) {
- this.dataIndex = dataIndex;
- }
-
- public int getStartRow() {
- return startRow;
- }
-
- public void setStartRow(int startRow) {
- this.startRow = startRow;
- }
-
public void setSortColumn(int sortColumn) {
this.sortColumn = sortColumn;
}
Modified: trunk/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
===================================================================
--- trunk/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-08-07 14:25:43 UTC (rev 2102)
+++ trunk/ui/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -27,7 +27,8 @@
import org.apache.commons.collections.iterators.IteratorChain;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.richfaces.event.scroll.ScrollEvent;
+import org.richfaces.event.AttributeHolder;
+import org.richfaces.event.ScrollableGridViewEvent;
import org.richfaces.event.sort.MultiColumnSortListener;
import org.richfaces.event.sort.SingleColumnSortListener;
import org.richfaces.event.sort.SortEvent;
@@ -54,11 +55,16 @@
private final static Log log = LogFactory.getLog(UIScrollableGrid.class);
- private boolean MODEL_RANGE = false;
+ /**
+ * Flag set on each phase to determine what range of data to walk
+ * true means - locally saved ranges (for data pending update)
+ * false means - use range that comes from component state
+ */
+ private boolean useSavedRanges = true;
-
- private transient Collection partialUpdateChildren;
-
+ /**
+ * hold list of ranges previously accessed until updates are fully done for them
+ */
private List ranges;
private Collection responseData = new ArrayList();
@@ -69,14 +75,6 @@
private SortListener sortListener;
- public int getReqRowsCount() {
- return reqRowsCount;
- }
-
- public void setReqRowsCount(int reqRowsCount) {
- this.reqRowsCount = reqRowsCount;
- }
-
public abstract SortOrder getSortOrder();
public abstract void setSortOrder(SortOrder sortOrder) ;
@@ -101,7 +99,7 @@
reqRowsCount = getRows();
}
- int rows = getReqRowsCount();
+ int rows = reqRowsCount;
int rowsCount = getExtendedDataModel().getRowCount();
@@ -127,7 +125,9 @@
public void processDecodes(FacesContext faces) {
- MODEL_RANGE = true;
+
+ useSavedRanges = false;
+
if (log.isTraceEnabled()) {
log.trace("UIScrollableGrid.processDecodes(faces)");
}
@@ -135,7 +135,7 @@
}
public void processValidators(FacesContext faces) {
- MODEL_RANGE = false;
+ useSavedRanges = true;
if (log.isTraceEnabled()) {
log.trace("UIScrollableGrid.processValidators(faces)");
}
@@ -143,7 +143,7 @@
}
public void processUpdates(FacesContext faces) {
- MODEL_RANGE = false;
+ useSavedRanges = true;
if (log.isTraceEnabled()) {
log.trace("UIScrollableGrid.processUpdates(faces)");
@@ -159,7 +159,7 @@
log.trace("UIScrollableGrid.encodeBegin(context)");
}
- MODEL_RANGE = true;
+ useSavedRanges = false;
super.encodeBegin(context);
}
@@ -224,7 +224,7 @@
Object values[] = new Object[4];
values[0] = super.saveState(context);
- values[1] = getRanges();
+ values[1] = ranges;
values[2] = scrollPos;
values[3] = saveAttachedState(context, sortListener);
@@ -235,7 +235,7 @@
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
- setRanges((List)values[1]);
+ ranges = ((List)values[1]);
scrollPos = (String)values[2];
sortListener = (SortListener) restoreAttachedState(context, values[3]);
}
@@ -273,19 +273,24 @@
super.broadcast(event);
+ if (event instanceof AttributeHolder) {
+ ((AttributeHolder) event).applyAttributes(this);
+ }
+
if(event instanceof AjaxEvent){
AjaxContext.getCurrentInstance().addComponentToAjaxRender(this);
}else if(event instanceof SortEvent){
processSortingChange(event);
// new AjaxEvent(this).queue();
- }else if(event instanceof ScrollEvent){
+ }else if(event instanceof ScrollableGridViewEvent){
// new AjaxEvent(this).queue();
processScrolling(event);
}
+
}
protected boolean broadcastLocal(FacesEvent event) {
- return super.broadcastLocal(event) || event instanceof SortEvent || event instanceof ScrollEvent;
+ return super.broadcastLocal(event) || event instanceof SortEvent || event instanceof ScrollableGridViewEvent;
}
public void queueEvent(FacesEvent event) {
@@ -295,7 +300,7 @@
}else if(event instanceof SortEvent){
new AjaxEvent(this).queue();
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- }else if(event instanceof ScrollEvent){
+ }else if(event instanceof ScrollableGridViewEvent){
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
new AjaxEvent(this).queue();
}
@@ -303,9 +308,11 @@
}
public void processScrolling(FacesEvent event){
- ScrollEvent e = (ScrollEvent)event;
- setReqRowsCount(e.getRows());
+ ScrollableGridViewEvent e = (ScrollableGridViewEvent)event;
+
setFirst(e.getFirst());
+ reqRowsCount = e.getRows();
+
getFacesContext().renderResponse();
}
@@ -314,9 +321,13 @@
SortEvent e = (SortEvent)event;
getSortListener().processSort(e);
+
+ setFirst(e.getFirst());
+ reqRowsCount = e.getRows();
resetDataModel();
+
getFacesContext().renderResponse();
}
@@ -332,7 +343,7 @@
ranges.add(visitedRange);
}
- if(!MODEL_RANGE){
+ if(useSavedRanges){
for (Iterator iter = ranges.iterator(); iter.hasNext();) {
ScrollableGridRange range = (ScrollableGridRange) iter.next();
@@ -350,33 +361,15 @@
}
}
- public Collection getPartialUpdateChildren() {
-
- if (partialUpdateChildren == null) {
- partialUpdateChildren = new ArrayList();
- }
- return partialUpdateChildren;
- }
-
-
public void encodeEnd(FacesContext context) throws IOException {
super.encodeEnd(context);
- partialUpdateChildren = null;
}
public boolean isCacheable() {
return true;
}
- public List getRanges() {
- return ranges;
- }
-
- public void setRanges(List ranges) {
- this.ranges = ranges;
- }
-
public String getScrollPos() {
return scrollPos;
}
Modified: trunk/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
--- trunk/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-08-07 14:25:43 UTC (rev 2102)
+++ trunk/ui/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-08-07 14:56:08 UTC (rev 2103)
@@ -617,36 +617,23 @@
int sortColumn = Integer.parseInt((String)parameters.get(clientId + ":sortColumn"));
int sortDataIndex = Integer.parseInt((String)parameters.get(clientId + ":sortIndex"));
Integer sortStartRow = Integer.valueOf((String)parameters.get(clientId + ":sortStartRow"));
- String sortOrder = (String)parameters.get(clientId + ":sortOrder");
- boolean asc = true;
- if(!sortOrder.equals("asc")){
- asc = false;
- }
UIScrollableGridColumn column = (UIScrollableGridColumn)grid.getChildren().get(sortColumn);
if(column.isSortable()){
- grid.getAttributes().put(GridUtils.CLIENT_ROW_KEY,sortStartRow);
- grid.setFirst(sortDataIndex);
- grid.setReqRowsCount(grid.getRows());
-
- if (log.isDebugEnabled()) {
-
- log.debug("rows " + grid.getRows() );
- log.debug("client start index" + grid.getAttributes().get(GridUtils.CLIENT_ROW_KEY));
- log.debug("data index " + grid.getFirst());
-
- }
-
sorted = true;
- SortEvent sortEvent = new SortEvent(grid,sortColumn, sortStartRow.intValue(), sortDataIndex, asc );
- grid.queueEvent(sortEvent);
+ SortEvent sortEvent = new SortEvent(grid,sortColumn, grid.getRows(), sortDataIndex);
+ sortEvent.setAttribute(GridUtils.CLIENT_ROW_KEY,sortStartRow);
+
if (ajaxContext.isAjaxRequest()) {
- component.getAttributes().put(PARTIAL_UPDATE, Boolean.TRUE);
- component.getAttributes().put(UPDATE_HEADER, Boolean.TRUE);
+ sortEvent.setAttribute(PARTIAL_UPDATE, Boolean.TRUE);
+ sortEvent.setAttribute(UPDATE_HEADER, Boolean.TRUE);
}
+
+
+ sortEvent.queue();
}
}
@@ -666,15 +653,18 @@
int first = 0;
if(!isEmpty){
- grid.getAttributes().put(GridUtils.CLIENT_ROW_KEY,Integer.valueOf(values[2]));
rows = Integer.parseInt(values[0]);
first = Integer.parseInt(values[1]);
ScrollEvent scrollEvent = new ScrollEvent(grid,rows,first);
- grid.queueEvent(scrollEvent);
+ scrollEvent.setAttribute(GridUtils.CLIENT_ROW_KEY,Integer.valueOf(values[2]));
+
if (ajaxContext.isAjaxRequest()) {
- component.getAttributes().put(PARTIAL_UPDATE, Boolean.TRUE);
+ scrollEvent.setAttribute(PARTIAL_UPDATE, Boolean.TRUE);
}
+
+ scrollEvent.queue();
+
}
}
More information about the richfaces-svn-commits
mailing list