Author: nbelaevski
Date: 2007-08-27 14:40:24 -0400 (Mon, 27 Aug 2007)
New Revision: 2519
Modified:
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/component/events/TreeEvents.java
trunk/ui/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java
trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
Log:
http://jira.jboss.com/jira/browse/RF-700 fixed, demo application updated
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-08-27 18:39:37
UTC (rev 2518)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-08-27 18:40:24
UTC (rev 2519)
@@ -22,10 +22,8 @@
package org.richfaces.component;
import java.io.IOException;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
import javax.faces.application.Application;
import javax.faces.component.NamingContainer;
@@ -38,7 +36,9 @@
import javax.faces.event.FacesListener;
import javax.faces.event.PhaseId;
+import org.ajax4jsf.component.AjaxComponent;
import org.ajax4jsf.component.UIDataAdaptor;
+import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.DataVisitor;
@@ -53,6 +53,8 @@
import org.richfaces.component.state.events.ExpandAllCommandEvent;
import org.richfaces.component.state.events.ExpandNodeCommandEvent;
import org.richfaces.component.state.events.TreeStateCommandEvent;
+import org.richfaces.event.AjaxExpandedEvent;
+import org.richfaces.event.AjaxSelectedEvent;
import org.richfaces.event.DragEvent;
import org.richfaces.event.DragListener;
import org.richfaces.event.DropEvent;
@@ -77,7 +79,7 @@
*/
public abstract class UITree extends UIDataAdaptor implements
-TreeListenerEventsProducer, Draggable, Dropzone {
+TreeListenerEventsProducer, Draggable, Dropzone, AjaxComponent {
public static final String COMPONENT_TYPE = "org.richfaces.Tree";
@@ -98,9 +100,6 @@
public final static String SELECTED_NODE_PARAMETER_NAME =
NamingContainer.SEPARATOR_CHAR
+ "selectedNode";
- public final static String LAST_ELEMENT_FLAG = NamingContainer.SEPARATOR_CHAR
- + "lastElement";
-
public static final String SELECTION_INPUT_ATTRIBUTE = "_selectionInput";
public final static String DEFAULT_SELECTED_CSS_CLASS = "dr-tree-i-sel";
@@ -109,8 +108,6 @@
private UITreeNode defaultFacet;
- private Set detachableRowKeys;
-
public UITree() {
super();
@@ -359,8 +356,7 @@
AbstractTreeDataModel extendedDataModel = (AbstractTreeDataModel)
getExtendedDataModel();
extendedDataModel.walkModel(faces, visitor,
(TreeRange) range, key, argument,
- faces.getExternalContext().getRequestParameterMap().get(
- getBaseClientId(faces) + LAST_ELEMENT_FLAG) != null);
+ false);
}
public String getSelectionStateInputName(FacesContext context) {
@@ -499,11 +495,23 @@
setSelected();
}
+ if (event instanceof AjaxSelectedEvent || event instanceof AjaxExpandedEvent) {
+ Object key = getRowKey();
+ if (key != null) {
+ this.addRequestKey(key);
+ }
+
+ FacesContext facesContext = getFacesContext();
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
+ ajaxContext.getAjaxAreasToRender().add(this.getClientId(facesContext));
+ }
+
// fire node events
TreeEvents.invokeListenerBindings(this, event, getFacesContext());
if (event instanceof AjaxEvent) {
- AjaxRendererUtils.addRegionsFromComponent(this, getFacesContext());
+ FacesContext facesContext = getFacesContext();
+ AjaxRendererUtils.addRegionsFromComponent(this, facesContext);
}
}
@@ -818,22 +826,6 @@
return null;
}
-
-
- public Set getDetachableRowKeys() {
- return detachableRowKeys;
- }
-
- public void resetDetachableRowKeys() {
- detachableRowKeys = null;
- }
-
- public Set getOrCreateDetachableRowKeys() {
- if (detachableRowKeys == null) {
- detachableRowKeys = new HashSet();
- }
- return detachableRowKeys;
- }
}
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java 2007-08-27
18:39:37 UTC (rev 2518)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java 2007-08-27
18:40:24 UTC (rev 2519)
@@ -12,6 +12,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
+import org.ajax4jsf.component.AjaxComponent;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.richfaces.component.events.TreeEvents;
@@ -29,7 +30,7 @@
*/
public abstract class UITreeNode extends UIComponentBase implements
-TreeListenerEventsProducer, Draggable, Dropzone {
+TreeListenerEventsProducer, Draggable, Dropzone, AjaxComponent {
private String dragType;
private Object acceptedTypes;
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/events/TreeEvents.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/events/TreeEvents.java 2007-08-27
18:39:37 UTC (rev 2518)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/events/TreeEvents.java 2007-08-27
18:40:24 UTC (rev 2519)
@@ -27,6 +27,7 @@
import javax.faces.event.FacesEvent;
import org.ajax4jsf.event.AjaxEvent;
+import org.richfaces.event.AjaxExpandedEvent;
import org.richfaces.event.AjaxSelectedEvent;
import org.richfaces.event.DragEvent;
import org.richfaces.event.DropEvent;
@@ -53,14 +54,14 @@
if (event instanceof NodeExpandedEvent) {
binding = eventsProducer.getChangeExpandListener();
- } else if (event instanceof AjaxSelectedEvent) {
- if (eventsProducer.hasAjaxSubmitSelection()) {
- binding = eventsProducer.getNodeSelectListener();
-
+ if (event instanceof AjaxExpandedEvent) {
new AjaxEvent(event.getComponent()).queue();
}
} else if (event instanceof NodeSelectedEvent) {
binding = eventsProducer.getNodeSelectListener();
+ if (event instanceof AjaxSelectedEvent &&
eventsProducer.hasAjaxSubmitSelection()) {
+ new AjaxEvent(event.getComponent()).queue();
+ }
} else if (event instanceof DropEvent) {
binding = eventsProducer.getDropListener();
} else if (event instanceof DragEvent) {
Modified: trunk/ui/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java 2007-08-27
18:39:37 UTC (rev 2518)
+++ trunk/ui/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java 2007-08-27
18:40:24 UTC (rev 2519)
@@ -4,11 +4,8 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -27,6 +24,7 @@
import org.richfaces.component.state.events.CollapseNodeCommandEvent;
import org.richfaces.component.state.events.ExpandNodeCommandEvent;
import org.richfaces.component.util.ViewUtil;
+import org.richfaces.event.AjaxExpandedEvent;
import org.richfaces.event.AjaxSelectedEvent;
import org.richfaces.event.NodeExpandedEvent;
import org.richfaces.event.NodeSelectedEvent;
@@ -39,25 +37,12 @@
public abstract class NodeRendererBase extends CompositeRenderer {
protected static final String NODE_EXPANDED_INPUT_SUFFIX = "NodeExpanded";
+ protected static final String AJAX_EXPANDED_SUFFIX = "AjaxExpanded";
private static class TreeNodeOptions extends ScriptOptions {
public TreeNodeOptions(UIComponent component) {
super(component);
-
- Map params = new HashMap();
-
- if (((Boolean) (component.getAttributes().get("isLastElement")))
- .booleanValue()) {
-
- UITree tree = ((UITreeNode) component).getUITree();
-
- params.put(tree.getBaseClientId(FacesContext
- .getCurrentInstance())
- + UITree.LAST_ELEMENT_FLAG, Boolean.TRUE);
- }
-
- addOption("parameters", params);
}
}
@@ -90,14 +75,8 @@
parameters.put(id + NODE_EXPANDED_INPUT_SUFFIX, String.valueOf(!tree
.isExpanded()));
+ parameters.put(id + AJAX_EXPANDED_SUFFIX, Boolean.TRUE);
- boolean isLast = false;
- if (((Boolean) (treeNode.getAttributes().get("isLastElement")))
- .booleanValue()) {
- parameters.put(tree.getBaseClientId(context)
- + UITree.LAST_ELEMENT_FLAG, Boolean.TRUE);
- isLast=true;
- }
function.addParameter(eventOptions);
StringBuffer buffer = new StringBuffer();
@@ -265,18 +244,12 @@
new CollapseNodeCommandEvent(tree, key).queue();
}
- new NodeExpandedEvent(node).queue();
- new NodeExpandedEvent(tree).queue();
-
- if (UITree.SWITCH_AJAX.equals(tree.getSwitchType()) &&
AjaxRendererUtils.isAjaxRequest(context)) {
- Set ajaxKeys = tree.getAjaxKeys();
- if (ajaxKeys == null) {
- ajaxKeys = new HashSet();
-
- tree.setAjaxKeys(ajaxKeys);
- }
-
- ajaxKeys.add(key);
+ if (Boolean.valueOf((String) requestMap.get(id + AJAX_EXPANDED_SUFFIX))) {
+ new AjaxExpandedEvent(node).queue();
+ new AjaxExpandedEvent(tree).queue();
+ } else {
+ new NodeExpandedEvent(node).queue();
+ new NodeExpandedEvent(tree).queue();
}
}
}
Modified: trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-08-27
18:39:37 UTC (rev 2518)
+++ trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-08-27
18:40:24 UTC (rev 2519)
@@ -23,12 +23,12 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
import javax.faces.FacesException;
import javax.faces.component.NamingContainer;
@@ -59,7 +59,7 @@
public int compare(Object key1, Object key2) {
TreeRowKey treeRowKey1 = (TreeRowKey) key1;
TreeRowKey treeRowKey2 = (TreeRowKey) key2;
-
+
if (treeRowKey1 == null) {
if (treeRowKey2 == null) {
return 0;
@@ -71,20 +71,20 @@
return 1;
}
}
-
+
Iterator iterator1 = treeRowKey1.iterator();
Iterator iterator2 = treeRowKey2.iterator();
-
+
while (iterator1.hasNext() && iterator2.hasNext()) {
String id1 = iterator1.next().toString();
String id2 = iterator2.next().toString();
-
+
int cr = id1.compareTo(id2);
if (cr != 0) {
return cr;
}
}
-
+
if (iterator1.hasNext()) {
return 1;
} else if (iterator2.hasNext()) {
@@ -94,9 +94,9 @@
}
}
};
-
+
private final class RendererDataModelEventNavigator extends
- TreeDataModelEventNavigator {
+ TreeDataModelEventNavigator {
private final FacesContext context;
private final UITree tree;
private final Flag droppedDownToLevelFlag;
@@ -105,7 +105,7 @@
private String clientId;
private boolean expanded;
private boolean showLines;
-
+
private RendererDataModelEventNavigator(UITree tree,
TreeRowKey floatingKey, FacesContext context, Flag droppedDownToLevelFlag) {
super(tree, floatingKey);
@@ -113,7 +113,7 @@
this.tree = tree;
this.droppedDownToLevelFlag = droppedDownToLevelFlag;
this.writer = context.getResponseWriter();
-
+
this.expanded = this.tree.isExpanded();
this.showLines = this.tree.isShowConnectingLines();
this.clientId = getClientId();
@@ -125,7 +125,7 @@
this.expanded = this.tree.isExpanded();
this.clientId = getClientId();
}
-
+
private String getClientId() {
Object rowKey = tree.getRowKey();
String id;
@@ -146,7 +146,7 @@
closeDiv();
droppedDownToLevelFlag.setContext(null);
}
-
+
//writer.write("** afterUp **");
for (int i = 0; i < levels; i++) {
closeDiv();
@@ -157,23 +157,23 @@
public void afterDown() throws IOException {
}
-
+
public void beforeDown() throws IOException {
Context c = droppedDownToLevelFlag.getContext();
droppedDownToLevelFlag.setContext(null);
openDiv(c);
//writer.write("** beforeDown **");
-
+
//if (this.getRowKey()==null ) openDiv();
}
public void beforeUp(int levels) throws IOException {
}
-
+
public void openDiv(Context context) throws IOException {
writer.startElement("div", tree);
-
+
if (context == null) {
context = new Context();
context.setLast(this.actualLast);
@@ -181,9 +181,9 @@
context.setExpanded(this.expanded);
context.setRowKey(this.getRowKey());
}
-
+
getUtils().writeAttribute(writer, "id", context.getClientId() +
"childs");
-
+
if (!context.isExpanded()) {
getUtils().writeAttribute(writer, "style", "display: none;");
} else {
@@ -196,7 +196,7 @@
}
}
}
-
+
String styleClasses = "";
if (context.getRowKey() != null) {
styleClasses = "dr-tree-layout-on dr-tree-h-ic-div
rich-tree-node-cildren";
@@ -204,7 +204,7 @@
}
if (styleClasses!="") getUtils().writeAttribute(writer, "class",
styleClasses);
}
-
+
public void closeDiv() throws IOException {
writer.endElement("div");
}
@@ -220,7 +220,7 @@
private final UITree tree;
private final RendererDataModelEventNavigator navigator;
-
+
private TreeStateAdvisor methodBindingAdvisor = null;
private Object floatingKey;
@@ -236,7 +236,7 @@
public void process(FacesContext context, Object rowKey, Object argument)
throws IOException {
processAdvisors(context, (TreeRowKey)rowKey);
-
+
navigator.followRowKey(context, (TreeRowKey) rowKey);
Context c = flag.getContext();
@@ -244,7 +244,7 @@
navigator.openDiv(c);
navigator.closeDiv();
}
-
+
UITreeNode nodeFacet = tree.getNodeFacet();
Object oldAttrValue = nodeFacet.getAttributes().get("isLastElement");
Object oldAjaxRootAttrValue =
nodeFacet.getAttributes().get("isAjaxUpdateRoot");
@@ -257,17 +257,17 @@
writer.writeAttribute("class", "dr-tree-last-node-marker",
null);
writer.endElement("p");
}
-
+
renderChild(context, nodeFacet);
-
+
c = new Context();
c.setClientId(nodeFacet.getClientId(context) + NamingContainer.SEPARATOR_CHAR);
c.setLast(this.isLastElement);
c.setExpanded(tree.isExpanded());
c.setRowKey(tree.getRowKey());
flag.setContext(c);
-
+
//writer.write("** after renderChild **");
//navigator.openDiv();
} finally {
@@ -294,11 +294,11 @@
isLastElement = false;
navigator.resetLastElement();
}
-
+
public void processAdvisors(FacesContext context, TreeRowKey rowKey) throws IOException
{
TreeState componentState = (TreeState) tree.getComponentState();
TreeStateAdvisor stateAdvisor = (TreeStateAdvisor)tree.getStateAdvisor();
-
+
if (null == stateAdvisor) {
if (null == methodBindingAdvisor) {
methodBindingAdvisor = new TreeStateAdvisor() {
@@ -309,7 +309,7 @@
}
return null;
}
-
+
public Boolean adviseNodeSelected(UITree tree) {
MethodBinding adviseNodeSelected = tree.getAdviseNodeSelected();
if (null != adviseNodeSelected) {
@@ -321,7 +321,7 @@
}
stateAdvisor = methodBindingAdvisor;
}
-
+
Boolean adviseOpened = stateAdvisor.adviseNodeOpened(tree);
if (null != adviseOpened) {
if (adviseOpened.booleanValue()) {
@@ -355,7 +355,7 @@
super();
addContributor(DraggableRendererContributor.getInstance());
addContributor(DropzoneRendererContributor.getInstance());
-
+
addParameterEncoder(DnDParametersEncoder.getInstance());
}
@@ -370,6 +370,9 @@
try {
if (component instanceof UITree) {
UITree tree = (UITree) component;
+
+ String id = path + tree.getId();
+
tree.captureOrigValue();
//Object rowKey = tree.getRowKey();
@@ -384,20 +387,17 @@
writeNamespace(context, component);
List encodedAreaIds = new ArrayList();
-
+
try {
- Set ajaxKeys = tree.getAjaxKeys();
+ Set ajaxKeys = tree.getAllAjaxKeys();
if (ajaxKeys != null) {
- Set keys = tree.getDetachableRowKeys();
- Set sortedKeys = new TreeSet(treeRowKeyComparator);
+ List sortedKeys = new ArrayList(ajaxKeys.size());
sortedKeys.addAll(ajaxKeys);
- if (keys != null) {
- sortedKeys.addAll(keys);
- }
+ Collections.sort(sortedKeys, treeRowKeyComparator);
Iterator ajaxKeysItr = sortedKeys.iterator();
TreeRowKey lastKey = null;
boolean nullRoot = false;
-
+
while (!nullRoot && ajaxKeysItr.hasNext()) {
TreeRowKey key = (TreeRowKey) ajaxKeysItr.next();
@@ -411,33 +411,31 @@
continue;
}
}
-
+
if (key == null || key.depth() == 0) {
nullRoot = true;
key = null;
}
-
+
tree.setRowKey(context, key);
-
- String id;
+
+ String treeClientId;
if (key == null) {
- id = tree.getClientId(context);
+ treeClientId = tree.getClientId(context);
} else {
- id = tree.getNodeFacet().getClientId(context);
+ treeClientId = tree.getNodeFacet().getClientId(context);
}
- String treeChildrenId = id + NamingContainer.SEPARATOR_CHAR + "childs";
- if (ids.isEmpty() || ids.contains(id) || ids.contains(tree.getClientId(context))/*
handle tree updates requests */) {
+ if (ids.contains(tree.getClientId(context)) || ids.contains(id)) {
+ String treeChildrenId = treeClientId + NamingContainer.SEPARATOR_CHAR +
"childs";
writeContent(context, tree, key);
encodeScripts = true;
- renderedAreas.add(id);
- encodedAreaIds.add(id);
-
+ renderedAreas.add(treeClientId);
+ encodedAreaIds.add(treeClientId);
+
renderedAreas.add(treeChildrenId);
//encodedAreaIds.add(id+":childs");
}
}
-
- tree.resetDetachableRowKeys();
//ajaxKeys.clear();
}
} catch (Exception e) {
@@ -460,6 +458,7 @@
}
responseWriter.endElement("div");
+ tree.clearRequestKeysSet();
}
} finally {
try {
@@ -494,13 +493,13 @@
String selectionHolderInputId = tree.getSelectionStateInputName(context);
writer.writeAttribute("id", selectionHolderInputId, null);
writer.writeAttribute("name", selectionHolderInputId, null);
-
+
writer.writeAttribute("value", result, null);
writer.endElement("input");
-
+
return selectionHolderInputId;
}
-
+
protected String getAjaxScript(FacesContext context, UITree tree) {
String id = tree.getBaseClientId(context);
JSFunction function = AjaxRendererUtils
@@ -540,9 +539,9 @@
String varName = getJavaScriptVarName(context, tree);
writer.writeText(varName + ".getNodeElements(" +
- ScriptUtils.toScript(encodedAreaIds) + ");", null);
-
+ ScriptUtils.toScript(encodedAreaIds) + ");", null);
+
writer.endElement("script");
writer.endElement("div");
@@ -573,11 +572,11 @@
final Flag droppedDownToLevelFlag = new Flag();
TreeRowKey rowKey = (TreeRowKey) key;
-
+
//Object savedRowKey = input.getRowKey();
try {
input.captureOrigValue();
-
+
if (key != null) {
droppedDownToLevelFlag.setContext(null);
//openLevelDownTable(context, input, writer);
@@ -598,12 +597,12 @@
public boolean processNode(TreeRowKey rowKey) {
Object currentKey = input.getRowKey();
-
+
if (currentKey == null ? rowKey != null : !currentKey.equals(rowKey)) {
//currentKey NE rowKey
input.setRowKey(context, rowKey);
}
-
+
UITreeNode nodeFacet = input.getNodeFacet();
if (!nodeFacet.isRendered()) {
return false;
@@ -611,9 +610,9 @@
return stateRange.processNode(rowKey);
}
-
+
};
-
+
input.walk(context, new DataVisitorWithLastElement(droppedDownToLevelFlag, input,
levelNavigator, key), treeRange, key, null);
@@ -631,7 +630,7 @@
class Flag {
private Context context;
-
+
public Context getContext() {
return context;
}