Author: nbelaevski
Date: 2009-07-23 12:55:55 -0400 (Thu, 23 Jul 2009)
New Revision: 14986
Added:
root/ui-sandbox/trunk/components/datafilterslider/
root/ui-sandbox/trunk/components/datafilterslider/src/
root/ui-sandbox/trunk/components/datafilterslider/src/main/
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderEvent.java
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderListener.java
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderSource.java
root/ui-sandbox/trunk/components/datascroller/
root/ui-sandbox/trunk/components/datascroller/src/
root/ui-sandbox/trunk/components/datascroller/src/main/
root/ui-sandbox/trunk/components/datascroller/src/main/java/
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerListener.java
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerSource.java
root/ui-sandbox/trunk/components/tables/api/
root/ui-sandbox/trunk/components/tables/api/src/
root/ui-sandbox/trunk/components/tables/impl/
root/ui-sandbox/trunk/components/tables/impl/src/
root/ui-sandbox/trunk/components/tables/impl/src/main/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/component/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/component/util/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/component/util/ColumnUtil.java
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/DataModelCache.java
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModel.java
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModifiableModel.java
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ListSequenceDataModel.java
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ModifiableModel.java
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/impl/
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/package-info.java
root/ui-sandbox/trunk/components/tables/impl/src/test/
root/ui-sandbox/trunk/components/tables/impl/src/test/java/
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/impl/
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/impl/expressive/
root/ui-sandbox/trunk/components/togglepanels/
root/ui-sandbox/trunk/components/togglepanels/src/
root/ui-sandbox/trunk/components/togglepanels/src/main/
root/ui-sandbox/trunk/components/togglepanels/src/main/java/
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/ISimpleToggleListener.java
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/SimpleToggleEvent.java
Removed:
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/model/
root/ui-sandbox/trunk/components/framework-api/
root/ui-sandbox/trunk/components/framework-impl/
root/ui-sandbox/trunk/components/tables/src/
Log:
Moving component APIs into ui-sandbox
Copied:
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DataFilterSliderEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderEvent.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,76 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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;
+import javax.faces.event.FacesListener;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.event.AjaxEvent;
+
+/**
+ * @author Wesley Hales
+ */
+public class DataFilterSliderEvent extends AjaxEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private Integer oldSliderVal;
+ private Integer newSliderVal;
+
+ /**
+ * Creates a new SliderEvent.
+ *
+ * @param component the source of the event
+ * @param thisOldSliderVal the previously showing item identifier
+ * @param thisNewSliderVal the currently showing item identifier
+ */
+ public DataFilterSliderEvent(UIComponent component, Integer thisOldSliderVal, Integer
thisNewSliderVal) {
+ super(component);
+ setPhaseId(PhaseId.INVOKE_APPLICATION);
+ oldSliderVal = thisOldSliderVal;
+ newSliderVal = thisNewSliderVal;
+ }
+
+ public Integer getOldSliderVal() {
+ return oldSliderVal;
+ }
+
+ public Integer getNewSliderVal() {
+ return newSliderVal;
+ }
+
+ public boolean isAppropriateListener(FacesListener listener){
+ return (listener instanceof DataFilterSliderListener);
+ }
+
+ /**
+ * Delivers this event to the SliderListener.
+ *
+ * @param listener the slider listener
+ */
+ public void processListener(FacesListener listener){
+ ((DataFilterSliderListener) listener).processSlider(this);
+ }
+}
Copied:
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DataFilterSliderListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderListener.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,33 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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.event.FacesListener;
+
+/**
+ * @author Wesley Hales
+ */
+public interface DataFilterSliderListener extends FacesListener {
+
+ public void processSlider(org.richfaces.event.DataFilterSliderEvent event);
+
+}
Copied:
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderSource.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DataFilterSliderSource.java)
===================================================================
---
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderSource.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datafilterslider/src/main/java/org/richfaces/event/DataFilterSliderSource.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,50 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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;
+
+/**
+ * @author Wesley Hales
+ */
+public interface DataFilterSliderSource {
+
+ /**
+ * Adds a DataFilterSliderListener to this DataFilterSliderSource.
+ *
+ * @param listener the Slider listener to be added
+ */
+ public void addSliderListener(org.richfaces.event.DataFilterSliderListener
listener);
+
+ /**
+ * Removes a DataFilterSliderListener from this DataFilterSliderSource.
+ *
+ * @param listener the Slider listener to be removed
+ */
+ public void removeSliderListener(DataFilterSliderListener listener);
+
+ /**
+ * Returns all SliderListeners for this DataFilterSliderSource.
+ *
+ * @return the Slider listener array
+ */
+ public DataFilterSliderListener[] getSliderListeners();
+
+}
Copied:
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DataScrollerEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Wesley Hales
+ */
+public class DataScrollerEvent extends ActionEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2657353903701932561L;
+ private String oldScrolVal;
+ private String newScrolVal;
+ private int page;
+
+ /**
+ * Creates a new ScrollerEvent.
+ *
+ * @param component the source of the event
+ * @param thisOldScrolVal the previously showing item identifier
+ * @param thisNewScrolVal the currently showing item identifier
+ */
+ public DataScrollerEvent(UIComponent component, String thisOldScrolVal, String
thisNewScrolVal, int page) {
+ super(component);
+ oldScrolVal = thisOldScrolVal;
+ newScrolVal = thisNewScrolVal;
+ this.page = page;
+ }
+
+ public String getOldScrolVal() {
+ return oldScrolVal;
+ }
+
+ public String getNewScrolVal() {
+ return newScrolVal;
+ }
+
+ /**
+ * @since 3.2
+ * @return new page or <code>-1</code> if not applicable
+ */
+ public int getPage() {
+ return page;
+ }
+
+ public boolean isAppropriateListener(FacesListener listener){
+ return super.isAppropriateListener(listener) || (listener instanceof
DataScrollerListener);
+ }
+
+ /**
+ * Delivers this event to the SliderListener.
+ *
+ * @param listener the slider listener
+ */
+ public void processListener(FacesListener listener){
+ if (listener instanceof DataScrollerListener) {
+ DataScrollerListener dataScrollerListener = (DataScrollerListener) listener;
+ dataScrollerListener.processScroller(this);
+ }
+
+ if (super.isAppropriateListener(listener)) {
+ super.processListener(listener);
+ }
+ }
+}
Copied:
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DataScrollerListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerListener.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,31 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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.event.FacesListener;
+
+
+public interface DataScrollerListener extends FacesListener {
+
+ public void processScroller(org.richfaces.event.DataScrollerEvent event);
+
+}
Copied:
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerSource.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DataScrollerSource.java)
===================================================================
---
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerSource.java
(rev 0)
+++
root/ui-sandbox/trunk/components/datascroller/src/main/java/org/richfaces/event/DataScrollerSource.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,47 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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;
+
+public interface DataScrollerSource {
+
+ /**
+ * Adds a DataScrollerListener to this DataScrollerSource.
+ *
+ * @param listener the Scroler listener to be added
+ */
+ public void addScrollerListener(org.richfaces.event.DataScrollerListener listener);
+
+ /**
+ * Removes a DataFilterSliderListener from this DataScrollerSourceSource.
+ *
+ * @param listener the Scroler listener to be removed
+ */
+ public void removeScrollerListener(DataScrollerListener listener);
+
+ /**
+ * Returns all ScrollerListeners for this DataScrollerSource.
+ *
+ * @return the Scroler listener array
+ */
+ public DataScrollerListener[] getScrollerListeners();
+
+}
Copied: root/ui-sandbox/trunk/components/tables/api/src (from rev 14985,
root/ui-sandbox/trunk/components/tables/src)
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/component/util/ColumnUtil.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/component/util/ColumnUtil.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/component/util/ColumnUtil.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/component/util/ColumnUtil.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,76 @@
+/**
+ * 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.component.util;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.Column;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ColumnUtil {
+
+ /**
+ * Extract sort expression from the column
+ *
+ * @param column
+ * @return logical representation of sort field assigned to column component given
+ * In case of EL-expression, an expression string is returned instead of value - so that
EL-expression can be evaluated later;
+ * If there's literal value of dedicated attribute is specified, return it;
+ * If attribute is not set, fall aback to component id
+ */
+
+ public static String getColumnSorting(UIComponent column) {
+
+ UIComponent component = (UIComponent) column;
+
+ ValueExpression binding = component.getValueExpression("sortExpression");
+
+ if (binding != null) {
+ return binding.getExpressionString();
+ }
+
+ if (component instanceof Column) {
+ Column col = (Column) component;
+ String sorting = col.getSortExpression();
+
+ if (sorting != null) {
+ return sorting;
+ }
+ }
+
+
+ return component.getId();
+ }
+
+
+ public static boolean isSortable(UIComponent component) {
+ if (component instanceof Column) {
+ return ((Column) component).isSortable();
+ }
+ return
Boolean.valueOf(String.valueOf(component.getAttributes().get("sortable")));
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/DataModelCache.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/model/DataModelCache.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/DataModelCache.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/DataModelCache.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,209 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.model;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SerializableDataModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Implementation stores last loaded data, so no additional requests to db will be
performed
+ * Acts as a proxy between the component and original data model
+ * @author Maksim Kaszynski
+ *
+ */
+public class DataModelCache extends ScrollableTableDataModel {
+
+ private static Log log = LogFactory.getLog(DataModelCache.class);
+
+ private static class DataRange {
+ private int startRow;
+ private int endRow;
+ private SortOrder sortOrder;
+ private List loadedData;
+
+ public DataRange(int startRow, int endRow, SortOrder sortOrder,
+ List loadedData) {
+ super();
+ this.startRow = startRow;
+ this.endRow = endRow;
+ this.sortOrder = sortOrder;
+ this.loadedData = loadedData;
+ }
+
+ public boolean match(int s, int e, SortOrder sortOrder) {
+ return s == startRow
+ && e == endRow
+ && sortOrdersMatch(sortOrder, this.sortOrder);
+ }
+
+ private boolean sortOrdersMatch(SortOrder sortOrder1, SortOrder sortOrder2) {
+ boolean result = sortOrder1 == sortOrder2;
+
+ if (sortOrder1 != null && sortOrder2 != null) {
+ result = sortOrder1.equals(sortOrder2);
+ }
+
+ return result;
+ }
+
+ }
+
+ private Map secondaryMapping = new HashMap();
+
+ private DataRange dataRange;
+
+ private ScrollableTableDataModel scrollableTableDataModel;
+
+ private int rowCount = Integer.MIN_VALUE;
+
+ public DataModelCache(ScrollableTableDataModel scrollableTableDataModel) {
+ super();
+ this.scrollableTableDataModel = scrollableTableDataModel;
+
+ if (log.isTraceEnabled()) {
+ log.trace("initializing with " + scrollableTableDataModel);
+ }
+ }
+
+ public void addDataModelListener(DataModelListener listener) {
+ scrollableTableDataModel.addDataModelListener(listener);
+ }
+
+ public DataModelListener[] getDataModelListeners() {
+ return scrollableTableDataModel.getDataModelListeners();
+ }
+
+ public Object getObjectById(Object id) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Trying to get object by id" + id);
+ }
+ //First try to find data in inner cache
+ //If not found - get it from original model
+ Object cached = secondaryMapping.get(id);
+
+ if (cached == null) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Cache miss " + id + " falling back to original
model");
+ }
+
+ cached = scrollableTableDataModel.getObjectById(id);
+ secondaryMapping.put(id, cached);
+
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("At last found element " + cached);
+ }
+
+ return cached;
+ }
+
+ public int getRowCount() {
+ if (rowCount == Integer.MIN_VALUE) {
+ rowCount = scrollableTableDataModel.getRowCount();
+ }
+ return rowCount;
+ }
+
+ public Object getRowData() {
+ Object secondaryMapped = secondaryMapping.get(getRowKey());
+
+ if (secondaryMapped == null) {
+ secondaryMapped = super.getRowData();
+ }
+ return secondaryMapped;
+ }
+
+ public int getRowIndex() {
+ return scrollableTableDataModel.getRowIndex();
+ }
+
+ public Object getRowKey() {
+ return scrollableTableDataModel.getRowKey();
+ }
+
+ public SerializableDataModel getSerializableModel(Range range) {
+ return scrollableTableDataModel.getSerializableModel(range);
+ }
+
+ public Object getWrappedData() {
+ return scrollableTableDataModel.getWrappedData();
+ }
+
+ public boolean isRowAvailable() {
+ return secondaryMapping.containsKey(getRowKey()) || super.isRowAvailable();
+ }
+
+ public List loadData(int startRow, int endRow, SortOrder sortOrder) {
+ if (dataRange == null || !dataRange.match(startRow, endRow, sortOrder)) {
+ List data = scrollableTableDataModel.loadData(startRow, endRow, sortOrder);
+ dataRange = new DataRange(startRow, endRow, sortOrder, data);
+ }
+ return dataRange.loadedData;
+ }
+
+ public void removeDataModelListener(DataModelListener listener) {
+ scrollableTableDataModel.removeDataModelListener(listener);
+ }
+
+ public void setRowIndex(int arg0) {
+ scrollableTableDataModel.setRowIndex(arg0);
+ }
+
+ public void setRowKey(Object key) {
+ scrollableTableDataModel.setRowKey(key);
+ super.setRowKey(key);
+ }
+
+ public void setWrappedData(Object arg0) {
+ scrollableTableDataModel.setWrappedData(arg0);
+ }
+
+ public Object getId(Object o) {
+ return scrollableTableDataModel.getId(o);
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+ // TODO Auto-generated method stub
+ super.walk(context, visitor, range, argument);
+ }
+ /*
+ * FIXME: see superclass
+ @Override
+ public void setSortOrder(SortOrder sortOrder) {
+ scrollableTableDataModel.setSortOrder(sortOrder);
+ }
+ */
+}
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModel.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedTableDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModel.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,284 @@
+/**
+* License Agreement.
+*
+* JBoss RichFaces - Ajax4jsf Component Library
+*
+* Copyright (C) 2008 CompuGROUP Holding AG
+*
+* 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.model;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Data model class for table components.<br>
+ * Usage:
+ * <pre>
+ * ExtendedTableDataModel<SomeDataType> dataModel = new
ExtendedTableDataModel<SomeDataType>(new DataProvider
<SomeDataType>());
+ * </pre>
+ * @author pawelgo
+ *
+ */
+public class ExtendedTableDataModel<T> extends ExtendedDataModel implements
Serializable{
+
+ private static final long serialVersionUID = 7374505108088114161L;
+
+ private static final Log log = LogFactory.getLog(ExtendedTableDataModel.class);
+
+ private DataProvider<T> dataProvider;
+ private Object rowKey;
+ private List<Object> wrappedKeys = null;
+ //private boolean detached = false;
+ private Map<Object, T> wrappedData = new HashMap<Object, T>();
+
+ public ExtendedTableDataModel(DataProvider<T> dataProvider) {
+ this.dataProvider = dataProvider;
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.SerializableDataModel#update()
+ */
+// public void update() {
+// ;
+// }
+
+ /**
+ * This method never called from framework.
+ * (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ /**
+ * This method normally called by Visitor before request Data Row.
+ * (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ public void setRowKey(Object key) {
+ rowKey = key;
+ }
+
+ /**
+ * This is main part of Visitor pattern. Method called by framework many times during
request processing.
+ * (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)
+ */
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+ int rowC = getRowCount();
+ int firstRow = ((SequenceRange) range).getFirstRow();
+ int numberOfRows = ((SequenceRange) range).getRows();
+ if (numberOfRows <= 0) {
+ numberOfRows = rowC;
+ }
+ if (wrappedKeys != null) { // Is this serialized model
+ // Here we just ignore current Rage and use whatever data was saved in serialized
model.
+ // Such approach uses much more getByPk() operations, instead of just one request by
range.
+ // Concrete case may be different from that, so you can just load data from data
provider by range.
+ // We are using wrappedKeys list only to preserve actual order of items.
+ for (Object key : wrappedKeys) {
+ setRowKey(key);
+ visitor.process(context, key, argument);
+ }
+ } else { // if not serialized, than we request data from data provider
+ wrappedKeys = new ArrayList<Object>();
+ int endRow = firstRow + numberOfRows;
+ if (endRow > rowC){
+ endRow = rowC;
+ }
+ for (T item : loadData(firstRow, endRow)) {
+ Object key = getKey(item);
+ wrappedKeys.add(key);
+ wrappedData.put(key, item);
+ visitor.process(context, key, argument);
+ }
+ }
+ }//walk
+
+ /**
+ * Load range of data items from the source.
+ * Starting from startRow, and up to but excluding endRow
+ * @param startRow
+ * @param endRow
+ * @return list of ordered data
+ */
+ protected List<T> loadData(int startRow, int endRow) {
+ if (log.isDebugEnabled())
+ log.debug("load data from range: " + startRow + " - " + endRow);
+ if (startRow < 0){
+ startRow = 0;
+ throw new IllegalArgumentException("Illegal start index value: " +
startRow);
+ }
+ int rowCount = getRowCount();
+ if (endRow > rowCount){
+ endRow = rowCount;
+ throw new IllegalArgumentException("Illegal end index value: " + endRow);
+ }
+ //load all from provider and get sublist
+ return dataProvider.getItemsByRange(startRow, endRow);
+ //return dataProvider.getItemsByRange(0, rowCount).subList(startRow, endRow);
+ }//loadData
+
+ /**
+ * This method must return actual data rows count from the Data Provider. It is used by
pagination control
+ * to determine total number of data items.
+ * (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ private Integer rowCount; // better to buffer row count locally
+
+ public int getRowCount() {
+ if (rowCount == null) {
+ rowCount = new Integer(dataProvider.getRowCount());
+ } else {
+ return rowCount.intValue();
+ }
+ return rowCount.intValue();
+ //return dataProvider.getRowCount();
+ }
+
+ /**
+ * This is main way to obtain data row. It is intensively used by framework.
+ * We strongly recommend use of local cache in that method.
+ * (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public T getRowData() {
+ if (rowKey == null) {
+ return null;
+ } else {
+ return getObjectByKey(rowKey);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getKey(T o) {
+ return dataProvider.getKey(o);
+ }
+
+ public T getObjectByKey(Object key) {
+ T t = wrappedData.get(key);
+ if (t == null){
+ t = dataProvider.getItemByKey(key);
+ wrappedData.put(key, t);
+ }
+ return t;
+ }
+
+ private Integer rowIndex;
+
+ /**
+ * Unused rudiment from old JSF staff. (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ public int getRowIndex() {
+ //throw new UnsupportedOperationException();
+ return rowIndex.intValue();
+ }
+
+ /**
+ * Unused rudiment from old JSF staff.
+ * (non-Javadoc)
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ //throw new UnsupportedOperationException();
+ this.rowIndex = rowIndex;
+ }
+
+ /**
+ * Unused rudiment from old JSF staff.
+ * (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Unused rudiment from old JSF staff.
+ * (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Never called by framework.
+ * (non-Javadoc)
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return getRowData() != null;
+ }
+
+ /**
+ * This method suppose to produce SerializableDataModel that will be
+ * serialized into View State and used on a post-back. In current
+ * implementation we just mark current model as serialized. In more
+ * complicated cases we may need to transform data to actually serialized
+ * form.
+ */
+// public SerializableDataModel getSerializableModel(Range range) {
+// if (wrappedKeys != null) {
+// detached = true;
+// // Some activity to detach persistent data from wrappedData map may be taken here.
+// // In that specific case we are doing nothing.
+// return this;
+// } else {
+// return null;
+// }
+// }
+
+ /**
+ * Resets internal cached data. Call this method to reload data from data
+ * provider on first access for data.
+ */
+ public void reset(){
+ wrappedKeys = null;
+ wrappedData.clear();
+ rowCount = null;
+ rowIndex = -1;
+ rowKey = null;
+ }
+
+ public DataProvider<T> getDataProvider() {
+ return dataProvider;
+ }
+
+ public void setDataProvider(DataProvider<T> dataProvider) {
+ this.dataProvider = dataProvider;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModifiableModel.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/model/ExtendedTableDataModifiableModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModifiableModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ExtendedTableDataModifiableModel.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,131 @@
+/**
+* License Agreement.
+*
+* JBoss RichFaces - Ajax4jsf Component Library
+*
+* Copyright (C) 2008 CompuGROUP Holding AG
+*
+* 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.model;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+
+/**
+ * @author pawelgo
+ *
+ */
+public class ExtendedTableDataModifiableModel<T> extends ModifiableModel {
+
+ //private static final Log log =
LogFactory.getLog(ExtendedTableDataModifiableModel.class);
+
+ private ExtendedTableDataModel<T> orgModel;
+ private boolean sortNeeded = true;
+ private boolean filterNeeded = true;
+
+ @SuppressWarnings("unchecked")
+ public ExtendedTableDataModifiableModel(DataProvider<T> dataProvider, String var)
{
+ super(new ExtendedTableDataModel<T>(dataProvider), var);
+ this.orgModel = (ExtendedTableDataModel<T>)this.originalModel;
+ }
+
+ public ExtendedTableDataModifiableModel(DataProvider<T> dataProvider) {
+ this(dataProvider, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ExtendedTableDataModifiableModel(ExtendedTableDataModel<T> dataModel,
String var) {
+ super(dataModel, var);
+ this.orgModel = dataModel;
+ }
+
+ @Override
+ public Object getRowKey() {
+ return originalModel.getRowKey();
+ }
+
+ @Override
+ public void setRowKey(Object key) {
+ originalModel.setRowKey(key);
+ }
+
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+ final SequenceRange seqRange = (SequenceRange) range;
+ int rows = seqRange.getRows();
+ int rowCount = getRowCount();
+ int currentRow = seqRange.getFirstRow();
+ if(rows > 0){
+ rows += currentRow;
+ rows = Math.min(rows, rowCount);
+ } else {
+ rows = rowCount;
+ }
+ for (; currentRow < rows; currentRow++) {
+ visitor.process(context, rowKeys.get(currentRow), argument);
+ }
+ }
+
+ /**
+ * Resets internal cached data. Call this method to reload data from data
+ * provider on first access for data.
+ */
+ public void reset(){
+ orgModel.reset();
+ rowKeys = null;
+ sortNeeded = true;
+ filterNeeded = true;
+ }
+
+ public Object getKey(T o) {
+ return orgModel.getKey(o);
+ }
+
+ public T getObjectByKey(Object key) {
+ return orgModel.getObjectByKey(key);
+ }
+
+ @Override
+ public void modify(List<FilterField> filterFields, List<SortField2>
sortFields) {
+ if (sortNeeded || filterNeeded){
+ if (var == null){
+ throw new IllegalStateException("\"var\" model attribute can not be
null.");
+ }
+ super.modify(filterFields, sortFields);
+ sortNeeded = false;
+ filterNeeded = false;
+ }
+ }
+
+ public void resetSort(){
+ sortNeeded = true;
+ }
+
+ public void resetFilter(){
+ filterNeeded = true;
+ }
+
+ public void setVar(String var){
+ this.var = var;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ListSequenceDataModel.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/model/ListSequenceDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ListSequenceDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ListSequenceDataModel.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,162 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.model;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ListSequenceDataModel extends ExtendedDataModel {
+
+ private List<?> list;
+ private int index;
+
+ public ListSequenceDataModel(List<?> list) {
+ setWrappedData(list);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
+ */
+ @Override
+ public Object getRowKey() {
+ if(index<0){
+ return null;
+ }
+ return new Integer(index);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ @Override
+ public void setRowKey(Object key) {
+ if(null == key){
+ index = -1;
+ } else {
+ setRowIndex(((Integer) key).intValue());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)
+ */
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+ final SequenceRange seqRange = (SequenceRange) range;
+ int rows = seqRange.getRows();
+ int rowCount = list !=null ? list.size() : -1;
+ int currentRow = seqRange.getFirstRow();
+ if(rows > 0){
+ rows += currentRow;
+ rows = Math.min(rows, rowCount);
+ } else {
+ rows = rowCount;
+ }
+ for (; currentRow < rows; currentRow++) {
+ setRowIndex(currentRow);
+ visitor.process(context, new Integer(currentRow), argument);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ @Override
+ public int getRowCount() {
+ if (list == null) {
+ return (-1);
+ }
+ return list.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ @Override
+ public Object getRowData() {
+ if (!isRowAvailable()) {
+ throw new IllegalArgumentException();
+ } else {
+ return list.get(index);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ @Override
+ public int getRowIndex() {
+ return index;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ @Override
+ public Object getWrappedData() {
+ return list;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ @Override
+ public boolean isRowAvailable() {
+ return list != null && 0 <= index && index < list.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ @Override
+ public void setRowIndex(int rowIndex) {
+ if (rowIndex < -1) {
+ throw new IllegalArgumentException();
+ }
+ index = rowIndex;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ @Override
+ public void setWrappedData(Object data) {
+ if (data == null) {
+ list = null;
+ setRowIndex(-1);
+ } else {
+ list = (List<?>) data;
+ setRowIndex(0);
+ }
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ModifiableModel.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/model/ModifiableModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ModifiableModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/ModifiableModel.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,277 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+import org.ajax4jsf.model.SerializableDataModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+import org.richfaces.model.impl.expressive.ObjectWrapperFactory;
+import org.richfaces.model.impl.expressive.WrappedBeanComparator2;
+import org.richfaces.model.impl.expressive.WrappedBeanFilter;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ModifiableModel extends ExtendedDataModel implements Modifiable, LocaleAware
{
+
+ protected class RowKeyWrapperFactory extends ObjectWrapperFactory {
+
+ private class ExtendedJavaBeanWrapper extends JavaBeanWrapper {
+
+ private Object key;
+
+ public ExtendedJavaBeanWrapper(Object key, Object o, Map<Object, Object> props)
{
+ super(o, props);
+ this.key = key;
+ }
+
+ public Object getKey() {
+ return key;
+ }
+ }
+
+ public RowKeyWrapperFactory(FacesContext context, String var,
+ List<? extends Field> sortOrder) {
+ super(context, var, sortOrder);
+ }
+
+ @Override
+ public JavaBeanWrapper wrapObject(Object key) {
+ originalModel.setRowKey(key);
+ JavaBeanWrapper wrapObject = super.wrapObject(originalModel.getRowData());
+ return new ExtendedJavaBeanWrapper(key, wrapObject.getWrappedObject(),
wrapObject.getProperties());
+ }
+
+ @Override
+ public Object unwrapObject(Object wrapper) {
+ return ((ExtendedJavaBeanWrapper) wrapper).getKey();
+ }
+ }
+
+ private static final Log log = LogFactory.getLog(ModifiableModel.class);
+
+ protected List<Object> rowKeys;
+
+ protected ExtendedDataModel originalModel;
+
+ protected String var;
+
+ protected Locale locale = null;
+
+ public ModifiableModel(ExtendedDataModel originalModel, String var) {
+ this.originalModel = originalModel;
+ this.var = var;
+ }
+
+ @Override
+ public void addDataModelListener(DataModelListener listener) {
+ originalModel.addDataModelListener(listener);
+ }
+
+ @Override
+ public DataModelListener[] getDataModelListeners() {
+ return originalModel.getDataModelListeners();
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ @Override
+ public Object getRowKey() {
+ Object originalModelKey = originalModel.getRowKey();
+ int idx = rowKeys.indexOf(originalModelKey);
+
+ if (originalModelKey != null || idx >= 0) {
+ return idx;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void setRowKey(Object key) {
+ Object originalKey = null;
+ if(key != null){
+ int i = (Integer)key;
+ if (i >= 0 && i < rowKeys.size()) {
+ originalKey = rowKeys.get(i);
+ }
+ }
+ originalModel.setRowKey(originalKey);
+ }
+
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+ final SequenceRange seqRange = (SequenceRange) range;
+ int rows = seqRange.getRows();
+ int rowCount = getRowCount();
+ int currentRow = seqRange.getFirstRow();
+ if(rows > 0){
+ rows += currentRow;
+ rows = Math.min(rows, rowCount);
+ } else {
+ rows = rowCount;
+ }
+ for (; currentRow < rows; currentRow++) {
+ visitor.process(context, currentRow, argument);
+ }
+ }
+
+ @Override
+ public int getRowCount() {
+ if (rowKeys == null) {
+ return -1;
+ } else {
+ return rowKeys.size();
+ }
+ }
+
+ @Override
+ public Object getRowData() {
+ return originalModel.getRowData();
+ }
+
+ @Override
+ public int getRowIndex() {
+ return rowKeys.indexOf(originalModel.getRowKey());
+ }
+
+ @Override
+ public Object getWrappedData() {
+ return originalModel.getWrappedData();
+ }
+
+ @Override
+ public boolean isRowAvailable() {
+ return originalModel.isRowAvailable();
+ }
+
+ @Override
+ public void setRowIndex(int rowIndex) {
+ Object originalKey = null;
+ if (rowIndex >= 0 && rowIndex < rowKeys.size()) {
+ originalKey = rowKeys.get(rowIndex);
+ }
+ originalModel.setRowKey(originalKey);
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ originalModel.setWrappedData(data);
+ }
+
+ @Override
+ public SerializableDataModel getSerializableModel(Range range) {
+ return originalModel.getSerializableModel(range);
+ }
+
+ @Override
+ public void removeDataModelListener(DataModelListener listener) {
+ originalModel.removeDataModelListener(listener);
+ }
+
+
+ public void modify(List<FilterField> filterFields, List<SortField2>
sortFields) {
+ int rowCount = originalModel.getRowCount();
+
+ if (rowCount > 0) {
+ rowKeys = new ArrayList<Object>(rowCount);
+ } else {
+ rowKeys = new ArrayList<Object>();
+ }
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ try {
+
+ originalModel.walk(context, new DataVisitor() {
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ originalModel.setRowKey(rowKey);
+ if (originalModel.isRowAvailable()) {
+ rowKeys.add(rowKey);
+ }
+ }
+ }, new SequenceRange(0, -1),
+ null);
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ filter(filterFields);
+ sort(sortFields);
+
+ }
+
+ protected List<Object> filter(List<FilterField> filterFields) {
+ if (filterFields != null && !filterFields.isEmpty()) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ List <Object> filteredCollection = new ArrayList<Object>();
+ ObjectWrapperFactory wrapperFactory = new RowKeyWrapperFactory(context, var,
filterFields);
+
+ WrappedBeanFilter wrappedBeanFilter = new WrappedBeanFilter(filterFields, locale);
+ wrapperFactory.wrapList(rowKeys);
+ for (Object object : rowKeys) {
+ if(wrappedBeanFilter.accept((JavaBeanWrapper)object)) {
+ filteredCollection.add(object);
+ }
+ }
+ rowKeys = filteredCollection;
+ wrapperFactory.unwrapList(rowKeys);
+ }
+ return rowKeys;
+ }
+
+ protected void sort(List<SortField2> sortFields) {
+ if (sortFields != null && !sortFields.isEmpty()) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ ObjectWrapperFactory wrapperFactory = new RowKeyWrapperFactory(
+ context, var, sortFields);
+
+ WrappedBeanComparator2 wrappedBeanComparator = new WrappedBeanComparator2(
+ sortFields, locale);
+ wrapperFactory.wrapList(rowKeys);
+ Collections.sort(rowKeys, wrappedBeanComparator);
+ wrapperFactory.unwrapList(rowKeys);
+ }
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/impl (from
rev 14980, root/framework/trunk/impl/src/main/java/org/richfaces/model/impl)
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/package-info.java
(from rev 14980,
root/framework/trunk/impl/src/main/java/org/richfaces/model/package-info.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/package-info.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/impl/src/main/java/org/richfaces/model/package-info.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,4 @@
+/**
+ * Models implementation classes
+ */
+package org.richfaces.model;
Copied:
root/ui-sandbox/trunk/components/tables/impl/src/test/java/org/richfaces/model/impl/expressive
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive)
Copied:
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/ISimpleToggleListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/ISimpleToggleListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/ISimpleToggleListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/ISimpleToggleListener.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,38 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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
+ */
+
+/*
+ * Created on 11.07.2006
+ */
+package org.richfaces.event;
+
+import javax.faces.event.FacesListener;
+
+/**
+ * @author igels
+ */
+
+//TODO by nick - denis - add addToggleListener method to component
+public interface ISimpleToggleListener extends FacesListener {
+
+ public void processToggle(SimpleToggleEvent event);
+
+}
\ No newline at end of file
Copied:
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/SimpleToggleEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/SimpleToggleEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/SimpleToggleEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/togglepanels/src/main/java/org/richfaces/event/SimpleToggleEvent.java 2009-07-23
16:55:55 UTC (rev 14986)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - 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
+ */
+
+/*
+ * Created on 11.07.2006
+ */
+package org.richfaces.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author igels
+ */
+public class SimpleToggleEvent extends ActionEvent {
+
+ private static final long serialVersionUID = 5582624805941635421L;
+ private boolean _opened;
+
+ /**
+ * @param source
+ * @param opened
+ */
+ public SimpleToggleEvent(UIComponent source, boolean opened) {
+ super(source);
+ this._opened = opened;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof ISimpleToggleListener ||
super.isAppropriateListener(listener);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+ public void processListener(FacesListener listener) {
+ if (listener instanceof ISimpleToggleListener) {
+ ((ISimpleToggleListener) listener).processToggle(this);
+ } else {
+ super.processListener(listener);
+ }
+
+ }
+
+ /**
+ * @return Returns the _state.
+ */
+ public boolean isIsOpen() {
+ return _opened;
+ }
+
+ /**
+ *
+ * @param opened The state to set
+ */
+ public void setIsOpen(boolean opened) {
+ this._opened = opened;
+ }
+}
\ No newline at end of file