You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2006/12/12 12:58:40 UTC

svn commit: r486105 - in /myfaces/tobago/trunk: example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/ example/sandbox/src/main/webapp/ sandbox/src/main/java/org/apache/myfaces/tobago/component/ sandbox/src/main/java/org/apache/myface...

Author: lofwyr
Date: Tue Dec 12 03:58:39 2006
New Revision: 486105

URL: http://svn.apache.org/viewvc?view=rev&rev=486105
Log:
TOBAGO-18: working on expand state and add a Java-Node-Object

Added:
    myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java   (with props)
Modified:
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNode.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java

Added: myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java?view=auto&rev=486105
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java (added)
+++ myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java Tue Dec 12 03:58:39 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2006 Atanion GmbH, Germany
+ * All rights reserved. Created 12.12.2006 11:06:14.
+ * $Id$
+ */
+package org.apache.myfaces.tobago.example.sandbox;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class Node {
+
+  private static final Log LOG = LogFactory.getLog(Node.class);
+
+  private String name;
+
+  public Node(String name) {
+    this.name = name;
+  }
+
+  public String action() {
+    LOG.info("action: name='" + name + "'");
+    return null;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+}

Propchange: myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Node.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp?view=diff&rev=486105&r1=486104&r2=486105
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp Tue Dec 12 03:58:39 2006
@@ -17,27 +17,29 @@
 
 <%@ page import="javax.swing.tree.DefaultMutableTreeNode" %>
 <%@ page import="org.apache.myfaces.tobago.model.TreeState" %>
+<%@ page import="org.apache.myfaces.tobago.example.sandbox.Node" %>
 
 <%
   // tree
-  DefaultMutableTreeNode tree = (DefaultMutableTreeNode) session.getAttribute("tree");
+  DefaultMutableTreeNode tree =
+      (DefaultMutableTreeNode) session.getAttribute("tree");
 
   DefaultMutableTreeNode music = null;
   DefaultMutableTreeNode temp = null;
   DefaultMutableTreeNode temp2 = null;
   if (tree == null) {
-    tree = new DefaultMutableTreeNode("Category");
-    tree.insert(new DefaultMutableTreeNode("Sports"), 0);
-    tree.insert(new DefaultMutableTreeNode("Movies"), 0);
-    music = new DefaultMutableTreeNode("Music");
+    tree = new DefaultMutableTreeNode(new Node("Category"));
+    tree.insert(new DefaultMutableTreeNode(new Node("Sports")), 0);
+    tree.insert(new DefaultMutableTreeNode(new Node("Movies")), 0);
+    music = new DefaultMutableTreeNode(new Node("Music"));
     tree.insert(music, 0);
-    tree.insert(new DefaultMutableTreeNode("Games"), 0);
-    temp = new DefaultMutableTreeNode("Science");
-    temp.insert(new DefaultMutableTreeNode("Geography"), 0);
-    temp.insert(new DefaultMutableTreeNode("Mathematics"), 0);
-    temp2 = new DefaultMutableTreeNode("Astronomy");
-    temp2.insert(new DefaultMutableTreeNode("Education"), 0);
-    temp2.insert(new DefaultMutableTreeNode("Pictures"), 0);
+    tree.insert(new DefaultMutableTreeNode(new Node("Games")), 0);
+    temp = new DefaultMutableTreeNode(new Node("Science"));
+    temp.insert(new DefaultMutableTreeNode(new Node("Geography")), 0);
+    temp.insert(new DefaultMutableTreeNode(new Node("Mathematics")), 0);
+    temp2 = new DefaultMutableTreeNode(new Node("Astronomy"));
+    temp2.insert(new DefaultMutableTreeNode(new Node("Education")), 0);
+    temp2.insert(new DefaultMutableTreeNode(new Node("Pictures")), 0);
     temp.insert(temp2, 2);
     tree.insert(temp, 2);
     session.setAttribute("tree", tree);
@@ -77,8 +79,9 @@
               mode="menu">
       <tcs:treeNode label="Root" id="root">
         <tcs:treeNodes value="#{tree}" var="node" id="data">
-          <tcs:treeNode label="#{node.userObject}" id="template"
+          <tcs:treeNode label="#{node.userObject.name}" id="template"
                         action="#{controller.action1}" value="#{node}"/>
+                        <%--action="#{node.userObject.action}" value="#{node}"/>--%>
         </tcs:treeNodes>
         <tcs:treeNode label="Action 1" action="#{controller.action1}" id="action1"/>
         <tcs:treeNode label="Action 2" action="#{controller.action2}" id="action2"/>

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNode.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNode.java?view=diff&rev=486105&r1=486104&r2=486105
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNode.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNode.java Tue Dec 12 03:58:39 2006
@@ -21,6 +21,8 @@
 import org.apache.commons.logging.LogFactory;
 
 import javax.swing.tree.DefaultMutableTreeNode;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
 
 public class UITreeNode extends UICommand {
 
@@ -42,4 +44,27 @@
     }
     return value;
   }
+
+  public String nodeStateId(FacesContext facesContext) {
+    // this must do the same as nodeStateId() in tree.js
+    String clientId = getClientId(facesContext);
+    UITree tree = findTree(this);
+    String treeId = tree.getClientId(facesContext);
+    return clientId.substring(treeId.length() + 1);
+  }
+
+  public UITree findTree() {
+    return findTree(this);
+  }
+
+  private UITree findTree(UIComponent component) {
+    while (component != null) {
+      if (component instanceof UITree) {
+        return (UITree) component;
+      }
+      component = component.getParent();
+    }
+    return null;
+  }
+
 }

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java?view=diff&rev=486105&r1=486104&r2=486105
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java Tue Dec 12 03:58:39 2006
@@ -61,20 +61,17 @@
     }
 
     UITreeNode node = (UITreeNode) component;
-    UITree tree = findTree(node);
+    UITree tree = node.findTree();
     TreeState state = tree.getState();
     String treeId = tree.getClientId(facesContext);
-    String nodeId = node.getId();
+    String nodeStateId = node.nodeStateId(facesContext);
     UIComponent parent = node.getParent();
-    if (parent != null && parent instanceof UITreeNodes) { // todo cleanup
-      nodeId += ((UITreeNodes) parent).getCurrentNodeId();
-    }
     Map requestParameterMap
         = facesContext.getExternalContext().getRequestParameterMap();
 
     // expand state
     String expandState = (String) requestParameterMap.get(treeId);
-    String searchString = ";" + nodeId + ";";
+    String searchString = ";" + nodeStateId + ";";
     if (expandState.indexOf(searchString) > -1) {
       state.addExpandState((DefaultMutableTreeNode) node.getValue());
     }
@@ -82,7 +79,7 @@
 
     if (TreeRenderer.isSelectable(tree)) { // selection
       String selected = (String) requestParameterMap.get(treeId + UITree.SELECT_STATE);
-      searchString = ";" + nodeId + ";";
+      searchString = ";" + nodeStateId + ";";
       if (selected.indexOf(searchString) > -1) {
         state.addSelection((DefaultMutableTreeNode) node.getValue());
       }
@@ -91,7 +88,7 @@
     // marker
     String marked = (String) requestParameterMap.get(treeId + UITree.MARKER);
     if (marked != null) {
-      searchString = treeId + NamingContainer.SEPARATOR_CHAR + nodeId;
+      searchString = treeId + NamingContainer.SEPARATOR_CHAR + nodeStateId;
 
       if (marked.equals(searchString)) {
         state.setMarker((DefaultMutableTreeNode) node.getValue());
@@ -128,7 +125,7 @@
       }
     }
 
-    UITree root = findTree(treeNode);
+    UITree root = treeNode.findTree();
     String rootId = root.getClientId(facesContext);
 
     String clientId = treeNode.getClientId(facesContext);
@@ -146,7 +143,7 @@
       }
     } else {
 
-      DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode.getValue();
+      DefaultMutableTreeNode modelNode = (DefaultMutableTreeNode) treeNode.getValue();
 
       ResponseWriter writer = facesContext.getResponseWriter();
 
@@ -234,7 +231,7 @@
       writer.writeText("',", null);
       if (treeNode.getChildCount() == 0
           || (selectable != null && !selectable.endsWith("LeafOnly"))) {
-        boolean selected = treeState.isSelected(node);
+        boolean selected = treeState.isSelected(modelNode);
         writer.writeText(Boolean.toString(selected), null);
         if (LOG.isDebugEnabled()) {
           debuging += selected ? "S" : "-";
@@ -244,16 +241,16 @@
         if (LOG.isDebugEnabled()) {
           debuging += "-";
         }
-        if (treeState.isSelected(node)) {
+        if (treeState.isSelected(modelNode)) {
           LOG.warn("Ignore selected FolderNode in LeafOnly selection tree!");
         }
       }
       writer.writeText(",", null);
-      writer.writeText(Boolean.toString(treeState.isMarked(node)), null);
+      writer.writeText(Boolean.toString(treeState.isMarked(modelNode)), null);
       writer.writeText(",", null);
 
       // expanded
-      boolean expanded = treeState.isExpanded(node);
+      boolean expanded = treeState.isExpanded(modelNode);
       writer.writeText(Boolean.toString(expanded), null);
       if (LOG.isDebugEnabled()) {
         debuging += expanded ? "E" : "-";
@@ -327,15 +324,5 @@
         LOG.debug(debuging);
       }
     }
-  }
-
-  private UITree findTree(UIComponent component) {
-    while (component != null) {
-      if (component instanceof UITree) {
-        return (UITree) component;
-      }
-      component = component.getParent();
-    }
-    return null;
   }
 }