Author: nbelaevski
Date: 2010-11-18 12:01:46 -0500 (Thu, 18 Nov 2010)
New Revision: 20105
Modified:
trunk/examples/iteration-demo/src/main/webapp/tree.xhtml
trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
trunk/ui/iteration/ui/src/main/templates/tree.template.xml
trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
Log:
https://jira.jboss.org/browse/RF-9714
Modified: trunk/examples/iteration-demo/src/main/webapp/tree.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 16:56:05 UTC (rev
20104)
+++ trunk/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 17:01:46 UTC (rev
20105)
@@ -31,6 +31,32 @@
</h:head>
<h:body>
+ <h:outputScript>
+ function getNodeStateString(treeNode) {
+ return treeNode.isLeaf() ?
+ 'leaf'
+ : (treeNode.isExpanded() ? 'expanded' : 'collapsed');
+ }
+
+ function handleNodeToggle(nodeData, event, isTreeNodeLevel) {
+ var treeNode = RichFaces.$(event.target);
+ RichFaces.log.info('Toggle event ' + (isTreeNodeLevel ? '(treeNode
level)' : '')
+ + '[' + nodeData + ']:\n ' + treeNode.getId() + ' became ' +
getNodeStateString(treeNode));
+ }
+
+ function handleNodeSelect(event) {
+ var treeNode = RichFaces.$(event.target);
+
+ var selectedNodes = event.rf.data.selection;
+ var selection = new Array();
+ jQuery.each(selectedNodes, function(k, v) {
+ selection.push(v.getId());
+ });
+
+ RichFaces.log.info('Select event:\n ' + selection.join(''));
+ }
+ </h:outputScript>
+
<h:messages id="messages" />
<h:form>
@@ -78,7 +104,9 @@
Tree with customized look:
<it:tree id="customizedTree" var="node"
value="#{treeBean.rootNodes}"
selectionType="#{treeBean.selectionType}"
toggleType="#{treeBean.toggleType}"
- styleClass="#{treeBean.showCustomClasses ? 'customClass' :
''}">
+ styleClass="#{treeBean.showCustomClasses ? 'customClass' :
''}"
+ nodeClass="customNodeClassFromTree"
+ handleClass="customHandleClassFromTree"
iconClass="customIconClassFromTree"
labelClass="customLabelClassFromTree">
<it:treeNode iconLeaf="/images/leaf.png"
iconExpanded="/images/minus.png" iconCollapsed="/images/plus.png"
styleClass="customNodeClass" handleClass="customHandleClass"
iconClass="customIconClass" labelClass="customLabelClass">
@@ -93,10 +121,11 @@
Tree with client-side event handlers:
<it:tree id="clientSideEventsTree" var="node"
value="#{treeBean.rootNodes}"
- selectionType="#{treeBean.selectionType}"
toggleType="#{treeBean.toggleType}">
+ selectionType="#{treeBean.selectionType}"
toggleType="#{treeBean.toggleType}"
+ onnodetoggle="handleNodeToggle("#{node.data}", event,
false)"
+ onselectionchange="handleNodeSelect(event)">
- <it:treeNode ontoggle="RichFaces.log.info('Toggle event: target is - '
+ event.target.id)"
- onselect="RichFaces.log.info('Select event: target is - ' +
event.target.id)">
+ <it:treeNode ontoggle="handleNodeToggle("#{node.data}",
event, true)">
#{node.data}
</it:treeNode>
</it:tree>
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-11-18
16:56:05 UTC (rev 20104)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -853,6 +853,10 @@
return clientId;
}
+ public String getBaseClientId(FacesContext context) {
+ return super.getClientId(context);
+ }
+
/**
* Save current state of data variable.
*
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -326,6 +326,8 @@
return false;
} else if (attributeValue instanceof Long && (Long) attributeValue ==
Long.MIN_VALUE) {
return false;
+ } else if (attributeValue instanceof Collection<?> || attributeValue
instanceof Map<?, ?>) {
+ return true;
}
return attributeValue.toString().length() > 0;
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -43,6 +43,7 @@
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
@@ -134,6 +135,26 @@
public abstract boolean isImmediate();
+ public abstract String getIconLeaf();
+
+ public abstract String getIconExpanded();
+
+ public abstract String getIconCollapsed();
+
+ public abstract String getNodeClass();
+
+ public abstract String getHandleClass();
+
+ public abstract String getIconClass();
+
+ public abstract String getLabelClass();
+
+ @Attribute(events = @EventName("nodetoggle"))
+ public abstract String getOnnodetoggle();
+
+ @Attribute(events = @EventName("selectionchange"))
+ public abstract String getOnselectionchange();
+
@Attribute(defaultValue = "SwitchType.DEFAULT")
public abstract SwitchType getToggleType();
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -28,6 +28,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunction;
import org.richfaces.component.AbstractTree;
import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.TreeRange;
@@ -125,6 +127,7 @@
null);
responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
treeNodeComponent.getClientId(context), null);
+ emitClientToggleEvent(treeNodeComponent, nodeState);
treeNodeComponent.encodeAll(context);
}
@@ -134,4 +137,15 @@
public abstract void encode() throws IOException;
+ private void emitClientToggleEvent(AbstractTreeNode treeNode, TreeNodeState
nodeState) {
+ if
(treeNode.getClientId(context).equals(context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_ATTRIBUTE)))
{
+ TreeNodeState submittedState = ((Boolean)
(context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_STATE_ATTRIBUTE)))
+ ? TreeNodeState.expanded : TreeNodeState.collapsed;
+
+ if (submittedState == nodeState || nodeState == TreeNodeState.leaf) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ajaxContext.appendOncomplete(new
JSFunction("RichFaces.ui.TreeNode.emitToggleEvent",
treeNode.getClientId(context)));
+ }
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -22,6 +22,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Collections;
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
@@ -58,6 +59,7 @@
PartialResponseWriter prw =
context.getPartialViewContext().getPartialResponseWriter();
prw.startUpdate(elementId);
+ Object clientEventHandlers = null;
Object initialRowKey = tree.getRowKey();
try {
TreeRenderingContext.create(context, tree);
@@ -66,6 +68,7 @@
prw.endUpdate();
+ clientEventHandlers = TreeRenderingContext.get(context).getHandlers();
} finally {
try {
tree.setRowKey(context, initialRowKey);
@@ -77,7 +80,8 @@
}
prw.startEval();
- JSFunction function = new
JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", elementId);
+ JSFunction function = new
JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", elementId,
+ Collections.singletonMap("clientEventHandlers",
clientEventHandlers));
prw.write(function.toScript());
prw.endEval();
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -21,6 +21,8 @@
*/
package org.richfaces.renderkit;
+import static org.richfaces.renderkit.RenderKitUtils.getFirstNonEmptyAttribute;
+
import java.io.IOException;
import java.util.Map;
@@ -29,6 +31,7 @@
import javax.faces.context.PartialViewContext;
import javax.faces.context.ResponseWriter;
+import org.richfaces.component.AbstractTree;
import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.SwitchType;
@@ -42,14 +45,14 @@
*/
public class TreeNodeRendererBase extends RendererBase implements MetaComponentRenderer
{
+ static final String AJAX_TOGGLED_NODE_ATTRIBUTE =
TreeNodeRendererBase.class.getName() + ":AJAX_TOGGLED_NODE_ATTRIBUTE";
+
+ static final String AJAX_TOGGLED_NODE_STATE_ATTRIBUTE =
TreeNodeRendererBase.class.getName() + ":AJAX_TOGGLED_NODE_STATE_ATTRIBUTE";
+
private static final String NEW_NODE_TOGGLE_STATE =
"__NEW_NODE_TOGGLE_STATE";
private static final String TRIGGER_NODE_AJAX_UPDATE =
"__TRIGGER_NODE_AJAX_UPDATE";
- private static final ComponentAttribute ONTOGGLE_ATTRIBUTE = new
ComponentAttribute("ontoggle").setEventNames("toggle");
-
- private static final ComponentAttribute ONSELECT_ATTRIBUTE = new
ComponentAttribute("onselect").setEventNames("select");
-
@Override
public void decode(FacesContext context, UIComponent component) {
super.decode(context, component);
@@ -68,6 +71,9 @@
PartialViewContext pvc = context.getPartialViewContext();
if (pvc.isAjaxRequest() && map.get(component.getClientId(context) +
TRIGGER_NODE_AJAX_UPDATE) != null) {
pvc.getRenderIds().add(treeNode.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR +
AbstractTreeNode.SUBTREE_META_COMPONENT_ID);
+
+ context.getAttributes().put(AJAX_TOGGLED_NODE_ATTRIBUTE,
component.getClientId(context));
+ context.getAttributes().put(AJAX_TOGGLED_NODE_STATE_ATTRIBUTE,
expanded);
}
}
}
@@ -91,12 +97,15 @@
return (TreeNodeState)
context.getAttributes().get(TreeEncoderBase.TREE_NODE_STATE_ATTRIBUTE);
}
+ protected UIComponent getTreeComponent(UIComponent treeNodeComponent) {
+ return ((AbstractTreeNode) treeNodeComponent).findTreeComponent();
+ }
+
protected void encodeDefaultIcon(FacesContext context, UIComponent component, String
styleClass) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HtmlConstants.SPAN_ELEM, component);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
- concatClasses(styleClass,
component.getAttributes().get("iconClass")), null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, styleClass, null);
writer.endElement(HtmlConstants.SPAN_ELEM);
}
@@ -104,55 +113,57 @@
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HtmlConstants.IMG_ELEMENT, component);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
- concatClasses(styleClass,
component.getAttributes().get("iconClass")), null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, styleClass, null);
writer.writeAttribute(HtmlConstants.ALT_ATTRIBUTE, "", null);
writer.writeURIAttribute(HtmlConstants.SRC_ATTRIBUTE,
RenderKitUtils.getResourceURL(iconSource, context), null);
writer.endElement(HtmlConstants.IMG_ELEMENT);
}
-
-
protected void encodeIcon(FacesContext context, UIComponent component) throws
IOException {
TreeNodeState nodeState = getNodeState(context);
AbstractTreeNode treeNode = (AbstractTreeNode) component;
+
+ AbstractTree tree = treeNode.findTreeComponent();
if (nodeState.isLeaf()) {
- String iconLeaf = (String)
treeNode.getAttributes().get("iconLeaf");
- encodeIconForNodeState(context, treeNode, nodeState, iconLeaf);
+ String iconLeaf = (String) getFirstNonEmptyAttribute("iconLeaf",
treeNode, tree);
+ encodeIconForNodeState(context, tree, treeNode, nodeState, iconLeaf);
} else {
- String iconExpanded = (String)
treeNode.getAttributes().get("iconExpanded");
- String iconCollapsed = (String)
treeNode.getAttributes().get("iconCollapsed");
+ String iconExpanded = (String)
getFirstNonEmptyAttribute("iconExpanded", treeNode, tree);
+ String iconCollapsed = (String)
getFirstNonEmptyAttribute("iconCollapsed", treeNode, tree);
if (Strings.isNullOrEmpty(iconCollapsed) &&
Strings.isNullOrEmpty(iconExpanded)) {
- encodeDefaultIcon(context, component, nodeState.getIconClass());
+ encodeIconForNodeState(context, tree, treeNode, nodeState, null);
} else {
SwitchType toggleType = treeNode.findTreeComponent().getToggleType();
if (toggleType == SwitchType.client || nodeState ==
TreeNodeState.collapsed) {
- encodeIconForNodeState(context, treeNode, TreeNodeState.collapsed,
iconCollapsed);
+ encodeIconForNodeState(context, tree, treeNode,
TreeNodeState.collapsed, iconCollapsed);
}
if (toggleType == SwitchType.client || nodeState ==
TreeNodeState.expanded) {
- encodeIconForNodeState(context, treeNode, TreeNodeState.expanded,
iconExpanded);
+ encodeIconForNodeState(context, tree, treeNode,
TreeNodeState.expanded, iconExpanded);
}
}
}
}
- protected void encodeIconForNodeState(FacesContext context, AbstractTreeNode
treeNode, TreeNodeState nodeState, String customIcon) throws IOException {
+ protected void encodeIconForNodeState(FacesContext context, AbstractTree tree,
AbstractTreeNode treeNode, TreeNodeState nodeState, String customIcon) throws IOException
{
if (Strings.isNullOrEmpty(customIcon)) {
- encodeDefaultIcon(context, treeNode, nodeState.getIconClass());
+ encodeDefaultIcon(context, treeNode, concatClasses(nodeState.getIconClass(),
treeNode.getAttributes().get("iconClass"),
+ tree.getAttributes().get("iconClass")));
} else {
- encodeCustomIcon(context, treeNode, nodeState.getCustomIconClass(),
customIcon);
+ encodeCustomIcon(context, treeNode,
concatClasses(nodeState.getCustomIconClass(),
treeNode.getAttributes().get("iconClass"),
+ tree.getAttributes().get("iconClass")), customIcon);
}
}
- protected void addEventHandlersToRenderingContext(FacesContext facesContext,
UIComponent component) {
- String ontoggle = (String)
RenderKitUtils.getAttributeAndBehaviorsValue(facesContext, component,
ONTOGGLE_ATTRIBUTE);
- String onselect = (String)
RenderKitUtils.getAttributeAndBehaviorsValue(facesContext, component,
ONSELECT_ATTRIBUTE);
+ protected void addClientEventHandlers(FacesContext facesContext, UIComponent
component) {
+ AbstractTreeNode treeNode = (AbstractTreeNode) component;
- TreeRenderingContext.get(facesContext).addHandlers(ontoggle, null, onselect,
null);
+ //TODO check toggle/selection types
+ TreeRenderingContext renderingContext = TreeRenderingContext.get(facesContext);
+ renderingContext.addHandlers(treeNode);
}
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java 2010-11-18
17:01:46 UTC (rev 20105)
@@ -29,8 +29,13 @@
import javax.faces.context.FacesContext;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptStringBase;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.SwitchType;
/**
* @author Nick Belaevski
@@ -40,24 +45,32 @@
private static final String ATTRIBUTE_NAME = TreeRenderingContext.class.getName() +
":ATTRIBUTE_NAME";
+ private static final ComponentAttribute ONTOGGLE_ATTRIBUTE = new
ComponentAttribute("ontoggle").setEventNames("toggle");
+
+ private static final ComponentAttribute ONNODETOGGLE_ATTRIBUTE = new
ComponentAttribute("onnodetoggle").setEventNames("nodetoggle");
+
public static final class Handlers extends ScriptStringBase {
-
+
private String toggleHandler;
- private String treeToggleHandler;
+ private String nodeToggleHandler;
- private String selectHandler;
-
- private String treeSelectHandler;
-
- public void setSelectHandler(String selectHandler) {
- this.selectHandler = selectHandler;
+ protected Object chain(String firstHandler, String secondHandler) {
+ if (isNullOrEmpty(firstHandler) && isNullOrEmpty(secondHandler)) {
+ return null;
+ }
+
+ if (isNullOrEmpty(firstHandler)) {
+ return secondHandler;
+ }
+
+ if (isNullOrEmpty(secondHandler)) {
+ return firstHandler;
+ }
+
+ return new JSFunction("jsf.util.chain", JSReference.THIS,
JSReference.EVENT, firstHandler, secondHandler).toScript();
}
- public String getSelectHandler() {
- return selectHandler;
- }
-
public void setToggleHandler(String toggleHandler) {
this.toggleHandler = toggleHandler;
}
@@ -66,41 +79,35 @@
return toggleHandler;
}
- public String getTreeToggleHandler() {
- return treeToggleHandler;
+ public String getNodeToggleHandler() {
+ return nodeToggleHandler;
}
- public void setTreeToggleHandler(String treeToggleHandler) {
- this.treeToggleHandler = treeToggleHandler;
+ public void setNodeToggleHandler(String nodeToggleHandler) {
+ this.nodeToggleHandler = nodeToggleHandler;
}
- public String getTreeSelectHandler() {
- return treeSelectHandler;
- }
-
- public void setTreeSelectHandler(String treeSelectHandler) {
- this.treeSelectHandler = treeSelectHandler;
- }
-
public void appendScript(Appendable target) throws IOException {
- // TODO Auto-generated method stub
-
+ Object chain = chain(toggleHandler, nodeToggleHandler);
+ ScriptUtils.appendScript(target, chain);
}
}
private FacesContext context;
-
+
private AbstractTree tree;
private String baseClientId;
private Map<String, Handlers> handlersMap = new HashMap<String,
Handlers>();
+ private Handlers handlers;
+
private TreeRenderingContext(FacesContext context, AbstractTree tree) {
super();
this.context = context;
this.tree = tree;
- this.baseClientId = tree.getClientId(context);
+ this.baseClientId = tree.getBaseClientId(context);
}
public static TreeRenderingContext create(FacesContext context, AbstractTree tree) {
@@ -117,24 +124,32 @@
context.getAttributes().remove(ATTRIBUTE_NAME);
}
- public void addHandlers(String toggleHandler, String treeToggleHandler, String
selectHandler, String treeSelectHandler) {
- String clientId = tree.findTreeNodeComponent().getClientId(context);
+ private Handlers getOrCreateHandlers(String relativeClientId) {
+ if (handlers == null) {
+ handlers = new Handlers();
+ handlersMap.put(relativeClientId, handlers);
+ }
+ return handlers;
+ }
+
+ public void addHandlers(AbstractTreeNode treeNode) {
+ handlers = null;
+ String clientId = treeNode.getClientId(context);
+
String relativeClientId = clientId.substring(baseClientId.length());
- if (isNullOrEmpty(toggleHandler) && isNullOrEmpty(treeToggleHandler)
- && isNullOrEmpty(selectHandler) &&
isNullOrEmpty(treeSelectHandler)) {
+ if (tree.getToggleType() != SwitchType.server) {
+ String toggleHandler = (String)
RenderKitUtils.getAttributeAndBehaviorsValue(context, treeNode, ONTOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(toggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setToggleHandler(toggleHandler);
+ }
- return;
+ String nodeToggleHandler = (String)
RenderKitUtils.getAttributeAndBehaviorsValue(context, tree, ONNODETOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(nodeToggleHandler)) {
+
getOrCreateHandlers(relativeClientId).setNodeToggleHandler(nodeToggleHandler);
+ }
}
-
- Handlers handlers = new Handlers();
- handlers.setToggleHandler(toggleHandler);
- handlers.setTreeToggleHandler(treeToggleHandler);
- handlers.setSelectHandler(selectHandler);
- handlers.setTreeSelectHandler(treeSelectHandler);
-
- handlersMap.put(relativeClientId, handlers);
}
public Object getHandlers() {
Modified:
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
---
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18
16:56:05 UTC (rev 20104)
+++
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18
17:01:46 UTC (rev 20105)
@@ -46,10 +46,16 @@
this.__initializeChildren(commonOptions);
- this.__clientEventHandlers = (commonOptions.clientEventHandlers ||
{})[commonOptions.treeId + id];
+ var __toggleHandler = (commonOptions.clientEventHandlers ||
{})[this.getId().substring(commonOptions.treeId.length)];
+
+ if (__toggleHandler) {
+ richfaces.Event.bind(this.__rootElt, "toggle", new
Function("event", __toggleHandler));
+ }
},
destroy: function() {
+ this.$super.destroy.call(this);
+
if (this.parent) {
this.parent.removeChild(this);
this.parent = null;
@@ -157,6 +163,10 @@
},
+ __fireToggleEvent: function() {
+ richfaces.Event.fire(this.__rootElt, "toggle");
+ },
+
__changeToggleState: function(newState) {
if (!this.isLeaf()) {
if (newState ^ this.isExpanded()) {
@@ -173,6 +183,7 @@
}
this.__updateClientToggleStateInput(newState);
+ this.__fireToggleEvent();
break;
case 'ajax':
@@ -221,6 +232,8 @@
richfaces.ui.TreeNode.initNodeByAjax = function(nodeId, commonOptions) {
var node = $(document.getElementById(nodeId));
+ var opts = commonOptions || {};
+
if (node.nextAll(".rf-tr-nd:first").length != 0) {
node.removeClass("rf-tr-nd-last");
}
@@ -230,11 +243,22 @@
var idx = node.prevAll(".rf-tr-nd").length;
var parentNode = richfaces.$(parent[0]);
- var newChild = new richfaces.ui.TreeNode(node[0], commonOptions);
+ opts.treeId = parentNode.getTree().getId();
+
+ var newChild = new richfaces.ui.TreeNode(node[0], opts);
parentNode.addChild(newChild, idx);
parentNode.getTree().__updateSelection();
};
+ richfaces.ui.TreeNode.emitToggleEvent = function(nodeId) {
+ var node = document.getElementById(nodeId);
+ if (!node) {
+ return;
+ }
+
+ richfaces.$(node).__fireToggleEvent();
+ };
+
var findTree = function(elt) {
return richfaces.$($(elt).closest(".rf-tr"));
};
@@ -267,6 +291,10 @@
this.__ajaxSubmitFunction = new Function("event", "source",
"params", options.ajaxSubmitFunction);
}
+ if (options.onselectionchange) {
+ richfaces.Event.bind(this.__treeRootElt, "selectionchange", new
Function("event", options.onselectionchange));
+ }
+
this.__selectionInput = $(" > .rf-tr-sel-inp", this.__treeRootElt);
this.__treeRootElt.delegate(".rf-trn-hnd", "click", this,
this.__itemHandleClicked);
@@ -369,13 +397,14 @@
this.__handleSelectionChange();
},
- __resetSelection: function() {
- this.__selectedNodeId = null;
- this.__selectionInput.val("");
- },
-
__updateSelection: function() {
var oldSelection = this.__selectedNodeId;
+ var nodeId = this.__selectionInput.val();
+
+ if (oldSelection == nodeId) {
+ return;
+ }
+
if (oldSelection) {
var oldSelectionNode = richfaces.$(oldSelection);
if (oldSelectionNode) {
@@ -383,13 +412,20 @@
}
}
- var nodeId = this.__selectionInput.val();
+ var newSelectionNode;
+ var selection = new Array();
- var newSelectionNode = richfaces.$(nodeId);
+ if (nodeId) {
+ newSelectionNode = richfaces.$(nodeId);
+ }
+
if (newSelectionNode) {
newSelectionNode.__setSelected(true);
+ selection.push(newSelectionNode);
}
+
this.__selectedNodeId = nodeId;
+ richfaces.Event.fire(this.__treeRootElt, "selectionchange", {selection:
selection});
}
});
Modified: trunk/ui/iteration/ui/src/main/templates/tree.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-18 16:56:05 UTC
(rev 20104)
+++ trunk/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-18 17:01:46 UTC
(rev 20105)
@@ -13,6 +13,7 @@
<cdk:resource-dependency name="ajax.reslib"
library="org.richfaces" />
<cdk:resource-dependency name="base-component.reslib"
library="org.richfaces" />
+ <cdk:resource-dependency name="richfaces-event.js" />
<cdk:resource-dependency name="tree.js"
library="org.richfaces" />
<cdk:resource-dependency name="tree.ecss"
library="org.richfaces" />
@@ -43,6 +44,7 @@
<cdk:scriptOption attributes="toggleType"
defaultValue="SwitchType.DEFAULT" />
<cdk:scriptOption name="selectionType"
value="#{getSelectionMode(facesContext, component)}"
defaultValue="SwitchType.client" />
<cdk:scriptOption name="ajaxSubmitFunction"
value="#{getAjaxSubmitFunction(facesContext, component)}" />
+ <cdk:scriptOption attributes="onselectionchange" />
<cdk:scriptOption variables="clientEventHandlers" />
</cdk:scriptObject>
Modified: trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 16:56:05 UTC
(rev 20104)
+++ trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 17:01:46 UTC
(rev 20105)
@@ -22,9 +22,11 @@
<cc:implementation>
<cdk:object name="nodeState"
value="#{getNodeState(facesContext)}"
type="org.richfaces.renderkit.TreeNodeState" />
- <div class="#{concatClasses('rf-trn',
component.attributes['styleClass'])}">
- <span class="#{concatClasses(nodeState.handleClass,
component.attributes['handleClass'])}"></span>
+ <cdk:call expression="addClientEventHandlers(facesContext,
component)" />
+ <div class="#{concatClasses('rf-trn',
component.attributes['styleClass'],
tree.attributes['nodeClass'])}">
+ <span class="#{concatClasses(nodeState.handleClass,
component.attributes['handleClass'],
tree.attributes['handleClass'])}"></span>
+
<span class="rf-trn-cnt">
<cdk:call expression="encodeIcon(facesContext, component)"
/>
<span class="#{concatClasses('rf-trn-lbl',
component.attributes['labelClass'])}">