Author: alevkovsky
Date: 2008-09-03 11:01:20 -0400 (Wed, 03 Sep 2008)
New Revision: 10299
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/tree/SimpleTreeDndBean.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree/examples/simpleDnd.xhtml
Log:
Bug fixing(RF-4335)
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/tree/SimpleTreeDndBean.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/tree/SimpleTreeDndBean.java 2008-09-03
14:57:19 UTC (rev 10298)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/tree/SimpleTreeDndBean.java 2008-09-03
15:01:20 UTC (rev 10299)
@@ -36,6 +36,7 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.context.AjaxContext;
+import org.richfaces.component.UIDragSupport;
import org.richfaces.component.UITree;
import org.richfaces.component.UITreeNode;
import org.richfaces.component.html.HtmlTree;
@@ -48,7 +49,7 @@
public class SimpleTreeDndBean {
private TreeNode rootNode = null;
- private List<String> selectedNodeChildren = new ArrayList<String>();
+ private List<TreeNode<String>> selectedNodeChildren = new
ArrayList<TreeNode<String>>();
private String nodeTitle;
private static final String DATA_PATH =
"/richfaces/tree/examples/simple-tree-data-dnd.properties";
@@ -103,15 +104,15 @@
HtmlTree tree = (HtmlTree) event.getComponent();
nodeTitle = (String) tree.getRowData();
selectedNodeChildren.clear();
- TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
+ TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
if (currentNode.isLeaf()){
- selectedNodeChildren.add((String)currentNode.getData());
+ selectedNodeChildren.add(currentNode);
}else
{
- Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
+ Iterator<Map.Entry<Object, TreeNode<String>>> it =
currentNode.getChildren();
while (it!=null &&it.hasNext()) {
- Map.Entry<Object, TreeNode> entry = it.next();
- selectedNodeChildren.add(entry.getValue().getData().toString());
+ Map.Entry<Object, TreeNode<String>> entry = it.next();
+ selectedNodeChildren.add(entry.getValue());
}
}
}
@@ -132,17 +133,23 @@
}
public void dropListener(DropEvent dropEvent) {
+
+ // resolve drag destination attributes
+ UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode)
dropEvent.getSource() : null;
+ UITree destTree = destNode != null ? destNode.getUITree() : null;
+ TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ?
(TreeRowKey) dropEvent.getDropValue() : null;
+ TreeNode droppedInNode = dropNodeKey != null ? destTree.getTreeNode(dropNodeKey) :
null;
+
// resolve drag source attributes
UITreeNode srcNode = (dropEvent.getDraggableSource() instanceof UITreeNode) ?
(UITreeNode) dropEvent.getDraggableSource() : null;
UITree srcTree = srcNode != null ? srcNode.getUITree() : null;
TreeRowKey dragNodeKey = (dropEvent.getDragValue() instanceof TreeRowKey) ?
(TreeRowKey) dropEvent.getDragValue() : null;
TreeNode draggedNode = dragNodeKey != null ? srcTree.getTreeNode(dragNodeKey) : null;
-
- // resolve drag destination attributes
- UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode)
dropEvent.getSource() : null;
- UITree destTree = destNode != null ? destNode.getUITree() : null;
- TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ?
(TreeRowKey) dropEvent.getDropValue() : null;
- TreeNode droppedInNode = dropNodeKey != null ? destTree.getTreeNode(dropNodeKey) :
null;
+ if (dropEvent.getDraggableSource() instanceof UIDragSupport && srcTree == null
&& draggedNode == null && dropEvent.getDragValue() instanceof TreeNode) {
+ srcTree = destTree;
+ draggedNode = (TreeNode) dropEvent.getDragValue();
+ dragNodeKey = srcTree.getTreeNodeRowKey(draggedNode) instanceof TreeRowKey ?
(TreeRowKey) srcTree.getTreeNodeRowKey(draggedNode) : null;
+ }
// Note: check if we dropped node on to itself or to item instead of folder here
if (droppedInNode != null && (droppedInNode.equals(draggedNode) ||
droppedInNode.getParent().getParent() != null || draggedNode.getParent().getParent() ==
null)) {
@@ -163,7 +170,10 @@
state = srcTree.removeNode(dragNodeKey);
// 2. add parent for rerender
Object rowKey = srcTree.getTreeNodeRowKey(parentNode);
- srcTree.addRequestKey(rowKey);
+ srcTree.addRequestKey(rowKey);
+ if (dropEvent.getDraggableSource() instanceof UIDragSupport){
+ selectedNodeChildren.remove(draggedNode);
+ }
} else if (dropEvent.getDragValue() != null) { // Drag from some drag source
draggedNode = new TreeNodeImpl<String>();
draggedNode.setData(dropEvent.getDragValue().toString());
@@ -185,11 +195,11 @@
}
- public List<String> getSelectedNodeChildren() {
+ public List<TreeNode<String>> getSelectedNodeChildren() {
return selectedNodeChildren;
}
- public void setSelectedNodeChildren(List<String> selectedNodeChildren) {
+ public void setSelectedNodeChildren(List<TreeNode<String>>
selectedNodeChildren) {
this.selectedNodeChildren = selectedNodeChildren;
}
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree/examples/simpleDnd.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree/examples/simpleDnd.xhtml 2008-09-03
14:57:19 UTC (rev 10298)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree/examples/simpleDnd.xhtml 2008-09-03
15:01:20 UTC (rev 10299)
@@ -13,17 +13,25 @@
.rich-table-cell, .rich-table{
border:none;
}
+ .indicatorPicture {
+ width: 50px;
+ height: 50px;
+ }
</style>
-
+ <rich:dragIndicator id="indicator1" >
+ <f:facet name="single">
+ {draggedImage}
+ </f:facet>
+ </rich:dragIndicator>
+ <rich:dragIndicator id="indicator2" />
<h:form>
<h:panelGrid columns="2" width="100%"
columnClasses="col1,col2">
-
+
<rich:tree ajaxKeys="#{null}" style="width:300px"
nodeSelectListener="#{simpleTreeDndBean.processSelection}"
- reRender="selectedNode" ajaxSubmitSelection="true"
switchType="client"
- value="#{simpleTreeDndBean.treeNode}" var="item"
id="tree" dragIndicator="indicator" treeNodeVar="treeNode"
+ reRender="selectedNode" ajaxSubmitSelection="true"
switchType="client" dragIndicator="indicator2"
+ value="#{simpleTreeDndBean.treeNode}" var="item"
id="tree" treeNodeVar="treeNode"
dropListener="#{simpleTreeDndBean.dropListener}"
nodeFace="#{treeNode.parent.parent == null ? 'node' :
'leaf'}">
-
<rich:treeNode type="node" acceptedTypes="pic">
<h:outputText value="#{item}"/>
</rich:treeNode>
@@ -32,8 +40,13 @@
</rich:treeNode>
</rich:tree>
<rich:panel id="selectedNode">
- <rich:dataGrid value="#{simpleTreeDndBean.selectedNodeChildren}"
var="pic" columns="3" border="0">
- <h:graphicImage value="/richfaces/jQuery/images/#{pic}"/>
+ <rich:dataGrid id="selectedNodeGrid"
value="#{simpleTreeDndBean.selectedNodeChildren}" var="item"
columns="3" border="0">
+ <rich:dragSupport dragIndicator="indicator1" dragType="pic"
dragValue="#{item}" reRender="selectedNodeGrid">
+ <rich:dndParam name="draggedImage">
+ <h:graphicImage styleClass="indicatorPicture"
value="/richfaces/jQuery/images/#{item.data}" />
+ </rich:dndParam>
+ </rich:dragSupport>
+ <h:graphicImage value="/richfaces/jQuery/images/#{item.data}" />
</rich:dataGrid>
</rich:panel>
</h:panelGrid>
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree.xhtml 2008-09-03 14:57:19
UTC (rev 10298)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/tree.xhtml 2008-09-03 15:01:20
UTC (rev 10299)
@@ -18,7 +18,7 @@
<rich:tab name="model" label="Default Tree Model">
<ui:include src="/richfaces/tree/simple-tree.xhtml" />
</rich:tab>
- <rich:tab name="dnd" label="Editable Tree with Drag and Drop
support">
+ <rich:tab name="dnd" label="Tree with Drag and Drop
support">
<ui:include src="/richfaces/tree/simple-tree-dnd.xhtml" />
</rich:tab>
<rich:tab name="info" label="Tag Information">