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/11/20 23:19:06 UTC

svn commit: r477366 - in /myfaces/tobago/trunk: example/sandbox/src/main/webapp/ sandbox/src/main/java/org/apache/myfaces/tobago/component/ sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/

Author: lofwyr
Date: Mon Nov 20 14:19:06 2006
New Revision: 477366

URL: http://svn.apache.org/viewvc?view=rev&rev=477366
Log:
working on TOBAGO-18
expand state
nodes

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/component/UITreeNodes.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java

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=477366&r1=477365&r2=477366
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/tree.jsp Mon Nov 20 14:19:06 2006
@@ -19,32 +19,41 @@
 <%@ page import="org.apache.myfaces.tobago.model.TreeState" %>
 
 <%
-  DefaultMutableTreeNode tree;
-  TreeState treeState;
+  // tree
+  DefaultMutableTreeNode tree = (DefaultMutableTreeNode) session.getAttribute("tree");
 
-  tree = new DefaultMutableTreeNode("Category");
-  tree.insert(new DefaultMutableTreeNode("Sports"), 0);
-  tree.insert(new DefaultMutableTreeNode("Movies"), 0);
-  DefaultMutableTreeNode music = new DefaultMutableTreeNode("Music");
-  tree.insert(music, 0);
-  tree.insert(new DefaultMutableTreeNode("Games"), 0);
-  DefaultMutableTreeNode temp = new DefaultMutableTreeNode("Science");
-  temp.insert(
-      new DefaultMutableTreeNode("Geography"), 0);
-  temp.insert(
-      new DefaultMutableTreeNode("Mathematics"), 0);
-  DefaultMutableTreeNode temp2 = new DefaultMutableTreeNode("Astronomy");
-  temp2.insert(new DefaultMutableTreeNode("Education"), 0);
-  temp2.insert(new DefaultMutableTreeNode("Pictures"), 0);
-  temp.insert(temp2, 2);
-  tree.insert(temp, 2);
-  treeState = new TreeState();
-  treeState.addExpandState(tree);
-  treeState.addExpandState(temp);
-  treeState.addSelection(temp2);
-  treeState.setMarker(music);
-  session.setAttribute("tree", tree);
-  session.setAttribute("treeState", treeState);
+  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.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);
+    temp.insert(temp2, 2);
+    tree.insert(temp, 2);
+    session.setAttribute("tree", tree);
+  }
+
+  // state
+
+  TreeState treeState = (TreeState) session.getAttribute("treeState");
+  if (treeState == null) {
+    treeState = new TreeState();
+    treeState.addExpandState(tree);
+    treeState.addExpandState(temp);
+    treeState.addSelection(temp2);
+    treeState.setMarker(music);
+    session.setAttribute("treeState", treeState);
+  }
 %>
 
 <%@ taglib uri="http://myfaces.apache.org/tobago/sandbox" prefix="tcs" %>
@@ -67,12 +76,10 @@
               showRoot="true"
               mode="menu">
       <tcs:treeNode label="Root">
-<%--
         <tcs:treeNodes value="#{tree}" var="node">
           <tcs:treeNode label="#{node.userObject}"
                         action="#{controller.action1}"/>
         </tcs:treeNodes>
---%>
         <tcs:treeNode label="Action 1" action="#{controller.action1}"/>
         <tcs:treeNode label="Action 2" action="#{controller.action2}"/>
         <tcs:treeNode label="Action 3" action="#{controller.action3}">
@@ -83,6 +90,7 @@
       </tcs:treeNode>
     </tcs:tree>
 
+    <%--
     <tcs:tree state="#{treeState}" id="tree"
               showIcons="true"
               showJunctions="true"
@@ -90,11 +98,9 @@
               showRoot="true"
               selectable="single">
       <tcs:treeNode label="Root">
-<%--
         <tcs:treeNodes value="#{tree}" var="node">
           <tcs:treeNode label="#{node.userObject}"/>
         </tcs:treeNodes>
---%>
         <tcs:treeNode label="Sub 1"/>
         <tcs:treeNode label="Sub 2"/>
         <tcs:treeNode label="Sub 3">
@@ -104,6 +110,8 @@
         <tcs:treeNode label="Sub 4"/>
       </tcs:treeNode>
     </tcs:tree>
+--%>
+    <tc:cell/>
 
     <tc:cell/>
 

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=477366&r1=477365&r2=477366
==============================================================================
--- 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 Mon Nov 20 14:19:06 2006
@@ -1,5 +1,10 @@
 package org.apache.myfaces.tobago.component;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -19,10 +24,20 @@
 
 public class UITreeNode extends UICommand {
 
+  private static final Log LOG = LogFactory.getLog(UITreeNode.class);
+
   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.TreeNode";
 
   @Override
   public boolean getRendersChildren() {
     return true;
+  }
+
+  public Object getValue() {
+    if (super.getValue() == null) { // XXX: hack!
+      setValue(new DefaultMutableTreeNode());
+      LOG.info("Created temporary Node");
+    }
+    return super.getValue();
   }
 }

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java?view=diff&rev=477366&r1=477365&r2=477366
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITreeNodes.java Mon Nov 20 14:19:06 2006
@@ -42,8 +42,42 @@
 
 
   @Override
-  public void decode(FacesContext context) {
-    super.decode(context);
+  public void decode(FacesContext facesContext) {
+    DefaultMutableTreeNode tree = (DefaultMutableTreeNode) getValue();
+
+    decodeNodes(tree, "", 0, facesContext);
+  }
+
+  private void decodeNodes(DefaultMutableTreeNode node, String position,
+      int index, FacesContext facesContext) {
+
+    if (node == null) { // XXX hotfix
+      LOG.warn("node is null");
+      return;
+    }
+
+    currentParentNodeId = position;
+    position += "_" + index;
+    currentNodeId = position;
+
+    currentNode = node;
+    if (var == null) {
+      LOG.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+      LOG.error("var not set");
+      LOG.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+      var = "node";
+    }
+    facesContext.getExternalContext().getRequestMap().put(var, currentNode);
+    getTemplateComponent().decode(facesContext);
+    facesContext.getExternalContext().getRequestMap().remove(var);
+    currentNode = null;
+
+    index = 0;
+    for (Enumeration e = node.children(); e.hasMoreElements();) {
+      DefaultMutableTreeNode subNode = (DefaultMutableTreeNode) e.nextElement();
+      decodeNodes(subNode, position, index, facesContext);
+      index++;
+    }
   }
 
   @Override
@@ -70,7 +104,7 @@
     }
 
     currentParentNodeId = position;
-    position += ":" + index;
+    position += "_" + index;
     currentNodeId = position;
 
     currentNode = node;

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=477366&r1=477365&r2=477366
==============================================================================
--- 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 Mon Nov 20 14:19:06 2006
@@ -68,6 +68,10 @@
     TreeState state = tree.getState();
     String treeId = tree.getClientId(facesContext);
     String nodeId = node.getId();
+    UIComponent parent = node.getParent();
+    if (parent != null && parent instanceof UITreeNodes) { // todo cleanup
+      nodeId += ((UITreeNodes) parent).getCurrentNodeId();
+    }
     Map requestParameterMap
         = facesContext.getExternalContext().getRequestParameterMap();
 
@@ -170,7 +174,7 @@
       parentClientId = treeNode.getParent().getClientId(facesContext);
     } else if (parent != null && parent instanceof UITreeNodes) {
       pos = ((UITreeNodes) parent).getCurrentNodeId();
-      if (":0".equals(pos)) {
+      if ("_0".equals(pos)) {
         UIComponent superParent = parent.getParent();
         parentClientId = superParent.getClientId(facesContext);
       } else {
@@ -305,7 +309,6 @@
       // action link
       String actionLink =
           (String) treeNode.getAttributes().get(ATTR_ACTION_LINK);
-      LOG.fatal("actionLink = '" + actionLink + "'");
       if (actionLink != null) {
         writer.writeText("'", null);
         writer.writeText(actionLink, null);
@@ -319,7 +322,6 @@
       if (onclick != null) {
         writer.writeText("'", null);
         onclick = onclick.replaceAll("\\'", "\\\\'");
-        LOG.fatal("onclick = '" + onclick + "'");
         writer.writeText(onclick, null);
         writer.writeText("',", null);
       } else {