Author: nbelaevski
Date: 2007-07-30 10:03:21 -0400 (Mon, 30 Jul 2007)
New Revision: 1927
Added:
trunk/framework/api/src/main/java/org/richfaces/model/LastAwareArrayDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/LastAwareDataModel.java
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModel.java
trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModelListener.java
Modified:
trunk/extensions/portlet/
trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java
trunk/samples/ajaxPortlet/
trunk/ui/tree/src/main/config/component/treeNode.xml
trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java
trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeDataModelEventNavigator.java
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
trunk/ui/tree/src/main/templates/htmlTree.jspx
Log:
- TreeModel API
- Tree component fixes & updates
Property changes on: trunk/extensions/portlet
___________________________________________________________________
Name: svn:ignore
- target
+ target
.classpath
.project
.settings
Added: trunk/framework/api/src/main/java/org/richfaces/model/LastAwareArrayDataModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/LastAwareArrayDataModel.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/LastAwareArrayDataModel.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -0,0 +1,118 @@
+/**
+ *
+ */
+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;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 26.07.2007
+ *
+ */
+public class LastAwareArrayDataModel extends ExtendedDataModel implements
LastAwareDataModel {
+
+ private Object[] wrappedData;
+ private Integer rowKey;
+
+ /* (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 = (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 (wrappedData != null) {
+ for (int i = 0; i < wrappedData.length; i++) {
+ Integer key = new Integer(i);
+
+ visitor.process(context, key, argument);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ return wrappedData != null ? wrappedData.length : 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public Object getRowData() {
+ if (wrappedData == null) {
+ return null;
+ }
+
+ return wrappedData[rowKey.intValue()];
+ }
+
+ /* (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 wrappedData != null && wrappedData.length < rowKey.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 = (Object[]) data;
+ }
+
+ public boolean isLast() {
+ return wrappedData != null && wrappedData.length == rowKey.intValue() + 1;
+ }
+
+ public LastAwareArrayDataModel(Object[] wrappedData) {
+ super();
+ setWrappedData(wrappedData);
+ }
+
+ public boolean isEmpty() {
+ return wrappedData == null || wrappedData.length == 0;
+ }
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/LastAwareDataModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/LastAwareDataModel.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/LastAwareDataModel.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 26.07.2007
+ *
+ */
+public interface LastAwareDataModel {
+ public boolean isLast();
+
+ public boolean isEmpty();
+}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java 2007-07-30
14:02:57 UTC (rev 1926)
+++ trunk/framework/api/src/main/java/org/richfaces/model/ListRowKey.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -57,7 +57,11 @@
*/
protected ListRowKey(ListRowKey parentRowKey) {
super();
- this.path = (ArrayList) parentRowKey.path.clone();
+ if (parentRowKey != null) {
+ this.path = (ArrayList) parentRowKey.path.clone();
+ } else {
+ this.path = new ArrayList();
+ }
}
/**
@@ -175,6 +179,10 @@
return path.listIterator(fromIndex);
}
+ public ListRowKey getSubKey(int fromIndex) {
+ return new ListRowKey(path.subList(fromIndex, path.size()));
+ }
+
public boolean isSubKey(TreeRowKey rowKey) {
if (rowKey instanceof ListRowKey) {
ListRowKey listRowKey = (ListRowKey) rowKey;
@@ -233,4 +241,8 @@
length++;
return length;
}
+
+ public Object get(int i) {
+ return path.get(i);
+ }
}
Added: trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -0,0 +1,387 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+
+/**
+ * @author Nick Belaevski mailto:nbelaevski@exadel.com created 25.07.2007
+ *
+ */
+public class StackingTreeModel extends AbstractTreeDataModel implements
TreeComponentModel {
+
+ private String id;
+
+ private String modelId;
+ private Object modelKey;
+
+ protected StackingTreeModel stackingTreeModel;
+
+ // private ExtendedDataModel dataModel;
+ protected StackingTreeModel parent;
+ private Map models = new LinkedHashMap();
+
+ private List treeComponentModelListeners = new ArrayList();
+
+ public ExtendedDataModel getDataModel() {
+ return null;
+ }
+
+ public StackingTreeModel(String id) {
+ super();
+ this.id = id;
+ }
+
+ public void leaveModel() {
+ if (stackingTreeModel != null && stackingTreeModel != this) {
+ stackingTreeModel.leaveModel();
+ }
+ stackingTreeModel = null;
+ modelId = null;
+ modelKey = null;
+ }
+
+ public void setupModel(Object object) {
+
+ }
+
+ public void setParent(StackingTreeModel parent) {
+ this.parent = parent;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.model.AbstractTreeDataModel#getTreeNode()
+ */
+ public TreeNode getTreeNode() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.model.AbstractTreeDataModel#isLeaf()
+ */
+ public boolean isLeaf() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ protected void doWalk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument,
+ boolean last) throws IOException {
+ final ListRowKey argumentKey = (ListRowKey) rowKey;
+
+ if (argument != null) {
+ Argument2 a = (Argument2) argument;
+
+ Object localRowKey = a.localKey;
+ ExtendedDataModel dataModel = a.dataModel;
+ if (dataModel == null) {
+ dataModel = getDataModel();
+ }
+ dataModel.setRowKey(localRowKey);
+ setupModel(dataModel.getRowData());
+ System.out.println(dataModel.getRowData() + (last ? " * " : "") +
" - " + argumentKey);
+
+ processElement(context, dataVisitor, argument, argumentKey, last);
+ }
+
+ ShiftingDataVisitor shiftingDataVisitor = new ShiftingDataVisitor(
+ new Visitor1(dataVisitor));
+ Iterator iterator = StackingTreeModel.this.getModels().entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ StackingTreeModel model = (StackingTreeModel) entry.getValue();
+ doSpecialWalk(context, shiftingDataVisitor, range, argumentKey, last, model);
+ }
+
+ shiftingDataVisitor.end(context);
+ }
+
+ public Map getModels() {
+ return models;
+ }
+
+ public void walk(FacesContext context, DataVisitor dataVisitor,
+ Range range, Object rowKey, Object argument,
+ boolean last) throws IOException {
+
+ if (rowKey != null) {
+ ListRowKey listRowKey = (ListRowKey) rowKey;
+ if (listRowKey != null) {
+ int depth = listRowKey.depth();
+ StackingTreeModel stackingTreeModel = this;
+ for (int i = 0; i < depth; i++) {
+ Key key = (Key) listRowKey.get(i);
+ if (key.modelId != null) {
+ stackingTreeModel = (StackingTreeModel)
stackingTreeModel.getModels().get(key.modelId);
+
+ this.stackingTreeModel = stackingTreeModel;
+ this.modelId = key.modelId;
+
+ if (i == depth - 1) {
+ Argument2 argument2 = new Argument2();
+ argument2.localKey = key.modelKey;
+ //argument2.dataModel = stackingTreeModel;
+ stackingTreeModel.doWalk(context, dataVisitor, range, listRowKey, argument2,
+ last);
+ } else {
+ stackingTreeModel.setLocalRowKey(key.modelKey);
+ }
+ }
+ }
+ }
+ } else {
+ doWalk(context, dataVisitor, range, rowKey, argument, last);
+ }
+ }
+
+ private void doSpecialWalk(FacesContext context,
+ ShiftingDataVisitor dataVisitor, Range range,
+ ListRowKey rowKey, boolean last, StackingTreeModel stackingTreeModel) throws
IOException {
+
+ Argument argument2 = new Argument();
+ argument2.listRowKey = rowKey;
+ // setup current model
+ argument2.model = stackingTreeModel;
+ argument2.dataModel = stackingTreeModel.getDataModel();
+ argument2.range = range;
+ argument2.dataModel.walk(context, dataVisitor, range,
+ argument2);
+ }
+
+ private class Argument {
+ private ExtendedDataModel dataModel;
+ private ListRowKey listRowKey;
+ private StackingTreeModel model;
+ private Range range;
+ }
+
+ private class Argument2 {
+ private Object localKey;
+ private ExtendedDataModel dataModel;
+ }
+
+ 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 Key(
+ a.model.id, rowKey));
+ //System.out.println(".walk() " + (theLast ? " * " : "")
+ listRowKey);
+ Argument2 argument2 = new Argument2();
+ argument2.localKey = rowKey;
+ argument2.dataModel = a.dataModel;
+ a.model.doWalk(context, dataVisitor, a.range, listRowKey, argument2,
+ theLast);
+ }
+
+ public void resetLastElement() {
+ theLast = false;
+ }
+
+ public void setLastElement() {
+ theLast = true;
+ }
+
+ }
+
+ private static class ShiftingDataVisitor implements DataVisitor {
+
+ private DataVisitor dataVisitor;
+
+ public DataVisitor getDataVisitor() {
+ return 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) {
+ if (dataVisitor instanceof LastElementAware) {
+ try {
+ ((LastElementAware) dataVisitor).setLastElement();
+ dataVisitor.process(context, this.rowKey, argument);
+ } finally {
+ ((LastElementAware) dataVisitor).resetLastElement();
+ }
+ } else {
+ dataVisitor.process(context, this.rowKey, argument);
+ }
+ }
+ }
+ }
+
+ /*
+ * (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() {
+ if (parent == null) {
+ ListRowKey listRowKey = new ListRowKey();
+ return listRowKey;
+ } else {
+ return new ListRowKey((ListRowKey) parent.getRowKey(), new Key(this.modelId,
modelKey));
+ }
+ }
+
+ protected void setLocalRowKey(Object rowKey) {
+ ExtendedDataModel dataModel = getDataModel();
+ this.modelKey = rowKey;
+ dataModel.setRowKey(rowKey);
+ setupModel(dataModel.getRowData());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.model.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ protected void doSetRowKey(Object key) {
+ ListRowKey listRowKey = (ListRowKey) key;
+ if (listRowKey != null) {
+ Key rowKey = (Key) listRowKey.get(0);
+ if (rowKey.modelId != null) {
+ StackingTreeModel stackingTreeModel = (StackingTreeModel)
this.getModels().get(rowKey.modelId);
+
+ this.stackingTreeModel = stackingTreeModel;
+ this.modelId = rowKey.modelId;
+
+ if (listRowKey.depth() == 1) {
+ stackingTreeModel.setLocalRowKey(rowKey.modelKey);
+ } else {
+ stackingTreeModel.setLocalRowKey(rowKey.modelKey);
+ stackingTreeModel.doSetRowKey(listRowKey.getSubKey(1));
+ }
+ }
+ }
+ }
+
+ public void setRowKey(Object key) {
+ leaveModel();
+
+ doSetRowKey(key);
+ }
+
+ public void addStackingModel(StackingTreeModel model) {
+ this.models.put(model.id, model);
+ model.setParent(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public Object getRowData() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ protected static class Key {
+ protected Object modelKey;
+ protected String modelId;
+
+ public Key(String modelId, Object modelKey) {
+ super();
+ this.modelId = modelId;
+ this.modelKey = modelKey;
+ }
+
+ public String toString() {
+ return this.modelId + ":" + this.modelKey;
+ }
+ }
+
+ public void addTreeComponentModelListener(
+ TreeComponentModelListener listener) {
+ this.treeComponentModelListeners.add(listener);
+ }
+
+ public void removeTreeComponentModelListener(
+ TreeComponentModelListener listener) {
+ this.treeComponentModelListeners.remove(listener);
+ }
+
+ protected void componentSelected(UIComponent component) {
+ for (Iterator iterator = this.treeComponentModelListeners.iterator();
iterator.hasNext();) {
+ TreeComponentModelListener listener = (TreeComponentModelListener) iterator.next();
+
+ listener.componentSelected(component);
+ }
+
+ if (parent != null) {
+ parent.componentSelected(component);
+ }
+ }
+}
Added:
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModelProvider.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+
+
+/**
+ * @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() {
+ Object[] data;
+ List nodes = (List) getNodes();
+ if (nodes != null) {
+ data = nodes.toArray();
+ } else {
+ data = new Object[0];
+ }
+ return data;
+ }
+
+ protected abstract StackingTreeModel createStackingTreeModel();
+
+ public StackingTreeModel getStackingModel() {
+ StackingTreeModel stackingTreeModel = createStackingTreeModel();
+ if (getChildCount() > 0) {
+ Iterator children = getChildren().iterator();
+ while (children.hasNext()) {
+ UIComponent component = (UIComponent) children.next();
+ if (component instanceof StackingTreeModelProvider) {
+ StackingTreeModelProvider provider = (StackingTreeModelProvider) component;
+
+ stackingTreeModel.addStackingModel(provider.getStackingModel());
+ }
+ }
+ }
+
+ return stackingTreeModel;
+ }
+}
Added: trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModel.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModel.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModel.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 24.07.2007
+ *
+ */
+public interface TreeComponentModel {
+ public void addTreeComponentModelListener(TreeComponentModelListener listener);
+ public void removeTreeComponentModelListener(TreeComponentModelListener listener);
+}
Added:
trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModelListener.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModelListener.java
(rev 0)
+++
trunk/framework/api/src/main/java/org/richfaces/model/TreeComponentModelListener.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 29.07.2007
+ *
+ */
+public interface TreeComponentModelListener {
+ public void componentSelected(UIComponent component);
+}
Property changes on: trunk/samples/ajaxPortlet
___________________________________________________________________
Name: svn:ignore
- target
+ target
.classpath
.project
.settings
Modified: trunk/ui/tree/src/main/config/component/treeNode.xml
===================================================================
--- trunk/ui/tree/src/main/config/component/treeNode.xml 2007-07-30 14:02:57 UTC (rev
1926)
+++ trunk/ui/tree/src/main/config/component/treeNode.xml 2007-07-30 14:03:21 UTC (rev
1927)
@@ -44,7 +44,7 @@
&attributes;
&ui_component_attributes;
- <property required="true">
+ <property>
<name>type</name>
<classname>java.lang.String</classname>
<description>A node type</description>
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-07-30 14:02:57
UTC (rev 1926)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-07-30 14:03:21
UTC (rev 1927)
@@ -23,10 +23,12 @@
import java.io.IOException;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.application.Application;
import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
@@ -60,6 +62,9 @@
import org.richfaces.event.NodeSelectedListener;
import org.richfaces.event.TreeListenerEventsProducer;
import org.richfaces.model.AbstractTreeDataModel;
+import org.richfaces.model.StackingTreeModel;
+import org.richfaces.model.StackingTreeModelProvider;
+import org.richfaces.model.TreeComponentModelListener;
import org.richfaces.model.TreeDataModel;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeRange;
@@ -136,10 +141,10 @@
return defaultFacet;
}
- /**
- * Return the data object representing the node for the currently
- * selected row key, if any
- *
+ /**
+ * Return the data object representing the node for the currently
+ * selected row key, if any
+ *
* @return {@link TreeNode} instance corresponding to the current row key
*/
public TreeNode getTreeNode() {
@@ -158,7 +163,6 @@
return facesEvent;
}
-
public void queueEvent(FacesEvent event) {
FacesEvent resultEvent = event;
if (event instanceof NodeExpandedEvent) {
@@ -213,13 +217,50 @@
public UITreeNode getNodeFacet() {
String facetName = this.getNodeFace();
if (facetName != null) {
- Iterator iterator = getChildren().iterator();
- while (iterator.hasNext()) {
- Object object = iterator.next();
- if (object instanceof UITreeNode) {
- UITreeNode treeNode = (UITreeNode) object;
+ if (getChildCount() > 0) {
+ Iterator iterator = getChildren().iterator();
+ while (iterator.hasNext()) {
+ Object object = iterator.next();
+ if (object instanceof UITreeNode) {
+ UITreeNode treeNode = (UITreeNode) object;
- if (facetName.equals(treeNode.getType())) {
+ if (!treeNode.isRendered()) {
+ continue;
+ }
+
+ if (facetName.equals(treeNode.getType())) {
+ return treeNode;
+ }
+ }
+ }
+ }
+ } else {
+ Iterator iterator = null;
+ if (visualModelComponent != null && visualModelComponent.isRendered()) {
+ if (visualModelComponent.getChildCount() > 0) {
+ iterator = visualModelComponent.getChildren().iterator();
+ }
+ } else {
+ if (getChildCount() > 0) {
+ iterator = getChildren().iterator();
+ }
+ }
+
+ if (iterator != null) {
+ while (iterator.hasNext()) {
+ UIComponent child = (UIComponent) iterator.next();
+
+ if (child instanceof UITreeNode) {
+ UITreeNode treeNode = (UITreeNode) child;
+
+ if (!treeNode.isRendered()) {
+ continue;
+ }
+
+ if (treeNode.getType() != null) {
+ continue;
+ }
+
return treeNode;
}
}
@@ -243,7 +284,7 @@
state.transferQueuedNodes();
// re-set stopInCollapsed to handle AJAX switch type change
state.setStopInCollapsed(isStopInCollapsed());
-
+
setExtendedDataModel(createDataModel(false));
}
@@ -442,7 +483,7 @@
// fire node events
TreeEvents.invokeListenerBindings(this, event, getFacesContext());
-
+
if (event instanceof AjaxEvent) {
AjaxRendererUtils.addRegionsFromComponent(this, getFacesContext());
}
@@ -452,24 +493,51 @@
return isAjaxSubmitSelection();
}
+ private transient UIComponent visualModelComponent;
+
private ExtendedDataModel createDataModel(boolean allowCached) {
- TreeDataModel treeDataModel = new TreeDataModel();
- treeDataModel.setWrappedData(this.getValue());
+ Object value = this.getValue();
+ if (value != null) {
+ TreeDataModel treeDataModel = new TreeDataModel();
+ treeDataModel.setWrappedData(this.getValue());
+
+ if (allowCached && PRESERVE_MODEL_REQUEST.equals(getPreserveModel())) {
+ treeDataModel = new CacheableTreeDataModel(treeDataModel);
+ }
- if (allowCached && PRESERVE_MODEL_REQUEST.equals(getPreserveModel())) {
- treeDataModel = new CacheableTreeDataModel(treeDataModel);
+ return treeDataModel;
+ } else {
+ //TODO implement request caching
+ StackingTreeModel stackingTreeModel = new StackingTreeModel(null);
+ if (getChildCount() > 0) {
+ Iterator children = getChildren().iterator();
+ while (children.hasNext()) {
+ UIComponent component = (UIComponent) children.next();
+ if (component instanceof StackingTreeModelProvider) {
+ StackingTreeModelProvider provider = (StackingTreeModelProvider) component;
+ stackingTreeModel.addStackingModel(provider.getStackingModel());
+ }
+ }
+ }
+
+ stackingTreeModel.addTreeComponentModelListener(new TreeComponentModelListener() {
+
+ public void componentSelected(UIComponent component) {
+ visualModelComponent = component;
+ }
+ });
+
+ return stackingTreeModel;
}
-
- return treeDataModel;
}
-
+
public void processUpdates(FacesContext faces) {
super.processUpdates(faces);
if (getExtendedDataModel() instanceof CacheableTreeDataModel) {
setExtendedDataModel(createDataModel(false));
}
}
-
+
protected ExtendedDataModel createDataModel() {
return createDataModel(true);
}
@@ -557,23 +625,23 @@
public abstract String getSelectedClass();
public abstract void setNodeFace(String nodeFace);
-
+
public abstract String getNodeFace();
public abstract void setToggleOnClick(boolean toggleOnClick);
public abstract boolean isToggleOnClick();
-
+
public abstract void setStateAdvisor(Object nodeFace);
-
+
public abstract Object getStateAdvisor();
-
+
public abstract MethodBinding getAdviseNodeOpened();
-
+
public abstract void setAdviseNodeOpened(MethodBinding adviseNodeOpened);
-
+
public abstract MethodBinding getAdviseNodeSelected();
-
+
public abstract void setAdviseNodeSelected(MethodBinding adviseNodeSelected);
public void addChangeExpandListener(NodeExpandedListener listener) {
@@ -631,7 +699,7 @@
public void removeDragListener(DragListener listener) {
removeFacesListener(listener);
}
-
+
public void setDragValue(Object value) {
// TODO Auto-generated method stub
@@ -642,16 +710,16 @@
}
- /**
- * Return the data object representing the node data for the contextual row key
- *
+ /**
+ * Return the data object representing the node data for the contextual row key
+ *
* @param rowKey contextual row key
* @return data corresponding to the current row key
*/
public Object getRowData(Object rowKey) {
Object storedKey = getRowKey();
FacesContext context = FacesContext.getCurrentInstance();
-
+
try {
setRowKey(context, rowKey);
@@ -665,9 +733,9 @@
}
}
- /**
- * Return the data object representing the node for the contextual row key
- *
+ /**
+ * Return the data object representing the node for the contextual row key
+ *
* @param rowKey contextual row key
* @return {@link TreeNode} instance corresponding to the current row key
*/
@@ -686,7 +754,7 @@
}
}
}
-
+
private UIOutput createDefaultNodeFaceOutput(FacesContext facesContext) {
UIOutput component = new UIOutput() {
@@ -713,7 +781,7 @@
public void setTransient(boolean transientFlag) {
if (!transientFlag) {
throw new IllegalArgumentException(
- "Default representation for node face cannot be set non-persistent!");
+ "Default representation for node face cannot be set non-persistent!");
}
}
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java 2007-07-30
14:02:57 UTC (rev 1926)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -146,23 +146,20 @@
/**
* Finds direct parent {@link UITree} component or throws
- * {@link ClassCastException} if parent is not {@link UITree}
*
* @return {@link UITree} instance
- * @throws ClassCastException
*/
- public UITree getUITree() throws ClassCastException {
+ public UITree getUITree() {
UIComponent parent = getParent();
- if (parent == null) {
- return null;
+ while (parent != null) {
+ if (parent instanceof UITree) {
+ return (UITree) parent;
+ } else {
+ parent = parent.getParent();
+ }
}
- if (parent instanceof UITree) {
- return (UITree) parent;
-
- } else {
- throw new ClassCastException("Parent should be UITree.");
- }
+ return null;
}
public void addDropListener(DropListener listener) {
Modified:
trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeDataModelEventNavigator.java
===================================================================
---
trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeDataModelEventNavigator.java 2007-07-30
14:02:57 UTC (rev 1926)
+++
trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeDataModelEventNavigator.java 2007-07-30
14:03:21 UTC (rev 1927)
@@ -62,6 +62,8 @@
int level = this.rowKey != null ? this.rowKey.depth() : 0;
int delta = level - newRowKey.depth();
+
+ //System.out.println("TreeDataModelEventNavigator.followRowKey() " +
delta);
if (delta > 0) {
beforeUp(delta);
Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
===================================================================
---
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-07-30
14:02:57 UTC (rev 1926)
+++
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-07-30
14:03:21 UTC (rev 1927)
@@ -111,7 +111,8 @@
getElements: function() {
var contentId = this.id;
- this.elements.contentTd = $(contentId);
+ this.elements.contentTd = $(contentId +
+ Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW + Tree.ID_DEVIDER + Tree.ID_CHILDS_TD);
if (this.elements.contentTd) {
for(var child = this.elements.contentTd.firstChild; child != null; child =
child.nextSibling ) {
Modified: trunk/ui/tree/src/main/templates/htmlTree.jspx
===================================================================
--- trunk/ui/tree/src/main/templates/htmlTree.jspx 2007-07-30 14:02:57 UTC (rev 1926)
+++ trunk/ui/tree/src/main/templates/htmlTree.jspx 2007-07-30 14:03:21 UTC (rev 1927)
@@ -44,8 +44,12 @@
<f:parameter value="id,style,class"/>
</f:call>
- <vcp:body />
-
+ <table width="100%" cellpadding="0" cellspacing="0"
border="0">
+ <tbody>
+ <vcp:body />
+ </tbody>
+ </table>
+
<f:call name="encodeSelectionStateInput" />
<f:clientId var="clientId" />
<script type="text/javascript">