Author: nbelaevski
Date: 2010-10-31 09:44:08 -0400 (Sun, 31 Oct 2010)
New Revision: 19794
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
Removed:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
Log:
https://jira.jboss.org/browse/RF-9315
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-31
13:42:28 UTC (rev 19793)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -21,6 +21,7 @@
*/
package org.richfaces.component;
+import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
@@ -30,6 +31,8 @@
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UpdateModelException;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.event.AbortProcessingException;
@@ -48,9 +51,11 @@
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.component.util.MessageUtil;
+import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.convert.SequenceRowKeyConverter;
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.model.TreeDataModelImpl;
+import org.richfaces.renderkit.MetaComponentRenderer;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
@@ -65,12 +70,14 @@
tag = @Tag(name = "tree"),
renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer")
)
-public abstract class AbstractTree extends UIDataAdaptor {
+public abstract class AbstractTree extends UIDataAdaptor implements
MetaComponentProcessor, MetaComponentResolver, MetaComponentEncoder {
public static final String COMPONENT_TYPE = "org.richfaces.Tree";
public static final String COMPONENT_FAMILY = "org.richfaces.Tree";
+ public static final String NODE_META_COMPONENT_ID = "node";
+
private static final Predicate<UIComponent> RENDERED_UITREE_NODE = new
Predicate<UIComponent>() {
public boolean apply(UIComponent input) {
return (input instanceof AbstractTreeNode) && input.isRendered();
@@ -83,8 +90,6 @@
expanded
}
- private transient UIComponent decoderHelper = null;
-
public AbstractTree() {
setRendererType("org.richfaces.TreeRenderer");
}
@@ -237,21 +242,32 @@
}
@Override
- public void decode(FacesContext context) {
- try {
- decoderHelper = new TreeDecoderHelper(this);
- super.decode(context);
- } finally {
- decoderHelper = null;
+ protected VisitResult visitDataChildrenMetaComponents(ExtendedVisitContext
extendedVisitContext,
+ VisitCallback callback) {
+
+ VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, NODE_META_COMPONENT_ID);
+ if (result != VisitResult.ACCEPT) {
+ return result;
}
+
+ return super.visitDataChildrenMetaComponents(extendedVisitContext, callback);
}
- @Override
- protected Iterator<UIComponent> dataChildren() {
- if (decoderHelper != null) {
- return Iterators.concat(super.dataChildren(),
Iterators.<UIComponent>singletonIterator(decoderHelper));
- } else {
- return super.dataChildren();
+ public void processMetaComponent(FacesContext context, String metaComponentId) {
+ if (context.getCurrentPhaseId() == PhaseId.APPLY_REQUEST_VALUES) {
+ ((MetaComponentRenderer) getRenderer(context)).decodeMetaComponent(context,
this, metaComponentId);
}
}
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this,
metaComponentId);
+ }
+
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
+ if (NODE_META_COMPONENT_ID.equals(metaComponentId)) {
+ return getClientId(facesContext) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ }
+
+ return null;
+ }
}
Deleted:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java 2010-10-31
13:42:28 UTC (rev 19793)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.component;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class TreeDecoderHelper extends UIComponentBase {
-
- public static final String HELPER_ID = "__treeDecoderHelper";
-
- private AbstractTree tree;
-
- public TreeDecoderHelper(AbstractTree tree) {
- super();
- this.tree = tree;
- setId(HELPER_ID);
- setTransient(true);
- }
-
- @Override
- public boolean isInView() {
- return tree.isInView();
- }
-
- @Override
- public boolean isRendered() {
- return tree.isRendered();
- }
-
- @Override
- public String getFamily() {
- return null;
- }
-
- @Override
- public UIComponent getParent() {
- return tree;
- }
-
-}
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java 2010-10-31
13:42:28 UTC (rev 19793)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -28,6 +28,7 @@
import javax.faces.context.FacesContext;
import javax.swing.tree.TreeNode;
+import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
@@ -170,10 +171,11 @@
while (keysIterator.hasNext()) {
Object object = (Object) keysIterator.next();
- visitor.process(context, object, argument);
-
- Iterator<Object> childrenIterator = getChildrenIterator(context,
object);
- walk(context, visitor, range, argument, childrenIterator);
+ DataVisitResult visitResult = visitor.process(context, object, argument);
+ if (visitResult == DataVisitResult.CONTINUE) {
+ Iterator<Object> childrenIterator = getChildrenIterator(context,
object);
+ walk(context, visitor, range, argument, childrenIterator);
+ }
}
}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.renderkit.TreeRendererBase.NodeState;
+import org.richfaces.renderkit.TreeRendererBase.QueuedData;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.UnmodifiableIterator;
+
+abstract class TreeEncoderBase {
+
+ private static final String TREE_NODE_HANDLE_CLASS_ATTRIBUTE =
"__treeNodeHandleClass";
+
+ private static final String TREE_NODE_ICON_CLASS_ATTRIBUTE =
"__treeNodeIconClass";
+
+ protected final FacesContext context;
+
+ protected final ResponseWriter responseWriter;
+
+ protected final AbstractTree tree;
+
+ private LinkedList<QueuedData> queuedData = new
LinkedList<QueuedData>();
+
+ public TreeEncoderBase(FacesContext context, AbstractTree tree) {
+ super();
+ this.context = context;
+ this.responseWriter = context.getResponseWriter();
+ this.tree = tree;
+ }
+
+ protected void encodeTree(Iterator<Object> childrenIterator) throws IOException
{
+ Predicate<Object> renderedTreeNodeKeyPredicate = new
Predicate<Object>() {
+ public boolean apply(Object input) {
+ tree.setRowKey(input);
+
+ if (!tree.isRowAvailable()) {
+ return false;
+ }
+
+ return tree.getTreeNodeComponent() != null;
+ }
+ };
+
+ UnmodifiableIterator<Object> filteredIterator =
Iterators.filter(childrenIterator, renderedTreeNodeKeyPredicate);
+ while (filteredIterator.hasNext()) {
+ Object rowKey = filteredIterator.next();
+
+ encodeTreeNode(rowKey, !filteredIterator.hasNext());
+ }
+ }
+
+ protected void encodeTreeNode(Object rowKey, boolean isLastNode) throws IOException
{
+ if (!queuedData.isEmpty()) {
+ QueuedData data = queuedData.getLast();
+ if (!data.isEncoded()) {
+ tree.setRowKey(context, data.getRowKey());
+
+ writeTreeNodeStartElement(NodeState.expanded, data.isLastNode());
+
+ data.setEncoded(true);
+ }
+ }
+
+ queuedData.add(new QueuedData(rowKey, isLastNode));
+
+ tree.setRowKey(context, rowKey);
+
+ boolean iterateChildren = tree.isExpanded();
+
+ if (iterateChildren) {
+ encodeTree(tree.getChildrenIterator(context, rowKey));
+ }
+
+ QueuedData data = queuedData.removeLast();
+ if (!data.isEncoded()) {
+ NodeState nodeState = iterateChildren ? NodeState.leaf :
NodeState.collapsed;
+ writeTreeNodeStartElement(nodeState, data.isLastNode());
+ }
+
+ writeTreeNodeEndElement();
+ }
+
+ protected void writeTreeNodeStartElement(NodeState nodeState, boolean isLast) throws
IOException {
+ context.getAttributes().put(TREE_NODE_HANDLE_CLASS_ATTRIBUTE,
nodeState.getHandleClass());
+ context.getAttributes().put(TREE_NODE_ICON_CLASS_ATTRIBUTE,
nodeState.getIconClass());
+
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, tree);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses("tree_node", isLast ?
"tree_node_last" : null),
+ null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
tree.getClientId(context), null);
+
+ tree.getTreeNodeComponent().encodeAll(context);
+ }
+
+ protected void writeTreeNodeEndElement() throws IOException {
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ public abstract void encode() throws IOException;
+
+}
\ No newline at end of file
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.AbstractTree;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+class TreeEncoderFull extends TreeEncoderBase {
+
+ public TreeEncoderFull(FacesContext context, AbstractTree tree) {
+ super(context, tree);
+ }
+
+ public void encode() throws java.io.IOException {
+ Object initialRowKey = tree.getRowKey();
+ try {
+ encodeTree(tree.getChildrenIterator(context, null));
+ } finally {
+ try {
+ tree.setRowKey(context, initialRowKey);
+ } catch (Exception e) {
+ TreeRendererBase.LOGGER.error(e.getMessage(), e);
+ }
+ }
+ }
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialResponseWriter;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.component.AbstractTree;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+class TreeEncoderPartial extends TreeEncoderBase {
+
+ private Object rowKey;
+
+ public TreeEncoderPartial(FacesContext context, AbstractTree tree) {
+ super(context, tree);
+
+ this.rowKey = tree.getRowKey();
+
+ if (this.rowKey == null) {
+ throw new NullPointerException("rowKey");
+ }
+ }
+
+ @Override
+ public void encode() throws IOException {
+ PartialResponseWriter prw =
context.getPartialViewContext().getPartialResponseWriter();
+ prw.startUpdate(tree.getClientId(context));
+
+ Object initialRowKey = tree.getRowKey();
+ try {
+
+ encodeTreeNode(rowKey, true);
+
+ prw.endUpdate();
+
+ } finally {
+ try {
+ tree.setRowKey(context, initialRowKey);
+ } catch (Exception e) {
+ TreeRendererBase.LOGGER.error(e.getMessage(), e);
+ }
+ }
+
+ prw.startEval();
+ JSFunction function = new
JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", tree.getClientId(context));
+ prw.write(function.toScript());
+ prw.endEval();
+ }
+}
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-10-31
13:42:28 UTC (rev 19793)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-10-31
13:44:08 UTC (rev 19794)
@@ -21,64 +21,69 @@
*/
package org.richfaces.renderkit;
+import static org.richfaces.component.AbstractTree.NODE_META_COMPONENT_ID;
import static org.richfaces.renderkit.util.AjaxRendererUtils.AJAX_FUNCTION_NAME;
import static org.richfaces.renderkit.util.AjaxRendererUtils.buildAjaxFunction;
import static org.richfaces.renderkit.util.AjaxRendererUtils.buildEventOptions;
import java.io.IOException;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.Map;
import javax.faces.component.UIComponent;
-import javax.faces.component.UINamingContainer;
-import javax.faces.component.visit.VisitCallback;
-import javax.faces.component.visit.VisitContext;
-import javax.faces.component.visit.VisitHint;
-import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
+import javax.faces.context.PartialViewContext;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.component.AbstractTree;
import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.SwitchType;
-import org.richfaces.component.TreeDecoderHelper;
-import org.richfaces.component.util.HtmlUtil;
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.UnmodifiableIterator;
/**
* @author Nick Belaevski
*
*/
-public abstract class TreeRendererBase extends RendererBase {
+public abstract class TreeRendererBase extends RendererBase implements
MetaComponentRenderer {
- private static final Logger LOGGER = RichfacesLogger.RENDERKIT.getLogger();
+ static final Logger LOGGER = RichfacesLogger.RENDERKIT.getLogger();
- private static final String TOGGLE_DATA = "toggleData";
+ private static final JSReference TOGGLE_PARAMS = new
JSReference("toggleParams");
+ private static final JSReference TOGGLE_SOURCE = new
JSReference("toggleSource");
+
private static final String TREE_TOGGLE_ID_PARAM =
"org.richfaces.Tree.TREE_TOGGLE_ID";
private static final String NODE_TOGGLE_ID_PARAM =
"org.richfaces.Tree.NODE_TOGGLE_ID";
private static final String NEW_STATE_PARAM =
"org.richfaces.Tree.NEW_STATE";
- private static final JSReference JS_TREE_ID = new JSReference(TOGGLE_DATA +
".treeId");
-
- private static final JSReference JS_NODE_ID = new JSReference(TOGGLE_DATA +
".nodeId");
+ enum NodeState {
+ expanded("tree_handle_expanded", "tree_icon_node"),
+ collapsed("tree_handle_collapsed", "tree_icon_node"),
+ leaf("tree_handle_leaf", "tree_icon_leaf");
+
+ private String handleClass;
+
+ private String iconClass;
- private static final JSReference JS_NEW_STATE = new JSReference(TOGGLE_DATA +
".treeId");
-
- private static final class QueuedData {
+ private NodeState(String handleClass, String iconClass) {
+ this.handleClass = handleClass;
+ this.iconClass = iconClass;
+ }
+ public String getHandleClass() {
+ return handleClass;
+ }
+ public String getIconClass() {
+ return iconClass;
+ }
+ }
+
+ static final class QueuedData {
private Object rowKey;
@@ -108,109 +113,10 @@
}
}
- private class TreeEncoder {
-
- private static final String TREE_NODE_HANDLE_CLASS_ATTRIBUTE =
"__treeNodeHandleClass";
-
- private static final String TREE_NODE_ICON_CLASS_ATTRIBUTE =
"__treeNodeIconClass";
-
- private FacesContext context;
-
- private ResponseWriter responseWriter;
-
- private AbstractTree tree;
-
- private LinkedList<QueuedData> queuedData = new
LinkedList<QueuedData>();
-
- public TreeEncoder(FacesContext context, AbstractTree tree) {
- super();
- this.context = context;
- this.responseWriter = context.getResponseWriter();
- this.tree = tree;
- }
-
- protected void encodeTree(Iterator<Object> childrenIterator) throws
IOException {
- Predicate<Object> renderedTreeNodeKeyPredicate = new
Predicate<Object>() {
- public boolean apply(Object input) {
- tree.setRowKey(input);
-
- if (!tree.isRowAvailable()) {
- return false;
- }
-
- return tree.getTreeNodeComponent() != null;
- }
- };
-
- UnmodifiableIterator<Object> filteredIterator =
Iterators.filter(childrenIterator, renderedTreeNodeKeyPredicate);
- while (filteredIterator.hasNext()) {
- Object rowKey = filteredIterator.next();
-
- encodeTreeNode(rowKey, !filteredIterator.hasNext());
- }
- }
-
- protected void encodeTreeNode(Object rowKey, boolean isLastNode) throws
IOException {
- if (!queuedData.isEmpty()) {
- QueuedData data = queuedData.getLast();
- if (!data.isEncoded()) {
- tree.setRowKey(context, data.getRowKey());
-
- writeTreeNodeStartElement(data.isLastNode(), false);
-
- data.setEncoded(true);
- }
- }
-
- queuedData.add(new QueuedData(rowKey, isLastNode));
-
- tree.setRowKey(context, rowKey);
-
- encodeTree(tree.getChildrenIterator(context, rowKey));
-
- QueuedData data = queuedData.removeLast();
- if (!data.isEncoded()) {
- writeTreeNodeStartElement(data.isLastNode(), true);
- }
-
- writeTreeNodeEndElement();
- }
-
- protected void writeTreeNodeStartElement(boolean isLast, boolean isLeaf) throws
IOException {
- context.getAttributes().put(TREE_NODE_HANDLE_CLASS_ATTRIBUTE, isLeaf ?
"tree_handle_leaf" : "tree_handle_expanded");
- context.getAttributes().put(TREE_NODE_ICON_CLASS_ATTRIBUTE, isLeaf ?
"tree_icon_leaf" : "tree_icon_node");
-
- responseWriter.startElement(HtmlConstants.DIV_ELEM, tree);
- responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
- HtmlUtil.concatClasses("tree_node", isLast ?
"tree_node_last" : null),
- null);
- responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
tree.getClientId(context), null);
-
- tree.getTreeNodeComponent().encodeAll(context);
- }
-
- protected void writeTreeNodeEndElement() throws IOException {
- responseWriter.endElement(HtmlConstants.DIV_ELEM);
- }
-
- public void encode() throws IOException {
- Object initialRowKey = tree.getRowKey();
- try {
- encodeTree(tree.getChildrenIterator(context, null));
- } finally {
- try {
- tree.setRowKey(context, initialRowKey);
- } catch (Exception e) {
- LOGGER.error(e.getMessage(), e);
- }
- }
- }
- }
-
public void encodeTree(FacesContext context, UIComponent component) throws
IOException {
AbstractTree tree = (AbstractTree) component;
- new TreeEncoder(context, tree).encode();
+ new TreeEncoderFull(context, tree).encode();
}
protected String getAjaxToggler(FacesContext context, UIComponent component) {
@@ -223,9 +129,8 @@
JSFunction ajaxFunction = buildAjaxFunction(context, component,
AJAX_FUNCTION_NAME);
AjaxEventOptions eventOptions = buildEventOptions(context, component);
- eventOptions.setParameter(TREE_TOGGLE_ID_PARAM, JS_TREE_ID);
- eventOptions.setParameter(NODE_TOGGLE_ID_PARAM, JS_NODE_ID);
- eventOptions.setParameter(NEW_STATE_PARAM, JS_NEW_STATE);
+ eventOptions.setAjaxComponent(TOGGLE_SOURCE);
+ eventOptions.setClientParameters(TOGGLE_PARAMS);
if (!eventOptions.isEmpty()) {
ajaxFunction.addParameter(eventOptions);
@@ -238,35 +143,44 @@
protected void doDecode(FacesContext context, UIComponent component) {
super.doDecode(context, component);
- final Map<String, String> map =
context.getExternalContext().getRequestParameterMap();
- String toggleId = map.get(TREE_TOGGLE_ID_PARAM);
- if (component.getClientId(context).equals(toggleId)) {
-
- String nodeId = map.get(NODE_TOGGLE_ID_PARAM) +
UINamingContainer.getSeparatorChar(context)
- + TreeDecoderHelper.HELPER_ID;
-
- VisitContext visitContext = createVisitContext(context, nodeId);
- component.visitTree(visitContext, new VisitCallback() {
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.renderkit.MetaComponentRenderer#encodeMetaComponent(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String)
+ */
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
+ throws IOException {
+
+ if (NODE_META_COMPONENT_ID.equals(metaComponentId)) {
+ AbstractTree tree = (AbstractTree) component;
+ new TreeEncoderPartial(context, tree).encode();
+ } else {
+ throw new IllegalArgumentException(metaComponentId);
+ }
+
+ // TODO Auto-generated method stub
+
+ }
+
+ public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
+ if (NODE_META_COMPONENT_ID.equals(metaComponentId)) {
+ final Map<String, String> map =
context.getExternalContext().getRequestParameterMap();
+ String toggleId = map.get(NODE_TOGGLE_ID_PARAM);
+ if (component.getClientId(context).equals(toggleId)) {
- public VisitResult visit(VisitContext context, UIComponent target) {
- AbstractTree tree = (AbstractTree) target.getParent();
- AbstractTreeNode treeNode = tree.getTreeNodeComponent();
- if (treeNode != null) {
- boolean expanded = Boolean.valueOf(map.get(NEW_STATE_PARAM));
- if (tree.isExpanded() ^ expanded) {
- new TreeToggleEvent(treeNode, expanded);
- }
- }
-
- return VisitResult.COMPLETE;
+ AbstractTree tree = (AbstractTree) component;
+ AbstractTreeNode treeNode = tree.getTreeNodeComponent();
+ boolean expanded = Boolean.valueOf(map.get(NEW_STATE_PARAM));
+ if (tree.isExpanded() ^ expanded) {
+ new TreeToggleEvent(treeNode, expanded).queue();
}
- });
-
+
+ PartialViewContext pvc = context.getPartialViewContext();
+ if (pvc.isAjaxRequest()) {
+ pvc.getRenderIds().add(tree.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + "node");
+ }
+ }
}
}
-
- private VisitContext createVisitContext(FacesContext context, String nodeId) {
- return VisitContext.createVisitContext(context, Collections.singleton(nodeId),
- EnumSet.<VisitHint>of(VisitHint.SKIP_UNRENDERED));
- }
+
}
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-10-31
13:42:28 UTC (rev 19793)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-10-31
13:44:08 UTC (rev 19794)
@@ -28,6 +28,12 @@
});
}
+ var TOGGLE_TREE_ID_PARAM = "org.richfaces.Tree.TREE_TOGGLE_ID";
+
+ var TOGGLE_NODE_ID_PARAM = "org.richfaces.Tree.NODE_TOGGLE_ID";
+
+ var TOGGLE_NEW_STATE_PARAM = "org.richfaces.Tree.NEW_STATE";
+
var TREE_HANDLE_CLASSES = ["tree_collapse", "tree_expand"];
var TREE_CLASSES = ["tree_handle_collapsed",
"tree_handle_expanded"];
@@ -98,7 +104,7 @@
},
isCollapsed: function() {
- return !this.isLeaf() && this.elt.hasClass("tree_collapse");
+ return !this.isLeaf() &&
this.handler.hasClass("tree_handle_collapsed");
},
isLeaf: function() {
@@ -128,13 +134,8 @@
break;
case 'ajax':
- var toggleData = {
- nodeId: richfaces.getDomElement(this.id).id,
- newState: newState
- };
-
//TODO - event?
- tree.toggleByAjax(null, toggleData);
+ tree.toggleByAjax(null, richfaces.getDomElement(this.id).id, newState);
break;
case 'server':
@@ -173,6 +174,21 @@
}
});
+ richfaces.ui.TreeNode.initNodeByAjax = function(nodeId) {
+ var node = $(document.getElementById(nodeId));
+
+ if (node.nextAll(".tree_node:first").length != 0) {
+ node.removeClass("tree_node_last");
+ }
+
+ var parent = node.parent(".tree_node, .rf-tree");
+
+ var idx = node.prevAll(".tree_node").length;
+
+ var parentNode = richfaces.$(parent[0]);
+ parentNode.addChild(new richfaces.ui.TreeNode(node[0]), idx);
+ };
+
richfaces.ui.Tree = richfaces.ui.TreeNode.extendClass({
name: "Tree",
@@ -184,7 +200,7 @@
this.__selectionMode = options.selectionMode || 'ajax';
if (options.ajaxToggler) {
- this.__ajaxToggler = new Function("event", "toggleData",
options.ajaxToggler);
+ this.__ajaxToggler = new Function("event", "toggleSource",
"toggleParams", options.ajaxToggler);
}
},
@@ -194,9 +210,13 @@
this.__ajaxToggler = null;
},
- toggleByAjax: function(event, toggleData) {
- toggleData.treeId = this.id;
- this.__ajaxToggler(event, toggleData);
+ toggleByAjax: function(event, toggleSource, newNodeState) {
+ var clientParams = {};
+ clientParams[TOGGLE_NEW_STATE_PARAM] = newNodeState;
+ clientParams[TOGGLE_NODE_ID_PARAM] = toggleSource;
+ clientParams[TOGGLE_TREE_ID_PARAM] = this.id;
+
+ this.__ajaxToggler(event, toggleSource + '@node', clientParams);
},
getToggleMode: function() {