Author: adubovsky
Date: 2008-12-04 13:02:17 -0500 (Thu, 04 Dec 2008)
New Revision: 11563
Added:
trunk/test-applications/jsp/src/main/java/tTree/TTreeDND.java
Modified:
trunk/test-applications/jsp/src/main/java/tTree/PVisability.java
trunk/test-applications/jsp/src/main/java/tTree/TTreeRNA.java
trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-tTree.xml
trunk/test-applications/jsp/src/main/webapp/tTree/tTree.jsp
trunk/test-applications/jsp/src/main/webapp/tTree/tTreeProperty.jsp
trunk/test-applications/jsp/src/main/webapp/tTree/tTreeStraightforward.jsp
Log:
+ to tTree
Modified: trunk/test-applications/jsp/src/main/java/tTree/PVisability.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/tTree/PVisability.java 2008-12-04 17:52:59
UTC (rev 11562)
+++ trunk/test-applications/jsp/src/main/java/tTree/PVisability.java 2008-12-04 18:02:17
UTC (rev 11563)
@@ -4,13 +4,23 @@
private boolean tTreeSubviewID;
private boolean tTreePropertySubviewID;
private boolean tTreeStraightforwardSubviewID;
+ private boolean tTreeDefaultSubviewID;
public PVisability() {
- tTreeSubviewID = true;
+ tTreeSubviewID = false;
tTreePropertySubviewID = false;
tTreeStraightforwardSubviewID = false;
+ tTreeDefaultSubviewID = true;
}
+ public boolean istTreeDefaultSubviewID() {
+ return tTreeDefaultSubviewID;
+ }
+
+ public void settTreeDefaultSubviewID(boolean treeDefaultSubviewID) {
+ tTreeDefaultSubviewID = treeDefaultSubviewID;
+ }
+
public boolean istTreeSubviewID() {
return tTreeSubviewID;
}
Added: trunk/test-applications/jsp/src/main/java/tTree/TTreeDND.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/tTree/TTreeDND.java
(rev 0)
+++ trunk/test-applications/jsp/src/main/java/tTree/TTreeDND.java 2008-12-04 18:02:17 UTC
(rev 11563)
@@ -0,0 +1,249 @@
+package tTree;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.richfaces.component.UITree;
+import org.richfaces.component.UITreeNode;
+import org.richfaces.event.DragEvent;
+import org.richfaces.event.DropEvent;
+import org.richfaces.event.NodeExpandedEvent;
+import org.richfaces.event.NodeSelectedEvent;
+import org.richfaces.model.TreeNode;
+import org.richfaces.model.TreeNodeImpl;
+import org.richfaces.model.TreeRowKey;
+
+public class TTreeDND {
+ private static final String DATA_PATH =
"org/richfaces/simpleTreeData.properties";
+
+ private TreeNode<String> treeNodeLeft;
+ private UITree leftTree;
+ private String leftSelectedNodeTitle;
+ private String rightSelectedNodeTitle;
+ private TreeNode<String> treeNodeRight;
+ private UITree rightTree;
+
+ private void addNodes(String path, TreeNode<String> node,
+ Properties properties) {
+ boolean end = false;
+ int counter = 1;
+ while (!end) {
+ String key = path != null ? path + '.' + counter : String
+ .valueOf(counter);
+ String value = properties.getProperty(key);
+ if (value != null) {
+ TreeNodeImpl<String> nodeImpl = new TreeNodeImpl<String>();
+ nodeImpl.setData(value);
+ node.addChild(new Integer(counter), nodeImpl);
+ addNodes(key, nodeImpl, properties);
+ counter++;
+ } else {
+ end = true;
+ }
+ }
+ }
+
+ private TreeNode<String> initPaneTree() {
+ TreeNode<String> rootNode = null;
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ExternalContext externalContext = facesContext.getExternalContext();
+
+ InputStream dataStream = this.getClass().getClassLoader()
+ .getResourceAsStream(DATA_PATH);
+
+ try {
+ Properties properties = new Properties();
+ properties.load(dataStream);
+ rootNode = new TreeNodeImpl<String>();
+ addNodes(null, rootNode, properties);
+ } catch (IOException e) {
+
+ throw new FacesException(e.getMessage(), e);
+
+ } finally {
+ if (dataStream != null) {
+ try {
+ dataStream.close();
+ } catch (IOException e) {
+ externalContext.log(e.getMessage(), e);
+ }
+ }
+ }
+ return rootNode;
+ }
+
+ private Object getNewId(TreeNode parentNode) {
+ Map<Object, TreeNode> childs = new HashMap<Object, TreeNode>();
+ Iterator<Map.Entry<Object, TreeNode>> iter = parentNode.getChildren();
+ while (iter != null && iter.hasNext()) {
+ Map.Entry<Object, TreeNode> entry = iter.next();
+ childs.put(entry.getKey(), entry.getValue());
+ }
+
+ Integer index = 1;
+ while (childs.containsKey(index)) {
+ index++;
+ }
+ return index;
+ }
+
+ public void onDrop(DropEvent dropEvent) {
+ System.out.println("onDrop occured.");
+ System.out.println("DragValue: " + dropEvent.getDragValue());
+ System.out.println("DropValue: " + dropEvent.getDropValue());
+
+ // 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;
+
+ // resolve drag destination attributes
+ UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode)
dropEvent
+ .getSource()
+ : null;
+ UITree destTree = destNode != null ? destNode.getUITree()
+ : (UITree) dropEvent.getComponent();
+ TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ?
(TreeRowKey) dropEvent
+ .getDropValue()
+ : null;
+
+ FacesContext context = FacesContext.getCurrentInstance();
+
+ if (dropNodeKey != null) {
+ // add destination node for rerender
+ destTree.addRequestKey(dropNodeKey);
+
+ Object state = null;
+ TreeNode draggedNode = null;
+ if (dragNodeKey != null) { // Drag from this or other tree
+ draggedNode = srcTree.getModelTreeNode(dragNodeKey);
+
+ TreeNode parentNode = draggedNode.getParent();
+ // 1. remove node from tree
+ state = srcTree.removeNode(dragNodeKey);
+ // 2. add parent for rerender
+ Object rowKey = srcTree.getTreeNodeRowKey(parentNode);
+ srcTree.addRequestKey(rowKey);
+ } else if (dropEvent.getDragValue() != null) { // Drag from some
+ // drag source
+ draggedNode = new TreeNodeImpl<String>();
+ draggedNode.setData(dropEvent.getDragValue().toString());
+ }
+
+ // generate new node id
+ Object id = getNewId(destTree.getTreeNode(dropNodeKey));
+ destTree.addNode(dropNodeKey, draggedNode, id, state);
+ }
+
+ AjaxContext ac = AjaxContext.getCurrentInstance();
+ // Add destination tree to reRender
+ try {
+ ac.addComponentToAjaxRender(destTree);
+ } catch (Exception e) {
+ System.err.print(e.getMessage());
+ }
+
+ // Add source tree to reRender
+ try {
+ ac.addComponentToAjaxRender(srcTree);
+ } catch (Exception e) {
+ System.err.print(e.getMessage());
+ }
+
+ System.out.println("+++++");
+ }
+
+ public void onExpand(NodeExpandedEvent event) {
+ UITree tree = (UITree) event.getComponent();
+ System.out.println("Tree ('" + tree.getId() + "') node "
+ + (tree.isExpanded() ? "expanded" : "collapsed") + " "
+ + tree.getRowKey());
+ }
+
+ public void onDrag(DragEvent dragEvent) {
+ System.out.println("onDrag occured.");
+ System.out.println("DragValue: " + dragEvent.getDragValue());
+ System.out.println("DropValue: " + dragEvent.getDropValue());
+ }
+
+ public void processLSelection(NodeSelectedEvent event) {
+ UITree tree = (UITree) event.getComponent();
+ if (tree != null) {
+ leftSelectedNodeTitle = (String) tree.getRowData();
+ }
+ }
+
+ public void processRSelection(NodeSelectedEvent event) {
+ UITree tree = (UITree) event.getComponent();
+ if (tree != null) {
+ rightSelectedNodeTitle = (String) tree.getRowData();
+ }
+ }
+
+ public TreeNode<String> getTreeNodeLeft() {
+ if (treeNodeLeft == null) {
+ treeNodeLeft = initPaneTree();
+ }
+ return treeNodeLeft;
+ }
+
+ public void setTreeNodeLeft(TreeNode<String> treeNodeLeft) {
+ this.treeNodeLeft = treeNodeLeft;
+ }
+
+ public UITree getLeftTree() {
+ return leftTree;
+ }
+
+ public void setLeftTree(UITree leftTree) {
+ this.leftTree = leftTree;
+ }
+
+ public String getRightSelectedNodeTitle() {
+ return rightSelectedNodeTitle;
+ }
+
+ public void setRightSelectedNodeTitle(String rightSelectedNodeTitle) {
+ this.rightSelectedNodeTitle = rightSelectedNodeTitle;
+ }
+
+ public String getLeftSelectedNodeTitle() {
+ return leftSelectedNodeTitle;
+ }
+
+ public void setLeftSelectedNodeTitle(String leftSelectedNodeTitle) {
+ this.leftSelectedNodeTitle = leftSelectedNodeTitle;
+ }
+
+ public UITree getRightTree() {
+ return rightTree;
+ }
+
+ public void setRightTree(UITree rightTree) {
+ this.rightTree = rightTree;
+ }
+
+ public TreeNode<String> getTreeNodeRight() {
+ if (treeNodeRight == null) {
+ treeNodeRight = initPaneTree();
+ }
+ return treeNodeRight;
+ }
+
+ public void setTreeNodeRight(TreeNode<String> treeNodeRight) {
+ this.treeNodeRight = treeNodeRight;
+ }
+}
Modified: trunk/test-applications/jsp/src/main/java/tTree/TTreeRNA.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/tTree/TTreeRNA.java 2008-12-04 17:52:59 UTC
(rev 11562)
+++ trunk/test-applications/jsp/src/main/java/tTree/TTreeRNA.java 2008-12-04 18:02:17 UTC
(rev 11563)
@@ -16,25 +16,26 @@
ArrayList<Package> subPackArr = new ArrayList<Package>();
treeRNAroots.clear();
- for (int i = 0; i < 3; i++) {
- dirsArr.clear();
- for (int j = 0; j < 4; j++) {
- packArr.clear();
- subDirsArr.clear();
- for (int k = 0; k < 5; k++) {
- packArr.add(new Package("package #" + i + " " + j + "
" + k));
+ dirsArr.clear();
+ for (int j = 0; j < 4; j++) {
+ packArr.clear();
+ subDirsArr.clear();
+ for (int k = 0; k < 5; k++) {
+ packArr.add(new Package("package #" + j + " " + k));
+ }
+ for (int f = 0; f < 4; f++) {
+ subPackArr.clear();
+ for (int l = 0; l < 5; l++) {
+ subPackArr.add(new Package("subPackage #" + j + " " + f
+ + " " + l));
}
- for (int f = 0; f < 4; f++) {
- subPackArr.clear();
- for (int l = 0; l < 5; l++) {
- subPackArr.add(new Package("subPackage #" + i + " " + j +
" "+ f + " " + l));
- }
- subDirsArr.add(new Dir("subDir #" + i + " " + j + " "
+ f, new ArrayList<Package>(subPackArr)));
- }
- dirsArr.add(new Dir("dir #" + i + " " + j, new
ArrayList<Package>(packArr), new ArrayList<Dir>(subDirsArr)));
+ subDirsArr.add(new Dir("subDir #" + j + " " + f,
+ new ArrayList<Package>(subPackArr)));
}
+ dirsArr.add(new Dir("dir #" + j, new ArrayList<Package>(packArr),
+ new ArrayList<Dir>(subDirsArr)));
}
- treeRNAroots.addAll(dirsArr);
+ treeRNAroots.add(new Dir("*** root ***", null, dirsArr));
}
public ArrayList<Dir> getTreeRNAroots() {
Modified: trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-tTree.xml
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-tTree.xml 2008-12-04
17:52:59 UTC (rev 11562)
+++ trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-tTree.xml 2008-12-04
18:02:17 UTC (rev 11563)
@@ -22,4 +22,9 @@
<managed-bean-class>tTree.TTreeRNA</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>tTreeDND</managed-bean-name>
+ <managed-bean-class>tTree.TTreeDND</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
</faces-config>
Modified: trunk/test-applications/jsp/src/main/webapp/tTree/tTree.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/tTree/tTree.jsp 2008-12-04 17:52:59 UTC
(rev 11562)
+++ trunk/test-applications/jsp/src/main/webapp/tTree/tTree.jsp 2008-12-04 18:02:17 UTC
(rev 11563)
@@ -18,10 +18,15 @@
<h:selectBooleanCheckbox
value="#{pVisability.tTreeStraightforwardSubviewID}"
onchange="submit();" />
+ <h:outputText value="Tree with Drag and Drop functionality: " />
+ <h:selectBooleanCheckbox
+ value="#{pVisability.tTreeDefaultSubviewID}"
+ onchange="submit();" />
</h:panelGrid>
<rich:spacer height="10" />
-
+
<h:panelGrid columns="1"
rendered="#{pVisability.tTreeSubviewID}">
+ <h:outputText value="default Tree" style="color: red"/>
<rich:tree id="dTree" switchType="#{tTree.switchType}"
value="#{tTree.data}" var="defTree"
binding="#{tTree.tree}"
ajaxSubmitSelection="false" immediate="false">
@@ -45,4 +50,6 @@
</h:selectOneRadio>
</h:panelGrid>
</h:panelGrid>
+
+ <rich:spacer height="10" />
</f:subview>
Modified: trunk/test-applications/jsp/src/main/webapp/tTree/tTreeProperty.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/tTree/tTreeProperty.jsp 2008-12-04
17:52:59 UTC (rev 11562)
+++ trunk/test-applications/jsp/src/main/webapp/tTree/tTreeProperty.jsp 2008-12-04
18:02:17 UTC (rev 11563)
@@ -6,6 +6,7 @@
<f:subview id="tTreePropertySubviewID"
rendered="#{pVisability.tTreePropertySubviewID}">
+ <h:outputText value="Tree with treeNodesAdaptor" style="color:
red"/>
<rich:tree>
<rich:treeNodesAdaptor nodes="#{tTreeNA.treeNA}"
var="project">
<rich:treeNode>
@@ -23,4 +24,5 @@
</rich:treeNodesAdaptor>
</rich:treeNodesAdaptor>
</rich:tree>
+ <rich:spacer height="10" />
</f:subview>
Modified: trunk/test-applications/jsp/src/main/webapp/tTree/tTreeStraightforward.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/tTree/tTreeStraightforward.jsp 2008-12-04
17:52:59 UTC (rev 11562)
+++ trunk/test-applications/jsp/src/main/webapp/tTree/tTreeStraightforward.jsp 2008-12-04
18:02:17 UTC (rev 11563)
@@ -3,20 +3,108 @@
<%@ taglib
uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib
uri="http://richfaces.org/rich" prefix="rich"%>
-<f:subview id="tTreeStraightforwardSubviewID"
- rendered="#{pVisability.tTreeStraightforwardSubviewID}">
+<f:subview id="tTreeStraightforwardSubviewID">
+<style type="text/css">
+.LeftTreePane {
+
+}
- <rich:tree>
- <rich:recursiveTreeNodesAdaptor var="dir"
roots="#{tTreeRNA.treeRNAroots}"
- nodes="#{dir.dirs}">
- <rich:treeNode>
- <h:outputText value="#{dir.name}" />
- </rich:treeNode>
- <rich:treeNodesAdaptor nodes="#{dir.packages}"
var="package">
+.RightTreePane {
+
+}
+
+.TreeContainer {
+ overflow: auto;
+ height: 400px;
+ border: 3px inset gray;
+}
+</style>
+
+ <h:panelGrid columns="1"
+ rendered="#{pVisability.tTreeStraightforwardSubviewID}">
+ <h:outputText value="Tree with recursiveTreeNodesAdaptor"
+ style="color: red" />
+ <rich:tree>
+ <rich:treeNodesAdaptor nodes="#{tTreeRNA.treeRNAroots}"
var="root">
<rich:treeNode>
- <h:outputText value="#{package.name}" />
+ <h:outputText value="#{root.name}" />
</rich:treeNode>
+ <rich:recursiveTreeNodesAdaptor var="dir"
roots="#{root.dirs}"
+ nodes="#{dir.dirs}">
+ <rich:treeNodesAdaptor nodes="#{dir.packages}"
var="package">
+ <rich:treeNode>
+ <h:outputText value="#{package.name}" />
+ </rich:treeNode>
+ </rich:treeNodesAdaptor>
+ <rich:treeNode>
+ <h:outputText value="#{dir.name}" />
+ </rich:treeNode>
+ </rich:recursiveTreeNodesAdaptor>
</rich:treeNodesAdaptor>
- </rich:recursiveTreeNodesAdaptor>
- </rich:tree>
+ </rich:tree>
+ </h:panelGrid>
+ <rich:spacer height="10" />
+ <h:panelGrid columns="1"
+ rendered="#{pVisability.tTreeDefaultSubviewID}">
+ <h:outputText value="Tree with Drag and Drop functionality"
+ style="color: red" />
+
+ <rich:dragIndicator id="treeIndicator">
+ <f:facet name="single">
+ <f:verbatim>{marker} {nodeParam}({treeParam})</f:verbatim>
+ </f:facet>
+ </rich:dragIndicator>
+
+ <h:panelGrid columns="2"
columnClasses="LeftTreePane,RightTreePane">
+
+ <h:panelGroup id="leftContainer" layout="block"
+ styleClass="TreeContainer">
+ <h:outputText escape="false"
+ value="Selected Node:
<b>#{tTreeDND.leftSelectedNodeTitle}</b>"
+ id="selectedNodeL" />
+
+ <rich:tree id="leftTree" style="width:300px"
+ nodeSelectListener="#{tTreeDND.processLSelection}"
+ reRender="selectedNodeL, leftContainer"
ajaxSubmitSelection="true"
+ switchType="client" value="#{tTreeDND.treeNodeLeft}"
+ changeExpandListener="#{tTreeDND.onExpand}"
+ binding="#{tTreeDND.leftTree}"
+ onselected="window.status='selectedNode: '+event.selectedNode;"
+ onexpand="window.status='expandedNode: '+event.expandedNode"
+ oncollapse="window.status='collapsedNode: '+event.collapsedNode"
+ dropListener="#{tTreeDND.onDrop}"
dragListener="#{tTreeDND.onDrag}"
+ dragIndicator="treeIndicator" acceptedTypes="treeNodeR"
+ dragType="treeNodeL" rowKeyVar="key" var="item">
+
+ <rich:dndParam name="treeParam" value="leftTree" />
+ </rich:tree>
+
+ </h:panelGroup>
+
+ <h:panelGroup id="rightContainer" layout="block"
+ styleClass="TreeContainer">
+ <h:outputText escape="false"
+ value="Selected Node:
<b>#{tTreeDND.rightSelectedNodeTitle}</b>"
+ id="selectedNodeR" />
+
+ <rich:tree id="rightTree" style="width:300px"
+ nodeSelectListener="#{tTreeDND.processRSelection}"
+ reRender="selectedNodeR,rightContainer"
ajaxSubmitSelection="true"
+ switchType="client" value="#{tTreeDND.treeNodeRight}"
+ changeExpandListener="#{tTreeDND.onExpand}"
+ binding="#{tTreeDND.rightTree}"
+ onselected="window.status='selectedNode: '+event.selectedNode;"
+ onexpand="window.status='expandedNode: '+event.expandedNode"
+ oncollapse="window.status='collapsedNode: '+event.collapsedNode"
+ rowKeyVar="key" dropListener="#{tTreeDND.onDrop}"
+ dragListener="#{tTreeDND.onDrag}" dragIndicator="treeIndicator"
+ acceptedTypes="treeNodeL" dragType="treeNodeR"
var="item">
+
+ <rich:dndParam name="treeParam" value="rightTree" />
+ </rich:tree>
+ </h:panelGroup>
+
+ </h:panelGrid>
+ </h:panelGrid>
+ <rich:spacer height="10" />
</f:subview>
\ No newline at end of file