Author: nbelaevski
Date: 2009-07-23 12:41:49 -0400 (Thu, 23 Jul 2009)
New Revision: 14985
Added:
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java
root/ui-sandbox/trunk/components/drag-drop/
root/ui-sandbox/trunk/components/drag-drop/src/
root/ui-sandbox/trunk/components/drag-drop/src/main/
root/ui-sandbox/trunk/components/drag-drop/src/main/java/
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Draggable.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Dropzone.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DnDEvent.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragEvent.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragListener.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropEvent.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropListener.java
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropSource.java
root/ui-sandbox/trunk/components/fileupload/
root/ui-sandbox/trunk/components/fileupload/src/
root/ui-sandbox/trunk/components/fileupload/src/main/
root/ui-sandbox/trunk/components/fileupload/src/main/java/
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/FileUploadListener.java
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/UploadEvent.java
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/model/
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/model/UploadItem.java
root/ui-sandbox/trunk/components/selects/
root/ui-sandbox/trunk/components/selects/src/
root/ui-sandbox/trunk/components/selects/src/main/
root/ui-sandbox/trunk/components/selects/src/main/java/
root/ui-sandbox/trunk/components/selects/src/main/java/org/
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleDataModel.java
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleRowKey.java
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/OrderingListDataModel.java
root/ui-sandbox/trunk/components/tables/
root/ui-sandbox/trunk/components/tables/src/
root/ui-sandbox/trunk/components/tables/src/main/
root/ui-sandbox/trunk/components/tables/src/main/java/
root/ui-sandbox/trunk/components/tables/src/main/java/org/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Column.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Filterable.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Row.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Selectable.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable2.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/extdt/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/scroll/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/sort/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/DataProvider.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ExtendedFilterField.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Field.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/FilterField.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/LocaleAware.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Modifiable.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Ordering.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataModel.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataRange.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SelectionMode.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField2.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortOrder.java
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/filter/
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/selection/
root/ui-sandbox/trunk/components/tables/src/test/
root/ui-sandbox/trunk/components/tables/src/test/java/
root/ui-sandbox/trunk/components/tables/src/test/java/org/
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/FilterFieldTest.java
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockDataModel.java
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockRange.java
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ModifiableModelTest.java
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ScrollableTableDataRangeSerializationTest.java
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/SortField2Test.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModel.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelDataProvider.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelKey.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeModelVisualComponentProvider.java
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/VisualStackingTreeModel.java
root/ui-sandbox/trunk/components/tree-model/api/src/test/
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Directory.java
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/File.java
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Named.java
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Project.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/component/xml/XmlNodeData.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxExpandedEvent.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxSelectedEvent.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedEvent.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedListener.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedEvent.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedListener.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEvent.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEventType.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeListenerEventsProducer.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableSwingTreeNodeImpl.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeNodeImpl.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicCacheableTreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ComplexTreeRowKey.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ConvertableKeyModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/LastElementAware.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ListRowKey.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/MapDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SequenceDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingCacheableTreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeDataModel.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNode.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRange.java
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRowKey.java
root/ui-sandbox/trunk/components/tree/api/src/test/
root/ui-sandbox/trunk/components/tree/api/src/test/java/
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/ClassicTreeModelKeyConversionTest.java
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/SwingTreeModelKeyConversionTest.java
Log:
Moving component APIs into ui-sandbox
Copied:
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,69 @@
+/**
+ * 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.event;
+
+import java.util.Date;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+public class CurrentDateChangeEvent extends FacesEvent {
+
+
+ private static final long serialVersionUID = -8169207286087810907L;
+ private Date currentDate = null;
+ private String currentDateString = null;
+
+ @Deprecated
+ public CurrentDateChangeEvent(UIComponent component, Date curentDate) {
+ super(component);
+ this.currentDate = curentDate;
+
+ }
+
+ public CurrentDateChangeEvent(UIComponent component, String curentDateString) {
+ super(component);
+ this.currentDateString = curentDateString;
+ }
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
+
+ public void processListener(FacesListener listener) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException();
+ }
+
+ public Date getCurrentDate() {
+ return currentDate;
+ }
+
+ public void setCurrentDate(Date currentDate) {
+ this.currentDate = currentDate;
+ }
+
+ public String getCurrentDateString() {
+ return currentDateString;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,36 @@
+/**
+ * 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 Alexej Kushunin - akushunin(a)exadel.com
+ * created 28.08.2007
+ *
+ * Base calendar events interface
+ */
+public interface CurrentDateChangeListener extends FacesListener {
+
+ public void processCurrentDateChange(CurrentDateChangeEvent event);
+
+}
\ No newline at end of file
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Draggable.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Draggable.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Draggable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Draggable.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,135 @@
+/**
+ * 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.component;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+
+import org.richfaces.event.DragListener;
+
+
+/**
+ * Interface for all draggable components. Describe bean properties, implemented by
component.
+ * @author shura
+ *
+ */
+public interface Draggable {
+
+ /**
+ * Getter for value parameter, used as key for draggable component.
+ * @return
+ */
+ public Object getDragValue();
+
+ public void setDragValue(Object value);
+
+ /**
+ * Getter for id of component ( instance of {@link UIDragIndicator} ) used for create
drag cursor.
+ * @return
+ */
+ public String getDragIndicator();
+
+ /**
+ * @param dragIndicator - id of cursor component
+ */
+ public void setDragIndicator(String dragIndicator);
+
+ /**
+ * Draggable implementation may wish to resolve drag indicator id to clientId itself
+ * @param facesContext {@link FacesContext} instance
+ * @return resolved indicator client id or null
+ * @since 3.1
+ */
+ public String getResolvedDragIndicator(FacesContext facesContext);
+
+ /**
+ * Getter for type of this draggable ( file, mail etc ).
+ * @return
+ */
+ public String getDragType();
+
+ /**
+ * @param dragType
+ */
+ public void setDragType(String dragType);
+
+ /**
+ * Getter for JavaScript event handler, called before start drag operation.
+ * If this handler return false, drag operation is cancelled.
+ * @return javaScript code of event handler.
+ */
+ public String getOndragstart();
+
+ /**
+ * @param dragType
+ */
+ public void setOndragstart(String ondrag);
+
+ /**
+ * Getter for JavaScript event handler; Called when drag operation end.
+ * @return javaScript code of event handler.
+ */
+ public String getOndragend();
+ public void setOndragend(String ondrag);
+
+ /**
+ * Getter for JavaScript event handler; Called when dragged element over the dropzone.
+ * @return javaScript code of event handler.
+ */
+ public String getOndropover();
+ public void setOndropover(String ondropover);
+
+ /**
+ * Getter for JavaScript event handler; Called when dragged element out the dropzone.
+ * @return javaScript code of event handler.
+ */
+ public String getOndropout();
+ public void setOndropout(String ondropout);
+
+ /**
+ * Append drag listener to component listeners collection
+ * @param listener
+ */
+ public void addDragListener(DragListener listener);
+
+ /**
+ * Get array of all Drop Listeners
+ * @return
+ */
+ public DragListener[] getDragListeners();
+
+ /**
+ * Remove drop listener from component listeners array.
+ * @param listener
+ */
+ public void removeDragListener(DragListener listener);
+
+ public void setDragListener(MethodBinding binding);
+ public MethodBinding getDragListener();
+
+ public String getGrabCursors();
+ public void setGrabCursors(String grabCursors);
+
+ public String getGrabbingCursors();
+ public void setGrabbingCursors(String grabbingCursors);
+
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Dropzone.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Dropzone.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Dropzone.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/component/Dropzone.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,122 @@
+/**
+ * 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.component;
+
+import org.richfaces.event.DropSource;
+
+/**
+ * Base interface for all components, accesible as drop zone.
+ * @author shura
+ *
+ */
+public interface Dropzone extends DropSource {
+
+ /**
+ * Getter for dropType's , accepted by this zone.
+ * @return
+ */
+ public Object getAcceptedTypes();
+
+ public void setAcceptedTypes(Object types);
+
+ /**
+ * Getter for mapping between drop types and indicator states.
+ * @return
+ */
+ public Object getTypeMapping();
+
+ public void setTypeMapping(Object types);
+
+
+ /**
+ * Getter for mapping between drop types and acceptable cursors
+ * @return
+ */
+ public Object getCursorTypeMapping();
+ public void setCursorTypeMapping(Object types);
+
+ /**
+ * Getter for JavaScript event handler, called then drag curcor enter in component
area.
+ * If this handler return false, or "declined", drop operation on this
component not allowed.
+ * If handler return true or "allowed" , or any other supported indicator
states, drop operation
+ * is allowed and corresponding indicator state will be displayed.
+ * @return javaScript code of event handler.
+ */
+ public String getOndragenter();
+
+ /**
+ * @param dragType
+ */
+ public void setOndragenter(String ondrag);
+
+ /**
+ * Getter for JavaScript event handler, called before drag cursor leave component
area.
+ * @return javaScript code of event handler.
+ */
+ public String getOndragexit();
+
+ /**
+ * @param dragType
+ */
+ public void setOndragexit(String ondrag);
+
+ public Object getDropValue();
+
+ public void setDropValue(Object o);
+
+ /**
+ * Javascript code called before drop event.
+ * @parameter
+ * @return the acceptClass
+ */
+ public abstract String getOndrop();
+
+ /**
+ * @param newOndrop the value to set
+ */
+ public abstract void setOndrop(String newOndrop);
+
+ /**
+ * Javascript handler for event fired on drop even the drop for given type is not
available
+ * @parameter
+ * @return the acceptClass
+ */
+ public abstract String getOndropend();
+
+ /**
+ * @param newname the value to set
+ */
+ public abstract void setOndropend(String ondropend);
+
+ /**
+ * Getter for the list of comma separated cursors that indicates when acceptable
draggable over dropzone
+ */
+ public String getAcceptCursors();
+ public void setAcceptCursors(String acceptCursors);
+
+ /**
+ * Getter for the list of comma separated cursors that indicates when rejectable
draggable over dropzone
+ */
+ public String getRejectCursors();
+ public void setRejectCursors(String rejectCursors);
+
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DnDEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DnDEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DnDEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DnDEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,46 @@
+/**
+ * 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.FacesEvent;
+
+/**
+ *
+ * <br /><br />
+ *
+ * Created 12.11.2007
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public abstract class DnDEvent extends FacesEvent {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2455016405742082110L;
+
+ public DnDEvent(UIComponent component) {
+ super(component);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DragEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,102 @@
+/**
+ * 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.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesListener;
+
+import org.richfaces.component.Draggable;
+import org.richfaces.component.Dropzone;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 27.12.2006
+ *
+ */
+public class DragEvent extends DnDEvent {
+
+ private Dropzone dropTarget;
+ private Object acceptedTypes;
+ private Object dropValue;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6179268394391836905L;
+
+ public DragEvent(UIComponent uiComponent) {
+ super(uiComponent);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+ public boolean isAppropriateListener(FacesListener faceslistener) {
+ return faceslistener instanceof DragListener;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+ public void processListener(FacesListener faceslistener) {
+ ((DragListener) faceslistener).processDrag(this);
+ }
+
+ public Object getDragValue() {
+ return ((Draggable) this.getSource()).getDragValue();
+ }
+
+ public Dropzone getDropTarget() {
+ return dropTarget;
+ }
+
+ /**
+ * @see java.util.EventObject#toString()
+ */
+/* public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).
+ append("component", getComponent()).append("source",
getSource()).append("phaseId", getPhaseId()).
+ append("dragValue", getDragValue()).
+ append("dropTarget", getDropTarget()).
+ append("dropValue", getDropValue()).
+ toString();
+ }
+*/
+ public void setDropTarget(Dropzone dropTarget) {
+ this.dropTarget = dropTarget;
+ }
+
+ public Object getAcceptedTypes() {
+ return acceptedTypes;
+ }
+
+ public void setAcceptedTypes(Object acceptedTypes) {
+ this.acceptedTypes = acceptedTypes;
+ }
+
+ public Object getDropValue() {
+ return dropValue;
+ }
+
+ public void setDropValue(Object dropValue) {
+ this.dropValue = dropValue;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DragListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DragListener.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,34 @@
+/**
+ * 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.event;
+
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 27.12.2006
+ *
+ */
+public interface DragListener extends FacesListener {
+ public void processDrag(DragEvent event);
+
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DropEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,107 @@
+/**
+ * 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.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesListener;
+
+import org.richfaces.component.Draggable;
+import org.richfaces.component.Dropzone;
+
+/**
+ * @author shura
+ *
+ */
+public class DropEvent extends DnDEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1660545054556302746L;
+
+ private Draggable draggableSource;
+ private String dragType;
+ private Object dragValue;
+
+ public DropEvent(UIComponent component) {
+ super(component);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof DropListener;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+ public void processListener(FacesListener listener) {
+ ((DropListener) listener).processDrop(this);
+ }
+
+ /**
+ * @return the dropValue
+ */
+ public Object getDropValue() {
+ return ((Dropzone) this.getSource()).getDropValue();
+ }
+
+ public Draggable getDraggableSource() {
+ return draggableSource;
+ }
+
+ /**
+ * @see java.util.EventObject#toString()
+ */
+/* public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).
+ append("component", getComponent()).
+ append("source", getSource()).
+ append("phaseId", getPhaseId()).
+ append("dropValue", getDropValue()).
+ append("draggableSource", getDraggableSource()).
+ append("dragValue", getDragValue()).
+ toString();
+ }
+*/
+ public void setDraggableSource(Draggable draggableSource) {
+ this.draggableSource = draggableSource;
+ }
+
+ public String getDragType() {
+ return dragType;
+ }
+
+ public void setDragType(String dragType) {
+ this.dragType = dragType;
+ }
+
+ public Object getDragValue() {
+ return dragValue;
+ }
+
+ public void setDragValue(Object dragValue) {
+ this.dragValue = dragValue;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DropListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropListener.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,39 @@
+/**
+ * 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.event;
+
+import javax.faces.event.FacesListener;
+
+/**
+ * Listener for process Drop events
+ * @author shura
+ *
+ */
+public interface DropListener extends FacesListener {
+
+ /**
+ * Process event on Drop for this component.
+ * @param event
+ */
+ public void processDrop(DropEvent event);
+
+}
Copied:
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropSource.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/DropSource.java)
===================================================================
---
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropSource.java
(rev 0)
+++
root/ui-sandbox/trunk/components/drag-drop/src/main/java/org/richfaces/event/DropSource.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,54 @@
+/**
+ * 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.event;
+
+import javax.faces.el.MethodBinding;
+
+/**
+ * Interface for component applicable to process drag/drop events.
+ * @author shura
+ *
+ */
+public interface DropSource {
+
+ /**
+ * Append drop listener to component listeners collection
+ * @param listener
+ */
+ public void addDropListener(DropListener listener);
+
+ /**
+ * Get array of all Drop Listeners
+ * @return
+ */
+ public DropListener[] getDropListeners();
+
+ /**
+ * Remove drop listener from component listeners array.
+ * @param listener
+ */
+ public void removeDropListener(DropListener listener);
+
+ public void setDropListener(MethodBinding binding);
+ public MethodBinding getDropListener();
+
+}
Copied:
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/FileUploadListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/FileUploadListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/FileUploadListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/FileUploadListener.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,29 @@
+/**
+ * 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 FileUploadListener extends FacesListener {
+
+ public void processUpload(UploadEvent event);
+}
Copied:
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/UploadEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/UploadEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/UploadEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/event/UploadEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,78 @@
+/**
+ * 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 java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+import org.richfaces.model.UploadItem;
+
+public class UploadEvent extends FacesEvent{
+
+ private static final long serialVersionUID = -7645197191376210068L;
+ private List<UploadItem> uploadItems = null;
+
+ public UploadEvent(UIComponent component, List<UploadItem> uploadItems) {
+ super(component);
+ this.uploadItems = uploadItems;
+ }
+
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
+
+
+ public void processListener(FacesListener listener) {
+
+ }
+
+ /**Returns UploadItem instance.
+ * Returns first element of list of UploadItems in case of multiple upload.
+ * @return the uploadItem
+ */
+ public UploadItem getUploadItem() {
+ if (uploadItems != null && uploadItems.size() > 0) {
+ return uploadItems.get(0);
+ }
+ return null;
+ }
+
+ /**
+ * Return list of UploadItems
+ * @return the uploadItem
+ * @since 3.2.2
+ */
+ public List<UploadItem> getUploadItems() {
+ return uploadItems;
+ }
+
+ /** Return true if multiple files were uploaded with form
+ * @return boolean
+ * @since 3.2.2
+ */
+ public boolean isMultiUpload() {
+ return (uploadItems != null && uploadItems.size() > 1);
+ }
+}
Copied:
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/model/UploadItem.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/UploadItem.java)
===================================================================
---
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/model/UploadItem.java
(rev 0)
+++
root/ui-sandbox/trunk/components/fileupload/src/main/java/org/richfaces/model/UploadItem.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,122 @@
+/**
+ * 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.File;
+import java.io.Serializable;
+
+/**
+ * Class provides object holder for file uploaded.
+ * Instance of this type will be returned by UploadEvent after appropriate listener
called after uploading has been completed.
+ * @author "Andrey Markavtsov"
+ *
+ */
+public class UploadItem implements Serializable{
+
+ /**
+ * Serial id
+ */
+ private static final long serialVersionUID = -111723029745124147L;
+
+ /** Users file name */
+ private String fileName;
+
+ /** Content type */
+ private String contentType;
+
+ /** java.io.File instance */
+ private File file;
+
+ /** File byte content */
+ private byte [] bytes;
+
+ /** File size */
+ private int fileSize;
+
+ /**
+ * Constructor for the UploadItem
+ */
+ public UploadItem(String fileName, int fileSize, String contentType, Object file) {
+ this.fileName = fileName;
+ this.contentType = contentType;
+ this.fileSize = fileSize;
+ if (null != file) {
+ if (file.getClass().isAssignableFrom(File.class)) {
+ this.file = (File) file;
+ } else if (file.getClass().isAssignableFrom(byte[].class)) {
+ this.bytes = (byte[]) file;
+ }
+ }
+ }
+
+ /**
+ * Return true if file is holding as java.io.File type.
+ * If true getFile method should be invoked to get file uploaded.
+ * In another case getData method should be invoked to get file's bytes.
+ * @return
+ */
+ public boolean isTempFile () {
+ return (null != file);
+ }
+
+ /**
+ * This method should called only in case of TRUE value returned by {@link
#isTempFile()} method.
+ * Otherwise null value will be returned by this method.
+ * @return the file
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * This method should called only in case of FALSE value returned by {@link
#isTempFile()} method.
+ * Otherwise null value will be returned by this method.
+ * @return the bytes
+ * @throws Exception
+ */
+ public byte[] getData() {
+ return bytes;
+ }
+
+ /**
+ * @return the fileName
+ */
+ public String getFileName() {
+ return fileName;
+ }
+
+ /**
+ * @return the contentType
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * @return the fileSize
+ */
+ public int getFileSize() {
+ return fileSize;
+ }
+
+
+}
Copied:
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ListShuttleDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,168 @@
+/**
+ * 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.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModel;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceDataModel;
+
+/**
+ * Dual map-based extended data model for model-translating components like list shuttle
+ * @author Nick Belaevski
+ *
+ */
+public class ListShuttleDataModel extends ExtendedDataModel {
+
+ private ListShuttleRowKey rowKey;
+
+ private SequenceDataModel sourceModel;
+ private SequenceDataModel targetModel;
+
+ private Map<Object, Object> data;
+
+ private Object wrappedData;
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ public void setRowKey(Object key) {
+ this.rowKey = (ListShuttleRowKey) key;
+ }
+
+ public void walk(final FacesContext context, final DataVisitor visitor, final Range
range,
+ final Object argument) throws IOException {
+ if (data != null) {
+ Iterator<Entry<Object, Object>> iterator = data.entrySet().iterator();
+
+ while (iterator.hasNext()) {
+ Entry<Object, Object> entry = iterator.next();
+
+ visitor.process(context, entry.getKey(), argument);
+ }
+
+ } else {
+ sourceModel.walk(context, new DataVisitor() {
+
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+
+ ListShuttleRowKey key = new ListShuttleRowKey(rowKey, true);
+ visitor.process(context, key, argument);
+ }
+ }, range, argument);
+
+ targetModel.walk(context, new DataVisitor() {
+
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+
+ ListShuttleRowKey key = new ListShuttleRowKey(rowKey, false);
+ visitor.process(context, key, argument);
+ }
+
+ }, range, argument);
+ }
+ }
+
+ public int getRowCount() {
+ if (data != null) {
+ return data.size();
+ } else {
+ return sourceModel.getRowCount() + targetModel.getRowCount();
+ }
+ }
+
+ public Object getRowData() {
+ if (data != null) {
+ return data.get(rowKey);
+ } else {
+ if (this.rowKey != null) {
+ if (this.rowKey.isSource()) {
+ return sourceModel.getRowData();
+ } else {
+ return targetModel.getRowData();
+ }
+ } else {
+ return null;
+ }
+ }
+ }
+
+ public int getRowIndex() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Object getWrappedData() {
+ return wrappedData;
+ }
+
+ public boolean isRowAvailable() {
+ if (data != null) {
+ return data.containsKey(rowKey);
+ } else {
+ if (rowKey != null) {
+ if (rowKey.isSource()) {
+ return sourceModel.isRowAvailable();
+ } else {
+ return targetModel.isRowAvailable();
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public void setRowIndex(int rowIndex) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setWrappedData(Object data) {
+ this.rowKey = null;
+ this.wrappedData = data;
+
+ if (data instanceof Map) {
+ this.data = (Map<Object, Object>) data;
+ } else {
+ DataModel[] models = (DataModel[]) data;
+ this.sourceModel = new SequenceDataModel(models[0]);
+ this.targetModel = new SequenceDataModel(models[1]);
+ }
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleRowKey.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ListShuttleRowKey.java)
===================================================================
---
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleRowKey.java
(rev 0)
+++
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/ListShuttleRowKey.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,99 @@
+/**
+ * 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.Serializable;
+
+/**
+ * Special type of row key containing information on item origin and new placement
+ *
+ * @author Nick Belaevski
+ *
+ */
+public class ListShuttleRowKey implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3308741255288495879L;
+
+ private boolean source;
+
+ private boolean facadeSource;
+
+ private Object rowKey;
+
+ public boolean isSource() {
+ return source;
+ }
+
+ public boolean isFacadeSource() {
+ return facadeSource;
+ }
+
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((rowKey == null) ? 0 : rowKey.hashCode());
+ result = prime * result + (source ? 1231 : 1237);
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ListShuttleRowKey other = (ListShuttleRowKey) obj;
+ if (rowKey == null) {
+ if (other.rowKey != null)
+ return false;
+ } else if (!rowKey.equals(other.rowKey))
+ return false;
+ if (source != other.source)
+ return false;
+ return true;
+ }
+
+ public String toString() {
+ return (source ? "" : "t") + rowKey.toString();
+ }
+
+ public ListShuttleRowKey(Object rowKey, boolean source) {
+ super();
+ this.rowKey = rowKey;
+ this.source = source;
+ this.facadeSource = source;
+ }
+
+ public ListShuttleRowKey(Object rowKey, boolean source, boolean facadeSource) {
+ super();
+ this.rowKey = rowKey;
+ this.source = source;
+ this.facadeSource = facadeSource;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/OrderingListDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/OrderingListDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/OrderingListDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/selects/src/main/java/org/richfaces/model/OrderingListDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,101 @@
+/**
+ * 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.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+
+/**
+ * Map-based extended data model for model-translating components like ordering list
+ *
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 07.11.2007
+ *
+ */
+public class OrderingListDataModel extends ExtendedDataModel {
+
+ private Map<Object, Object> data;
+
+ private Object rowKey;
+
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ public void setRowKey(Object rowKey) {
+ this.rowKey = rowKey;
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+
+ Set<Entry<Object,Object>> entrySet = data.entrySet();
+ Iterator<Entry<Object, Object>> iterator = entrySet.iterator();
+
+ while (iterator.hasNext()) {
+ Entry<Object, Object> entry = iterator.next();
+
+ visitor.process(context, entry.getKey(), argument);
+ }
+ }
+
+ public int getRowCount() {
+ return data.size();
+ }
+
+ public Object getRowData() {
+ return data.get(rowKey);
+ }
+
+ public int getRowIndex() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Object getWrappedData() {
+ return data;
+ }
+
+ public boolean isRowAvailable() {
+ return data.containsKey(rowKey);
+ }
+
+ public void setRowIndex(int rowIndex) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setWrappedData(Object data) {
+ this.rowKey = null;
+ this.data = (Map<Object, Object>) data;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Column.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Column.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Column.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Column.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,82 @@
+/**
+ * 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.component;
+
+import javax.el.MethodExpression;
+
+import org.richfaces.model.Ordering;
+
+/**
+ * Marker interface for all components used as column in UIDataTable
+ * @author shura
+ *
+ */
+public interface Column {
+
+
+ /**
+ * Out this column on new row
+ * @parameter
+ * @return the acceptClass
+ */
+ public abstract boolean isBreakBefore();
+
+ /**
+ * @param newBreakBefore the value to set
+ */
+ public abstract void setBreakBefore(boolean newBreakBefore);
+
+
+ /**
+ * The column allows data sorting
+ * @return
+ */
+ public abstract boolean isSortable();
+
+ public abstract void setSortable(boolean sortable);
+
+ /**
+ * expression used for column sorting.
+ * literal value is treated as property of data object
+ * EL-expression is evaluated on every data row
+ * @param sortExpression
+ */
+ public abstract void setSortExpression(String sortExpression);
+ public abstract String getSortExpression();
+
+ /**
+ * SortOrder is an enumeration of the possible sort orderings.
+ *
+ * @param sortOrder
+ */
+ public abstract void setSortOrder(Ordering sortOrder);
+ public abstract Ordering getSortOrder();
+
+ public abstract void setFilterMethod(MethodExpression methodExpression);
+ public abstract MethodExpression getFilterMethod();
+
+ public abstract void setFilterValue(String filterValue);
+ public abstract String getFilterValue();
+
+ public abstract boolean isSelfSorted();
+ public abstract void setSelfSorted(boolean selfSorted);
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Filterable.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Filterable.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Filterable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Filterable.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,37 @@
+/**
+ * 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.component;
+
+import java.util.List;
+
+import org.richfaces.model.FilterField;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public interface Filterable {
+
+ public List<FilterField> getFilterFields();
+
+ public void setFilterFields(List<FilterField> filterFields);
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Row.java
(from rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/component/Row.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Row.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Row.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,41 @@
+/**
+ * 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.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * Marker interface for table columns, rendered as entire row.
+ * @author shura
+ *
+ */
+public interface Row extends Column {
+
+ /**
+ * Get iterator for all columns contained in this row.
+ * @return
+ */
+ public Iterator<UIComponent> columns();
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Selectable.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Selectable.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Selectable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Selectable.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,32 @@
+/**
+ * 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.component;
+
+import org.richfaces.model.selection.Selection;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface Selectable {
+ public Selection getSelection();
+ public void setSelection (Selection selection);
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Sortable.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,23 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2006
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/components/data-view-grid/src/component/com/exadel/jsf/component/Sortable.java,v
$
+ * $Revision: 1.1 $
+ */
+
+package org.richfaces.component;
+
+import org.richfaces.model.SortOrder;
+
+
+/**
+ * @author Maksim Kaszynski
+ * Base interface for sort capable components
+ */
+public interface Sortable {
+ public SortOrder getSortOrder();
+ public void setSortOrder(SortOrder sortOrder);
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable2.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/Sortable2.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable2.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/component/Sortable2.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,37 @@
+/**
+ * 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.component;
+
+import java.util.List;
+
+import org.richfaces.model.SortField2;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface Sortable2 {
+
+ public List<SortField2> getSortFields();
+
+ public void setSortFields(List<SortField2> sortFields);
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/ScrollableGridViewEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,70 @@
+/**
+ * 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;
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class ScrollableGridViewEvent extends AttributedEvent {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7417387605074667926L;
+ /**
+ * 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
Copied: root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/extdt
(from rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/event/extdt)
Copied: root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/scroll
(from rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/event/scroll)
Copied: root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/event/sort
(from rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/event/sort)
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/DataProvider.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/DataProvider.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/DataProvider.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/DataProvider.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,68 @@
+/**
+* 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.Serializable;
+import java.util.List;
+
+/**
+ * DataProvider is an interface that defines methods for manage loading data.<br>
+ * Usage:
+ * <pre>
+ * DataProvider<SomeDataType> dataProvider = new
DataProvider<SomeDataType>();
+ * </pre>
+ * @author pawelgo
+ *
+ */
+public interface DataProvider<T> extends Serializable {
+
+ /**
+ * Get number of all rows.
+ * @return number of rows.
+ */
+ public int getRowCount();
+
+ /**
+ * Loads elements from given range.
+ * Starting from startRow, and up to but excluding endRow.
+ * @param firstRow first row to load
+ * @param endRow end row to load
+ * @return element list
+ */
+ public List<T> getItemsByRange(int firstRow, int endRow);
+
+ /**
+ * Load single element by given key.
+ * @param key element key to be loaded.
+ * @return element or null, if not found
+ */
+ public T getItemByKey(Object key);
+
+ /**
+ * Get element key.
+ * If key is not instance of Integer or
org.richfaces.model.ScrollableTableDataModel.SimpleRowKey,
+ * it is necessary to implement javax.faces.convert.Converter for key type.
+ * @param item element, which key to be get
+ * @return element key
+ */
+ public Object getKey(T item);
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ExtendedFilterField.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ExtendedFilterField.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ExtendedFilterField.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ExtendedFilterField.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,50 @@
+/**
+ * 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 javax.el.Expression;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ExtendedFilterField extends FilterField{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5443560922389498666L;
+
+ private String filterValue;
+
+ public ExtendedFilterField(Expression expression, String filterValue) {
+ super(expression);
+ this.filterValue = filterValue;
+ }
+
+ public ExtendedFilterField(Expression expression) {
+ this(expression, "");
+ }
+
+ public String getFilterValue() {
+ return filterValue;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Field.java (from
rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/model/Field.java)
===================================================================
--- root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Field.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Field.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,75 @@
+/**
+ * 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.Serializable;
+
+import javax.el.Expression;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public abstract class Field implements Serializable{
+
+ private static final long serialVersionUID = 7576046308828980778L;
+
+ private Expression expression;
+
+ public Field(Expression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Field other = (Field) obj;
+ if (expression == null) {
+ if (other.expression != null)
+ return false;
+ } else {
+ return expression.equals(other.expression);
+ }
+ return true;
+ }
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((expression == null) ? 0 : expression.hashCode());
+ return result;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/FilterField.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/FilterField.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/FilterField.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/FilterField.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,37 @@
+/**
+ * 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 javax.el.Expression;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class FilterField extends Field{
+
+ private static final long serialVersionUID = -5453359866996963829L;
+
+ public FilterField(Expression expression) {
+ super(expression);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/LocaleAware.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/LocaleAware.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/LocaleAware.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/LocaleAware.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -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
+ */
+
+package org.richfaces.model;
+
+import java.util.Locale;
+
+/**
+ * Models that are based on locale-dependent operations should implement this interface
+ *
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+
+public interface LocaleAware {
+
+ public Locale getLocale();
+
+ public void setLocale(Locale locale);
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Modifiable.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/Modifiable.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Modifiable.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Modifiable.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,32 @@
+/**
+ * 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.util.List;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public interface Modifiable{
+
+ void modify(List<FilterField> filterFields, List<SortField2> sortFields);
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Ordering.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/Ordering.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Ordering.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/Ordering.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,31 @@
+/**
+ * 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;
+/**
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public enum Ordering {
+ ASCENDING,
+ DESCENDING,
+ UNSORTED
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ScrollableTableDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,267 @@
+/**
+ * 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.io.Serializable;
+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.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Base class for data models
+ * Subclasses must implement {@link #loadData(int, int, SortOrder)}
+ * For certain features (like selection and sorting) to work correctly together,
+ * both {@link #getId(Object)} and {@link #getObjectById(Object)}
+ * methods need to be overriden
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class ScrollableTableDataModel<T> extends ExtendedDataModel {
+
+ /**
+ * Simple implementation - index-based row key
+ * @author Maksim Kaszynski
+ *
+ */
+ public static class SimpleRowKey extends Number implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String PREFIX = "srk";
+ private int i;
+
+ public SimpleRowKey(int i) {
+ super();
+ this.i = i;
+ }
+
+ public int intValue() {
+ return i;
+ }
+
+ public String toString() {
+ return PREFIX + String.valueOf(i);
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + i;
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SimpleRowKey other = (SimpleRowKey) obj;
+ if (i != other.i)
+ return false;
+ return true;
+ }
+ @Override
+ public double doubleValue() {
+ return i;
+ }
+ @Override
+ public float floatValue() {
+ return i;
+ }
+ @Override
+ public long longValue() {
+ return i;
+ }
+
+ }
+
+
+ private static final Log log = LogFactory.getLog(ScrollableTableDataModel.class);
+
+ private Object rowKey;
+
+ private Map<Object, T> mapping;
+
+ protected SortOrder lastSortOrder;
+
+
+ /**
+ * Load range of data items from the source.
+ * Starting from startRow, and up to but excluding endRow
+ * @param startRow
+ * @param endRow
+ * @param sortOrder
+ * @return list of ordered data
+ */
+ public abstract List<T> loadData(int startRow, int endRow, SortOrder sortOrder);
+
+
+ /**
+ * Load data range, and iterate over it
+ */
+ public void walk(FacesContext context, DataVisitor visitor, Range range,
+ Object argument) throws IOException {
+
+ if (log.isTraceEnabled()) {
+ log.trace("Starting walk");
+ }
+
+ ScrollableTableDataRange sequenceRange = (ScrollableTableDataRange) range;
+
+ int startIndex = sequenceRange.getFirst();
+ int last = sequenceRange.getLast();
+
+ lastSortOrder = sequenceRange.getSortOrder();
+
+ List<T> objects = loadData(startIndex, last, lastSortOrder);
+
+ mapping = new HashMap<Object, T>();
+
+ for (int i = 0; i < objects.size(); i++,startIndex++) {
+ T data = objects.get(i);
+ Object key = getId(data);
+
+ if (key == null) {
+ key = new SimpleRowKey(startIndex);
+ }
+
+ mapping.put(key, data);
+
+ visitor.process(context, key, argument);
+
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("Ending walk");
+ }
+
+ }
+
+
+ /**
+ * This method is the reverse of {@link #getId(Object)}
+ * If you override this method, you need to override {@link #getId(Object)} as well
+ * @param id
+ * @return
+ */
+ public T getObjectById(Object id) {
+
+ if (id instanceof SimpleRowKey) {
+ int i = ((SimpleRowKey) id).intValue();
+
+ List<T> l = loadData(i, i + 1, lastSortOrder);
+
+ return l.get(0);
+
+ }
+
+ return null;
+ }
+
+ /**
+ * Implementations may override it to provide domain-specific searches
+ * Id should be serializable
+ * Default implementation returns <code>null</code> anyway
+ * If you override this method, you need to override {@link #getObjectById(Object)} as
well
+ * @param o
+ * @return
+ */
+ public Object getId(T o) {
+ return null;
+ }
+
+
+ public Object getRowData() {
+
+ if (mapping != null && mapping.containsKey(rowKey)) {
+ return mapping.get(rowKey);
+ } else {
+ return loadAndMap(rowKey);
+ }
+
+ }
+
+ /**
+ * Row indexes navigation is no longer supported
+ */
+ public int getRowIndex() {
+ return -1;
+ }
+
+ /**
+ * Quite simple implementation - data will be cached, so the call will be cheap
+ */
+ public boolean isRowAvailable() {
+ return getRowData() != null;
+ }
+
+ /**
+ * Row indexes navigation is no longer supported
+ */
+ public void setRowIndex(int index) {
+ //if(index != -1)
+ //throw new UnsupportedOperationException("setRowIndex");
+ //setRowKey(null);
+ }
+
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ public void setRowKey(Object key) {
+ rowKey = key;
+ }
+
+ private Object loadAndMap(Object id) {
+
+ if (log.isTraceEnabled()) {
+ log.trace("loadAndMap " + id);
+ }
+
+ T t = getObjectById(id);
+ if (t != null) {
+ if (mapping == null) {
+ mapping = new HashMap<Object, T>();
+ }
+ mapping.put(id, t);
+ }
+ return t;
+ }
+ /*
+ * FIXME: This method is most likely redundant
+ public void setSortOrder(SortOrder sortOrder) {
+ lastSortOrder = sortOrder;
+ }
+ */
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataRange.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ScrollableTableDataRange.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataRange.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/ScrollableTableDataRange.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,121 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2006
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/components/data-view-grid/src/component/com/exadel/jsf/model/ScrollableTableDataRange.java,v
$
+ * $Revision: 1.7 $
+ */
+
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import org.ajax4jsf.model.SequenceRange;
+
+/**
+ * Iteration range for Scrollable Grid
+ * @author Maksim Kaszynski
+ * @modified by Anton Belevich
+ */
+public class ScrollableTableDataRange extends SequenceRange implements Serializable{
+
+ private static final long serialVersionUID = -6675002421400464892L;
+
+ private SortOrder sortOrder;
+
+ public ScrollableTableDataRange() {
+ super();
+ }
+
+ public ScrollableTableDataRange(int first, int last, SortOrder sortOrder) {
+ super(first, last > 0 ? last - first : -1);
+ this.sortOrder = sortOrder;
+ }
+
+ /**
+ * @return the bufferSize
+ */
+ public int getLast() {
+ return getFirstRow() + getRows();
+ }
+ /**
+ * @param bufferSize the bufferSize to set
+ */
+ public void setLast(int lastRow) {
+ setRows(lastRow > 0 ? lastRow - getFirstRow() : -1);
+ }
+ /**
+ * @return the first
+ */
+ public int getFirst() {
+ return getFirstRow();
+ }
+ /**
+ * @param first the first to set
+ */
+ public void setFirst(int first) {
+ setFirstRow(first);
+ }
+
+ public SortOrder getSortOrder() {
+ return sortOrder;
+ }
+
+ public void setSortOrder(SortOrder sortOrder) {
+ this.sortOrder = sortOrder;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getFirstRow();
+ result = prime * result + getRows();
+ result = prime * result
+ + ((sortOrder == null) ? 0 : sortOrder.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ScrollableTableDataRange other = (ScrollableTableDataRange) obj;
+ if (getFirstRow() != other.getFirstRow())
+ return false;
+ if (getRows() != other.getRows())
+ return false;
+ if (sortOrder == null) {
+ if (other.sortOrder != null)
+ return false;
+ } else if (!sortOrder.equals(other.sortOrder))
+ return false;
+ return true;
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws IOException {
+
+ out.defaultWriteObject();
+
+ out.writeInt(getFirstRow());
+ out.writeInt(getRows());
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+
+ in.defaultReadObject();
+
+ setFirstRow(in.readInt());
+ setRows(in.readInt());
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SelectionMode.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SelectionMode.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SelectionMode.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SelectionMode.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,36 @@
+/**
+ * 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;
+/**
+ *
+ * @author Konstantin Mishin
+ *
+ */
+public enum SelectionMode {
+ none,
+ single,
+ multi;
+
+ public boolean isSelectionEnabled() {
+ return !equals(none);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SortField.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,93 @@
+/**
+ * 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.Serializable;
+
+/**
+ * Sort field is the piece of {@link SortOrder}
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortField implements Serializable{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private String name = null;
+ private Boolean ascending = null;
+
+
+
+ public SortField(String name, Boolean ascending) {
+ super();
+ this.name = name;
+ this.ascending = ascending;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Boolean getAscending() {
+ return ascending;
+ }
+
+ public void setAscending(Boolean ascending) {
+ this.ascending = ascending;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((ascending == null) ? 0 : ascending.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SortField other = (SortField) obj;
+ if (ascending == null) {
+ if (other.ascending != null)
+ return false;
+ } else if (!ascending.equals(other.ascending))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField2.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SortField2.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField2.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortField2.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,78 @@
+/**
+ * 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 javax.el.Expression;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortField2 extends Field{
+
+ private static final long serialVersionUID = 4578290842517554179L;
+
+ private Ordering ordering;
+
+ public SortField2(Expression expression) {
+ super(expression);
+ }
+
+ public SortField2(Expression expression, Ordering ordering) {
+ super(expression);
+ this.ordering = ordering;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((ordering == null) ? 0 : ordering.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SortField2 other = (SortField2) obj;
+ if (ordering == null) {
+ if (other.ordering != null)
+ return false;
+ } else if (!ordering.equals(other.ordering))
+ return false;
+ return true;
+ }
+
+ public Ordering getOrdering() {
+ return ordering;
+ }
+
+ public void setOrdering(Ordering ordering) {
+ this.ordering = ordering;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortOrder.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SortOrder.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortOrder.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/SortOrder.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,91 @@
+/**
+ * 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.Serializable;
+import java.util.Arrays;
+/**
+ * Class representing grid sort order
+ * Sort Order is the combination of {@link SortField}
+ * Order of occurrence of sort fields must be maintained
+ * to guarantee stable sorting
+ * @author Maksim Kaszynski
+ */
+public class SortOrder implements Serializable {
+
+ private static final long serialVersionUID = 2423450561570551363L;
+
+ private static int hashCode(Object[] array) {
+ final int prime = 31;
+ if (array == null)
+ return 0;
+ int result = 1;
+ for (int index = 0; index < array.length; index++) {
+ result = prime * result
+ + (array[index] == null ? 0 : array[index].hashCode());
+ }
+ return result;
+ }
+
+ private SortField [] fields;
+
+ public SortOrder() {
+
+ }
+
+ public SortOrder(SortField[] fields) {
+ super();
+ this.fields = fields;
+ }
+
+
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SortOrder other = (SortOrder) obj;
+ if (!Arrays.equals(fields, other.fields))
+ return false;
+ return true;
+ }
+
+ public SortField[] getFields() {
+ return fields;
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + SortOrder.hashCode(fields);
+ return result;
+ }
+
+ public void setFields(SortField[] fields) {
+ this.fields = fields;
+ }
+
+
+
+}
\ No newline at end of file
Copied: root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/filter
(from rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/model/filter)
Copied:
root/ui-sandbox/trunk/components/tables/src/main/java/org/richfaces/model/selection (from
rev 14980, root/framework/trunk/api/src/main/java/org/richfaces/model/selection)
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/FilterFieldTest.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/FilterFieldTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/FilterFieldTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/FilterFieldTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class FilterFieldTest extends TestCase {
+
+ private Field field;
+ private ValueExpression expression;
+
+ /**
+ * @param name
+ */
+ public FilterFieldTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ expression = EasyMock.createNiceMock(ValueExpression.class);
+ field = new FilterField(expression);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ field = null;
+ expression = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.FilterField#FilterField(javax.el.ValueExpression)}.
+ */
+ public final void testFilterField() {
+ Field filterField = new FilterField(expression);
+ assertEquals(filterField, field);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.Field#hashCode()}.
+ */
+ public final void testHashCode() {
+ Field filterField = new FilterField(expression);
+ assertEquals(filterField.hashCode(), field.hashCode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.Field#equals(java.lang.Object)}.
+ */
+ public final void testEqualsObject() {
+ Field filterField = new FilterField(null);
+ assertFalse(filterField.equals(field));
+ filterField.setExpression(expression);
+ assertTrue(filterField.equals(field));
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.Field#getExpression()}.
+ */
+ public final void testGetExpression() {
+ assertSame(field.getExpression(), expression);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.Field#setExpression(javax.el.ValueExpression)}.
+ */
+ public final void testSetExpression() {
+ field.setExpression(null);
+ assertNull(field.getExpression());
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,133 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.SequenceRange;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ListSequenceDataModelTest extends TestCase {
+
+ private List<Integer> list;
+ private ListSequenceDataModel model;
+ private ListSequenceDataModel nullModel;
+
+ /**
+ * @param name
+ */
+ public ListSequenceDataModelTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ list = new ArrayList<Integer>();
+ for (int i = 0; i < 10; i++) {
+ list.add(new Integer(i));
+ }
+ model = new ListSequenceDataModel(list);
+ nullModel = new ListSequenceDataModel(null);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ nullModel = null;
+ model = null;
+ list = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ListSequenceDataModel#isRowAvailable()}.
+ */
+ public final void testIsRowAvailable() {
+ assertFalse(nullModel.isRowAvailable());
+ assertTrue(model.isRowAvailable());
+ model.setRowIndex(-1);
+ assertFalse(model.isRowAvailable());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ListSequenceDataModel#getRowCount()}.
+ */
+ public final void testGetRowCount() {
+ assertEquals(model.getRowCount(), list.size());
+ assertEquals(nullModel.getRowCount(), -1);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ListSequenceDataModel#setRowIndex()}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getRowIndex()}.
+ */
+ public final void testRowIndex() {
+ int i = 3;
+ model.setRowIndex(i);
+ assertEquals(model.getRowIndex(), i);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ListSequenceDataModel#setRowKey(java.lang.Object)}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getRowKey(java.lang.Object)}.
+ */
+ public final void testRowKey() {
+ Integer i = 3;
+ model.setRowKey(i);
+ assertEquals(model.getRowKey(), i);
+ model.setRowKey(null);
+ assertNull(model.getRowKey());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ListSequenceDataModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getRowData()}.
+ */
+ public final void testWalk() {
+ DataVisitor visitor = new DataVisitor(){
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ Object key = model.getRowKey();
+ model.setRowKey(rowKey);
+ assertEquals(model.getRowData(), list.get(((Integer)rowKey).intValue()));
+ model.setRowKey(key);
+ }
+ };
+ try {
+ SequenceRange range = new SequenceRange(0, -1);
+ model.walk(null, visitor, range, null);
+ range = new SequenceRange(0, 5);
+ model.walk(null, visitor, range, null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ListSequenceDataModel#ListSequenceDataModel(java.util.List)},
+ * {@link org.richfaces.model.ListSequenceDataModel#setWrappedData(java.lang.Object)}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getWrappedData()} .
+ */
+ public final void testListSequenceDataModel() {
+ assertNull(nullModel.getWrappedData());
+ ListSequenceDataModel dataModel = new ListSequenceDataModel(list);
+ assertSame(dataModel.getWrappedData(), model.getWrappedData());
+
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockDataModel.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/MockDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,170 @@
+/**
+ * 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 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 shura
+ *
+ */
+public class MockDataModel extends ExtendedDataModel {
+
+ public static final int ROWS = 10;
+
+ private int rowIndex = 0;
+
+ private int minRow = 0;
+
+ private int maxRow = ROWS;
+
+ private Object wrappedData;
+ /**
+ * @return the maxRow
+ */
+ public int getMaxRow() {
+ return maxRow;
+ }
+
+ /**
+ * @param maxRow the maxRow to set
+ */
+ public void setMaxRow(int maxRow) {
+ this.maxRow = maxRow;
+ }
+
+ /**
+ * @return the minRow
+ */
+ public int getMinRow() {
+ return minRow;
+ }
+
+ /**
+ * @param minRow the minRow to set
+ */
+ public void setMinRow(int minRow) {
+ this.minRow = minRow;
+ }
+
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
+ int first=0;
+ int count=ROWS;
+ if (range instanceof MockRange) {
+ MockRange mockRange = (MockRange) range;
+ count = mockRange.getCount();
+ } else if (range instanceof SequenceRange) {
+ SequenceRange seqRange = (SequenceRange) range;
+ first = seqRange.getFirstRow();
+ int rows = seqRange.getRows();
+ if(rows>0){
+ count = rows+first;
+ }
+ }
+ for(int row = first; row < count && row < ROWS;row++){
+ visitor.process(context, new Integer(row), argument);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ // TODO Auto-generated method stub
+ return rowIndex<0?null:new Integer(rowIndex);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ public void setRowKey(Object key) {
+ if(null == key){
+ rowIndex = -1;
+ } else {
+ rowIndex = ((Integer) key).intValue();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ // TODO Auto-generated method stub
+ return getMaxRow();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public Object getRowData() {
+ // TODO Auto-generated method stub
+ return isRowAvailable()?String.valueOf(rowIndex):null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ public int getRowIndex() {
+ // TODO Auto-generated method stub
+ return rowIndex;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ // TODO Auto-generated method stub
+ return wrappedData;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ // TODO Auto-generated method stub
+ return rowIndex>=getMinRow() && rowIndex<getMaxRow();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ wrappedData = data;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockRange.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/MockRange.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockRange.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/MockRange.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,41 @@
+/**
+ * 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 org.ajax4jsf.model.Range;
+
+/**
+ * @author shura
+ *
+ */
+public class MockRange implements Range {
+
+ private int count;
+
+ public MockRange(int count) {
+ this.count = count;
+ }
+
+ public int getCount(){
+ return count;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ModifiableModelTest.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/ModifiableModelTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ModifiableModelTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ModifiableModelTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,107 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.SequenceRange;
+import org.easymock.classextension.EasyMock;
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ModifiableModelTest extends AbstractFacesTest {
+
+ private ModifiableModel model;
+ private ExtendedDataModel originalModel;
+ private String var;
+ private List<FilterField> filterFields;
+ private List<SortField2> sortFields;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ var = "var";
+ originalModel = new MockDataModel();
+ filterFields = new LinkedList<FilterField>();
+ sortFields = new LinkedList<SortField2>();
+ model = new ModifiableModel(originalModel, var);
+ model.modify(filterFields, sortFields);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ model = null;
+ var = null;
+ filterFields = null;
+ sortFields = null;
+ originalModel = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)}.
+ */
+ public final void testWalk() {
+ SequenceRange range = new SequenceRange(0, -1);
+ DataVisitor visitor = new DataVisitor(){
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ Object key = model.getRowKey();
+ model.setRowKey(rowKey);
+ Object key2 = originalModel.getRowKey();
+ originalModel.setRowKey(rowKey);
+ assertEquals(model.getRowData(), originalModel.getRowData());
+ model.setRowKey(key);
+ originalModel.setRowKey(key2);
+ }
+ };
+ try {
+ model.walk(null, visitor, range, null);
+ ValueExpression expression =
+ facesContext.getApplication().getExpressionFactory().createValueExpression(Boolean.TRUE,
Boolean.class);
+ filterFields.add(new FilterField(expression));
+ sortFields.add(new SortField2(expression, Ordering.ASCENDING));
+ model.walk(null, visitor, range, null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#addDataModelListener(javax.faces.model.DataModelListener)}.
+ */
+ public final void testAddDataModelListenerDataModelListener() {
+ DataModelListener mockedListener = EasyMock.createNiceMock(DataModelListener.class);
+ model.addDataModelListener(mockedListener);
+ assertEquals(model.getDataModelListeners()[0], mockedListener);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#removeDataModelListener(javax.faces.model.DataModelListener)}.
+ */
+ public final void testRemoveDataModelListenerDataModelListener() {
+ DataModelListener mockedListener = EasyMock.createNiceMock(DataModelListener.class);
+ model.addDataModelListener(mockedListener);
+ assertSame(model.getDataModelListeners()[0], mockedListener);
+ model.removeDataModelListener(mockedListener);
+ assertEquals(model.getDataModelListeners().length, 0);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ScrollableTableDataRangeSerializationTest.java
(from rev 14980,
root/framework/trunk/api/src/test/java/org/richfaces/model/ScrollableTableDataRangeSerializationTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ScrollableTableDataRangeSerializationTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/ScrollableTableDataRangeSerializationTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,59 @@
+/**
+ * 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.model;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+
+public class ScrollableTableDataRangeSerializationTest extends TestCase {
+
+ private ScrollableTableDataRange readWriteRange(ScrollableTableDataRange range) throws
Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(range);
+ oos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+
+ return (ScrollableTableDataRange) ois.readObject();
+ }
+
+ public void testSerialization() throws Exception {
+ SortOrder order = new SortOrder(new SortField[] { new SortField("xxx", true)
});
+ ScrollableTableDataRange range = new ScrollableTableDataRange(10, 300, order);
+
+ ScrollableTableDataRange serializedRange = readWriteRange(range);
+
+ assertNotSame(range, serializedRange);
+ assertEquals(range, serializedRange);
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/SortField2Test.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/SortField2Test.java)
===================================================================
---
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/SortField2Test.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/src/test/java/org/richfaces/model/SortField2Test.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,99 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class SortField2Test extends TestCase {
+
+ private SortField2 field;
+ private ValueExpression expression;
+ private Ordering ordering;
+ /**
+ * @param name
+ */
+ public SortField2Test(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ expression = EasyMock.createNiceMock(ValueExpression.class);
+ ordering = Ordering.ASCENDING;
+ field = new SortField2(expression, ordering);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ field = null;
+ ordering = null;
+ expression = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.SortField2#hashCode()}.
+ */
+ public final void testHashCode() {
+ Field sortField = new SortField2(expression, ordering);
+ assertEquals(sortField.hashCode(), field.hashCode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.SortField2#equals(java.lang.Object)}.
+ */
+ public final void testEqualsObject() {
+ SortField2 sortField = new SortField2(null);
+ assertFalse(sortField.equals(field));
+ sortField.setExpression(expression);
+ sortField.setOrdering(ordering);
+ assertTrue(sortField.equals(field));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.SortField2#SortField2(javax.el.ValueExpression)}.
+ */
+ public final void testSortField2ValueExpression() {
+ SortField2 sortField2 = new SortField2(expression);
+ field.setOrdering(null);
+ assertEquals(sortField2, field);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.SortField2#SortField2(javax.el.ValueExpression,
org.richfaces.model.Ordering)}.
+ */
+ public final void testSortField2ValueExpressionOrdering() {
+ SortField2 sortField2 = new SortField2(expression, ordering);
+ assertEquals(sortField2, field);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.SortField2#getOrdering()}.
+ */
+ public final void testGetOrdering() {
+ assertEquals(field.getOrdering(), ordering);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.SortField2#setOrdering(org.richfaces.model.Ordering)}.
+ */
+ public final void testSetOrdering() {
+ field.setOrdering(null);
+ assertNull(field.getOrdering());
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/component/xml/XmlNodeData.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/component/xml/XmlNodeData.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/component/xml/XmlNodeData.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/component/xml/XmlNodeData.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,82 @@
+/**
+ * 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.component.xml;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 16.11.2006
+ *
+ */
+public class XmlNodeData implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8320619478974873168L;
+
+ private String namespace;
+
+ private String name = "";
+
+ private String text;
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ public Map<String, Object> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttribute(String key, Object value) {
+ this.attributes.put(key, value);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getText() {
+ return text != null ? text : "";
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public String toString() {
+ return getName() + "{" + attributes.toString() + " <" +
getText().trim() + ">" + "}";
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxExpandedEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/AjaxExpandedEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxExpandedEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxExpandedEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+/**
+ *
+ * <br /><br />
+ *
+ * Created 27.08.2007
+ * @author mikalaj
+ * @since 3.1
+ */
+
+public class AjaxExpandedEvent extends NodeExpandedEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5191468583939051390L;
+
+ public AjaxExpandedEvent(UIComponent component) {
+ super(component);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxSelectedEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/AjaxSelectedEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxSelectedEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/AjaxSelectedEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,43 @@
+/**
+ * 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 org.richfaces.model.TreeRowKey;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class AjaxSelectedEvent extends NodeSelectedEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1156974665865521208L;
+
+ public AjaxSelectedEvent(UIComponent component, TreeRowKey oldSelection) {
+ super(component, oldSelection);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/NodeExpandedEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,58 @@
+/**
+ * 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.FacesEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 27.11.2006
+ *
+ */
+public class NodeExpandedEvent extends FacesEvent {
+
+ public NodeExpandedEvent(UIComponent component) {
+ super(component);
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2620359072575831666L;
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof NodeExpandedListener;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+ public void processListener(FacesListener listener) {
+ ((NodeExpandedListener) listener).processExpansion(this);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/NodeExpandedListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeExpandedListener.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,34 @@
+/**
+ * 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.AbortProcessingException;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 27.11.2006
+ *
+ */
+public interface NodeExpandedListener extends FacesListener {
+ public void processExpansion(NodeExpandedEvent nodeExpandedEvent) throws
AbortProcessingException;
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/NodeSelectedEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,69 @@
+/**
+ * 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.FacesEvent;
+import javax.faces.event.FacesListener;
+
+import org.richfaces.model.TreeRowKey;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 27.11.2006
+ *
+ */
+public class NodeSelectedEvent extends FacesEvent {
+
+ private TreeRowKey oldSelection;
+
+ public NodeSelectedEvent(UIComponent component, TreeRowKey oldSelection) {
+ super(component);
+
+ this.oldSelection = oldSelection;
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1292268859927735863L;
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof NodeSelectedListener;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+
+ public void processListener(FacesListener listener) {
+ ((NodeSelectedListener) listener).processSelection(this);
+ }
+
+ public TreeRowKey getOldSelection() {
+ return oldSelection;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedListener.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/NodeSelectedListener.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedListener.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/NodeSelectedListener.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,34 @@
+/**
+ * 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.AbortProcessingException;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 27.11.2006
+ *
+ */
+public interface NodeSelectedListener extends FacesListener {
+ public void processSelection(NodeSelectedEvent nodeSelectedEvent) throws
AbortProcessingException;
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEvent.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/TreeAjaxEvent.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEvent.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEvent.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,55 @@
+/**
+ * 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 org.ajax4jsf.event.AjaxEvent;
+
+/**
+ * Event send by tree component in case of AJAX of action (node expansion/collapsion or
selection).
+ * Contains data to distinguish between different action types in order to support
different re-rendering
+ * behaviors for particular actions.
+ *
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+
+public class TreeAjaxEvent extends AjaxEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2410803626536767706L;
+
+ private TreeAjaxEventType eventType;
+
+ public TreeAjaxEvent(UIComponent component, TreeAjaxEventType eventType) {
+ super(component);
+
+ this.eventType = eventType;
+ }
+
+ public TreeAjaxEventType getEventType() {
+ return eventType;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEventType.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/TreeAjaxEventType.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEventType.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeAjaxEventType.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -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;
+
+/**
+ * Types enumeration for possible tree actions to be used in {@link TreeAjaxEvent}
+ *
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+
+public enum TreeAjaxEventType {
+ EXPANSION, SELECTION
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeListenerEventsProducer.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/event/TreeListenerEventsProducer.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeListenerEventsProducer.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/event/TreeListenerEventsProducer.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,51 @@
+/**
+ * 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.el.MethodBinding;
+
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 29.11.2006
+ *
+ * Base tree events interface
+ */
+public interface TreeListenerEventsProducer {
+ public abstract void setChangeExpandListener(MethodBinding binding);
+ public abstract MethodBinding getChangeExpandListener();
+
+ public abstract void setNodeSelectListener(MethodBinding binding);
+ public abstract MethodBinding getNodeSelectListener();
+
+ public abstract void setDropListener(MethodBinding binding);
+ public abstract MethodBinding getDropListener();
+
+ public abstract void setDragListener(MethodBinding binding);
+ public abstract MethodBinding getDragListener();
+
+ public void addNodeSelectListener(NodeSelectedListener listener);
+ public void addChangeExpandListener(NodeExpandedListener listener);
+
+ //TODO - rename this
+ public boolean hasAjaxSubmitSelection();
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/AbstractTreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,176 @@
+/**
+ * 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.model;
+
+import java.io.IOException;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+
+/**
+ * Base class for all tree data models
+ * @author Nick Belaevski - nbelaevski(a)exadel.com created 07.12.2006
+ */
+public abstract class AbstractTreeDataModel extends ExtendedDataModel {
+ public final static char SEPARATOR = NamingContainer.SEPARATOR_CHAR;
+
+ public final int getRowCount() {
+ return -1;
+ }
+
+ public final int getRowIndex() {
+ return -1;
+ }
+
+ public final void setRowIndex(int rowIndex) {
+ if(rowIndex!=-1) {
+ throw new IllegalArgumentException("In AbstractTreeDataModel rowIndex must be
-1.");
+ }
+ }
+
+ public final void walk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object argument) throws IOException {
+ walk(context, dataVisitor, range, null, argument, false);
+ }
+
+ /**
+ * walk sub-model having row key argument as its root
+ * @param context faces context
+ * @param dataVisitor {@link org.ajax4jsf.ajax.repeat.UIDataAdaptor.ComponentVisitor}
+ * @param range {@link TreeRange} to constraint the walk
+ * @param rowKey row key to treat as root of sub-model
+ * @param argument implementation specific argument
+ * @param last boolean flag indicating whether we started our walk from last element
+ * @throws IOException
+ *
+ * @see {@link ExtendedDataModel#walk(FacesContext, DataVisitor, Range, Object)}
+ */
+ public abstract void walk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument, boolean last) throws IOException;
+
+ /**
+ * returns whether this node is leaf
+ * @return
+ */
+ public abstract boolean isLeaf();
+
+ /**
+ * Walk backing sub-model having row key argument as its root. If there is no backing
model
+ * configured, calling this method is equivalent to calling {@link #walk(FacesContext,
DataVisitor, Range, Object, Object, boolean)}
+ * @param facesContext faces context
+ * @param visitor {@link org.ajax4jsf.ajax.repeat.UIDataAdaptor.ComponentVisitor}
instance
+ * @param range {@link Range} to constraint the walk
+ * @param key row key to treat as root of sub-model
+ * @param argument implementation-specific argument
+ * @throws IOException
+ *
+ * @see {@link #walk(FacesContext, DataVisitor, Range, TreeRowKey, Object, boolean)}
+ */
+ public abstract void walkModel(FacesContext facesContext, DataVisitor visitor, Range
range, Object key, Object argument, boolean last) throws IOException;
+
+ /**
+ * Processes concrete tree node. Knows about {@link LastElementAware} interface and
handles it
+ * properly. Checks if argument is instance of {@link SubTreeChildrenAppender} and if it
is so
+ * does appending current element
+ * @param context
+ * @param dataVisitor
+ * @param argument
+ * @param treeRowKey
+ * @param last
+ * @throws IOException
+ */
+ protected void processElement(FacesContext context, DataVisitor dataVisitor, Object
argument, TreeRowKey treeRowKey, boolean last) throws IOException {
+ if (last && dataVisitor instanceof LastElementAware) {
+ try {
+ ((LastElementAware) dataVisitor).setLastElement();
+ dataVisitor.process(context, treeRowKey, argument);
+ } finally {
+ ((LastElementAware) dataVisitor).resetLastElement();
+ }
+ } else {
+ dataVisitor.process(context, treeRowKey, argument);
+ }
+ }
+
+ /**
+ * Get current tree node.
+ * Note: valid only for classical TreeNode based tree data model implementation
+ *
+ * @return current tree node
+ */
+ public abstract TreeNode getTreeNode();
+
+ /**
+ * Get model node recursively with all sub nodes.
+ * Note: valid only for classical TreeNode based tree data model implementation
+ *
+ * @return current tree node
+ */
+ public TreeNode getModelTreeNode() {
+ return getTreeNode();
+ }
+
+ public abstract Object convertToKey(FacesContext context, String keyString,
+ UIComponent component, Converter converter);
+
+ /**
+ * Get row key for certain tree node object
+ *
+ * @param node to get key for
+ * @return node row key
+ */
+ public Object getTreeNodeRowKey(Object node) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Get node local id in it's parent childs collection
+ *
+ * @param childNode node to get identifier for
+ * @return node local identifier
+ */
+ public Object getChildNodeId(Object childNode) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getParentRowKey(Object key) {
+ return ((TreeRowKey) key).getParentKey();
+ }
+
+ public void addNode(Object parentRowKey, Object newNode, Object id) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addNode(Object parentRowKey, TreeNode newNode, Object id) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeNode(Object rowKey) {
+ throw new UnsupportedOperationException();
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableSwingTreeNodeImpl.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/CacheableSwingTreeNodeImpl.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableSwingTreeNodeImpl.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableSwingTreeNodeImpl.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,43 @@
+/**
+ * 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.model;
+
+/**
+ * This class provides the solution for "false leaves" issue of cacheable
trees
+ *
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+
+public class CacheableSwingTreeNodeImpl extends SwingTreeNodeImpl {
+
+ private boolean notLeaf = false;
+
+ @Override
+ public boolean isLeaf() {
+ return !this.notLeaf && super.isLeaf();
+ }
+
+ public void setNotLeaf(boolean notLeaf) {
+ this.notLeaf = notLeaf;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/CacheableTreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,226 @@
+/**
+ * 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.model;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Extension of {@link TreeDataModel} supporting lazy data fetching for caching
+ *
+ * created 08.01.2007
+ *
+ * @author Nick - mailto:nbelaevski@exadel.com
+ */
+public abstract class CacheableTreeDataModel<T> extends TreeDataModel<T> {
+
+ private Log log = LogFactory.getLog(CacheableTreeDataModel.class);
+
+ private final class CacheFillingVisitor implements DataVisitor {
+
+ private CacheFillingVisitor() {
+ }
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+ TreeRowKey treeRowKey = (TreeRowKey) rowKey;
+ treeDataModel.setRowKey(treeRowKey);
+ setDefaultNodeData(locateTreeNode(treeRowKey, true), treeDataModel.getRowData());
+ }
+
+ }
+
+ private final static DataVisitor NULL_VISITOR = new DataVisitor() {
+
+ public void process(FacesContext context, Object rowKey, Object argument) throws
IOException {
+ //do nothing
+ }
+
+ };
+
+ private TreeDataModel<T> treeDataModel;
+
+ public boolean isLeaf() {
+ TreeRowKey rowKey = (TreeRowKey) getRowKey();
+ T treeNode = locateTreeNode(rowKey);
+ if (treeNode != null && !nodeAdaptor.isLeaf(treeNode)) {
+ return false;
+ }
+
+ treeNode = treeDataModel.locateTreeNode(rowKey);
+ if (treeNode != null) {
+ return nodeAdaptor.isLeaf(treeNode);
+ }
+
+ return false;
+ }
+
+ public CacheableTreeDataModel(TreeDataModel<T> model, MissingNodeHandler<T>
missingNodeHandler) {
+ super(model.getClazz(), model.getNodeAdaptor(), missingNodeHandler);
+ setWrappedData(missingNodeHandler.handleMissingNode(null, null));
+ setTreeDataModel(model);
+ }
+
+ public void walkModel(FacesContext context, DataVisitor visitor,
+ Range range, Object key, Object argument, boolean last)
+ throws IOException {
+ treeDataModel.walkModel(context, visitor, range, key,
+ argument, last);
+ }
+
+ public void setTreeDataModel(TreeDataModel<T> treeDataModel) {
+ this.treeDataModel = treeDataModel;
+ }
+
+ public TreeDataModel<T> getTreeDataModel() {
+ return treeDataModel;
+ }
+
+ public void walk(FacesContext context, final DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument, boolean last)
+ throws IOException {
+
+ T cachedTreeNode = locateTreeNode((TreeRowKey) rowKey);
+ T treeNode = treeDataModel.locateTreeNode((TreeRowKey) rowKey);
+
+ if (treeNode != null) {
+ if (cachedTreeNode == null || (nodeAdaptor.isLeaf(cachedTreeNode) &&
!nodeAdaptor.isLeaf(treeNode))) {
+ //fill cache
+ treeDataModel.walk(context, new CacheFillingVisitor(), range,
+ rowKey, argument, last);
+ }
+
+ super.walk(context, dataVisitor, range, rowKey, argument, last);
+ }
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ if (!newTransientValue) {
+ throw new IllegalArgumentException(
+ "ReplaceableTreeDataModel shouldn't be transient!");
+ }
+ }
+
+ protected abstract void setDefaultNodeData(T node, Object data);
+
+ @Override
+ public Object convertToKey(FacesContext context, String keyString, UIComponent
component, Converter converter) {
+ Object convertedKey = treeDataModel.convertToKey(context, keyString, component,
converter);
+
+ if (convertedKey != null) {
+ final TreeRowKey treeRowKey = (TreeRowKey) convertedKey;
+ try {
+ walk(context, NULL_VISITOR, new TreeRange() {
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ return rowKey == null || rowKey.isSubKey(treeRowKey);
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return this.processChildren(rowKey) || rowKey.equals(treeRowKey);
+ }
+
+ }, null);
+ } catch (IOException e) {
+ context.getExternalContext().log(e.getLocalizedMessage(), e);
+
+ return null;
+ }
+ }
+
+ return convertedKey;
+ }
+
+ @Override
+ public T locateTreeNode(TreeRowKey rowKey) {
+ return locateTreeNode(rowKey, true);
+ }
+
+ @Override
+ public void addNode(Object parentRowKey, TreeNode newNode, Object id) {
+ super.addNode(parentRowKey, newNode, id);
+
+ if (treeDataModel != null) {
+ Object savedRowKey = treeDataModel.getRowKey();
+
+ try {
+ treeDataModel.setRowKey(getRowKey());
+ treeDataModel.addNode(parentRowKey, newNode, id);
+ } finally {
+ try {
+ treeDataModel.setRowKey(savedRowKey);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void removeNode(Object rowKey) {
+ super.removeNode(rowKey);
+
+ if (treeDataModel != null) {
+ Object savedRowKey = treeDataModel.getRowKey();
+
+ try {
+ treeDataModel.setRowKey(getRowKey());
+ treeDataModel.removeNode(rowKey);
+ } finally {
+ try {
+ treeDataModel.setRowKey(savedRowKey);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public TreeNode getModelTreeNode() {
+ TreeNode node = null;
+ if (treeDataModel != null) {
+ Object savedRowKey = treeDataModel.getRowKey();
+
+ try {
+ treeDataModel.setRowKey(getRowKey());
+ node = treeDataModel.getModelTreeNode();
+ } finally {
+ try {
+ treeDataModel.setRowKey(savedRowKey);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ return node;
+ }
+}
\ No newline at end of file
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeNodeImpl.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/CacheableTreeNodeImpl.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeNodeImpl.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/CacheableTreeNodeImpl.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,48 @@
+/**
+ * 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.model;
+
+/**
+ * This class provides the solution for "false leaves" issue of cacheable
trees
+ *
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+
+public class CacheableTreeNodeImpl<T> extends TreeNodeImpl<T> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5918388225735277820L;
+
+ private boolean notLeaf = false;
+
+ @Override
+ public boolean isLeaf() {
+ return !this.notLeaf && super.isLeaf();
+ }
+
+ public void setNotLeaf(boolean notLeaf) {
+ this.notLeaf = notLeaf;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicCacheableTreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ClassicCacheableTreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicCacheableTreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicCacheableTreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,73 @@
+/**
+ * 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.model;
+
+/**
+ * {@link CacheableTreeDataModel} implementation for classic {@link TreeNode} instances
+ *
+ * Created 01.11.2007
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class ClassicCacheableTreeDataModel extends CacheableTreeDataModel<TreeNode>
{
+
+ private static final MissingNodeHandler<TreeNode> missingNodeHandler = new
MissingNodeHandler<TreeNode>() {
+
+ public TreeNode handleMissingNode(TreeNode parentNode,
+ Object pathSegment) {
+
+ TreeNodeImpl childNode = new CacheableTreeNodeImpl();
+
+ if (parentNode != null) {
+ parentNode.addChild(pathSegment, childNode);
+ }
+
+ return childNode;
+ }
+
+ };
+
+ public ClassicCacheableTreeDataModel(TreeDataModel<TreeNode> model) {
+ super(model, missingNodeHandler);
+ }
+
+ @Override
+ protected void setDefaultNodeData(TreeNode node, Object data) {
+ if (node != null) {
+ CacheableTreeNodeImpl cacheableTreeNode = (CacheableTreeNodeImpl) node;
+ cacheableTreeNode.setData(data);
+ cacheableTreeNode.setNotLeaf(!isLeaf());
+ }
+ }
+
+ @Override
+ public TreeNode getTreeNode() {
+ if (isRowAvailable()) {
+ return locateTreeNode((TreeRowKey) getRowKey());
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ClassicTreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,94 @@
+/**
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ * {@link TreeDataModel} implementation for classic {@link TreeNode} instances
+ *
+ * Created 01.11.2007
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class ClassicTreeDataModel extends TreeDataModel<TreeNode> {
+
+ public ClassicTreeDataModel() {
+ super(TreeNode.class, TreeDataModelNodeAdaptor.classicTreeNodeAdaptor, null);
+ }
+
+ @Override
+ public TreeNode getTreeNode() {
+ if (isRowAvailable()) {
+ return locateTreeNode((TreeRowKey) getRowKey());
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ @Override
+ public Object convertToKey(FacesContext context, String keyString, UIComponent
component, Converter converter) {
+ //TODO optimize search for empty string
+ String[] strings = ListRowKey.fromString(keyString);
+ List<Object> list = new ArrayList<Object>(strings.length);
+ TreeNode node = (TreeNode) getWrappedData();
+
+ for (int i = 0; i < strings.length; i++) {
+ String key = strings[i];
+ TreeNode<?> child = node.getChild(key);
+ if (child != null) {
+ node = child;
+ list.add(key);
+ } else {
+ boolean found = false;
+ Iterator<Entry<Object, TreeNode>> children = node.getChildren();
+
+ while (children.hasNext() && !found) {
+ Entry<Object, TreeNode> entry = children.next();
+ Object keyObject = entry.getKey();
+ if (key.equals(keyObject.toString())) {
+ node = entry.getValue();
+ list.add(keyObject);
+ found = true;
+ }
+ }
+
+ if (!found) {
+ return null;
+ }
+ }
+ }
+
+ return new ListRowKey<Object>(list);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ComplexTreeRowKey.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ComplexTreeRowKey.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ComplexTreeRowKey.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ComplexTreeRowKey.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,36 @@
+/**
+ * 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.model;
+
+/**
+ * Marks complex tree row keys containing several segments
+ *
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+
+public interface ComplexTreeRowKey {
+
+ public int getKeySegmentsCount();
+
+ public Object getKeySegment(int i);
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ConvertableKeyModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ConvertableKeyModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ConvertableKeyModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ConvertableKeyModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,51 @@
+/**
+ * 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.model;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ * Models that can handle keys conversion should implement this interface
+ *
+ * For internal use only
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public interface ConvertableKeyModel {
+
+ /**
+ * Converts {@link String} to model object key
+ *
+ * @param context
+ * @param key
+ * @param component
+ * @param converter
+ * @return
+ */
+ public Object getKeyAsObject(FacesContext context, String key,
+ UIComponent component, Converter converter);
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/LastElementAware.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/LastElementAware.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/LastElementAware.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/LastElementAware.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,43 @@
+/**
+ * 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.model;
+
+/**
+ * {@link org.ajax4jsf.ajax.repeat.UIDataAdaptor.ComponentVisitor} instances can
implement this interface in order to
+ * be notified of last element occurence at the current tree level. {@link
#setLastElement()}
+ * method is invoked before visiting last element and {@link #resetLastElement()} is
called after
+ * visiting last element.
+ *
+ * @author Konstantin Mishin
+ */
+public interface LastElementAware {
+
+ /**
+ * The method is invoked to notify that last element occured
+ */
+ public void setLastElement();
+ /**
+ * The method is invoked to notify that we're done with last element
+ */
+ public void resetLastElement();
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ListRowKey.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/ListRowKey.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ListRowKey.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/ListRowKey.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,265 @@
+/**
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.NamingContainer;
+
+/**
+ * Default {@link TreeRowKey} implementation based on {@link ArrayList}
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 17.11.2006
+ */
+public class ListRowKey<T> extends TreeRowKey<T> {
+
+ private ArrayList<T> path;
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7718335783201397177L;
+
+ public String toString() {
+ return getPath();
+ }
+
+ /**
+ * Default constructor
+ */
+ public ListRowKey() {
+ super();
+ this.path = new ArrayList<T>();
+ }
+
+ /**
+ * Copy constructor
+ * @param parentRowKey row key to clone
+ */
+
+ @SuppressWarnings("unchecked")
+ public ListRowKey(ListRowKey<T> parentRowKey) {
+ super();
+ if (parentRowKey != null) {
+ this.path = (ArrayList<T>) parentRowKey.path.clone();
+ } else {
+ this.path = new ArrayList<T>();
+ }
+ }
+
+ /**
+ * Appending constructor
+ *
+ * @param parentRowKey base row key
+ * @param pathElement path segment to append to base row key
+ */
+ public ListRowKey(ListRowKey<T> parentRowKey, T pathElement) {
+ this(parentRowKey);
+ this.path.add(pathElement);
+ }
+
+ /**
+ * Appending constructor
+ * @param parentRowKey base row key
+ * @param pathElement path segment to append to base row key
+ */
+ public ListRowKey(ListRowKey<T> parentRowKey, ListRowKey<T> childRowKey) {
+ this(parentRowKey);
+ this.path.addAll(childRowKey.path);
+ }
+
+ protected ListRowKey(ArrayList<T> list) {
+ super();
+
+ this.path = list;
+ }
+
+ /**
+ * Path object constructor
+ * @param path first path segment
+ * @deprecated
+ */
+ public ListRowKey(T path) {
+ super();
+ this.path = new ArrayList<T>(1);
+ this.path.add(path);
+ }
+
+ /**
+ * List constructor
+ * @param list List of strings to create corresponding row key from
+ */
+ public ListRowKey(List<T> list) {
+ super();
+
+ this.path = new ArrayList<T>(list);
+ }
+
+ public int depth() {
+ return path.size();
+ }
+
+ public Iterator<T> iterator() {
+ return path.iterator();
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final ListRowKey<?> other = (ListRowKey<?>) obj;
+ if (path == null) {
+ if (other.path != null)
+ return false;
+ } else if (!path.equals(other.path))
+ return false;
+ return true;
+ }
+
+ public Iterator<T> getSubPathIterator(int fromIndex) {
+ return path.listIterator(fromIndex);
+ }
+
+ @Override
+ public TreeRowKey<T> getSubKey(int fromIndex) {
+ return new ListRowKey<T>(path.subList(fromIndex, path.size()));
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public boolean isSubKey(TreeRowKey<T> rowKey) {
+ if (rowKey instanceof ListRowKey) {
+ ListRowKey<T> listRowKey = (ListRowKey<T>) rowKey;
+
+ return depth() == getCommonPathLength(listRowKey);
+ } else {
+ return super.isSubKey(rowKey);
+ }
+ }
+
+ private void appendSegment(StringBuilder builder, String segment) {
+ StringBuilder escapedSubPath = new StringBuilder();
+ for (int i = 0; i < segment.length(); i++) {
+ char ch = segment.charAt(i);
+
+ //escape
+ if (AbstractTreeDataModel.SEPARATOR == ch || ListRowKey.SEPARATOR_ESCAPE_CHAR == ch)
{
+ escapedSubPath.append(ListRowKey.SEPARATOR_ESCAPE_CHAR);
+ }
+
+ escapedSubPath.append(ch);
+ }
+
+ builder.append(escapedSubPath.toString());
+ }
+
+ public String getPath() {
+ StringBuilder result = new StringBuilder();
+ Iterator<T> iterator = path.iterator();
+ boolean hasNext = iterator.hasNext();
+
+ while (hasNext) {
+ T segment = iterator.next();
+
+ if (segment instanceof ComplexTreeRowKey) {
+ ComplexTreeRowKey complexKey = (ComplexTreeRowKey) segment;
+
+ int segmentsCount = complexKey.getKeySegmentsCount();
+ for (int i = 0; i < segmentsCount; i++) {
+ appendSegment(result, complexKey.getKeySegment(i).toString());
+ if (i < segmentsCount - 1) {
+ result.append(AbstractTreeDataModel.SEPARATOR);
+ }
+ }
+
+ } else {
+ appendSegment(result, segment.toString());
+ }
+
+ hasNext = iterator.hasNext();
+
+ if (hasNext) {
+ result.append(AbstractTreeDataModel.SEPARATOR);
+ }
+ }
+
+ return result.toString();
+ }
+
+ public int getCommonPathLength(TreeRowKey<T> otherRowKey) {
+ if (otherRowKey == null)
+ return 0;
+ Iterator<T> iterator = this.iterator();
+ Iterator<T> otherIterator = otherRowKey.iterator();
+ int length = 0;
+ while (iterator.hasNext() && otherIterator.hasNext()
+ && iterator.next().equals(otherIterator.next()))
+ length++;
+ return length;
+ }
+
+ public T get(int i) {
+ return path.get(i);
+ }
+
+ private static final String SEPARATOR = "(?<!" +
ListRowKey.SEPARATOR_ESCAPE_CHAR + ")\\"
+ + NamingContainer.SEPARATOR_CHAR;
+
+ public static String[] fromString(String keyString) {
+ String[] split = keyString.split(SEPARATOR);
+ for (int i = 0; i < split.length; i++) {
+ //TODO exception if not escaped properly
+ split[i] = split[i].replaceAll("_(:|_)", "$1");
+ }
+
+ return split;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(Arrays.toString(fromString("test_:abc:123:a__b")));
+ }
+
+ @Override
+ public TreeRowKey<T> getParentKey() {
+ int toIdx = path.size() - 1;
+ TreeRowKey<T> result = null;
+
+ if (toIdx >= 0) {
+ result = new ListRowKey<T>(new ArrayList<T>(path.subList(0, toIdx)));
+ }
+
+ return result;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/MapDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/MapDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/MapDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/MapDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,240 @@
+/**
+ * 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.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski mailto:nbelaevski@exadel.com created 30.07.2007
+ */
+public class MapDataModel extends ExtendedDataModel implements ConvertableKeyModel {
+
+ private Map<Object, Object> map;
+ private Object rowKey;
+ private Object wrappedData;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+
+ public void setRowKey(Object key) {
+ this.rowKey = key;
+ }
+
+ /*
+ * (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 {
+ if (map != null) {
+ for (Iterator<Object> iterator = map.keySet().iterator(); iterator.hasNext();)
{
+ Object key = (Object) iterator.next();
+
+ visitor.process(context, key, argument);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+
+ public int getRowCount() {
+ return map != null ? map.size() : 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+
+ public Object getRowData() {
+ return map != null ? map.get(rowKey) : null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+
+ public int getRowIndex() {
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ return wrappedData;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return map != null && map.containsKey(rowKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ this.wrappedData = data;
+ if (data instanceof NamedNodeMap) {
+ this.map = new AbstractMap<Object, Object>() {
+
+ private Set<Entry<Object, Object>> entrySet = new
AbstractSet<Entry<Object, Object>>() {
+
+ public Iterator<Entry<Object, Object>> iterator() {
+ return new Iterator<Entry<Object, Object>>() {
+ private int index = 0;
+
+ public boolean hasNext() {
+ return index < ((NamedNodeMap) getWrappedData()).getLength();
+ }
+
+ public Entry<Object, Object> next() {
+ final Node node = ((NamedNodeMap) getWrappedData()).item(index++);
+ if (node == null) {
+ throw new NoSuchElementException();
+ } else {
+ return new Map.Entry<Object, Object>() {
+
+ public Object getKey() {
+ return node.getNodeName();
+ }
+
+ public Object getValue() {
+ return node;
+ }
+
+ public Object setValue(Object arg0) {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public int size() {
+ return ((NamedNodeMap) getWrappedData()).getLength();
+ }
+
+ };
+
+ public boolean containsKey(Object key) {
+ return ((NamedNodeMap) getWrappedData()).getNamedItem((String) key) != null;
+ }
+
+ public Object get(Object key) {
+ return ((NamedNodeMap) getWrappedData()).getNamedItem((String) key);
+ }
+
+ public Set<Entry<Object, Object>> entrySet() {
+ return entrySet;
+ }
+
+ };
+ } else if (data != null) {
+ this.map = (Map<Object, Object>) data;
+ } else {
+ this.map = null;
+ }
+ }
+
+ public Object getKeyAsObject(FacesContext context, String key, UIComponent component,
Converter converter) {
+ if (this.map != null) {
+ if (this.map.containsKey(key)) {
+ return key;
+ } else {
+ Set<Entry<Object,Object>> set = this.map.entrySet();
+ for (Entry<Object, Object> entry : set) {
+ Object keyObject = entry.getKey();
+ if (key.equals(keyObject.toString())) {
+ return keyObject;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SequenceDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SequenceDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SequenceDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SequenceDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,171 @@
+/**
+ * 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.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.w3c.dom.NodeList;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class SequenceDataModel extends ExtendedDataModel implements ConvertableKeyModel
{
+
+ private Object wrappedData;
+ private List list;
+ private Integer key;
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ return key;
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ public void setRowKey(Object key) {
+ this.key = (Integer) key;
+ }
+
+ /* (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 {
+
+ if (list != null) {
+ int i = 0;
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ iterator.next();
+
+ visitor.process(context, new Integer(i), argument);
+
+ i++;
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ return list != null ? list.size() : 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public Object getRowData() {
+ return (list != null && key != null) ? list.get(key.intValue()) : null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ public int getRowIndex() {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ return wrappedData;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return list != null && key != null && list.size() > key.intValue();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ this.wrappedData = data;
+ if (data instanceof List) {
+ this.list = (List) data;
+ } else if (data instanceof Collection) {
+ this.list = new ArrayList((Collection) data);
+ //copying all collection content into new collection here should prevent us
+ //from possible issues caused by iteration tricks. e.g.: returning custom iterator
+ //caching current element and comparing indices inside get()
+ //
+ //possible concurrent collection modifications and multithreading will break the
magic
+ } else if (data instanceof NodeList) {
+ this.list = new AbstractList() {
+
+ public Object get(int index) {
+ return ((NodeList) getWrappedData()).item(index);
+ }
+
+ public int size() {
+ return ((NodeList) getWrappedData()).getLength();
+ }
+
+ };
+ } else if (data instanceof Object[]) {
+ this.list = Arrays.asList((Object[]) data);
+ } else if (data != null) {
+ this.list = Collections.singletonList(data);
+ } else {
+ this.list = null;
+ }
+ }
+
+ public Object getKeyAsObject(FacesContext context, String keyString, UIComponent
component, Converter converter) {
+ int key = Integer.parseInt(keyString);
+ if (key >= 0 && this.list != null && key < this.list.size())
{
+ return key;
+ } else {
+ return null;
+ }
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingCacheableTreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SwingCacheableTreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingCacheableTreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingCacheableTreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,77 @@
+/**
+ * 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.model;
+
+import javax.swing.tree.TreeNode;
+
+/**
+ * {@link CacheableTreeDataModel} implementation for Swing {@link TreeNode} instances
+ *
+ * Created 01.11.2007
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class SwingCacheableTreeDataModel extends CacheableTreeDataModel<TreeNode>
{
+
+ private static final MissingNodeHandler<TreeNode> missingNodeHandler = new
MissingNodeHandler<TreeNode>() {
+
+ public TreeNode handleMissingNode(TreeNode parent,
+ Object pathSegment) {
+
+ SwingTreeNodeImpl childNode = new CacheableSwingTreeNodeImpl();
+
+ if (parent != null) {
+ SwingTreeNodeImpl parentNode = (SwingTreeNodeImpl) parent;
+
+ parentNode.addChild(pathSegment, childNode);
+ childNode.setParent(parentNode);
+ }
+
+ return childNode;
+ }
+
+ };
+
+ public SwingCacheableTreeDataModel(TreeDataModel<TreeNode> model) {
+ super(model, missingNodeHandler);
+ }
+
+ @Override
+ public Object getRowData() {
+ SwingTreeNodeImpl swingTreeNodeImpl = ((SwingTreeNodeImpl) super.getRowData());
+ if (swingTreeNodeImpl != null) {
+ return swingTreeNodeImpl.getData();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected void setDefaultNodeData(TreeNode node, Object data) {
+ CacheableSwingTreeNodeImpl cacheableTreeNode = (CacheableSwingTreeNodeImpl) node;
+ cacheableTreeNode.setData(data);
+ cacheableTreeNode.setNotLeaf(!isLeaf());
+ }
+}
+
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,110 @@
+/**
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.swing.tree.TreeNode;
+
+/**
+ * {@link TreeDataModel} implementation for classic {@link TreeNode} instances
+ *
+ * Created 01.11.2007
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class SwingTreeDataModel extends TreeDataModel<TreeNode> {
+
+ private TreeNode treeNode;
+
+ public SwingTreeDataModel() {
+ super(TreeNode.class, TreeDataModelNodeAdaptor.swingTreeNodeAdaptor, null);
+ }
+
+ @Override
+ protected TreeNode getData() {
+ return treeNode;
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ if (data != null) {
+ SwingTreeNodeImpl treeNodeImpl = new SwingTreeNodeImpl();
+
+ if (data instanceof Collection<?>) {
+ Collection<?> collection = (Collection<?>) data;
+
+ for (Iterator<?> iterator = collection.iterator(); iterator
+ .hasNext();) {
+ treeNodeImpl.addChild((TreeNode) iterator.next());
+ }
+ } else if (data.getClass().isArray()) {
+ Object[] nodes = (Object[]) data;
+ for (int i = 0; i < nodes.length; i++) {
+ treeNodeImpl.addChild((TreeNode) nodes[i]);
+ }
+ } else {
+ treeNodeImpl.addChild((TreeNode) data);
+ }
+
+ this.treeNode = treeNodeImpl;
+ } else {
+ this.treeNode = null;
+ }
+
+ super.setWrappedData(data);
+ }
+
+
+ @Override
+ public Object convertToKey(FacesContext context, String keyString, UIComponent
component, Converter converter) {
+ String[] strings = ListRowKey.fromString(keyString);
+ List<Integer> list = new ArrayList<Integer>(strings.length);
+ TreeNode node = this.treeNode;
+
+ if (node != null) {
+ TreeDataModelNodeAdaptor<TreeNode> adaptor = getNodeAdaptor();
+
+ for (int i = 0; i < strings.length; i++) {
+ int key = Integer.parseInt(strings[i]);
+
+ node = adaptor.getChild(node, key);
+ if (node != null) {
+ list.add(key);
+ } else {
+ return null;
+ }
+ }
+ }
+
+ return new ListRowKey<Integer>(list);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,145 @@
+/**
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.tree.TreeNode;
+
+/**
+ * Map-based Swing {@link TreeNode} implementation
+ *
+ * Created 01.11.2007
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+@Deprecated
+public class SwingTreeNodeImpl implements TreeNode {
+
+ private List<TreeNode> children = new ArrayList<TreeNode>();
+
+ private TreeNode parent;
+
+ private Object data;
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#children()
+ */
+ public Enumeration children() {
+ return new Enumeration() {
+ private Iterator<?> iterator = children.iterator();
+
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+
+ public Object nextElement() {
+ return iterator.next();
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getAllowsChildren()
+ */
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ public void setAllowsChildren(boolean allowsChildren) {
+ if (!allowsChildren) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getChildAt(int)
+ */
+ public TreeNode getChildAt(int childIndex) {
+ return children.get(childIndex);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getChildCount()
+ */
+ public int getChildCount() {
+ return children.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
+ */
+ public int getIndex(TreeNode node) {
+ return children.indexOf(node);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#getParent()
+ */
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.tree.TreeNode#isLeaf()
+ */
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ public void addChild(TreeNode node) {
+ children.add(node);
+ }
+
+ public void addChild(Object key, TreeNode node) {
+ if (Integer.valueOf(children.size()).equals(key)) {
+ children.add(node);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public void removeChild(TreeNode node) {
+ this.children.remove(node);
+ }
+
+ public void removeChildByKey(Object key) {
+ this.children.remove(((Integer) key).intValue());
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeDataModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeDataModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeDataModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeDataModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,401 @@
+/**
+ * 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.model;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski - nbelaevski(a)exadel.com created 16.11.2006
+ *
+ */
+public abstract class TreeDataModel<T> extends AbstractTreeDataModel {
+
+ private Object wrappedData;
+ private Class<T> clazz;
+
+ private TreeRowKey currentRowKey;
+
+ private TreeRowKey oldRowKey;
+
+ private Boolean rowAvailable = Boolean.FALSE;
+ private T rowTreeData;
+
+ protected final TreeDataModelNodeAdaptor<T> nodeAdaptor;
+
+ private MissingNodeHandler<T> missingNodeHandler;
+
+ /**
+ * Interface aimed to handle missing nodes for externally-generated keys.
+ * Typical usage for the interface is filling model cache
+ * @param <T> generic tree node type
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+ public static interface MissingNodeHandler<T> {
+ T handleMissingNode(T parentNode, Object pathSegment);
+ };
+
+ public TreeDataModel(Class<T> clazz, TreeDataModelNodeAdaptor<T>
nodeAdaptor,
+ MissingNodeHandler<T> missingNodeHandler) {
+
+ this.clazz = clazz;
+ this.nodeAdaptor = nodeAdaptor;
+ this.missingNodeHandler = missingNodeHandler;
+ }
+
+ public final Class<T> getClazz() {
+ return clazz;
+ }
+
+ public final TreeDataModelNodeAdaptor<T> getNodeAdaptor() {
+ return nodeAdaptor;
+ }
+
+ public Object getRowKey() {
+ return this.currentRowKey;
+ }
+
+ public void setRowKey(Object rowKey) {
+ if (rowKey != null) {
+ ListRowKey newRowKey = (ListRowKey) rowKey;
+ this.currentRowKey = newRowKey;
+ this.rowAvailable = null;
+ } else {
+ this.currentRowKey = null;
+ this.oldRowKey = null;
+ this.rowTreeData = null;
+ this.rowAvailable = Boolean.FALSE;
+ }
+ }
+
+ protected void doWalk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument, boolean last) throws IOException {
+ ListRowKey listRowKey = (ListRowKey) rowKey;
+
+ T node = locateTreeNode(listRowKey);
+
+ if (node != null) {
+ TreeRange treeRange = (TreeRange) range;
+
+ if (treeRange == null || treeRange.processNode(listRowKey)) {
+
+ //root node is not processed, it is considered fake for this class of models
+ if (listRowKey != null && listRowKey.depth() > 0) {
+ processElement(context, dataVisitor, argument, listRowKey, last);
+ }
+
+ if (treeRange == null || treeRange.processChildren(listRowKey)) {
+ if (!nodeAdaptor.isLeaf(node)) {
+ Iterator<Map.Entry<Object, T>> children =
nodeAdaptor.getChildren(node);
+
+ if (children != null) {
+ Map.Entry<Object, T> childEntry = children.hasNext() ? children.next() :
null;
+ T childNode;
+ Object identifier;
+
+ if (childEntry != null) {
+ childNode = childEntry.getValue();
+ identifier = childEntry.getKey();
+ } else {
+ childNode = null;
+ identifier = null;
+ }
+
+ do {
+ Map.Entry<Object, T> nextChildEntry = children.hasNext() ? children.next()
: null;
+ T nextChildNode;
+ Object nextIdentifier;
+
+ if (nextChildEntry != null) {
+ //TODO consider lazy initialization of value
+ nextChildNode = nextChildEntry.getValue();
+ nextIdentifier = nextChildEntry.getKey();
+ } else {
+ nextChildNode = null;
+ nextIdentifier = null;
+ }
+
+ if (childNode != null) {
+
+ boolean isLast = nextChildNode == null;
+
+ ListRowKey newRowKey = new ListRowKey(listRowKey, identifier);
+ this.doWalk(context, dataVisitor, range, newRowKey, argument, isLast);
+ }
+
+ identifier = nextIdentifier;
+ childNode = nextChildNode;
+ } while (childNode != null);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public void walk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument, boolean last) throws IOException {
+
+ if (rowKey != null) {
+ setRowKey(rowKey);
+ if (!isRowAvailable()) {
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+ }
+
+ doWalk(context, dataVisitor, range, rowKey, argument, last);
+ }
+
+ public T locateTreeNode(TreeRowKey rowKey) {
+ return locateTreeNode(rowKey, false);
+ }
+
+ public T locateTreeNode(TreeRowKey rowKey, boolean allowCreate) {
+ T tmpRowTreeData = this.rowTreeData;
+ TreeRowKey tmpOldRowKey = this.oldRowKey;
+
+ boolean useCached = (rowTreeData != null && rowKey != null &&
rowKey.equals(tmpOldRowKey));
+ if (!useCached) {
+ T rootNode = getData();
+
+ if (rootNode != null) {
+ if (rowKey != null) {
+ int commonPathLength = rowKey.getCommonPathLength(tmpOldRowKey);
+ if (tmpOldRowKey == null) {
+ tmpRowTreeData = rootNode;
+ } else {
+ int rootOpsCount = rowKey.depth();
+ int currentUpOpsCount = tmpOldRowKey.depth() - commonPathLength;
+ int currentOpsCount = currentUpOpsCount + rootOpsCount - commonPathLength;
+
+ if (rootOpsCount > currentOpsCount) {
+ for (int i = 0; i < tmpOldRowKey.depth()
+ - commonPathLength; i++) {
+
+ tmpRowTreeData = nodeAdaptor.getParent(tmpRowTreeData);
+ }
+ } else {
+ commonPathLength = 0;
+ tmpRowTreeData = rootNode;
+ tmpOldRowKey = null;
+ }
+ }
+ tmpOldRowKey = rowKey;
+ Iterator<?> iterator = rowKey.getSubPathIterator(commonPathLength);
+ while (iterator.hasNext()) {
+ //TODO nick - check rowTreeData for null
+
+ Object pathSegment = iterator.next();
+ T childRowTreeData = nodeAdaptor.getChild(tmpRowTreeData, pathSegment);
+
+ if (childRowTreeData == null) {
+ if (!allowCreate) {
+ //TODO nick - reset rowTreeData
+ return null;
+ } else {
+ if (missingNodeHandler != null) {
+ childRowTreeData = missingNodeHandler.
+ handleMissingNode(tmpRowTreeData, pathSegment);
+
+ if (childRowTreeData == null) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+ }
+
+ tmpRowTreeData = childRowTreeData;
+ }
+ } else {
+ return rootNode;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ // check whether we were found something and store it
+ if (tmpRowTreeData != null) {
+ rowTreeData = tmpRowTreeData;
+ oldRowKey = tmpOldRowKey;
+ }
+ return rowTreeData;
+ }
+
+ public boolean isRowAvailable() {
+ if (Boolean.FALSE.equals(rowAvailable)) {
+ return false;
+ }
+
+ T data = locateTreeNode(this.currentRowKey);
+
+ if (data != null) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public Object getRowData() {
+ if (isRowAvailable()) {
+ T treeNode = locateTreeNode(this.currentRowKey);
+ if (treeNode != null) {
+ return nodeAdaptor.getRowData(treeNode);
+ }
+
+ return null;
+ }
+
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ public boolean isLeaf() {
+ if (isRowAvailable()) {
+ T treeNode = locateTreeNode(this.currentRowKey);
+ if (treeNode != null) {
+ return nodeAdaptor.isLeaf(treeNode);
+ }
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ public void walkModel(FacesContext context, DataVisitor visitor, Range range, Object
key, Object argument, boolean last) throws IOException {
+ walk(context, visitor, range, key, argument, last);
+ }
+
+ @Override
+ public Object getWrappedData() {
+ return wrappedData;
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ this.wrappedData = data;
+ }
+
+ protected T getData() {
+ return clazz.cast(wrappedData);
+ }
+
+ public TreeNode<T> getTreeNode() {
+ return null;
+ }
+
+ /**
+ * Get row key for certain tree node object
+ *
+ * @param node to get key for
+ * @return node row key
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object getTreeNodeRowKey(Object node) {
+ if (node == null) {
+ throw new UnsupportedOperationException();
+ }
+
+ T childNode = (T) node;
+ List<Object> path = new LinkedList<Object>();
+ Object id = nodeAdaptor.getChildNodeId(childNode);
+ if (id != null) {
+ path.add(id);
+ }
+
+ T parentNode = childNode;
+ while ((parentNode = nodeAdaptor.getParent(parentNode)) != null) {
+ id = nodeAdaptor.getChildNodeId(parentNode);
+ if (id != null) {
+ path.add(0, id);
+ } else if (nodeAdaptor.getParent(parentNode) != null) {
+ throw new UnsupportedOperationException();
+ }
+ }
+ return new ListRowKey(path);
+ }
+
+ /**
+ * Get node local id in it's parent childs collection
+ *
+ * @param childNode node to get identifier for
+ * @return node local identifier
+ */
+ @Override
+ public Object getChildNodeId(Object childNode) {
+ return getNodeAdaptor().getChildNodeId((T) childNode);
+ }
+
+ @Override
+ public void addNode(Object parentRowKey, TreeNode newNode, Object id) {
+ addNode(parentRowKey, (Object) newNode, id);
+ }
+
+ public void addNode(Object parentRowKey, Object newNode, Object id) {
+ Object initialRowKey = getRowKey();
+ try {
+ T parentTreeNode = locateTreeNode((TreeRowKey) parentRowKey);
+
+ if (parentTreeNode == null) {
+ throw new IllegalArgumentException("Parent node not found!");
+ }
+
+ getNodeAdaptor().appendChild(parentTreeNode, id, clazz.cast(newNode));
+ } finally {
+ setRowKey(initialRowKey);
+ }
+ }
+
+ @Override
+ public void removeNode(Object rowKey) {
+ Object initialRowKey = getRowKey();
+ try {
+ T treeNode = locateTreeNode((TreeRowKey) rowKey);
+
+ if (treeNode == null) {
+ throw new IllegalArgumentException("Node not fond!");
+ }
+
+ getNodeAdaptor().removeFromParent(treeNode);
+ } finally {
+ setRowKey(initialRowKey);
+ }
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNode.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeNode.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNode.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNode.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,112 @@
+/**
+ * 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.model;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.component.NamingContainer;
+
+
+/**
+ * Interface representing tree ADT nodes
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 16.11.2006
+ */
+public interface TreeNode<T> extends Serializable{
+
+ /**
+ * getter for node attached data
+ * @return node attached data
+ */
+ public T getData();
+ /**
+ * setter for node attached data
+ * @param data data to set as attached node data
+ */
+ public void setData(T data);
+
+ /**
+ * Returns whether this node is leaf
+ * @return <code>true</code> if this node is leaf else returns
<code>false</code>
+ */
+ public boolean isLeaf();
+
+ /**
+ * Getter for children entries. Each children entry contains identifier (key) and child
node (value).
+ *
+ * Identifiers are used to generate model keys representing paths to tree node. Model
keys are used:
+ * <ol>
+ * <li>
+ * For persisting tree state. That means that identifiers should be serializable when
+ * some JSF features are used, e.g. client-side state saving.
+ * </li>
+ * <li>
+ * For constructing client identifiers. Client identifier for tree nodes consists of
+ * {@link Object#toString()} representations of identifier separated with
+ * {@link NamingContainer#SEPARATOR_CHAR} chars. String representation of identifier
+ * should be a valid XML ID, e.g. conform to this: <a
href="http://www.w3.org/TR/xml11/#NT-Name">
+ * XML Name Production</a>
+ * production.
+ * </li>
+ * </ol>
+ *
+ * @return {@link Iterator} of {@link Map.Entry} instances containing {@link TreeNode}
as values
+ * and their identifiers as keys.
+ *
+ */
+ public Iterator<Map.Entry<Object, TreeNode<T>>> getChildren();
+ /**
+ * find child by id
+ * Please see {@link #getChildren()} for more information about identifier constraints.
+ * @param id identifier of the child to find
+ * @return designated {@link TreeNode} instance or <code>null</code>
+ */
+ public TreeNode<T> getChild(Object id);
+
+ /**
+ * adds child to children collection
+ * @param identifier child identifier.
+ * Please see {@link #getChildren()} for more information about identifier constraints.
+ * @param child child
+ */
+ public void addChild(Object identifier, TreeNode<T> child);
+
+ /**
+ * Please see {@link #getChildren()} for more information about identifier constraints.
+ * removes child from children collection by child id
+ * @param id id of the child to remove
+ */
+ public void removeChild(Object id);
+
+ /**
+ * getter for parent {@link TreeNode}
+ * @return parent {@link TreeNode} instance or <code>null</code> if this
node is root
+ */
+ public TreeNode<T> getParent();
+ /**
+ * setter for parent {@link TreeNode}
+ * @param parent {@link TreeNode} to set as parent
+ */
+ public void setParent(TreeNode<T> parent);
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeNodeImpl.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeNodeImpl.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,84 @@
+/**
+ * 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.model;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Default {@link TreeNode} implementation based on {@link LinkedHashMap} to preserve
+ * elements ordering
+ *
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 16.11.2006
+ */
+public class TreeNodeImpl<T> implements TreeNode<T> {
+
+ private static final long serialVersionUID = -5498990493803705085L;
+ private T data;
+ private TreeNode<T> parent;
+
+ private Map<Object, TreeNode<T>> childrenMap =
+ new LinkedHashMap<Object, TreeNode<T>>();
+
+ public T getData() {
+ return data;
+ }
+
+ public TreeNode<T> getChild(Object identifier) {
+ return (TreeNode<T>) childrenMap.get(identifier);
+ }
+
+ public void addChild(Object identifier, TreeNode<T> child) {
+ child.setParent(this);
+ childrenMap.put(identifier, child);
+ }
+
+ public void removeChild(Object identifier) {
+ TreeNode<T> treeNode = childrenMap.remove(identifier);
+ if (treeNode != null) {
+ treeNode.setParent(null);
+ }
+ }
+
+ public void setData(T data) {
+ this.data = data;
+ }
+
+ public TreeNode<T> getParent() {
+ return parent;
+ }
+
+ public void setParent(TreeNode<T> parent) {
+ this.parent = parent;
+ }
+
+ public Iterator<Map.Entry<Object, TreeNode<T>>> getChildren() {
+ return childrenMap.entrySet().iterator();
+ }
+
+ public boolean isLeaf() {
+ return childrenMap.isEmpty();
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRange.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeRange.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRange.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRange.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,66 @@
+/**
+ * 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.model;
+
+import org.ajax4jsf.model.Range;
+
+/**
+ * {@link Range} implmentation variant for {@link AbstractTreeDataModel}
+ *
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 23.11.2006
+ */
+public interface TreeRange extends Range {
+
+ /**
+ * Returns <code>true</code> if node with that rowKey should be processed.
+ * If <code>false</code> is returned, then skips processing child nodes
also.
+ * @param rowKey {@link TreeRowKey} key instance
+ * @return <code>true</code> or <code>false</code>
+ */
+ public boolean processNode(TreeRowKey rowKey);
+
+ /**
+ * Returns <code>true</code> if children of the node with that rowKey should
be processed
+ * @param rowKey {@link TreeRowKey} key instance
+ * @return <code>true</code> or <code>false</code>
+ */
+ public boolean processChildren(TreeRowKey rowKey);
+
+
+ /**
+ * Unconstrained variant of {@link TreeRange}.
+ * Is stateless and safe to use in multi-threaded environments.
+ *
+ * @since 3.2.2
+ * @author Nick Belaevski
+ */
+ public final static TreeRange RANGE_UNCONSTRAINED = new TreeRange() {
+ public boolean processChildren(TreeRowKey rowKey) {
+ return true;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return true;
+ }
+ };
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRowKey.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeRowKey.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRowKey.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/main/java/org/richfaces/model/TreeRowKey.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,103 @@
+/**
+ * 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.model;
+
+import java.io.Serializable;
+import java.util.Iterator;
+
+/**
+ * Base abstract clas for all tree row keys
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 06.12.2006
+ */
+public abstract class TreeRowKey<T> implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7318192501938658798L;
+
+ public static final char SEPARATOR_ESCAPE_CHAR = '_';
+
+ /**
+ * getter for key depth
+ * @return key depth
+ */
+ public abstract int depth();
+
+ /**
+ * getter for subpath iterator
+ * @param fromIndex
+ * @return subpath segments iterator
+ */
+ public abstract Iterator<T> getSubPathIterator(int fromIndex);
+
+ /**
+ * getter for path string representation
+ * @return path string
+ */
+ public abstract String getPath();
+
+ public String toString() {
+ return getPath();
+ }
+
+ /**
+ * tests if specified rowKey is sub-key of this row key
+ * @param rowKey
+ * @return
+ */
+ public boolean isSubKey(TreeRowKey<T> rowKey) {
+ if (rowKey == null) {
+ return false;
+ }
+
+ String otherPath = rowKey.getPath();
+ String path = getPath();
+
+ if (otherPath.startsWith(path)) {
+ return otherPath.length() == path.length() ||
+ otherPath.charAt(path.length()) == AbstractTreeDataModel.SEPARATOR;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * getter for path iterator
+ * @return path segments iterator
+ */
+ public abstract Iterator<T> iterator();
+
+ /**
+ * returns this row key and otherRowKey argument row key common path segments count
+ * @param otherRowKey {@link TreeRowKey} to count common path segments for
+ * @return common path segmments count
+ */
+ public abstract int getCommonPathLength(TreeRowKey<T> otherRowKey);
+
+ public abstract TreeRowKey<T> getParentKey();
+
+ public TreeRowKey<T> getSubKey(int fromIndex) {
+ throw new UnsupportedOperationException();
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/ClassicTreeModelKeyConversionTest.java
(from rev 14980,
root/framework/trunk/api/src/test/java/org/richfaces/model/ClassicTreeModelKeyConversionTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/ClassicTreeModelKeyConversionTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/ClassicTreeModelKeyConversionTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,142 @@
+/**
+ * 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.model;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+/**
+ * Created 26.08.2008
+ * @author Nick Belaevski
+ * @since 3.2.2
+ */
+
+public class ClassicTreeModelKeyConversionTest extends TestCase {
+
+ private ClassicTreeDataModel dataModel;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ dataModel = new ClassicTreeDataModel();
+
+ TreeNodeImpl<String> rootNode = new TreeNodeImpl<String>();
+
+ TreeNodeImpl<String> node;
+
+ node = new TreeNodeImpl<String>();
+ node.addChild("0", new TreeNodeImpl<String>());
+ node.addChild("1", new TreeNodeImpl<String>());
+ for (int i = 2; i < 5; i++) {
+ node.addChild(Long.valueOf(i), new TreeNodeImpl<String>());
+ }
+ rootNode.addChild("6", node);
+
+ node = new TreeNodeImpl<String>();
+ for (int i = 0; i < 3; i++) {
+ node.addChild(Integer.valueOf(i), new TreeNodeImpl<String>());
+ }
+ rootNode.addChild("abc_cde:fgh", node);
+
+ dataModel.setWrappedData(rootNode);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ dataModel = null;
+ }
+
+ public void testEmptyString() throws Exception {
+ TreeRowKey<Object> key = (TreeRowKey<Object>) dataModel.convertToKey(null,
"", null, null);
+ assertNull(key);
+ }
+
+ public void testStraightWayShort() throws Exception {
+ TreeRowKey<Object> key = (TreeRowKey<Object>) dataModel.convertToKey(null,
"6", null, null);
+ assertNotNull(key);
+
+ Iterator<Object> iterator = key.iterator();
+ assertEquals("6", iterator.next());
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testStraightWay() throws Exception {
+ TreeRowKey<Object> key = (TreeRowKey<Object>) dataModel.convertToKey(null,
"6:1", null, null);
+ assertNotNull(key);
+
+ Iterator<Object> iterator = key.iterator();
+ assertEquals("6", iterator.next());
+ assertEquals("1", iterator.next());
+ assertFalse(iterator.hasNext());
+
+ key = (TreeRowKey<Object>) dataModel.convertToKey(null, "6:1", null,
null);
+ assertNotNull(key);
+
+ iterator = key.iterator();
+ assertEquals("6", iterator.next());
+ assertEquals("1", iterator.next());
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testSearch() throws Exception {
+ TreeRowKey<Object> key = (TreeRowKey<Object>) dataModel.convertToKey(null,
"6:4", null, null);
+ assertNotNull(key);
+
+ Iterator<Object> iterator = key.iterator();
+ assertEquals("6", iterator.next());
+ assertEquals(Long.valueOf(4), iterator.next());
+ assertFalse(iterator.hasNext());
+
+ }
+
+ public void testSearchMissing() throws Exception {
+ assertNull(dataModel.convertToKey(null, "6:10", null, null));
+ assertNull(dataModel.convertToKey(null, "7", null, null));
+ }
+
+ public void testUnescape() throws Exception {
+ TreeRowKey<Object> key = (TreeRowKey<Object>) dataModel.convertToKey(null,
"abc__cde_:fgh:1", null, null);
+ assertNotNull(key);
+
+ Iterator<Object> iterator = key.iterator();
+ assertEquals("abc_cde:fgh", iterator.next());
+ assertEquals(Integer.valueOf(1), iterator.next());
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testUnescapeShort() throws Exception {
+ TreeRowKey<Object> key = (TreeRowKey<Object>) dataModel.convertToKey(null,
"abc__cde_:fgh", null, null);
+ assertNotNull(key);
+
+ Iterator<Object> iterator = key.iterator();
+ assertEquals("abc_cde:fgh", iterator.next());
+ assertFalse(iterator.hasNext());
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/SwingTreeModelKeyConversionTest.java
(from rev 14980,
root/framework/trunk/api/src/test/java/org/richfaces/model/SwingTreeModelKeyConversionTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/SwingTreeModelKeyConversionTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree/api/src/test/java/org/richfaces/model/SwingTreeModelKeyConversionTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,109 @@
+/**
+ * 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.model;
+
+import java.util.Iterator;
+
+import javax.swing.tree.TreeNode;
+
+import junit.framework.TestCase;
+
+/**
+ * Created 26.08.2008
+ * @author Nick Belaevski
+ * @since 3.2.2
+ */
+
+public class SwingTreeModelKeyConversionTest extends TestCase {
+
+ private SwingTreeDataModel dataModel;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ dataModel = new SwingTreeDataModel();
+
+ //1
+ SwingTreeNodeImpl node = new SwingTreeNodeImpl();
+ //1:0
+ node.addChild(new SwingTreeNodeImpl());
+ //1:1
+ node.addChild(new SwingTreeNodeImpl());
+ //1:2
+ node.addChild(new SwingTreeNodeImpl());
+
+ dataModel.setWrappedData(new TreeNode[] {
+ new SwingTreeNodeImpl(), node
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ dataModel = null;
+ }
+
+ public void testEmptyString() throws Exception {
+ //TODO make it work
+// Object key = dataModel.convertToKey(null, "", null, null);
+// assertNull(key);
+ }
+
+ public void testStraightWay() throws Exception {
+ TreeRowKey<Integer> key;
+ Iterator<Integer> iterator;
+
+ key = (TreeRowKey<Integer>) dataModel.convertToKey(null, "0", null,
null);
+ iterator = key.iterator();
+ assertEquals(Integer.valueOf(0), iterator.next());
+ assertFalse(iterator.hasNext());
+
+ key = (TreeRowKey<Integer>) dataModel.convertToKey(null, "1", null,
null);
+ iterator = key.iterator();
+ assertEquals(Integer.valueOf(1), iterator.next());
+ assertFalse(iterator.hasNext());
+
+ key = (TreeRowKey<Integer>) dataModel.convertToKey(null, "1:0", null,
null);
+ iterator = key.iterator();
+ assertEquals(Integer.valueOf(1), iterator.next());
+ assertEquals(Integer.valueOf(0), iterator.next());
+ assertFalse(iterator.hasNext());
+
+ key = (TreeRowKey<Integer>) dataModel.convertToKey(null, "1:2", null,
null);
+ iterator = key.iterator();
+ assertEquals(Integer.valueOf(1), iterator.next());
+ assertEquals(Integer.valueOf(2), iterator.next());
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testMissingNodes() throws Exception {
+ assertNull(dataModel.convertToKey(null, "2", null, null));
+ assertNull(dataModel.convertToKey(null, "0:3", null, null));
+ }
+}
+
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/StackingTreeModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,615 @@
+/**
+ * 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.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.iterators.FilterIterator;
+import org.w3c.dom.NamedNodeMap;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski mailto:nbelaevski@exadel.com created 25.07.2007
+ *
+ */
+public class StackingTreeModel extends AbstractTreeDataModel {
+
+ //ctor arguments
+ private String id;
+ private String var;
+ private StackingTreeModelDataProvider dataProvider;
+
+ //structural elements
+ private StackingTreeModel parent;
+ private Map<String, StackingTreeModel> models = new LinkedHashMap<String,
StackingTreeModel>();
+
+ private Object rowKey;
+
+ private class StackEntry {
+ private Object modelKey;
+ private Object varObject;
+ private StackingTreeModel model;
+ private Object rowData;
+
+ public StackEntry(Object varObject, Object modelKey, Object rowData, StackingTreeModel
model) {
+ super();
+ this.varObject = varObject;
+ this.modelKey = modelKey;
+ this.rowData = rowData;
+ this.model = model;
+ }
+ }
+
+// private StackingTreeModel stackingTreeModel;
+ private LinkedList<StackEntry> stackEntries = new LinkedList<StackEntry>();
+
+ public ExtendedDataModel getDataModel() {
+ Object data = dataProvider.getData();
+ ExtendedDataModel dataModel;
+ if (data instanceof Map || data instanceof NamedNodeMap) {
+ dataModel = new MapDataModel();
+ } else {
+ dataModel = new SequenceDataModel();
+ }
+
+ dataModel.setWrappedData(data);
+ return dataModel;
+ }
+
+ protected StackingTreeModel getCurrentModel() {
+ if (this.rowKey == null) {
+ return this;
+ }
+
+ if (isRowAvailable()) {
+ return ((StackEntry) stackEntries.getLast()).model;
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ public boolean isEmpty() {
+ //TODO optimize that
+ return getDataModel().getRowCount() == 0;
+ }
+
+ private void leaveModel(Iterator<StackEntry> iterator, StackEntry currentEntry,
FacesContext context) {
+ if (iterator == null) {
+ return ;
+ }
+
+ LinkedList<StackEntry> stack = new LinkedList<StackEntry>();
+
+ StackingTreeModel lastModel = null;
+ if (currentEntry != null) {
+ iterator.remove();
+ stack.addFirst(currentEntry);
+ lastModel = currentEntry.model;
+ }
+
+ while (iterator.hasNext()) {
+ StackEntry entry = (StackEntry) iterator.next();
+ if (entry.model != lastModel) {
+ //always true for non-recursive models
+ lastModel = entry.model;
+ stack.addFirst(entry);
+ }
+
+ iterator.remove();
+ }
+
+ for (Iterator<StackEntry> iterator2 = stack.iterator(); iterator2.hasNext();) {
+ StackEntry stackEntry = (StackEntry) iterator2.next();
+ stackEntry.model.setupVariable(stackEntry.varObject, context);
+ }
+ }
+
+ protected StackingTreeModel doSetupKey(Iterator<StackingTreeModelKey> keyIterator,
Iterator<StackEntry> entriesIterator, FacesContext context, Object modelKey) {
+ if (modelKey != null) {
+ if (!setupModel(modelKey, context)) {
+ //no key is available
+ leaveModel(getRoot().stackEntries.iterator(), null, context);
+ return null;
+ }
+
+ //TODO what's here?
+ }
+
+ if (keyIterator != null && keyIterator.hasNext()) {
+ StackingTreeModelKey key = keyIterator.next();
+ StackingTreeModel stackingTreeModel = this.getInternalModelById(key.modelId);
+ Iterator<StackEntry> nextEntriesIterator = null;
+ Object nextModelKey = key.modelKey;
+
+ if (entriesIterator != null && entriesIterator.hasNext()) {
+ StackEntry entry = entriesIterator.next();
+ if (!entry.model.equals(stackingTreeModel) || !entry.modelKey.equals(nextModelKey))
{
+ leaveModel(entriesIterator, entry, context);
+ } else {
+ //continue iterating entries, they still lead us by key path
+ nextEntriesIterator = entriesIterator;
+ nextModelKey = null;
+ }
+ }
+
+ //should not be called when nextEntriesIterator & nextModelKey are both valid
+ return stackingTreeModel.doSetupKey(keyIterator, nextEntriesIterator, context,
nextModelKey);
+
+ } else {
+ leaveModel(entriesIterator, null, context);
+ return this;
+ }
+ }
+
+ protected StackingTreeModel setupKey(Object key, FacesContext context) {
+ if (key == this.rowKey) {
+ if (stackEntries.isEmpty()) {
+ return this;
+ } else {
+ return (stackEntries.getLast()).model;
+ }
+ } else {
+ Iterator<StackingTreeModelKey> keyIterator = null;
+ if (key != null) {
+ keyIterator = ((ListRowKey<StackingTreeModelKey>) key).iterator();
+ }
+
+ StackingTreeModel model = doSetupKey(keyIterator, stackEntries.iterator(), context,
null);
+ this.rowKey = key;
+
+ return model;
+ }
+ }
+
+ public StackingTreeModel(String id, String var, StackingTreeModelDataProvider
dataProvider) {
+ super();
+ this.id = id;
+ this.var = var;
+ this.dataProvider = dataProvider;
+ }
+
+ public StackingTreeModel() {
+ this(null, null, null);
+ }
+
+ private Object setupVariable(Object variable, FacesContext context) {
+ if (var != null) {
+ Map<String, Object> map = context.getExternalContext().getRequestMap();
+ return map.put(var, variable);
+ }
+
+ return null;
+ }
+
+ public boolean setupModel(Object key, FacesContext facesContext) {
+ ExtendedDataModel dataModel = getDataModel();
+ dataModel.setRowKey(key);
+
+ if (dataModel.isRowAvailable()) {
+ Object rowData = dataModel.getRowData();
+ //System.out.println("StackingTreeModel.setupModel() " + rowData);
+ Object varObject = setupVariable(rowData, facesContext);
+
+ getRoot().stackEntries.add(new StackEntry(varObject, key, rowData, this));
+
+ return true;
+ }
+
+ return false;
+ }
+
+ public void setParent(StackingTreeModel parent) {
+ this.parent = parent;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.model.AbstractTreeDataModel#getTreeNode()
+ */
+ public TreeNode getTreeNode() {
+ if (isRowAvailable()) {
+ return null;
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.model.AbstractTreeDataModel#isLeaf()
+ */
+ public boolean isLeaf() {
+ if (isRowAvailable()) {
+ StackEntry lastEntry = (StackEntry) stackEntries.getLast();
+ for (Iterator<StackingTreeModel> iterator =
lastEntry.model.getInternalModelsIterator(); iterator.hasNext();) {
+ StackingTreeModel stackingTreeModel = iterator.next();
+
+ if (!stackingTreeModel.isEmpty()) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ protected StackingTreeModel getRoot() {
+ if (parent != null) {
+ return parent.getRoot();
+ }
+
+ return this;
+ }
+
+ protected void doWalk(FacesContext context, DataVisitor dataVisitor,
+ Range range, ListRowKey argumentKey, Object argument,
+ boolean last) throws IOException {
+
+ TreeRange treeRange = (TreeRange) range;
+
+ if (treeRange == null || treeRange.processNode(argumentKey)) {
+ StackingTreeModel rootModel = getRoot();
+
+ if (argumentKey != null) {
+ processElement(context, dataVisitor, argument, argumentKey, last);
+ }
+
+ final ShiftingDataVisitor shiftingDataVisitor = new ShiftingDataVisitor(
+ new Visitor1(dataVisitor));
+
+ if (treeRange == null || treeRange.processChildren(argumentKey)) {
+
+ Object savedRowKey = rootModel.getRowKey();
+ //setup key in order for nested components to initialize data models
+ rootModel.setRowKey(context, argumentKey);
+ Iterator<StackingTreeModel> iterator = this.getInternalModelsIterator();
+ rootModel.setRowKey(context, savedRowKey);
+
+ while (iterator.hasNext()) {
+ final StackingTreeModel model = iterator.next();
+
+ savedRowKey = rootModel.getRowKey();
+ rootModel.setRowKey(context, argumentKey);
+ final ExtendedDataModel scalarModel = model.getDataModel();
+ rootModel.setRowKey(context, savedRowKey);
+
+ Argument argument2 = new Argument();
+ argument2.listRowKey = argumentKey;
+ argument2.argument = argument;
+ // setup current model
+ argument2.model = model;
+ argument2.range = range;
+
+ scalarModel.walk(context, new DataVisitor() {
+
+ public void process(FacesContext context,
+ Object rowKey, Object argument)
+ throws IOException {
+
+ Object key = scalarModel.getRowKey();
+ scalarModel.setRowKey(rowKey);
+ Object data = scalarModel.getRowData();
+
+ Object variable = model.setupVariable(data, context);
+ boolean activeData = model.isActiveData();
+ model.setupVariable(variable, context);
+ scalarModel.setRowKey(key);
+
+ if (activeData) {
+ shiftingDataVisitor.process(context, rowKey, argument);
+ }
+ }
+
+ }, null, argument2);
+
+ }
+ }
+
+ shiftingDataVisitor.end(context);
+ }
+ }
+
+ private StackingTreeModel getInternalModelById(String id) {
+ StackingTreeModel model = getModelById(id);
+ if (model.isActive()) {
+ return model;
+ }
+
+ throw new IllegalStateException();
+ }
+
+ public StackingTreeModel getModelById(String id) {
+ return (StackingTreeModel) models.get(id);
+ }
+
+ private Iterator<StackingTreeModel> getInternalModelsIterator() {
+ return new FilterIterator(getModelsIterator(), ACTIVE_MODEL_PREDICATE);
+ }
+
+ public Iterator<StackingTreeModel> getModelsIterator() {
+ return models.values().iterator();
+ }
+
+ public void walk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument,
+ boolean last) throws IOException {
+ StackingTreeModel rootModel = getRoot();
+
+ if (rowKey != null) {
+ ListRowKey listRowKey = (ListRowKey) rowKey;
+
+ StackingTreeModel treeModel = rootModel.setupKey(listRowKey, context);
+
+ treeModel.doWalk(context, dataVisitor, range, listRowKey, argument,
+ last);
+
+ } else {
+ doWalk(context, dataVisitor, range,
+ (ListRowKey) rowKey, argument, last);
+ }
+ }
+
+ private class Argument {
+ private ListRowKey listRowKey;
+ private StackingTreeModel model;
+ private Range range;
+ private Object argument;
+ }
+
+ private class Visitor1 implements DataVisitor, LastElementAware {
+ private DataVisitor dataVisitor;
+ private boolean theLast;
+
+ public Visitor1(DataVisitor dataVisitor) {
+ super();
+ this.dataVisitor = dataVisitor;
+ }
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ Argument a = (Argument) argument;
+ ListRowKey listRowKey = new ListRowKey(a.listRowKey, new StackingTreeModelKey(
+ a.model.id, rowKey));
+ //System.out.println(".walk() " + (theLast ? " * " : "")
+ listRowKey);
+
+ a.model.doWalk(context, dataVisitor, a.range, listRowKey, a.argument,
+ theLast);
+ }
+
+ public void resetLastElement() {
+ theLast = false;
+ }
+
+ public void setLastElement() {
+ theLast = true;
+ }
+
+ }
+
+ private static class ShiftingDataVisitor implements DataVisitor {
+
+ private DataVisitor dataVisitor;
+
+ public ShiftingDataVisitor(DataVisitor dataVisitor) {
+ super();
+ this.dataVisitor = dataVisitor;
+ }
+
+ private Object rowKey;
+ private Object argument;
+ private boolean shifted = false;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ if (!shifted) {
+ this.rowKey = rowKey;
+ this.argument = argument;
+ this.shifted = true;
+ } else {
+ dataVisitor.process(context, this.rowKey, this.argument);
+ this.rowKey = rowKey;
+ this.argument = argument;
+ }
+ }
+
+ public void end(FacesContext context) throws IOException {
+ if (shifted) {
+ try {
+ ((LastElementAware) dataVisitor).setLastElement();
+ dataVisitor.process(context, this.rowKey, argument);
+ } finally {
+ ((LastElementAware) dataVisitor).resetLastElement();
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.richfaces.model.AbstractTreeDataModel#walkModel(javax.faces.context.FacesContext,
+ * org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range,
+ * java.lang.Object, java.lang.Object, boolean)
+ */
+ public void walkModel(FacesContext facesContext, DataVisitor visitor,
+ Range range, Object key, Object argument, boolean last)
+ throws IOException {
+
+ walk(facesContext, visitor, range, key, argument, last);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.model.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ public void setRowKey(Object key) {
+ setRowKey(FacesContext.getCurrentInstance(), key);
+ }
+
+ public void setRowKey(FacesContext context, Object key) {
+ setupKey(key, context);
+ }
+
+ public void addStackingModel(StackingTreeModel model) {
+ this.models.put(model.id, model);
+ model.setParent(this);
+ }
+
+ public void removeStackingModel(StackingTreeModel model) {
+ this.models.remove(model.id);
+ model.setParent(null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public Object getRowData() {
+ if (isRowAvailable()) {
+ StackEntry lastEntry = (StackEntry) stackEntries.getLast();
+ return lastEntry.rowData;
+ }
+
+ throw new IllegalStateException(
+ "No tree element available or row key not set!");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return !stackEntries.isEmpty();
+ }
+
+ public StackingTreeModel getParent() {
+ return parent;
+ }
+
+ protected boolean isActiveData() {
+ return true;
+ }
+
+ protected boolean isActive() {
+ return true;
+ }
+
+ private final static Predicate ACTIVE_MODEL_PREDICATE = new Predicate() {
+
+ public boolean evaluate(Object object) {
+ StackingTreeModel model = (StackingTreeModel) object;
+ if (model == null) {
+ return false;
+ }
+
+ return model.isActive();
+ }
+
+ };
+
+ @Override
+ public Object getWrappedData() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object convertToKey(FacesContext context, String keyString,
+ UIComponent component, Converter converter) {
+
+ //force model leave
+ setRowKey(context, null);
+
+ String[] strings = ListRowKey.fromString(keyString);
+ int l = strings.length / 2;
+ List<Object> list = new ArrayList<Object>(l);
+ StackingTreeModel model = getRoot();
+
+ for (int i = 0; i < l; i++) {
+ int idx = i*2;
+
+ String modelId = strings[idx];
+ model = model.getModelById(modelId);
+ if (model.isActive()) {
+ Object key = model.convert(context, strings[idx + 1], component, converter);
+ if (key == null) {
+ return null;
+ }
+
+ list.add(new StackingTreeModelKey(modelId, key));
+
+ if (!model.setupModel(key, context) || !model.isActiveData()) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ return new ListRowKey<Object>(list);
+ }
+
+ protected Object convert(FacesContext context, String string,
+ UIComponent component, Converter converter) {
+
+ ConvertableKeyModel convertable = (ConvertableKeyModel) getDataModel();
+ return convertable.getKeyAsObject(context, string, component, converter);
+ }
+
+ public String getId() {
+ return id;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelDataProvider.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/StackingTreeModelDataProvider.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelDataProvider.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelDataProvider.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,33 @@
+/**
+ * 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;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public interface StackingTreeModelDataProvider {
+ public Object getData();
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelKey.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/StackingTreeModelKey.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelKey.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelKey.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,103 @@
+/**
+ * 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.Serializable;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski
+ */
+public class StackingTreeModelKey<T> implements Serializable, ComplexTreeRowKey {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6821854350257816571L;
+ protected T modelKey;
+ protected String modelId;
+
+ public StackingTreeModelKey(String modelId, T modelKey) {
+ super();
+ this.modelId = modelId;
+ this.modelKey = modelKey;
+ }
+
+ public String toString() {
+ return this.modelId + AbstractTreeDataModel.SEPARATOR + this.modelKey;
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((modelId == null) ? 0 : modelId.hashCode());
+ result = prime * result
+ + ((modelKey == null) ? 0 : modelKey.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final StackingTreeModelKey other = (StackingTreeModelKey) obj;
+ if (modelId == null) {
+ if (other.modelId != null)
+ return false;
+ } else if (!modelId.equals(other.modelId))
+ return false;
+ if (modelKey == null) {
+ if (other.modelKey != null)
+ return false;
+ } else if (!modelKey.equals(other.modelKey))
+ return false;
+ return true;
+ }
+
+ public String getModelId() {
+ return modelId;
+ }
+
+ public Object getModelKey() {
+ return modelKey;
+ }
+
+ public int getKeySegmentsCount() {
+ return 2;
+ }
+
+ public Object getKeySegment(int i) {
+ switch (i) {
+ case 0:
+ return modelId;
+ case 1:
+ return modelKey;
+
+ default:
+ throw new IllegalArgumentException(String.valueOf(i));
+ }
+ }
+}
\ No newline at end of file
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,78 @@
+/**
+ * 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.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski mailto:nbelaevski@exadel.com created 25.07.2007
+ *
+ */
+public abstract class StackingTreeModelProvider extends UIComponentBase {
+
+ public abstract Object getNodes();
+ public abstract void setNodes(Object nodes);
+
+ public Object getData() {
+ return getNodes();
+ }
+
+ protected abstract StackingTreeModel createStackingTreeModel();
+
+ private List<StackingTreeModel> createChildModelsList() {
+ List<StackingTreeModel> childModels = new ArrayList<StackingTreeModel>();
+
+ if (getChildCount() > 0) {
+ Iterator<UIComponent> children = getChildren().iterator();
+ while (children.hasNext()) {
+ UIComponent component = children.next();
+ if (component instanceof StackingTreeModelProvider) {
+ StackingTreeModelProvider provider = (StackingTreeModelProvider) component;
+ childModels.add(provider.getStackingModel());
+ }
+ }
+ }
+
+ return childModels;
+ }
+
+ protected void addChildModels(StackingTreeModel model, List<StackingTreeModel>
childModels) {
+ for (StackingTreeModel childModel : childModels) {
+ model.addStackingModel(childModel);
+ }
+ }
+
+ public StackingTreeModel getStackingModel() {
+ StackingTreeModel stackingTreeModel = createStackingTreeModel();
+
+ addChildModels(stackingTreeModel, createChildModelsList());
+
+ return stackingTreeModel;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeDataModelNodeAdaptor.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,278 @@
+/**
+ * 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.model;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.swing.tree.MutableTreeNode;
+import javax.swing.tree.TreeNode;
+
+/**
+ * {@link TreeDataModel} adaptor for generic types. Contains adaptors for Swing &
classic ({@link TreeNode})
+ * tree node types embedded into this interface as static instances
+ *
+ * Created 01.11.2007
+ *
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public interface TreeDataModelNodeAdaptor<T> {
+ public T getParent(T node);
+
+ public boolean isLeaf(T node);
+
+ public T getChild(T node, Object key);
+
+ public Iterator<Map.Entry<Object, T>> getChildren(T node);
+
+ public Object getRowData(T node);
+
+ /**
+ * Get node local id in it's parent childs collection
+ *
+ * @param childNode node to get identifier for
+ * @return node local identifier
+ */
+ public Object getChildNodeId(T childNode);
+
+ public void appendChild(T parentNode, Object key, T childNode);
+
+ public void removeFromParent(T childNode);
+
+ /**
+ * Instance of {@link TreeDataModelNodeAdaptor} for {@link org.richfaces.model.TreeNode}
nodes handling
+ */
+ @SuppressWarnings("unchecked")
+ public static final TreeDataModelNodeAdaptor<org.richfaces.model.TreeNode>
classicTreeNodeAdaptor =
+ new TreeDataModelNodeAdaptor<org.richfaces.model.TreeNode>() {
+
+ public org.richfaces.model.TreeNode getChild(org.richfaces.model.TreeNode node, Object
key) {
+ return node.getChild(key);
+ }
+
+ public Iterator<Entry<Object, org.richfaces.model.TreeNode>> getChildren(
+ org.richfaces.model.TreeNode node) {
+ return node.getChildren();
+ }
+
+ public org.richfaces.model.TreeNode getParent(org.richfaces.model.TreeNode node) {
+ return node.getParent();
+ }
+
+ public Object getRowData(org.richfaces.model.TreeNode node) {
+ return node.getData();
+ }
+
+ public boolean isLeaf(org.richfaces.model.TreeNode node) {
+ return node.isLeaf();
+ }
+
+ /**
+ * Get node local id in it's parent childs collection
+ *
+ * @param childNode node to get identifier for
+ * @return node local identifier
+ */
+ public Object getChildNodeId(org.richfaces.model.TreeNode childNode) {
+ org.richfaces.model.TreeNode parentNode = getParent(childNode);
+ if (childNode != null && parentNode != null) {
+ Iterator<Map.Entry<Object, TreeNode>> iter =
parentNode.getChildren();
+ while (iter != null && iter.hasNext()) {
+ Map.Entry<Object, TreeNode> entry = iter.next();
+ if (entry != null && childNode.equals(entry.getValue())) {
+ return entry.getKey();
+ }
+ }
+ }
+ return null;
+ }
+
+ public void appendChild(org.richfaces.model.TreeNode parentNode,
+ Object childKey, org.richfaces.model.TreeNode childNode) {
+
+ parentNode.addChild(childKey, childNode);
+ }
+
+ public void removeFromParent(org.richfaces.model.TreeNode childNode) {
+ org.richfaces.model.TreeNode parent = childNode.getParent();
+ Object childNodeId = getChildNodeId(childNode);
+ if (childNodeId != null) {
+ parent.removeChild(childNodeId);
+ }
+ }
+ };
+
+ /**
+ * Instance of {@link TreeDataModelNodeAdaptor} for {@link javax.swing.tree.TreeNode}
nodes handling
+ */
+ public static final TreeDataModelNodeAdaptor<javax.swing.tree.TreeNode>
swingTreeNodeAdaptor =
+ new TreeDataModelNodeAdaptor<javax.swing.tree.TreeNode>() {
+
+ final class SwingNodeMapEntry implements Map.Entry<Object, TreeNode> {
+
+ private Object key;
+ private TreeNode child;
+
+ public SwingNodeMapEntry(int i, TreeNode child) {
+ this.key = Integer.valueOf(i);
+ this.child = child;
+ }
+
+ public Object getKey() {
+ return this.key;
+ }
+
+ public TreeNode getValue() {
+ return child;
+ }
+
+ public TreeNode setValue(TreeNode value) {
+ TreeNode node = this.child;
+ this.child = value;
+
+ return node;
+ }
+
+ };
+
+ public javax.swing.tree.TreeNode getChild(
+ javax.swing.tree.TreeNode node, Object key) {
+
+ int intKey = ((Integer) key).intValue();
+ if (intKey < node.getChildCount() && intKey >= 0) {
+ return node.getChildAt(intKey);
+ }
+
+ return null;
+ }
+
+ public Iterator<Entry<Object, javax.swing.tree.TreeNode>> getChildren(
+ final javax.swing.tree.TreeNode node) {
+
+ if (node.getAllowsChildren()) {
+ return new Iterator<Entry<Object,javax.swing.tree.TreeNode>>() {
+
+ private final Enumeration<?> e = node.children();
+ private int counter = 0;
+
+ public boolean hasNext() {
+ return e.hasMoreElements();
+ }
+
+ public Entry<Object, javax.swing.tree.TreeNode> next() {
+ javax.swing.tree.TreeNode child = (javax.swing.tree.TreeNode) e.nextElement();
+ SwingNodeMapEntry entry = new SwingNodeMapEntry(counter++, child);
+ return entry;
+
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ }
+
+ return null;
+ }
+
+ public javax.swing.tree.TreeNode getParent(
+ javax.swing.tree.TreeNode node) {
+ return node.getParent();
+ }
+
+ public Object getRowData(javax.swing.tree.TreeNode node) {
+ return node;
+ }
+
+ public boolean isLeaf(javax.swing.tree.TreeNode node) {
+ return !node.getAllowsChildren() || node.isLeaf();
+ }
+
+ /**
+ * Get node local id in it's parent childs collection
+ *
+ * @param childNode node to get identifier for
+ * @return node local identifier
+ */
+ public Object getChildNodeId(javax.swing.tree.TreeNode childNode) {
+ javax.swing.tree.TreeNode parentNode = getParent(childNode);
+ if (childNode != null && parentNode != null) {
+ int idx = parentNode.getIndex(childNode);
+ if (idx != -1) {
+ return idx;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void appendChild(javax.swing.tree.TreeNode parentNode, Object key,
+ javax.swing.tree.TreeNode childNode) {
+
+ if (childNode instanceof MutableTreeNode) {
+ MutableTreeNode mutableChildNode = (MutableTreeNode) childNode;
+ MutableTreeNode mutableParentNode = (MutableTreeNode) parentNode;
+ int idx;
+
+ if (key != null) {
+ idx = (Integer) key;
+ } else {
+ idx = mutableParentNode.getChildCount();
+ }
+
+ mutableParentNode.insert(mutableChildNode, idx);
+ } else {
+ SwingTreeNodeImpl swingTreeNodeImpl = (SwingTreeNodeImpl) childNode;
+ SwingTreeNodeImpl parent = (SwingTreeNodeImpl) parentNode;
+
+ if (key != null) {
+ parent.addChild(key, swingTreeNodeImpl);
+ } else {
+ parent.addChild(swingTreeNodeImpl);
+ }
+
+ swingTreeNodeImpl.setParent(parent);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void removeFromParent(javax.swing.tree.TreeNode node) {
+ if (node instanceof MutableTreeNode) {
+ ((MutableTreeNode) node).removeFromParent();
+ } else {
+ SwingTreeNodeImpl swingTreeNodeImpl = (SwingTreeNodeImpl) node;
+ SwingTreeNodeImpl parent = (SwingTreeNodeImpl) swingTreeNodeImpl.getParent();
+
+ parent.removeChild(swingTreeNodeImpl);
+ swingTreeNodeImpl.setParent(null);
+ }
+ }
+ };
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeModelVisualComponentProvider.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/TreeModelVisualComponentProvider.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeModelVisualComponentProvider.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/TreeModelVisualComponentProvider.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,35 @@
+/**
+ * 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 javax.faces.component.UIComponent;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 29.07.2007
+ *
+ */
+public interface TreeModelVisualComponentProvider {
+ public UIComponent getComponent();
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/VisualStackingTreeModel.java
(from rev 14980,
root/framework/trunk/api/src/main/java/org/richfaces/model/VisualStackingTreeModel.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/VisualStackingTreeModel.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/main/java/org/richfaces/model/VisualStackingTreeModel.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,61 @@
+/**
+ * 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 javax.faces.component.UIComponent;
+
+/**
+ * That is intended for internal use
+ *
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 15.08.2007
+ *
+ */
+public class VisualStackingTreeModel extends StackingTreeModel implements
TreeModelVisualComponentProvider {
+ private UIComponent component;
+
+ public VisualStackingTreeModel(UIComponent component) {
+ super();
+
+ this.component = component;
+ }
+
+ public VisualStackingTreeModel(String id, String var,
+ StackingTreeModelDataProvider dataProvider, UIComponent component) {
+ super(id, var, dataProvider);
+
+ this.component = component;
+ }
+
+ public UIComponent getComponent() {
+ if (this.component != null) {
+ return this.component;
+ }
+
+ StackingTreeModel currentModel = getCurrentModel();
+ if (currentModel != null && currentModel != this) {
+ return ((TreeModelVisualComponentProvider) currentModel).getComponent();
+ }
+
+ return null;
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,450 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.richfaces.model.entity.Directory;
+import org.richfaces.model.entity.File;
+import org.richfaces.model.entity.Named;
+import org.richfaces.model.entity.Project;
+import org.richfaces.test.AbstractFacesTest;
+
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class StackingTreeDataModelTest extends AbstractFacesTest {
+
+ private StackingTreeModel stackingTreeModel;
+ private StackingTreeModel projectsModel;
+ private StackingTreeModel directoriesModel;
+ private StackingTreeModel filesModel;
+
+ private Object projectRequestObject;
+ private Object directoryRequestObject;
+ private Object fileRequestObject;
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ this.stackingTreeModel = new StackingTreeModel();
+ projectsModel = new StackingTreeModel("project", "project", new
StackingTreeModelDataProvider() {
+
+ private Map<String, Project> data = null;
+
+ public Object getData() {
+ if (data == null) {
+ data = new LinkedHashMap<String, Project>();
+ Project projectA = new Project("projectA", 10);
+
+ Directory adir1 = new Directory("ADir1", 50);
+
+ adir1.addFile(new File("AFile1", 60));
+ adir1.addFile(new File("AFile2", 61));
+
+ Directory adir2 = new Directory("ADir2", 101);
+
+ projectA.addDirectory(adir1);
+ projectA.addDirectory(adir2);
+
+ data.put(projectA.getName(), projectA);
+
+ Project projectB = new Project("projectB", 501);
+
+ Directory bdir1 = new Directory("BDir1", 600);
+ Directory bdir2 = new Directory("BDir2", 700);
+ Directory bdir3 = new Directory("BDir3", 801);
+
+ projectB.addDirectory(bdir1);
+ projectB.addDirectory(bdir2);
+ projectB.addDirectory(bdir3);
+
+ data.put(projectB.getName(), projectB);
+ }
+ return data;
+ }
+ });
+ final ValueBinding dirVB =
application.createValueBinding("#{project.directories}");
+ directoriesModel = new StackingTreeModel("directory", "directory",
new StackingTreeModelDataProvider() {
+ public Object getData() {
+ return dirVB.getValue(facesContext);
+ }
+ });
+ final ValueBinding fileVB =
application.createValueBinding("#{directory.files}");
+ filesModel = new StackingTreeModel("file", "file", new
StackingTreeModelDataProvider() {
+ public Object getData() {
+ return fileVB.getValue(facesContext);
+ }
+ });
+ directoriesModel.addStackingModel(filesModel);
+ projectsModel.addStackingModel(directoriesModel);
+ this.stackingTreeModel.addStackingModel(projectsModel);
+
+ projectRequestObject = new Object();
+ directoryRequestObject = new Object();
+ fileRequestObject = new Object();
+
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+ requestMap.put("project", projectRequestObject);
+ requestMap.put("directory", directoryRequestObject);
+ requestMap.put("file", fileRequestObject);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ this.stackingTreeModel = null;
+ this.projectsModel = null;
+ this.directoriesModel = null;
+ this.filesModel = null;
+
+ this.projectRequestObject = null;
+ this.directoryRequestObject = null;
+ this.fileRequestObject = null;
+ }
+
+ public void testWalk() throws Exception {
+ StackingTreeDataModelTestVisitor1 visitor1 = new StackingTreeDataModelTestVisitor1();
+ this.stackingTreeModel.walk(facesContext, visitor1, null, null);
+ assertEquals(9, visitor1.getCounter());
+ this.stackingTreeModel.setRowKey(null);
+ assertFalse(this.stackingTreeModel.isRowAvailable());
+
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+ assertSame(this.projectRequestObject, requestMap.get("project"));
+ assertSame(this.directoryRequestObject, requestMap.get("directory"));
+ assertSame(this.fileRequestObject, requestMap.get("file"));
+ }
+
+ public void testBadKey() throws Exception {
+ StackingTreeDataModelTestVisitor1 visitor1 = new StackingTreeDataModelTestVisitor1();
+ this.stackingTreeModel.walk(facesContext, visitor1, null, null);
+ this.stackingTreeModel.setRowKey(new ListRowKey(new
StackingTreeModelKey("project", "projectA")));
+ assertTrue(this.stackingTreeModel.isRowAvailable());
+ assertNotNull(this.stackingTreeModel.getRowData());
+
+ assertNull(this.stackingTreeModel.getTreeNode());
+ assertFalse(this.stackingTreeModel.isLeaf());
+
+ this.stackingTreeModel.setRowKey(new ListRowKey(new
StackingTreeModelKey("project", "projectAAAAA")));
+ assertFalse(this.stackingTreeModel.isRowAvailable());
+ try {
+ Object rowData = this.stackingTreeModel.getRowData();
+ assertNull(rowData);
+ //FIXME: Maksim - bad keys happen for a reason
+ //fail();
+ } catch (Exception e) {
+
+ }
+
+ try {
+ boolean leaf = this.stackingTreeModel.isLeaf();
+ assertTrue(leaf);
+ //FIXME: Maksim - bad keys happen for a reason
+ //fail();
+ } catch (Exception e) {
+
+ }
+
+ try {
+ TreeNode node = this.stackingTreeModel.getTreeNode();
+ assertNull(node);
+ //FIXME: Maksim - bad keys happen for a reason
+ //fail();
+ } catch (Exception e) {
+
+ }
+ }
+
+ public void testActiveData() throws Exception {
+ final ValueBinding fileVB =
application.createValueBinding("#{directory.files}");
+ StackingTreeModel localFilesModel = new StackingTreeModel("file",
"file", new StackingTreeModelDataProvider() {
+ public Object getData() {
+ return fileVB.getValue(facesContext);
+ }
+
+ }) {
+ protected boolean isActiveData() {
+ Map requestMap = facesContext.getExternalContext().getRequestMap();
+ Object object = requestMap.get("file");
+ assertNotNull(object);
+ File file = (File) object;
+ if (file.getTag() == 61) {
+ return false;
+ }
+
+ return super.isActiveData();
+ }
+ };
+ directoriesModel.removeStackingModel(filesModel);
+ directoriesModel.addStackingModel(localFilesModel);
+
+ stackingTreeModel.walk(facesContext, new StackingTreeDataModelTestVisitor3(), null,
null);
+ }
+
+ public void testKey() throws Exception {
+ StackingTreeModelKey key = new StackingTreeModelKey("aaa", new Integer(10));
+ StackingTreeModelKey key2 = new StackingTreeModelKey("aaa", new
Integer(11));
+ StackingTreeModelKey key3 = new StackingTreeModelKey("aaa", new
Integer(10));
+ StackingTreeModelKey key4 = new StackingTreeModelKey("bbb", new
Integer(10));
+
+ assertFalse(key.equals(new StackingTreeModelKey("aaa", new Integer(0)) {}
));
+
+ assertTrue(key.equals(key3));
+ assertTrue(key3.equals(key));
+ assertTrue(key2.equals(key2));
+ assertTrue(key4.equals(key4));
+
+ assertTrue(key.hashCode() == key3.hashCode());
+ assertTrue(key3.hashCode() == key.hashCode());
+ assertTrue(key2.hashCode() == key2.hashCode());
+ assertTrue(key4.hashCode() == key4.hashCode());
+
+ assertFalse(key.equals(key2));
+ assertFalse(key3.equals(key2));
+ assertFalse(key2.equals(key));
+ assertFalse(key2.equals(key3));
+
+ assertFalse(key.hashCode() == key2.hashCode());
+ assertFalse(key3.hashCode() == key2.hashCode());
+ assertFalse(key2.hashCode() == key.hashCode());
+ assertFalse(key2.hashCode() == key3.hashCode());
+
+ assertFalse(key4.equals(key));
+ assertFalse(key4.equals(key2));
+ assertFalse(key4.equals(key3));
+
+ assertFalse(key4.hashCode() == key.hashCode());
+ assertFalse(key4.hashCode() == key2.hashCode());
+ assertFalse(key4.hashCode() == key3.hashCode());
+
+ assertFalse(key.equals(key4));
+ assertFalse(key2.equals(key4));
+ assertFalse(key3.equals(key4));
+
+ assertFalse(new StackingTreeModelKey("aaa", new Integer(10)).equals(null));
+ assertFalse(new StackingTreeModelKey("aaa", null).equals(null));
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).equals(null));
+ assertFalse(new StackingTreeModelKey(null, null).equals(null));
+
+ assertFalse(key.hashCode() == key4.hashCode());
+ assertFalse(key2.hashCode() == key4.hashCode());
+ assertFalse(key3.hashCode() == key4.hashCode());
+
+ assertFalse(key.hashCode() == 0);
+ assertFalse(key2.hashCode() == 0);
+ assertFalse(key3.hashCode() == 0);
+ assertFalse(key4.hashCode() == 0);
+
+ assertTrue(new StackingTreeModelKey(null, new Integer(11)).equals(new
StackingTreeModelKey(null, new Integer(11))));
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).equals(new
StackingTreeModelKey(null, new Integer(11))));
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).equals(new
StackingTreeModelKey("aaa", new Integer(10))));
+
+ assertTrue(new StackingTreeModelKey(null, new Integer(11)).hashCode() == new
StackingTreeModelKey(null, new Integer(11)).hashCode());
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).hashCode() == new
StackingTreeModelKey(null, new Integer(11)).hashCode());
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).hashCode() == new
StackingTreeModelKey("aaa", new Integer(10)).hashCode());
+
+ assertTrue(new StackingTreeModelKey("aaa", null).equals(new
StackingTreeModelKey("aaa", null)));
+ assertFalse(new StackingTreeModelKey("aaa", null).equals(new
StackingTreeModelKey("bbb", null)));
+ assertFalse(new StackingTreeModelKey("aaa", null).equals(new
StackingTreeModelKey("aaa", new Integer(10))));
+
+ assertTrue(new StackingTreeModelKey("aaa", null).hashCode() == new
StackingTreeModelKey("aaa", null).hashCode());
+ assertFalse(new StackingTreeModelKey("aaa", null).hashCode() == new
StackingTreeModelKey("bbb", null).hashCode());
+ assertFalse(new StackingTreeModelKey("aaa", null).hashCode() == new
StackingTreeModelKey("aaa", new Integer(10)).hashCode());
+ }
+
+ class StackingTreeDataModelTestVisitor1 implements DataVisitor, LastElementAware {
+
+ private boolean last;
+ private int tag = 0;
+ private int counter = 0;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ StackingTreeDataModelTestVisitor2 visitor2 = new StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor2, null, new ListRowKey(new
StackingTreeModelKey("project", "projectA")),
+ argument, false);
+
+ assertEquals(5, visitor2.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor20 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor20, new TreeRange() {
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ return false;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return false;
+ }
+
+ }, new ListRowKey(new StackingTreeModelKey("project",
"projectA")),
+ argument, false);
+
+ assertEquals(0, visitor20.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor21 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor21, new TreeRange() {
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ return false;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return true;
+ }
+
+ }, new ListRowKey(new StackingTreeModelKey("project",
"projectA")),
+ argument, false);
+
+ assertEquals(1, visitor21.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor22 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor22, null, new ListRowKey(new
StackingTreeModelKey("project", "projectB")),
+ argument, false);
+
+ assertEquals(4, visitor22.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor23 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor23, new TreeRange() {
+
+ private boolean rootProcessed = false;
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ boolean result = rootProcessed;
+ rootProcessed = true;
+ return !result;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return true;
+ }
+
+ }, new ListRowKey(new StackingTreeModelKey("project",
"projectB")),
+ argument, false);
+
+ assertEquals(4, visitor23.getCounter());
+
+ stackingTreeModel.setRowKey(rowKey);
+
+ assertSame(rowKey, stackingTreeModel.getRowKey());
+
+ assertNull(stackingTreeModel.getTreeNode());
+ Object rowData = stackingTreeModel.getRowData();
+ assertNotNull(rowData);
+ assertTrue(rowData instanceof Named);
+
+ Named named = (Named) rowData;
+
+ int currentTag = named.getTag();
+ assertTrue(currentTag > tag);
+ this.tag = currentTag;
+
+ if (this.tag % 10 == 1) {
+ assertTrue(last);
+ } else {
+ assertFalse(last);
+ }
+
+ if (named instanceof Directory) {
+ if ("ADir1".equals(named.getName())) {
+ assertFalse(stackingTreeModel.isLeaf());
+ } else {
+ assertTrue(stackingTreeModel.isLeaf());
+ }
+ } else if (named instanceof Project) {
+ assertFalse(stackingTreeModel.isLeaf());
+ } else if (named instanceof File) {
+ assertTrue(stackingTreeModel.isLeaf());
+ } else {
+ fail();
+ }
+
+ counter++;
+ }
+
+ public void resetLastElement() {
+ this.last = false;
+ }
+
+ public void setLastElement() {
+ this.last = true;
+ }
+
+ public int getCounter() {
+ return counter;
+ }
+ }
+
+ class StackingTreeDataModelTestVisitor2 implements DataVisitor {
+ private int counter = 0;
+ private int tag = 0;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ stackingTreeModel.setRowKey(rowKey);
+ Object rowData = stackingTreeModel.getRowData();
+ assertNotNull(rowData);
+ Named named = (Named) rowData;
+
+ int currentTag = named.getTag();
+ assertTrue(currentTag > tag);
+ tag = currentTag;
+ counter++;
+ }
+
+ public int getCounter() {
+ return counter;
+ }
+ }
+
+ class StackingTreeDataModelTestVisitor3 implements DataVisitor, LastElementAware {
+
+ private boolean last;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ stackingTreeModel.setRowKey(rowKey);
+ Named named = (Named) stackingTreeModel.getRowData();
+ int tag = named.getTag();
+
+ if (tag == 60) {
+ assertTrue(last);
+ }
+ assertFalse(tag == 61);
+ }
+
+ public void resetLastElement() {
+ this.last = false;
+ }
+
+ public void setLastElement() {
+ this.last = true;
+ }
+ }
+}
+
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Directory.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/entity/Directory.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Directory.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Directory.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class Directory extends Named {
+
+ public Directory(String name, int tag) {
+ super(name, tag);
+ }
+
+ private List files = new ArrayList();
+
+ public List getFiles() {
+ return files;
+ }
+
+ public void addFile(File file) {
+ this.files.add(file);
+ }
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/File.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/entity/File.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/File.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/File.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class File extends Named {
+
+ public File(String name, int tag) {
+ super(name, tag);
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Named.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/entity/Named.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Named.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Named.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,27 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class Named {
+ private String name;
+ private int tag;
+ public String getName() {
+ return name;
+ }
+ public int getTag() {
+ return tag;
+ }
+ public Named(String name, int tag) {
+ super();
+ this.name = name;
+ this.tag = tag;
+ }
+
+}
Copied:
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Project.java
(from rev 14980,
root/framework/trunk/impl/src/test/java/org/richfaces/model/entity/Project.java)
===================================================================
---
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Project.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tree-model/api/src/test/java/org/richfaces/model/entity/Project.java 2009-07-23
16:41:49 UTC (rev 14985)
@@ -0,0 +1,29 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class Project extends Named {
+ public Project(String name, int tag) {
+ super(name, tag);
+ }
+
+ private List directories = new ArrayList();
+
+ public List getDirectories() {
+ return directories;
+ }
+
+ public void addDirectory(Directory directory) {
+ directories.add(directory);
+ }
+}