[richfaces-svn-commits] JBoss Rich Faces SVN: r2328 - in trunk: samples/tree-demo/src/main/java/org/richfaces and 8 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Fri Aug 17 15:11:40 EDT 2007
Author: nbelaevski
Date: 2007-08-17 15:11:40 -0400 (Fri, 17 Aug 2007)
New Revision: 2328
Modified:
trunk/framework/api/src/main/java/org/richfaces/component/Draggable.java
trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java
trunk/samples/tree-demo/src/main/webapp/pages/index.jsp
trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java
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/TreeRendererBase.java
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js
trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js
trunk/ui/tree/src/main/templates/htmlTree.jspx
trunk/ui/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
Log:
- http://jira.jboss.com/jira/browse/RF-629 fixed & JUnit test updated
- treeDemo validation error fixed
Modified: trunk/framework/api/src/main/java/org/richfaces/component/Draggable.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/component/Draggable.java 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/framework/api/src/main/java/org/richfaces/component/Draggable.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -21,6 +21,7 @@
package org.richfaces.component;
+import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import org.richfaces.event.DragListener;
@@ -52,6 +53,13 @@
*/
public void setDragIndicator(String dragIndicator);
+ /**
+ * Draggable implementation may wish to resolve drag indicator id to clientId itself
+ * @param facesContext {@link FacesContext} instance
+ * @return resolved indicator client id or null
+ * @since 3.1
+ */
+ public String getResolvedDragIndicator(FacesContext facesContext);
/**
* Getter for type of this draggable ( file, mail etc ).
Modified: trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/samples/tree-demo/src/main/java/org/richfaces/Bean.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -66,7 +66,7 @@
private String iconLeaf = null;
private String icon = null;
- private String styleClass = "";
+ private String styleClass = "treeIcon16";
private boolean renderFacets = false;
Modified: trunk/samples/tree-demo/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/samples/tree-demo/src/main/webapp/pages/index.jsp 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/samples/tree-demo/src/main/webapp/pages/index.jsp 2007-08-17 19:11:40 UTC (rev 2328)
@@ -83,7 +83,7 @@
<h:outputText value="Tree icon size:" />
<h:selectOneRadio value="#{bean.styleClass}" onclick="submit()">
- <f:selectItem itemLabel="16x16 (default)" itemValue="" />
+ <f:selectItem itemLabel="16x16 (default)" itemValue="treeIcon16" />
<f:selectItem itemLabel="32x32" itemValue="treeIcon32" />
</h:selectOneRadio>
Modified: trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java
===================================================================
--- trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -21,6 +21,7 @@
package org.richfaces.component;
+import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
@@ -77,4 +78,9 @@
}
}
}
+
+ public String getResolvedDragIndicator(FacesContext facesContext) {
+ return null;
+ }
+
}
Modified: trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java
===================================================================
--- trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -140,24 +140,21 @@
options.addOption("parameters", parameters);
- String indicatorId = draggable.getDragIndicator();
-
- if (indicatorId != null) {
- UIComponent indicator = null;
- if (component instanceof NamingContainer) {
- //we're searching in parent component because we're rendering naming containers
- if (component.getParent() != null) {
- indicator = component.getParent().findComponent(indicatorId);
+ String indicatorId = draggable.getResolvedDragIndicator(context);
+ if (indicatorId == null) {
+ String simpleId = draggable.getDragIndicator();
+ if (simpleId != null) {
+ UIComponent indicator = component.findComponent(simpleId);
+ if (indicator != null) {
+ indicatorId = indicator.getClientId(context);
}
- } else {
- indicator = component.findComponent(indicatorId);
}
-
- if (indicator != null) {
- options.addOption("dragIndicator", indicator.getClientId(context));
- }
}
+ if (indicatorId != null) {
+ options.addOption("dragIndicator", indicatorId);
+ }
+
return options;
}
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-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -821,6 +821,19 @@
defaultFacet.setParent(this);
}
}
+
+ public String getResolvedDragIndicator(FacesContext facesContext) {
+ String dragIndicator = getDragIndicator();
+ UIComponent parent = getParent();
+ if (dragIndicator != null && parent != null) {
+ UIComponent indicator = parent.findComponent(dragIndicator);
+ if (indicator != null) {
+ return indicator.getClientId(facesContext);
+ }
+ }
+
+ return null;
+ }
}
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-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITreeNode.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -34,7 +34,8 @@
private String dragType;
private Object acceptedTypes;
-
+ private String dragIndicator;
+
public static final String COMPONENT_TYPE = "org.richfaces.TreeNode";
public static final String COMPONENT_FAMILY = "org.richfaces.TreeNode";
@@ -307,11 +308,12 @@
}
public Object saveState(FacesContext context) {
- Object[] state = new Object[3];
+ Object[] state = new Object[4];
state[0] = super.saveState(context);
state[1] = this.dragType;
state[2] = this.acceptedTypes;
-
+ state[3] = this.dragIndicator;
+
return state;
}
@@ -320,5 +322,59 @@
super.restoreState(context, _state[0]);
this.dragType = (String) _state[1];
this.acceptedTypes = _state[2];
+ this.dragIndicator = (String) _state[3];
}
+
+ public void setDragIndicator(String dragIndicator) {
+ this.dragIndicator = dragIndicator;
+ }
+
+ protected String getLocalDragIndicator() {
+ if (dragIndicator != null) {
+ return dragIndicator;
+ }
+
+ ValueBinding vb = getValueBinding("dragIndicator");
+ if (vb != null) {
+ return (String) vb.getValue(getFacesContext());
+ }
+
+ return null;
+ }
+
+ public String getDragIndicator() {
+ String localDragIndicator = getLocalDragIndicator();
+ if (localDragIndicator == null) {
+ UITree tree = getUITree();
+ if (tree != null) {
+ return tree.getDragIndicator();
+ } else {
+ return null;
+ }
+ } else {
+ return localDragIndicator;
+ }
+ }
+
+ public String getResolvedDragIndicator(FacesContext facesContext) {
+ String indicatorId = getLocalDragIndicator();
+ UITree tree = getUITree();
+ if (tree != null) {
+ if (indicatorId != null) {
+ //tree is naming container
+ UIComponent parent = tree.getParent();
+ if (parent != null) {
+ UIComponent indicator = parent.findComponent(indicatorId);
+ if (indicator != null) {
+ return indicator.getClientId(facesContext);
+ }
+ }
+ } else {
+ return tree.getResolvedDragIndicator(facesContext);
+ }
+ }
+
+ return null;
+ }
+
}
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-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -428,20 +428,6 @@
return buffer.toString();
}
- protected String getDragIndicatorId(FacesContext context, UITree tree) {
- if(tree.getAttributes().get("dragIndicator") instanceof String) {
- String dragIndicator = (String) tree.getAttributes().get("dragIndicator");
- if (dragIndicator != null) {
- UIComponent component = tree.getParent().findComponent(dragIndicator);
- if (component != null) {
- return component.getClientId(context);
- }
- }
- }
-
- return "";
- }
-
protected String getScriptContributions(FacesContext context, UITree tree) {
return super.getScriptContributions(getJavaScriptVarName(context, tree), context, tree);
}
Modified: trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js
===================================================================
--- trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item-dnd.js 2007-08-17 19:11:40 UTC (rev 2328)
@@ -78,7 +78,9 @@
},
getIndicator: function() {
- var indicator = $(this.tree.dragIndicatorId);
+ var opts = this.getDraggableOptions();
+ var indicatorId = opts ? opts.dragIndicator : null;
+ var indicator = $(indicatorId);
if (!indicator) {
indicator = this.getOrCreateDefaultIndicator();
}
@@ -94,9 +96,6 @@
Object.extend(drag.params, opts.parameters);
}
- var indicator = this.getIndicator();
-
-
this.dragEnter(event);
},
@@ -105,9 +104,17 @@
},
getDraggableOptions: function() {
+ if (window.drag && window.drag.treeDraggableOptions) {
+ return window.drag.treeDraggableOptions;
+ }
+
var attr = Richfaces.getNSAttribute("draggableoptions", $(this.elementID.icon));
if (attr) {
- return attr.parseJSON();
+ var opts = attr.parseJSON();
+ if (window.drag) {
+ window.drag.treeDraggableOptions = opts;
+ }
+ return opts;
}
return null;
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-08-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree.js 2007-08-17 19:11:40 UTC (rev 2328)
@@ -19,13 +19,12 @@
Tree.CLASS_AJAX_SELECTED_LISTENER_FLAG = "ajax_selected_listener_flag";
Tree.prototype = {
- initialize: function(id, input, switchType, events, onAjaxSelect, dragIndicatorId, toggleOnClick) {
+ initialize: function(id, input, switchType, events, onAjaxSelect, toggleOnClick) {
this.childs = [];
this.elements = {};
this.id = id;
this.switchType = switchType;
- this.dragIndicatorId = dragIndicatorId;
this.onselect = new Function('event', (events.onselect ? events.onselect : "") + "; return true;");
this.onexpand = new Function('event', (events.onexpand ? events.onexpand : "") + "; return true;");
this.oncollapse = new Function('event', (events.oncollapse ? events.oncollapse : "") + "; return true;");
Modified: trunk/ui/tree/src/main/templates/htmlTree.jspx
===================================================================
--- trunk/ui/tree/src/main/templates/htmlTree.jspx 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/main/templates/htmlTree.jspx 2007-08-17 19:11:40 UTC (rev 2328)
@@ -68,7 +68,6 @@
function(event) {
#{this:getAjaxScript(context, component)}
},
- "#{this:getDragIndicatorId(context, component)}",
#{component.toggleOnClick}
);
#{this:getScriptContributions(context, component)}
Modified: trunk/ui/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
===================================================================
--- trunk/ui/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-08-17 17:08:52 UTC (rev 2327)
+++ trunk/ui/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-08-17 19:11:40 UTC (rev 2328)
@@ -28,6 +28,7 @@
import java.util.Set;
import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
@@ -398,13 +399,7 @@
UIOutput output = new UIOutput();
tree.getChildren().add(output);
output.getChildren().add(treeNode2);
- try {
- treeNode2.getUITree();
-
- fail();
- } catch (Exception e) {
- }
-
+ assertSame(tree, treeNode2.getUITree());
UITreeNode treeNode3 = (UITreeNode) application.createComponent(UITreeNode.COMPONENT_TYPE);
assertNull(treeNode3.getUITree());
}
@@ -764,6 +759,48 @@
*/
public final void testGetTreeNodeObject() {
}
+
+ public void testResolveDragIndicator() throws Exception {
+ UIComponent indicator1 = application.createComponent(UIOutput.COMPONENT_TYPE);
+ indicator1.setId("indicator1");
+ form.getChildren().add(indicator1);
+
+ form.setId("form");
+ tree.setId("tree");
+ treeNode.setId("treeNode");
+
+ String indicatorId = indicator1.getClientId(facesContext);
+
+ tree.setDragIndicator("indicator1");
+ assertEquals(indicatorId, treeNode.getResolvedDragIndicator(facesContext));
+
+ tree.setDragIndicator(null);
+ assertNull(treeNode.getResolvedDragIndicator(facesContext));
+
+ treeNode.setDragIndicator("indicator1");
+ assertEquals(indicatorId, treeNode.getResolvedDragIndicator(facesContext));
+
+ treeNode.setDragIndicator(null);
+ assertNull(treeNode.getResolvedDragIndicator(facesContext));
+
+ tree.setDragIndicator("indicator1");
+ treeNode.setDragIndicator("indicator2");
+ assertNull(treeNode.getResolvedDragIndicator(facesContext));
+
+ tree.setDragIndicator("indicator2");
+ treeNode.setDragIndicator("indicator1");
+ assertEquals(indicatorId, treeNode.getResolvedDragIndicator(facesContext));
+ }
+
+ public void testGetDragIndicator() throws Exception {
+ treeNode.setDragIndicator("indicator1");
+ assertEquals("indicator1", treeNode.getDragIndicator());
+ tree.setDragIndicator("indicator2");
+ assertEquals("indicator1", treeNode.getDragIndicator());
+ treeNode.setDragIndicator(null);
+ assertEquals("indicator2", treeNode.getDragIndicator());
+ assertNull(treeNode.getLocalDragIndicator());
+ }
}
More information about the richfaces-svn-commits
mailing list