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 2007/05/29 11:35:55 UTC

svn commit: r542472 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ sandbox/src/main/java/org/apache/myfaces/tobago/component/ sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/...

Author: lofwyr
Date: Tue May 29 02:35:54 2007
New Revision: 542472

URL: http://svn.apache.org/viewvc?view=rev&rev=542472
Log:
Cleanup the new Tree

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITree.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeNodeRenderer.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTag.java
    myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTagDeclaration.java
    myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-tree.js
    myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java Tue May 29 02:35:54 2007
@@ -37,9 +37,9 @@
 import org.apache.myfaces.tobago.context.ResourceManagerUtil;
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.LayoutInformationProvider;
+import org.apache.myfaces.tobago.renderkit.LayoutableRendererBase;
 import org.apache.myfaces.tobago.renderkit.RenderUtil;
 import org.apache.myfaces.tobago.renderkit.RendererBaseWrapper;
-import org.apache.myfaces.tobago.renderkit.LayoutableRendererBase;
 import org.apache.myfaces.tobago.util.LayoutUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriterWrapper;
@@ -496,8 +496,7 @@
     writeScriptLoader(facesContext, new String[]{script}, null);
   }
 
-  public static void writeScriptLoader(
-      FacesContext facesContext, String[] scripts, String[] afterLoadCmds)
+  public static void writeScriptLoader(FacesContext facesContext, String[] scripts, String[] afterLoadCmds)
       throws IOException {
     TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
 
@@ -509,15 +508,21 @@
     StringBuilder script = new StringBuilder();
     script.append("new Tobago.ScriptLoader(\n    ");
     script.append(allScripts);
+
     if (afterLoadCmds != null && afterLoadCmds.length > 0) {
       script.append(", \n");
-      for (int i = 0; i < afterLoadCmds.length; i++) {
-        String cmd = StringUtils.replace(afterLoadCmds[i], "\\", "\\\\");
-        cmd = StringUtils.replace(cmd, "\"", "\\\"");
-        script.append(i == 0 ? "          " : "        + ");
-        script.append("\"");
-        script.append(cmd);
-        script.append("\"\n");
+      boolean first = true;
+      for (String afterLoadCmd : afterLoadCmds) {
+        String[] splittedStrings = StringUtils.split(afterLoadCmd, '\n'); // split on <CR> to have nicer JS
+        for (String splitted : splittedStrings) {
+          String cmd = StringUtils.replace(splitted, "\\", "\\\\");
+          cmd = StringUtils.replace(cmd, "\"", "\\\"");
+          script.append(first ? "          " : "        + ");
+          script.append("\"");
+          script.append(cmd);
+          script.append("\"\n");
+          first = false;
+        }
       }
     }
     script.append(");");

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITree.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITree.java?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITree.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/component/UITree.java Tue May 29 02:35:54 2007
@@ -17,8 +17,6 @@
  * limitations under the License.
  */
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MODE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTABLE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ICONS;
@@ -26,32 +24,26 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROOT;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROOT_JUNCTION;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
-import org.apache.myfaces.tobago.model.TreeState;
 import org.apache.myfaces.tobago.model.MixedTreeModel;
+import org.apache.myfaces.tobago.model.TreeState;
 import org.apache.myfaces.tobago.util.MessageFactory;
 
 import javax.faces.application.FacesMessage;
-import javax.faces.component.ActionSource;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
 import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
 import javax.faces.el.ValueBinding;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ActionListener;
-import javax.faces.event.FacesEvent;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
 import javax.swing.tree.DefaultMutableTreeNode;
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
-public class UITree extends UIInput implements NamingContainer, ActionSource {
-
-  private static final Log LOG = LogFactory.getLog(UITree.class);
+public class UITree extends UIInput implements NamingContainer {
 
   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Tree";
   public static final String MESSAGE_NOT_LEAF = "tobago.tree.MESSAGE_NOT_LEAF";
@@ -65,20 +57,6 @@
   public static final String FACET_TREE_NODE_COMMAND = "treeNodeCommand";
   public static final String PARAMETER_TREE_NODE_ID = "treeNodeId";
 
-  public static final String COMMAND_PREFIX = "command";
-
-  public static final String COMMAND_NEW = "new";
-  public static final String COMMAND_DELETE = "delete";
-  public static final String COMMAND_EDIT = "edit";
-  public static final String COMMAND_CUT = "cut";
-  public static final String COMMAND_COPY = "copy";
-  public static final String COMMAND_PASTE = "paste";
-  public static final String COMMAND_MOVE_UP = "moveUp";
-  public static final String COMMAND_MOVE_DOWN = "moveDown";
-
-  private Command[] treeCommands;
-
-  private MethodBinding actionListenerBinding;
   private TreeState treeState;
 
   private boolean showJunctions = true;
@@ -93,40 +71,6 @@
   private String mode;
   private MixedTreeModel model;
 
-  public UITree() {
-    treeCommands = new Command[]{
-      new Command(COMMAND_NEW),
-      new Command(COMMAND_DELETE),
-      new Command(COMMAND_EDIT),
-      new Command(COMMAND_CUT),
-      new Command(COMMAND_COPY),
-      new Command(COMMAND_PASTE),
-      new Command(COMMAND_MOVE_UP),
-      new Command(COMMAND_MOVE_DOWN),
-    };
-  }
-
-// ---------------------------- interface ActionSource
-
-  public void broadcast(FacesEvent event) throws AbortProcessingException {
-    super.broadcast(event);
-
-    MethodBinding binding = getActionListener();
-
-    if (binding != null) {
-      FacesContext context = getFacesContext();
-      binding.invoke(context, new Object[] {event});
-    }
-  }
-
-  public MethodBinding getAction() {
-    return null;
-  }
-
-  public void setAction(MethodBinding methodBinding) {
-
-  }
-
   public String getMode() {
     if (mode != null) {
       return mode;
@@ -143,46 +87,19 @@
     this.mode = mode;
   }
 
-  public MethodBinding getActionListener() {
-    return actionListenerBinding;
-  }
-
-  public void setActionListener(MethodBinding actionListener) {
-    this.actionListenerBinding = actionListener;
-  }
-
-  public void addActionListener(ActionListener actionListener) {
-    addFacesListener(actionListener);
-  }
-
-  public ActionListener[] getActionListeners() {
-    return (ActionListener[]) getFacesListeners(ActionListener.class);
-  }
-
-  public void removeActionListener(ActionListener actionListener) {
-    removeFacesListener(actionListener);
-  }
-
   public UITreeNode getRoot() {
     // find the UITreeNode in the childen.
-    for (Iterator i = getChildren().iterator(); i.hasNext();) {
-      UIComponent child = (UIComponent) i.next();
+    for (UIComponent child : (List<UIComponent>)getChildren()) {
       if (child instanceof UITreeNode) {
         return (UITreeNode) child;
       }
     }
-    // in a new UITree isn't a root
     return null;
   }
 
-  public void encodeChildren(FacesContext context)
-      throws IOException {
-//     will be called from end.jsp
-  }
-
   public void encodeEnd(FacesContext context) throws IOException {
     model = new MixedTreeModel();
-    
+
     buildModel();
     super.encodeEnd(context);
   }
@@ -204,11 +121,11 @@
 
   public boolean isSelectableTree() {
     final Object selectable
-        = ComponentUtil.getAttribute(this , ATTR_SELECTABLE);
+        = ComponentUtil.getAttribute(this, ATTR_SELECTABLE);
     return selectable != null
         && (selectable.equals("multi") || selectable.equals("multiLeafOnly")
-            || selectable.equals("single") || selectable.equals("singleLeafOnly")
-            || selectable.equals("sibling") || selectable.equals("siblingLeafOnly"));
+        || selectable.equals("single") || selectable.equals("singleLeafOnly")
+        || selectable.equals("sibling") || selectable.equals("siblingLeafOnly"));
   }
 
   public void processDecodes(FacesContext facesContext) {
@@ -271,7 +188,7 @@
         }
       }
     }
-  }      
+  }
 
   public void updateModel(FacesContext facesContext) {
     // nothig to update for tree's
@@ -279,53 +196,47 @@
   }
 
   public Object saveState(FacesContext context) {
-    Object[] state = new Object[7];
+    Object[] state = new Object[6];
     state[0] = super.saveState(context);
-    state[1] = saveAttachedState(context, actionListenerBinding);
-    state[2] = showJunctionsSet ? showJunctions : null;
-    state[3] = showIconsSet ? showIcons : null;
-    state[4] = showRootSet ? showRoot : null;
-    state[5] = showRootJunctionSet ? showRootJunction : null;
-    state[6] = mode;
+    state[1] = showJunctionsSet ? showJunctions : null;
+    state[2] = showIconsSet ? showIcons : null;
+    state[3] = showRootSet ? showRoot : null;
+    state[4] = showRootJunctionSet ? showRootJunction : null;
+    state[5] = mode;
     return state;
   }
 
   public void restoreState(FacesContext context, Object state) {
     Object[] values = (Object[]) state;
     super.restoreState(context, values[0]);
-    actionListenerBinding = (MethodBinding) restoreAttachedState(context, values[1]);
-    if (values[2] != null) {
-      showJunctions = (Boolean) values[2];
+    if (values[1] != null) {
+      showJunctions = (Boolean) values[1];
       showJunctionsSet = true;
     }
-    if (values[3] != null) {
-      showIcons = (Boolean) values[3];
+    if (values[2] != null) {
+      showIcons = (Boolean) values[2];
       showIconsSet = true;
     }
-    if (values[4] != null) {
-      showRoot = (Boolean) values[4];
+    if (values[3] != null) {
+      showRoot = (Boolean) values[3];
       showRootSet = true;
     }
-    if (values[5] != null) {
-      showRootJunction = (Boolean) values[5];
+    if (values[4] != null) {
+      showRootJunction = (Boolean) values[4];
       showRootJunctionSet = true;
     }
-    mode = (String) values[6];
-  }
-
-  public Command[] getCommands() {
-    return treeCommands;
+    mode = (String) values[5];
   }
 
   public TreeState getState() {
     if (treeState != null) {
-        return treeState;
+      return treeState;
     }
     ValueBinding valueBinding = getValueBinding(ATTR_STATE);
     if (valueBinding != null) {
-        return (TreeState) valueBinding.getValue(getFacesContext());
+      return (TreeState) valueBinding.getValue(getFacesContext());
     } else {
-        return null;
+      return null;
     }
   }
 
@@ -335,13 +246,13 @@
 
   public boolean isShowJunctions() {
     if (showJunctionsSet) {
-        return (showJunctions);
+      return (showJunctions);
     }
     ValueBinding vb = getValueBinding(ATTR_SHOW_JUNCTIONS);
     if (vb != null) {
-        return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
+      return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
     } else {
-        return (this.showJunctions);
+      return (this.showJunctions);
     }
   }
 
@@ -352,13 +263,13 @@
 
   public boolean isShowIcons() {
     if (showIconsSet) {
-        return (showIcons);
+      return (showIcons);
     }
     ValueBinding vb = getValueBinding(ATTR_SHOW_ICONS);
     if (vb != null) {
-        return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
+      return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
     } else {
-        return (this.showIcons);
+      return (this.showIcons);
     }
   }
 
@@ -369,13 +280,13 @@
 
   public boolean isShowRoot() {
     if (showRootSet) {
-        return (showRoot);
+      return (showRoot);
     }
     ValueBinding vb = getValueBinding(ATTR_SHOW_ROOT);
     if (vb != null) {
-        return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
+      return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
     } else {
-        return (this.showRoot);
+      return (this.showRoot);
     }
   }
 
@@ -386,13 +297,13 @@
 
   public boolean isShowRootJunction() {
     if (showRootJunctionSet) {
-        return (showRootJunction);
+      return (showRootJunction);
     }
     ValueBinding vb = getValueBinding(ATTR_SHOW_ROOT_JUNCTION);
     if (vb != null) {
-        return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
+      return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
     } else {
-        return (this.showRootJunction);
+      return (this.showRootJunction);
     }
   }
 

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=542472&r1=542471&r2=542472
==============================================================================
--- 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 May 29 02:35:54 2007
@@ -227,7 +227,7 @@
       throws IOException {
     String menuOpen = ResourceManagerUtil.getImageWithPath(facesContext, "image/treeMenuOpen.gif");
     String menuClose = ResourceManagerUtil.getImageWithPath(facesContext, "image/treeMenuClose.gif");
-    String onclick = "new_tobagoTreeNodeToggle(this.parentNode, '" + treeId + "', null, null, '"
+    String onclick = "tobagoTreeNodeToggle(this.parentNode, '" + treeId + "', null, null, '"
         + menuOpen + "', '" + menuClose + "')";
     String src = expanded ? menuOpen : menuClose;
     writer.startElement(IMG, null);
@@ -321,13 +321,11 @@
   }
 
   private String createOnclickForToggle(FacesContext facesContext, String treeId) {
-    return "new_tobagoTreeNodeToggle(this.parentNode, '" + treeId + "', '"
+    return "tobagoTreeNodeToggle(this.parentNode, '" + treeId + "', '"
           + ResourceManagerUtil.getImageWithPath(facesContext, "image/openfoldericon.gif") + "', '"
           + ResourceManagerUtil.getImageWithPath(facesContext, "image/foldericon.gif") + "', null, null)";
   }
 
-
-
 /*
   if (this.isFolder) {
     str += '<img class="tree-icon" id="' + this.id + '-icon" '
@@ -343,7 +341,6 @@
   }
 */
 
-
   private void encodeLabel(
       TobagoResponseWriter writer, CommandRendererHelper helper, UITreeNode node, boolean marked, String treeId)
       throws IOException {
@@ -354,7 +351,7 @@
       writer.startElement(A, null);
       writer.writeAttribute(HtmlAttributes.HREF, helper.getHref(), true);
       writer.writeAttribute(HtmlAttributes.ONCLICK, helper.getOnclick(), true); // xxx is escaping required?
-      writer.writeAttribute(HtmlAttributes.ONFOCUS, "storeMarker(this.parentNode, '" + treeId + "')", false);
+      writer.writeAttribute(HtmlAttributes.ONFOCUS, "Tobago.Tree.storeMarker(this.parentNode, '" + treeId + "')", false);
     }
     if (marked) {
       StyleClasses classes = new StyleClasses();
@@ -410,118 +407,3 @@
   }
 
 }
-/*
-
-TreeNode.prototype.toString = function (depth, last) {
-    if (!depth) depth = 0;
-
-    var str = '';
-    if (! this.hideRoot || depth > 0) {
-      str += '<div id="' + this.id + '" class="' + this.cssClass + '" '
-          + 'style="width: ' + this.width + ';">';
-      if (this.mode == "menu") {
-        if (this.isFolder) {
-          // FIXME: change the icons when klick on the icon
-          str += '<img class="tobago-tree-menu-icon" id="' + this.id + '-menuIcon"'
-              + 'src="' + (this.expanded ? this.treeResources.getImage("treeMenuOpen.gif")
-              : this.treeResources.getImage("treeMenuClose.gif")) + ' " '
-              + 'onclick="toggle(this.parentNode, \'' + this.treeHiddenId
-              + '\', null, null, \'' + this.treeResources.getImage("treeMenuOpen.gif")
-              + '\', \'' + this.treeResources.getImage("treeMenuClose.gif")
-              + '\')"'
-              + ' alt="">';
-        }
-      }
-      str += this.indent(depth, last);
-      if (!(   this.hideJunctions
-            || this.hideRootJunction && depth == 0
-            || this.hideRootJunction && this.hideRoot && depth == 1)) {
-        str += '<img class="tree-junction" id="' + this.id
-            + '-junction" src="' + (this.expanded
-              ? ((depth == 0)
-                ? this.treeResources.getImage("Rminus.gif")
-                : (last)
-                  ? this.treeResources.getImage("Lminus.gif")
-                  : this.treeResources.getImage("Tminus.gif"))
-              : ((depth == 0)
-                ? this.treeResources.getImage("Rplus.gif")
-                : (last)
-                  ? this.treeResources.getImage(this.isFolder ? "Lplus.gif" : "L.gif")
-                  : this.treeResources.getImage(this.isFolder ? "Tplus.gif" : "T.gif"))
-              )
-            + '" onclick="toggle(this.parentNode, \'' + this.treeHiddenId
-            + '\', \'' + this.treeResources.getImage("openfoldericon.gif")
-            + '\', \'' + this.treeResources.getImage("foldericon.gif")
-            + '\')"'
-            + ' alt="">';
-      } else if (( !this.hideRoot && depth >0 ) || (this.hideRoot && depth > 1)) {
-        str += '<img class="tree-junction" id="' + this.id
-            + '-junction" src="' + this.treeResources.getImage("blank.gif")
-            + '" alt="">';
-      }
-      if (! this.hideIcons) {
-        if (this.isFolder) {
-          str += '<img class="tree-icon" id="' + this.id + '-icon" '
-              + 'src="' + (this.expanded ? this.openIcon : this.icon) + ' " '
-              + 'onclick="toggle(this.parentNode, \'' + this.treeHiddenId
-              + '\', \'' + this.treeResources.getImage("openfoldericon.gif")
-              + '\', \'' + this.treeResources.getImage("foldericon.gif")
-              + '\')"'
-              + ' alt="">';
-        } else {
-          str += '<img class="tree-icon" id="' + this.id
-              + '-icon" src="' + this.treeResources.getImage("new.gif") + '" alt="">';
-        }
-      }
-      if (this.selectable) {
-        var markIcon = '';
-        var markIconOnClickFunction = '';
-        if (this.selectable.match(/LeafOnly$/) && this.isFolder) {
-          markIcon = this.treeResources.getImage("1x1.gif");
-        } else {
-          if (this.selected) {
-            markIcon = this.treeResources.getImage("checked" + (this.disabled ? "Disabled" : "") + ".gif");
-          } else {
-            markIcon = this.treeResources.getImage("unchecked" + (this.disabled ? "Disabled" : "") + ".gif");
-          }
-          if (!this.disabled) {
-            markIconOnClickFunction
-                = 'onclick="toggleSelect(this.parentNode, \'' + this.treeHiddenId
-                + '\', \'' + this.treeResources.getImage("unchecked.gif")
-                + '\', \'' + this.treeResources.getImage("checked.gif")
-                + '\')"';
-          }
-        }
-
-        str += '<img class="tree-icon" id="' + this.id
-            + '-markIcon" src="' + markIcon + '" ' + markIconOnClickFunction + ' alt="">';
-      }
-      str += '<a class="' + this.cssClassLabel + '"';
-      if (this.tip) {
-        str += ' title="' + this.tip + '"';
-      }
-      if (!this.disabled) {
-        str += ' href="' + Tobago.EMPTY_HREF +  '"'
-            + ' onclick="Tobago.Tree.onClick(this)"'
-            + ' ondblclick="Tobago.Tree.onDblClick(this)"'
-            + ' onfocus="' + this.onfocus + '"';
-      }
-      str += '>'
-          + this.label + '</a>';
-      str += '</div>';
-    }
-    if (this.isFolder) {
-      str += '<div id="' + this.id
-          + '-cont" style="display: '
-          + (this.expanded ? 'block' : 'none') + ';">';
-      for (var i=0; i<this.childNodes.length; ++i) {
-        var lastChild = i+1 == this.childNodes.length;
-        var n = this.childNodes[i];
-        str += n.toString(depth+1, lastChild);
-      }
-      str += '</div>';
-    }
-
-    return str;
-  };
-*/

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java Tue May 29 02:35:54 2007
@@ -25,7 +25,6 @@
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UITree;
 import org.apache.myfaces.tobago.component.UITreeNode;
-import org.apache.myfaces.tobago.config.TobagoConfig;
 import org.apache.myfaces.tobago.context.ResourceManagerUtil;
 import org.apache.myfaces.tobago.model.TreeState;
 import org.apache.myfaces.tobago.renderkit.LayoutableRendererBase;
@@ -42,7 +41,6 @@
 import java.io.IOException;
 import java.io.StringWriter;
 import java.util.List;
-import java.util.StringTokenizer;
 
 public class TreeRenderer extends LayoutableRendererBase {
 
@@ -102,6 +100,11 @@
   }
 
   @Override
+  public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
+    // will be rendered in encodeEnd()
+  }
+
+  @Override
   public void encodeEnd(FacesContext facesContext,
       UIComponent component) throws IOException {
 
@@ -139,50 +142,21 @@
       writer.endElement(HtmlConstants.INPUT);
     }
 
-//    writer.startElement(HtmlConstants.DIV, null);
-    writer.startElement(HtmlConstants.TABLE, tree);
-    writer.writeAttribute(HtmlAttributes.CELLPADDING, 0);
-    writer.writeAttribute(HtmlAttributes.CELLSPACING, 0);
-    writer.writeAttribute(HtmlAttributes.BORDER, 0);
-    writer.writeAttribute(HtmlAttributes.SUMMARY, "", false);
-    writer.writeClassAttribute();
-    writer.startElement(HtmlConstants.TR, null);
-    writer.startElement(HtmlConstants.TD, null);
-    writer.writeIdAttribute(clientId + "-cont");
-    writer.writeComment("placeholder for treecontent");
-    writer.endElement(HtmlConstants.TD);
-    writer.endElement(HtmlConstants.TR);
-    writer.endElement(HtmlConstants.TABLE);
-//    writer.endElement(HtmlConstants.DIV);
-
-    String[] scriptTexts = createJavascript(facesContext, clientId, root);
+    String scriptTexts = createJavascript(facesContext);
 
-    String[] scripts = {"script/tobago-tree.js"};
+    String treeScript = "script/tobago-tree.js";
+    // todo: this may be removed, it is twice on the page 1. in the header 2. in the ScriptLoader
     List<String> scriptFiles = ComponentUtil.findPage(facesContext, tree).getScriptFiles();
-    for (String script : scripts) {
-      scriptFiles.add(script);
-    }
+    scriptFiles.add(treeScript);
 
-    if (!TobagoConfig.getInstance(facesContext).isAjaxEnabled()) {
-
-      StringBuilder script = new StringBuilder();
-      for (String scriptText : scriptTexts) {
-        script.append(scriptText);
-        script.append('\n');
-      }
-      writer.writeJavascript(script.toString());
-    } else {
-      HtmlRendererUtil.writeScriptLoader(facesContext, scripts, scriptTexts);
-    }
+    HtmlRendererUtil.writeScriptLoader(facesContext, new String[]{treeScript}, new String[]{scriptTexts});
 
     RenderUtil.encode(facesContext, root);
 
     writer.endElement(HtmlConstants.DIV);
   }
 
-  private String[] createJavascript(FacesContext facesContext, String clientId,
-                                  UITreeNode root)
-  throws IOException {
+  private String createJavascript(FacesContext facesContext) throws IOException {
     StringBuilder sb = new StringBuilder();
 
     sb.append("{\n");
@@ -192,8 +166,7 @@
       sb.append("  treeResourcesHelp[\"");
       sb.append(images);
       sb.append("\"] = \"");
-      sb.append(ResourceManagerUtil.getImageWithPath(facesContext,
-          "image/" + images));
+      sb.append(ResourceManagerUtil.getImageWithPath(facesContext, "image/" + images));
       sb.append("\";\n");
     }
     sb.append(" \n  treeResourcesHelp.getImage = function (name) {\n");
@@ -206,32 +179,8 @@
     sb.append("\";\n");
     sb.append("    }\n");
     sb.append("  };\n \n");
-
-    sb.append("/* disabled!!! \n");
-
-//    sb.append(getNodesAsJavascript(facesContext, root));
-
-    sb.append("  var treeDiv = document.getElementById('");
-    sb.append(clientId);
-    sb.append("-cont');\n");
-    sb.append("  treeDiv.innerHTML = ");
-    String rootNode = createJavascriptVariable(root.getClientId(facesContext));
-    sb.append(rootNode);
-    sb.append(".toString(0, true);\n  ");
-
-    sb.append(rootNode);
-    sb.append(".initSelection();\n");
-
-    sb.append("disabled!!! */");
-
     sb.append("}");
-//    return sb.toString();
-    StringTokenizer tokenizer = new StringTokenizer(sb.toString(), "\n");
-    String[] strings = new String[tokenizer.countTokens()];
-    for (int i = 0; i < strings.length; i++) {
-      strings[i] = tokenizer.nextToken();
-    }
-    return strings;
+    return sb.toString();
   }
 
   protected String getNodesAsJavascript(FacesContext facesContext, UITreeNode root) throws IOException {

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTag.java?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTag.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTag.java Tue May 29 02:35:54 2007
@@ -30,7 +30,6 @@
 import org.apache.myfaces.tobago.component.UITree;
 import org.apache.myfaces.tobago.taglib.component.TobagoTag;
 
-import javax.faces.component.ActionSource;
 import javax.faces.component.UIComponent;
 
 public class TreeTag extends TobagoTag implements TreeTagDeclaration {
@@ -47,8 +46,6 @@
 
   private String required;
 
-  private String actionListener;
-
   private String mode;
 
   @Override
@@ -71,7 +68,6 @@
     ComponentUtil.setStringProperty(component, ATTR_SELECTABLE, selectable);
 
     ComponentUtil.setBooleanProperty(component, ATTR_REQUIRED, required);
-    ComponentUtil.setActionListener((ActionSource) component, actionListener);
     ComponentUtil.setStringProperty(component, ATTR_MODE, mode);
   }
 
@@ -86,7 +82,6 @@
     showRootJunction = null;
     selectable = null;
     required = null;
-    actionListener = null;
     mode = null;
   }
 
@@ -108,13 +103,6 @@
 
   public String getShowIcons() {
     return showIcons;
-  }
-
-  public void setActionListener(String actionListener) {
-    this.actionListener = actionListener;
-  }
-  public String getActionListener() {
-    return actionListener;
   }
 
   public void setShowIcons(String showIcons) {

Modified: myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTagDeclaration.java?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTagDeclaration.java (original)
+++ myfaces/tobago/trunk/sandbox/src/main/java/org/apache/myfaces/tobago/taglib/sandbox/TreeTagDeclaration.java Tue May 29 02:35:54 2007
@@ -23,29 +23,23 @@
 import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
 import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
 import org.apache.myfaces.tobago.taglib.component.TobagoTagDeclaration;
-import org.apache.myfaces.tobago.taglib.decl.HasActionListener;
 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
 import org.apache.myfaces.tobago.taglib.decl.HasState;
 import org.apache.myfaces.tobago.taglib.decl.HasTreeNodeValue;
 import org.apache.myfaces.tobago.taglib.decl.IsRequired;
 
-/*
- * Created by IntelliJ IDEA.
- * User: bommel
- * Date: 11.02.2006
- * Time: 13:28:14
- */
 /**
  * Renders a tree view.
+ *
+ * Date: 11.02.2006 13:28:14
  */
 @Tag(name = "tree")
 @BodyContentDescription(anyTagOf = "<tcs:treeNode>")
 @UIComponentTag(
     uiComponent = "org.apache.myfaces.tobago.component.UITree",
     rendererType = "Tree")
-public interface TreeTagDeclaration extends TobagoTagDeclaration,
-    HasIdBindingAndRendered, HasTreeNodeValue, HasState,
-    HasActionListener, IsRequired {
+public interface TreeTagDeclaration 
+    extends TobagoTagDeclaration, HasIdBindingAndRendered, HasTreeNodeValue, HasState, IsRequired {
 
   /**
    * Flag indicating whether or not this component should be render selectable items.

Modified: myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-tree.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-tree.js?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-tree.js (original)
+++ myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tobago-tree.js Tue May 29 02:35:54 2007
@@ -15,842 +15,9 @@
  * limitations under the License.
  */
 
-function toggle(node, treeHiddenId, openFolderIcon, folderIcon, openMenuIcon, closeMenuIcon) {
-  LOG.debug("toggle("+node+", "+treeHiddenId+", " + openFolderIcon + ", " + folderIcon + ", " + openMenuIcon + ", " + closeMenuIcon + ")");
-  var content = document.getElementById(node.id + "-cont");
-  if (content) {
-    var selectState = document.getElementById(treeHiddenId + '-selectState');
-    var icon = document.getElementById(node.id + '-icon');
-    var menuIcon = document.getElementById(node.id + '-menuIcon');
-    var junction = document.getElementById(node.id + '-junction');
-    var hidden = document.getElementById(treeHiddenId);
-    if (content.style.display == 'none') {
-      content.style.display = 'block';
-      if (icon) {
-        icon.src = openFolderIcon;
-      }
-      if (menuIcon) {
-        menuIcon.src = openMenuIcon;
-      }
-      if (junction) {
-        junction.src = junction.src.replace(/plus\./, "minus.");
-      }
-      hidden.value = hidden.value + nodeStateId(node) + ";" ;
-    } else {
-      content.style.display = 'none';
-      if (icon) {
-        icon.src = folderIcon;
-      }
-      if (menuIcon) {
-        menuIcon.src = closeMenuIcon;
-      }
-      if (junction) {
-        junction.src = junction.src.replace(/minus\./, "plus.");
-      }
-      hidden.value = hidden.value.replace(";" + nodeStateId(node) + ";" , ";");
-    }
-  }
-}
-
-function tbgTreeStates(hiddenId) {
-  LOG.debug("expandState =" + document.getElementById(hiddenId).value);
-  LOG.debug("selectState =" + document.getElementById(hiddenId + "-selectState").value);
-}
-
-function tbgToggleExpand(node, treeHiddenId) {
-  LOG.debug("tbgToggleExpand(" + node.label + ", " + treeHiddenId + ")");
-  var expandState = document.getElementById(treeHiddenId);
-  if (node.expanded) {
-    node.expanded = false;
-    expandState.value
-        = expandState.value.replace(";" + nodeStateId(node) + ";" , ";");
-  } else {
-    node.expanded = true;
-    expandState.value = expandState.value + nodeStateId(node) + ";";
-  }
-}
-
-function tbgSetExpand(node, treeHiddenId) {
-  var expandState = document.getElementById(treeHiddenId);
-  if (node.parentNode) {
-    tbgUnexpandNodeRecursive(node.parentNode)
-  }
-  var state = ";";
-  node.expanded = true;
-  state = state + nodeStateId(node) + ";";
-  while (node.parentNode) {
-    node = node.parentNode;
-    node.expanded = true;
-    state = ";" + nodeStateId(node) + state;
-  }
-}
-
-
-function tbgUnexpandNodeRecursive(node) {
-  node.expanded = false;
-  if (node.hasChildren()) {
-    for (var i = 0 ; i < node.childNodes.length; i++) {
-      tbgUnexpandNodeRecursive(node.childNodes[i]);
-    }
-  }
-}
-
-function tbgUnexpand(node, expandState) {
-  node.expanded = false;
-  expandState.value
-      = expandState.value.replace(";" + nodeStateId(node) + ";" , ";");
-}
-
-
-function tbgToggleSelect(node, treeHiddenId) {
-//  LOG.debug("tbgToggleSelect(" + node.label + ", " + treeHiddenId + ")");
-  if (!node.selectable) {
-    return;
-  }
-
-  var selectState = document.getElementById(treeHiddenId + '-selectState');
-  var setSelected = true;
-  if (node.selected) {
-    node.selected = false;
-    selectState.value
-        = selectState.value.replace(";" + nodeStateId(node) + ";" , ";");
-    if (!node.required || selectState.value.length > 1) {
-      setSelected = false;
-    }
-  }
-  if (setSelected){
-
-    var rootNode = document.getElementById(treeHiddenId).rootNode;
-    if (node.selectable.match(/^single/)) {
-      // remove all other selection marks
-      clearSelectionExcept(rootNode, selectState, node);
-    } else if (node.selectable.match(/^sibling/)) {
-      if (node.selectable.match(/LeafOnly$/) && node.hasChildren()) {
-        clearSelectionExcept(rootNode, selectState, node);
-      } else {
-        clearSelectionExceptSibling(rootNode, selectState, node);
-      }
-    }
-
-    if (!node.selectable.match(/LeafOnly$/) || !node.hasChildren()) {
-      node.selected = true;
-      selectState.value = selectState.value + nodeStateId(node) + ";"
-//      LOG.debug("selectable = " + node.selectable);
-    }
-  }
-//  LOG.debug("tbgToggleSelect -> selected = " + selectState.value);
-}
-
-function tbgUnselect(node, selectState) {
-  node.selected = false;
-    selectState.value
-        = selectState.value.replace(";" + nodeStateId(node) + ";" , ";");
-}
-
-function clearSelectionExcept(node, selectState, selectedNode) {
-  tbgTreeClearSelection(node)
-  selectedNode.selected = true;
-  selectState.value = ";" + nodeStateId(selectedNode) + ";";
-}
-
-function tbgTreeClearSelection(node) {
-  node.selected = false;
-  if (node.childNodes) {
-    for (var i = 0; i < node.childNodes.length; i++) {
-      tbgTreeClearSelection(node.childNodes[i]);
-    }
-  }
-}
-
-function clearSelectionExceptSibling(node, selectState, selectedNode) {
-//  LOG.debug(node.label + "  ---");
-  if (node.parentNode && selectedNode.parentNode != node.parentNode) {
-    tbgUnselect(node, selectState);
-  }
-  if (node.childNodes) {
-    for (var i = 0; i < node.childNodes.length; i++) {
-      clearSelectionExceptSibling(node.childNodes[i], selectState, selectedNode);
-    }
-  }
-}
-
-
-function toggleSelect(node, treeHiddenId, uncheckedIcon, checkedIcon) {
-  var selectState = document.getElementById(treeHiddenId + '-selectState');
-  var hidden = document.getElementById(treeHiddenId);
-  var icon = document.getElementById(node.id + '-markIcon');
-  var treeNode = Tobago.treeNodes[node.id];
-//  LOG.debug("treeNode.required = " + treeNode.required);
-  if (! (treeNode.selectable.match(/LeafOnly$/) && treeNode.childNodes.length > 0)) {
-    if (treeNode.selectable.match(/^single/)) {
-      if (! (selectState.value.indexOf(";" + nodeStateId(node) + ";", 0) > -1)) {
-//        LOG.debug("single selection changed");
-        icon.src = checkedIcon;
-        oldIcon = getIconForId(node, selectState.value);
-        oldNode = getNodeForId(treeNode, selectState.value);
-        if (oldIcon && oldIcon != icon
-            && (!(oldNode && oldNode.childNodes.length > 0 && oldNode.selectable
-                  && oldNode.selectable.match(/LeafOnly$/)))) {
-          oldIcon.src = uncheckedIcon;
-        }
-        selectState.value = ";" +  nodeStateId(node) + ";" ;
-      } else {
-//        LOG.debug("single selection cleared");
-        if (! treeNode.required) {
-          icon.src = uncheckedIcon;
-          selectState.value = ";" ;
-        } else {
-//          LOG.debug("single selection hold");
-        }
-      }
-    }
-    else {
-      if (selectState.value.indexOf(";" + nodeStateId(node) + ";", 0) > -1) {
-        // actual node is selected -> remove selection
-//        LOG.debug("selectState.value = " + selectState.value);
-//        LOG.debug("nodeSelectState   = " + ";" + nodeStateId(node) + ";" );
-//        LOG.debug("required          = " +  treeNode.required);
-        if (!(treeNode.required && selectState.value == ";" + nodeStateId(node) + ";") ) {
-          icon.src = uncheckedIcon;
-          selectState.value = selectState.value.replace(";" + nodeStateId(node) + ";" , ";");
-        }
-
-//        LOG.debug("selectState.value = " + selectState.value);
-      } else {
-        // actual node is not selected -> set selection
-        if (treeNode.selectable.match(/^siblings/)) {
-           // remove all nodes which are not siblings of actual node
-          // TODO:
-
-
-        } else {
-          icon.src = checkedIcon;
-          selectState.value = selectState.value + nodeStateId(node) + ";" ;
-        }
-      }
-    }
-  }
-}
-
-function createJavascriptVariable(id) {
-  if (id && id.replace) {
-    return id.replace(/:/g, "_");
-  }
-  else {
-    return id;
-  }
-}
-
-function getIconForId(node, selectId) {
-  var id = node.id.substring(0, node.id.lastIndexOf(":") + 1) + selectId.replace(/;/g, "") + '-markIcon';
-  return document.getElementById(id);
-}
-
-function getNodeForId(node, selectId) {
-
-  var match = selectId.match(/^;(.*);$/);
-  if (match) {
-    selectId = match[1];
-  } else {
-      return null;
-  }
-  while (node.parentNode) {
-    node = node.parentNode;
-    if (nodeStateId(node) == selectId) {
-      return node;
-    }
-  }
-
-  // node is rootNode
-  return getNodeForIdRecursiv(node, selectId);
-}
-
-function getNodeForIdRecursiv(node, selectId) {
-
-  for (var i=0; i<node.childNodes.length; ++i) {
-    if (nodeStateId(node.childNodes[i]) == selectId) {
-      return node.childNodes[i];
-    }
-    var found = getNodeForIdRecursiv(node.childNodes[i], selectId);
-    if (found) {
-      return found;
-    }
-  }
-}
-
-function storeMarker(node, treeHiddenId) {
-  var markerHidden = document.getElementById(treeHiddenId + '-marker');
-  if (markerHidden) {
-    Tobago.Tree.updateMarker(markerHidden.value, false);
-    markerHidden.value = node.id;
-  }
-  Tobago.Tree.updateMarker(node.id, true);
-}
-
-function nodeStateId(node) {
-  // this must do the same as nodeStateId() in TreeRenderer.java
-  var treeNodeObject = Tobago.treeNodes[node.id]
-  return node.id.substring(treeNodeObject.treeHiddenId.length + 1);
-}
-
-var TreeManager = {
-  _counter: 0,
-  getId: function() {
-    return "tobago.node." + this._counter++;
-  }
-};
-
-function TreeNode(label, tip, id, mode, isFolder,
-    hideIcons, hideJunctions, hideRootJunction,
-    hideRoot, treeHiddenId, selectable, mutable,
-    formId, selected, marked,
-    expanded, required, disabled, treeResources,
-    action, target, onclick, parent, icon, openIcon, width, cssClass, cssClassLabel) {
-  this.label = label;
-  this.tip = tip;
-  this.id = id;
-  Tobago.treeNodes[id] = this;
-  this.mode = mode
-  this.isFolder = isFolder
-  this.hideIcons = hideIcons || false;
-  this.hideJunctions = hideJunctions || false;
-  this.hideRootJunction = hideRootJunction || false;
-  this.hideRoot = hideRoot || false;
-  this.treeHiddenId = treeHiddenId;
-  this.selectable = selectable;
-  this.mutable = mutable;
-  this.formId = formId;
-  this.selected = selected;
-  this.marked = marked;
-  this.expanded = expanded;
-  this.required = required;
-  this.disabled = disabled;
-  this.treeResources = treeResources;
-	this.action = action;
-	this.onclick = onclick;
-  this.target = target;
-  this.icon = icon
-      || treeResources.getImage("foldericon.gif");
-  this.openIcon = openIcon
-      || treeResources.getImage("openfoldericon.gif");
-  this.width = width;
-  this.cssClass = cssClass;
-  this.cssClassLabel = cssClassLabel;
-  this.childNodes = [];
-  this.onfocus = "storeMarker(this.parentNode, '" + treeHiddenId + "')";
-
-  if (this.expanded) {
-    var hidden = document.getElementById(this.treeHiddenId);
-    var nodeStId = nodeStateId(this);
-    var regex = new RegExp(";" + nodeStId + ";");
-    if (! hidden.value.match(regex)) {
-      hidden.value = hidden.value + nodeStId + ";" ;
-    }
-  }                    
-
-  if (marked) {
-    storeMarker(this, treeHiddenId);
-  }
-
-	if (parent) {
-	  parent.add(this);
-	}
-}
-
-TreeNode.prototype.toString = function (depth, last) {
-    if (!depth) depth = 0;
-
-    var str = '';
-    if (! this.hideRoot || depth > 0) {
-      str += '<div id="' + this.id + '" class="' + this.cssClass + '" '
-          + 'style="width: ' + this.width + ';">';
-      if (this.mode == "menu") {
-        if (this.isFolder) {
-          // FIXME: change the icons when klick on the icon
-          str += '<img class="tobago-tree-menu-icon" id="' + this.id + '-menuIcon"'
-              + 'src="' + (this.expanded ? this.treeResources.getImage("treeMenuOpen.gif") : this.treeResources.getImage("treeMenuClose.gif")) + ' " '
-              + 'onclick="toggle(this.parentNode, \'' + this.treeHiddenId
-              + '\', null, null, \'' + this.treeResources.getImage("treeMenuOpen.gif")
-              + '\', \'' + this.treeResources.getImage("treeMenuClose.gif")
-              + '\')"'
-              + ' alt="">';
-        }
-      }
-      str += this.indent(depth, last);
-      if (!(   this.hideJunctions
-            || this.hideRootJunction && depth == 0
-            || this.hideRootJunction && this.hideRoot && depth == 1)) {
-        str += '<img class="tree-junction" id="' + this.id
-            + '-junction" src="' + (this.expanded
-              ? ((depth == 0)
-                ? this.treeResources.getImage("Rminus.gif")
-                : (last)
-                  ? this.treeResources.getImage("Lminus.gif")
-                  : this.treeResources.getImage("Tminus.gif"))
-              : ((depth == 0)
-                ? this.treeResources.getImage("Rplus.gif")
-                : (last)
-                  ? this.treeResources.getImage(this.isFolder ? "Lplus.gif" : "L.gif")
-                  : this.treeResources.getImage(this.isFolder ? "Tplus.gif" : "T.gif"))
-              )
-            + '" onclick="toggle(this.parentNode, \'' + this.treeHiddenId
-            + '\', \'' + this.treeResources.getImage("openfoldericon.gif")
-            + '\', \'' + this.treeResources.getImage("foldericon.gif")
-            + '\')"'
-            + ' alt="">';
-      } else if (( !this.hideRoot && depth >0 ) || (this.hideRoot && depth > 1)) {
-        str += '<img class="tree-junction" id="' + this.id
-            + '-junction" src="' + this.treeResources.getImage("blank.gif")
-            + '" alt="">';
-      }
-      if (! this.hideIcons) {
-        if (this.isFolder) {
-          str += '<img class="tree-icon" id="' + this.id + '-icon" '
-              + 'src="' + (this.expanded ? this.openIcon : this.icon) + ' " '
-              + 'onclick="toggle(this.parentNode, \'' + this.treeHiddenId
-              + '\', \'' + this.treeResources.getImage("openfoldericon.gif")
-              + '\', \'' + this.treeResources.getImage("foldericon.gif")
-              + '\')"'
-              + ' alt="">';
-        } else {
-          str += '<img class="tree-icon" id="' + this.id
-              + '-icon" src="' + this.treeResources.getImage("new.gif") + '" alt="">';
-        }
-      }
-      if (this.selectable) {
-        var markIcon = '';
-        var markIconOnClickFunction = '';
-        if (this.selectable.match(/LeafOnly$/) && this.isFolder) {
-          markIcon = this.treeResources.getImage("1x1.gif");
-        } else {
-          if (this.selected) {
-            markIcon = this.treeResources.getImage("checked" + (this.disabled ? "Disabled" : "") + ".gif");
-          } else {
-            markIcon = this.treeResources.getImage("unchecked" + (this.disabled ? "Disabled" : "") + ".gif");
-          }
-          if (!this.disabled) {
-            markIconOnClickFunction
-                = 'onclick="toggleSelect(this.parentNode, \'' + this.treeHiddenId
-                + '\', \'' + this.treeResources.getImage("unchecked.gif")
-                + '\', \'' + this.treeResources.getImage("checked.gif")
-                + '\')"';
-          }
-        }
-
-        str += '<img class="tree-icon" id="' + this.id
-            + '-markIcon" src="' + markIcon + '" ' + markIconOnClickFunction + ' alt="">';
-      }
-      str += '<a class="' + this.cssClassLabel + '"';
-      if (this.tip) {
-        str += ' title="' + this.tip + '"';
-      }
-      if (!this.disabled) {
-        str += ' href="' + Tobago.EMPTY_HREF +  '"'
-            + ' onclick="Tobago.Tree.onClick(this)"'
-            + ' ondblclick="Tobago.Tree.onDblClick(this)"'
-            + ' onfocus="' + this.onfocus + '"';
-      }
-      str += '>'
-          + this.label + '</a>';
-      str += '</div>';
-    }
-    if (this.isFolder) {
-      str += '<div id="' + this.id
-          + '-cont" style="display: '
-          + (this.expanded ? 'block' : 'none') + ';">';
-      for (var i=0; i<this.childNodes.length; ++i) {
-        var lastChild = i+1 == this.childNodes.length;
-        var n = this.childNodes[i];
-        str += n.toString(depth+1, lastChild);
-      }
-      str += '</div>';
-    }
-
-    return str;
-  };
-
-// is the node the last child of its paranet?
-TreeNode.prototype.isLast = function() {
-  if (!this.parentNode) return true;
-  var siblings = this.parentNode.childNodes;
-  if (siblings.length == 0) return true;
-  return (this == siblings[siblings.length-1]);
-};
-
-TreeNode.prototype.indent = function(depth, last) {
-  if (!depth) depth = 0;
-  var str = "";
-  var node = this;
-  while (node.parentNode) {
-    node = node.parentNode;
-    if((!node.parentNode && (node.hideRootJunction || node.hideRoot))
-        || (node.parentNode && !node.parentNode.parentNode
-        && node.hideRootJunction && node.hideRoot)) {
-      break;
-    }
-    str = '<img class="tree-junction" src="'
-        + ((node.isLast() || node.hideJunctions)
-        ? this.treeResources.getImage("blank.gif")
-        : this.treeResources.getImage("I.gif")) + '" alt="">' + str;
-  }
-  return str;
-};
-
-TreeNode.prototype.initSelection = function() {
-  if (this.selected) {
-    var selectState = document.getElementById(this.treeHiddenId + '-selectState');
-    if (selectState) {
-      selectState.value = selectState.value + nodeStateId(this) + ";";
-    }
-  }
-  if (this.childNodes) {
-    for (var i = 0; i < this.childNodes.length; i++) {
-      this.childNodes[i].initSelection();
-    }
-  }
-};
-
-TreeNode.prototype.hasChildren = function() {
-  return (this.childNodes && this.childNodes.length > 0);
-}
-
-TreeNode.prototype.add = function (node) {
-  node.parentNode = this;
-  this.childNodes[this.childNodes.length] = node;
-  return node;
-};
-
-TreeNode.prototype.onClick = function() {
-  LOG.debug("click on tree;");
-  this.singleClick = true;
-  setTimeout(Tobago.bind(this, "doOnClick"), Tobago.Tree.DBL_CLICK_TIMEOUT);
-}
-
-TreeNode.prototype.doOnClick = function() {
-  if (!this.singleClick) {
-    return;
-  }
-
-  LOG.debug("doClick on tree;");
-  this.singleClick = false;
-  if (this.action && !this.disabled) {
-    Tobago.navigateToUrl(this.action);
-  } else if (this.onclick && !this.disabled) {
-    eval(this.onclick);
-  } else if (this.mutable) {
-      // nothing to do, storeMarker is already don in onFocus()
-//      storeMarker(Tobago.element(this.id), this.treeHiddenId);
-  } else if (this.selectable) {
-    toggleSelect(Tobago.element(this.id),
-        this.treeHiddenId,
-        this.treeResources.getImage("unchecked.gif"),
-        this.treeResources.getImage("checked.gif"));
-  } else {
-    Tobago.submitAction(this.id, true, this.target);
-  }
-}
-
-TreeNode.prototype.onDblClick = function() {
-  LOG.debug("dblclick on tree;");
-  this.singleClick = false;
-  toggle(Tobago.element(this.id),
-      this.treeHiddenId,
-      this.treeResources.getImage("openfoldericon.gif"),
-      this.treeResources.getImage("foldericon.gif"));
-}
-
-
-
-// //////////////////////////////////////////////////  listTree
-
-function tobagoTreeListboxInitSelection(node) {
-  node.initSelection();
-}
-
-function tobagoTreeListboxClearValueChangedMarker(hiddenId) {
-  var rootNode = document.getElementById(hiddenId).rootNode;
-  rootNode.valueChanged = false;
-
-}
-
-function tobagoTreeListboxChange(element, hiddenId) {
-  return;
-}
-
-function tbgGetParentNode(selectElement, rootNode) {
-  var level = selectElement.id.lastIndexOf("_");
-  var idPrefix = selectElement.id.substr(0, level);
-  level = selectElement.id.substr(level + 1) - 0;
-
-  var selector = document.getElementById(idPrefix + "_" + level);
-
-  var node = rootNode;
-  for (var actualLevel = 0 ;actualLevel < level; actualLevel++) {
-    for (var i = 0; i < node.childNodes.length; i++) {
-      if (node.childNodes[i].hasChildren() && node.childNodes[i].expanded) {
-        node = node.childNodes[i];
-        break;
-      }
-    }
-  }
-
-  return node;
-}
-
-
-function tbgGetActualNode(element, rootNode) {
-  var selectElement = element.parentNode;
-  var level = selectElement.id.lastIndexOf("_");
-  var idPrefix = selectElement.id.substr(0, level);
-  level = selectElement.id.substr(level + 1) - 0;
-
-  var selector = document.getElementById(idPrefix + "_" + level);
-
-  var node = rootNode;
-  for (var actualLevel = 0 ;actualLevel < level; actualLevel++) {
-    for (var i = 0; i < node.childNodes.length; i++) {
-      if (node.childNodes[i].hasChildren() && node.childNodes[i].expanded) {
-        node = node.childNodes[i];
-        break;
-      }
-    }
-  }
-
-  return node.childNodes[selector.value];
-}
-
-
-function tbgGetSelectionCount(element) {
-  var count = 0;
-  for (var i = 0; i < element.options.length; i++) {
-    if (element.options[i].selected) {count++;}
-  }
-  return count;
-}
-
-function tbgClearSelectionStates(node) {
-  node.selected = false;
-  if (node.hasChildren()) {
-    for (var i = 0; i < node.childNodes.length; i++) {
-      tbgClearSelectionStates(node.childNodes[i]);
-    }
-  }
-}
-
-function tbgGetSelectedIndizes(element) {
-  var indizes = new Array();
-  for (var i = 0; i < element.options.length; i++) {
-    if (element.options[i].selected) {
-      indizes[indizes.length] = i;
-    }
-  }
-  return indizes;
-}
-
-function tbgTreeListboxChange(element, hiddenId) {
-  // this handler is invoked only in sibling mode
-  var rootNode = document.getElementById(hiddenId).rootNode;
-  var expandState = document.getElementById(hiddenId);
-  var selectState = document.getElementById(hiddenId + '-selectState');
-//  LOG.debug("1 selectState : " + selectState.value);
-//  LOG.debug("1 expandState : " + expandState.value);
-
-  var parentNode = tbgGetParentNode(element, rootNode);
-
-  var singleSelection = tbgGetSelectionCount(element) == 1;
-
-  tbgClearSelectionStates(rootNode);
-
-  var level = element.id.lastIndexOf("_");
-  var idPrefix = element.id.substr(0, level);
-  level = element.id.substr(level + 1) - 0;
-
-  if (singleSelection) {
-    // if selected is folderNode : expand folder
-    // else : set new selected.
-
-    var actualNode = parentNode.childNodes[element.selectedIndex];
-    if (actualNode.hasChildren()) {
-      // actual node is folder : expand
-      tbgSetExpand(actualNode, hiddenId);
-      selectState.value = ";";
-      tobagoTreeListboxSetup(actualNode, idPrefix, level + 1, hiddenId);
-    } else {
-      tbgClearExpandStatesRecursiv(parentNode, expandState);
-      actualNode.selected = true;
-      selectState.value = ";" + nodeStateId(actualNode) + ";";
-
-      tobagoTreeListboxDisable(idPrefix, level + 1);
-    }
-  } else {
-    // multiselection
-
-    var selected = tbgGetSelectedIndizes(element);
-    selectState.value = ";";
-    for (var i = 0; i < selected.length; i++) {
-      var idx = selected[i];
-      if (!parentNode.childNodes[idx].hasChildren()) {
-        parentNode.childNodes[idx].selecded = true;
-        selectState.value += nodeStateId(parentNode.childNodes[idx]) + ";";
-      } else {
-        element.options[idx].selected = false;
-      }
-    }
-  }
-
-//  LOG.debug("2 selectState : " + selectState.value);
-//  LOG.debug("2 expandState : " + expandState.value);
-
-}
-
-function tbgTreeListboxClick(selectElement, hiddenId) {
-
-  var rootNode = document.getElementById(hiddenId).rootNode;
-  var expandState = document.getElementById(hiddenId);
-  var selectState = document.getElementById(hiddenId + '-selectState');
-//  LOG.debug("1 selectState : " + selectState.value);
-//  LOG.debug("1 expandState : " + expandState.value);
-
-  var actualNode = tbgGetClickedNode(selectElement, rootNode);
-
-//  var actualNode = tbgGetActualNode(element, rootNode);
-
-
-  tbgSetExpand(actualNode, hiddenId);
-  tbgToggleSelect(actualNode, hiddenId);
-
-
-  // update gui
-  var parentNode = actualNode.parentNode;
-  for (var i = 0; i < selectElement.options.length; i++) {
-      selectElement.options[i].selected
-          = (parentNode.childNodes[i].selected
-             || (parentNode.childNodes[i].hasChildren() && parentNode.childNodes[i].expanded));
-  }
-
-  var level = selectElement.id.lastIndexOf("_");
-  var idPrefix = selectElement.id.substr(0, level);
-  level = selectElement.id.substr(level + 1) - 0;
-
-  var parentSelectElement = document.getElementById(idPrefix + "_" + (level - 1));
-  if (parentSelectElement) {
-//    LOG.debug("clear parent");
-    parentNode = parentNode.parentNode;
-    for (var i = 0; i < parentSelectElement.options.length; i++) {
-      parentSelectElement.options[i].selected
-          = (parentNode.childNodes[i].hasChildren() && parentNode.childNodes[i].expanded);
-    }
-  }
-
-
-  if (actualNode.childNodes && actualNode.childNodes.length > 0 && actualNode.expanded ) {
-    tobagoTreeListboxSetup(actualNode, idPrefix, level + 1, hiddenId);
-  } else {
-    tobagoTreeListboxDisable(idPrefix, level + 1);
-  }
-//  LOG.debug("2 selectState : " + selectState.value);
-//  LOG.debug("2 expandState : " + expandState.value);
-
-}
-
-function tbgGetClickedNode(element, rootNode) {
-  // alle selected options von element aufsammeln
-  // alle selected nodes von actualNode aufsammeln
-  // die node die nur in einer der samlungen vorkommt ist die geclickte!
-  var parentNode = tbgGetParentNode(element, rootNode);
-
-  var idx = -1;
-
-  if (rootNode.selectable.match(/^single/)) {
-    idx = element.selectedIndex;
-    if (idx == -1) {
-      // node was deselected
-      for (var i = 0; i < parentNode.childNodes; i++ ) {
-        if (parentNode.childNodes[i].selected) {
-          idx = i;
-          break;
-        }
-      }
-    }
-  }
-
-  if (idx > -1) {
-    return parentNode.childNodes[idx];
-  }
-
-  return undefined;
-}
-
-/*function   tbgGetdif(bigArray, smallArray) {
-  if (smallArray.length < 1 && bigArray.length == 1) {
-    return bigArray[0];
-  }
-  for (var i = 0; i < smallArray.length; i++) {
-    if (bigArray[i] != smallArray[i]) {return bigArray[i]; }
-  }
-  return -1;
-}*/
-
-
-
-
-function tobagoTreeListboxSetup(node, idPrefix, level, hiddenId) {
-  tobagoTreeListboxEnable(idPrefix, level);
-  var selector = document.getElementById(idPrefix + "_" + level);
-  for (var i = 0; i < node.childNodes.length; i++) {
-    selector.options[selector.options.length] = tobagoTreeListboxCreateOption(node.childNodes[i], i, hiddenId);
-  }
-}
-
-function tobagoTreeListboxCreateOption(node, index, hiddenId) {
-  var label = node.label;
-  if (node.childNodes && node.childNodes.length) {
-    label += " \u2192";
-  }
-  var option = new Option(label, index);
-  option.hiddenId = hiddenId;
-  if (node.tip) {
-    option.title = node.tip;
-  }
-//  Tobago.addEventListener(option, 'click', tbgTreeListboxClick);
-
-  return option;
-}
-
-function tobagoTreeListboxRemoveOptions(idPrefix, start) {
-  var selector = document.getElementById(idPrefix + "_" + start);
-  while (selector && selector.hasChildNodes()) {
-    selector.removeChild(selector.firstChild);
-  }
-}
-
-function tobagoTreeListboxEnable(idPrefix, start) {
-  var selector = document.getElementById(idPrefix + "_" + start);
-  while (selector) {
-    tobagoTreeListboxRemoveOptions(idPrefix, start++);
-    Tobago.removeCssClass(selector, "tobago-treeListbox-unused");
-    selector = document.getElementById(idPrefix + "_" + start);
-  }
-}
-function tobagoTreeListboxDisable(idPrefix, start) {
-  tobagoTreeListboxRemoveOptions(idPrefix, start);
-  var selector = document.getElementById(idPrefix + "_" + start);
-  while (selector) {
-    tobagoTreeListboxRemoveOptions(idPrefix, start++);
-    Tobago.addCssClass(selector, "tobago-treeListbox-unused");
-    selector.oldValue = -1;
-    selector = document.getElementById(idPrefix + "_" + start);
-  }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-function new_tobagoTreeNodeOnclick() {
-
-}
-
-function new_tobagoTreeNodeToggle(node, treeHiddenId, openFolderIcon, folderIcon, openMenuIcon, closeMenuIcon) {
-  LOG.debug("toggle("+node+", "+treeHiddenId+", " + openFolderIcon + ", " + folderIcon + ", " + openMenuIcon + ", " + closeMenuIcon + ")");
+function tobagoTreeNodeToggle(node, treeHiddenId, openFolderIcon, folderIcon, openMenuIcon, closeMenuIcon) {
+  LOG.debug("toggle(" + node + ", " + treeHiddenId + ", " + openFolderIcon + ", " + folderIcon + ", "
+      + openMenuIcon + ", " + closeMenuIcon + ")");
   var content = document.getElementById(node.id + "-cont");
   if (content) {
     var expandedState = document.getElementById(node.id + '-expanded');
@@ -869,7 +36,7 @@
       if (junction) {
         junction.src = junction.src.replace(/plus\./, "minus.");
       }
-      hidden.value = hidden.value + new_nodeStateId(node) + ";" ;
+      hidden.value = hidden.value + nodeStateId(node) + ";";
       expandedState.value = "true";
     } else {
       content.style.display = 'none';
@@ -882,14 +49,13 @@
       if (junction) {
         junction.src = junction.src.replace(/minus\./, "plus.");
       }
-      hidden.value = hidden.value.replace(";" + new_nodeStateId(node) + ";" , ";");
+      hidden.value = hidden.value.replace(";" + nodeStateId(node) + ";", ";");
       expandedState.value = "false";
     }
   }
 }
 
-function new_nodeStateId(node) {
+function nodeStateId(node) {
   // this must do the same as nodeStateId() in TreeRenderer.java
   return node.id.substring(node.id.lastIndexOf(':') + 1);
 }
-

Modified: myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js?view=diff&rev=542472&r1=542471&r2=542472
==============================================================================
--- myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js (original)
+++ myfaces/tobago/trunk/sandbox/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js Tue May 29 02:35:54 2007
@@ -62,4 +62,13 @@
       node = node.nextSibling;
     }
   }
-}
\ No newline at end of file
+}
+
+Tobago.Tree.storeMarker = function(node, treeHiddenId) {
+  var markerHidden = document.getElementById(treeHiddenId + '-marker');
+  if (markerHidden) {
+    Tobago.Tree.updateMarker(markerHidden.value, false);
+    markerHidden.value = node.id;
+  }
+  Tobago.Tree.updateMarker(node.id, true);
+}