Author: abelevich
Date: 2007-05-28 14:12:21 -0400 (Mon, 28 May 2007)
New Revision: 904
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java
Log:
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-05-28
18:12:13 UTC (rev 903)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGrid.java 2007-05-28
18:12:21 UTC (rev 904)
@@ -4,26 +4,37 @@
package org.richfaces.component;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import javax.faces.model.DataModel;
+import org.ajax4jsf.ajax.repeat.DataComponentState;
import org.ajax4jsf.ajax.repeat.DataVisitor;
+import org.ajax4jsf.ajax.repeat.Range;
+import org.ajax4jsf.ajax.repeat.UIDataAdaptor;
import org.ajax4jsf.ajax.repeat.UIRepeat;
import org.ajax4jsf.framework.ajax.AjaxComponent;
import org.ajax4jsf.framework.ajax.AjaxContext;
import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.apache.commons.collections.iterators.IteratorChain;
import org.richfaces.event.sort.SortEvent;
+import org.richfaces.model.BufferedSequenceRange;
+import org.richfaces.model.ScrollableGridDataModel2;
import org.richfaces.model.SortOrder;
+import org.richfaces.model.visual.DefaultGridVisualModel;
+import org.richfaces.model.visual.ScrollableGridVisualModel;
+
/**
* @author Anton Belevich
*
@@ -37,42 +48,131 @@
private Integer _startRow = new Integer(0);
+ private transient Collection partialUpdateChildren;
+ private ScrollableGridVisualModel visualModel;
+
+
+
+ protected DataComponentState createComponentState() {
+
+ return new DataComponentState(){
+
+ public Range getRange() {
+
+ int curentRow = getFirst();
+ int rows = getRows();
+ int rowsCount = getExtendedDataModel().getRowCount();
+
+ if(rows > 0){
+
+ rows += curentRow;
+
+ if(rows >=0){
+ rows = Math.min(rows, rowsCount);
+ }
+
+ } else if(rowsCount >=0 ){
+ rows = rowsCount;
+
+ } else {
+ rows = -1;
+ }
+
+ BufferedSequenceRange range = new BufferedSequenceRange(curentRow,rows);
+ range.setSortOrder(getVisualModel().getSortOrder());
+
+ return range;
+ }
+ };
+ }
+
+ public ScrollableGridVisualModel getVisualModel() {
+
+ FacesContext context = getFacesContext();
+ boolean needToUpdateBinding = false;
+ ValueBinding valueExpression = getValueBinding("visualModel");
+ if (valueExpression != null) {
+
+ ScrollableGridVisualModel viModel = (ScrollableGridVisualModel)
valueExpression.getValue(context);
+ if(viModel == null) {
+ needToUpdateBinding = true;
+ } else {
+ setUpVisualModel(viModel);
+ return viModel;
+ }
+ }
+
+ if (visualModel == null) {
+ visualModel = new DefaultGridVisualModel();
+ setUpVisualModel(visualModel);
+
+ if (needToUpdateBinding) {
+ valueExpression.setValue(context, visualModel);
+ }
+ }
+
+ return visualModel;
+ }
+
+ private void setUpVisualModel(ScrollableGridVisualModel visualModel) {
+
+ }
+
+ public void setVisualModel(ScrollableGridVisualModel visualModel) {
+ if (visualModel != null) {
+ ValueBinding valueExpression = getValueBinding("visualModel");
+ if (valueExpression != null) {
+ ScrollableGridVisualModel anotherModel =
+ (ScrollableGridVisualModel) valueExpression.getValue(getFacesContext());
+ if (anotherModel == null) {
+ valueExpression.setValue(getFacesContext(), visualModel);
+ }
+ }
+ }
+ this.visualModel = visualModel;
+
+ }
+
+ public void setSortOrder(SortOrder sortOrder) {
+ getVisualModel().setSortOrder(sortOrder);
+ Object value = getValue();
+ if (value instanceof ScrollableGridDataModel2) {
+ ScrollableGridDataModel2 gridDataModel = (ScrollableGridDataModel2) value;
+ gridDataModel.setSortOrder(sortOrder);
+ }
+ }
+
+ public SortOrder getSortOrder() {
+ return getVisualModel().getSortOrder();
+ }
+
public Integer getDataIndex() {
return _dataIndex;
}
-
-
public void setDataIndex(Integer dataIndex) {
this._dataIndex = dataIndex;
}
-
-
public Integer getRow_count() {
return _row_count;
}
-
-
public void setRow_count(Integer row_count) {
this._row_count = row_count;
}
-
-
public Integer getStartRow() {
return _startRow;
}
-
-
public void setStartRow(Integer startRow) {
this._startRow = startRow;
}
public Object saveState(FacesContext context) {
+
Object values[] = new Object[4];
values[0] = super.saveState(context);
values[1] = _row_count;
@@ -84,6 +184,7 @@
}
public void restoreState(FacesContext context, Object state) {
+
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
_row_count = (Integer)values[1];
@@ -122,33 +223,90 @@
}
public void broadcast(FacesEvent event) throws AbortProcessingException {
+
super.broadcast(event);
+
if(event instanceof AjaxEvent){
AjaxContext.getCurrentInstance().addComponentToAjaxRender(this);
+ }else if(event instanceof SortEvent){
+ processSortingChange(event);
+ new AjaxEvent(this).queue();
}
}
+ protected boolean broadcastLocal(FacesEvent event) {
+ return super.broadcastLocal(event) || event instanceof SortEvent;
+ }
+
public void queueEvent(FacesEvent event) {
+
if(event instanceof AjaxEvent){
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
}else if(event instanceof SortEvent){
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
}
+
super.queueEvent(event);
}
- public void walk(FacesContext faces, DataVisitor visitor, Object argument) throws
IOException {
- super.walk(faces, visitor, argument);
+ public void processSortingChange(FacesEvent event){
+
+ SortEvent e = (SortEvent)event;
+ int sortColumn = e.getSortColumn();
+ int dataIndex = e.getDataIndex();
+ int startRow = e.getStartRow();
+
+ boolean asc = true;
+
+ SortOrder sortOrder = getSortOrder();
+ int oldSortColumn = -1;
+ int newSortColumn = sortColumn;
+
+ if (sortOrder != null) {
+ /**
+ * toggle sort direction
+ */
+ oldSortColumn = sortOrder.getSortColumn();
+ if (sortOrder.getSortColumn() == sortColumn) {
+ asc = !sortOrder.isAscending();
+ }
+ }
+
+ SortOrder newSortOrder = new SortOrder(sortColumn, startRow, dataIndex, asc);
+ setSortOrder(newSortOrder);
+ resetDataModel();
+
+// setSelection(new CascadeSelection());
+// addRequestStateKey(SORT_EVENT);
+ FacesContext context = getFacesContext();
+
+
+// TODO add to AjaxContext
+
+
+// if (log.isTraceEnabled()) {
+// log.trace("Sorting has changed " + sortOrder);
+// }
}
+ public void walk(FacesContext context, DataVisitor visitor, Object argument) throws
IOException {
+ super.walk(context, visitor, argument);
+ }
+
public DataModel getStoredDataModel() {
return super.getDataModel();
}
- public SortOrder getSortOrder() {
- return null;
+
+ public Collection getPartialUpdateChildren() {
+
+ if (partialUpdateChildren == null) {
+ partialUpdateChildren = new ArrayList();
+ }
+ return partialUpdateChildren;
}
- public void setSortOrder(SortOrder sortOrder) {
+ public void encodeEnd(FacesContext context) throws IOException {
+ super.encodeEnd(context);
+ partialUpdateChildren = null;
}
-
}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java 2007-05-28
18:12:13 UTC (rev 903)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/component/UIScrollableGridColumn.java 2007-05-28
18:12:21 UTC (rev 904)
@@ -5,29 +5,25 @@
import java.util.Iterator;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
import org.richfaces.event.sort.SortListener;
import org.richfaces.event.sort.SortSource;
+import org.richfaces.model.visual.ColumnVisualModel;
+import org.richfaces.model.visual.DefaultColumnVisualModel;
/**
* @author Anton Belevich
*
*/
-public class UIScrollableGridColumn extends UIColumn implements SortSource{
+public abstract class UIScrollableGridColumn extends UIColumn implements SortSource{
- /* (non-Javadoc)
- * @see org.richfaces.component.Column#isBreakBefore()
- */
- public boolean isBreakBefore() {
- // TODO Auto-generated method stub
- return false;
+ private ColumnVisualModel visualModel;
+
+ static final class AutoCreatedVisualModel extends DefaultColumnVisualModel{
+ private static final long serialVersionUID = 8528834472198966115L;
}
-
- /* (non-Javadoc)
- * @see org.richfaces.component.Column#setBreakBefore(boolean)
- */
- public void setBreakBefore(boolean arg0) {
- // TODO Auto-generated method stub
- }
public Iterator getChildIterator(){
return getChildren().iterator();
@@ -49,4 +45,33 @@
removeFacesListener(listener);
}
+ /**
+ * @return the visualModel
+ */
+ public ColumnVisualModel getVisualModel() {
+
+ ValueBinding valueExpression = getValueBinding("visualModel");
+ if (valueExpression != null) {
+ return (ColumnVisualModel)
valueExpression.getValue(FacesContext.getCurrentInstance());
+ }
+
+ if (visualModel == null) {
+ visualModel = new AutoCreatedVisualModel();
+ }
+
+ return visualModel;
+ }
+
+ /**
+ * @param visualModel the visualModel to set
+ */
+ public void setVisualModel(ColumnVisualModel visualModel) {
+ this.visualModel = visualModel;
+ }
+
+
+ public abstract boolean isSortable();
+
+ public abstract void setSortable(boolean sortable);
+
}
Show replies by date