You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2013/05/10 09:59:35 UTC

svn commit: r1480910 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/model/ tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/04-listbox/ tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/my...

Author: weber
Date: Fri May 10 07:59:35 2013
New Revision: 1480910

URL: http://svn.apache.org/r1480910
Log:
TOBAGO-1263 - TreeListbox  did not work in 2.0

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeDataModel.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeNodeDataModel.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/04-listbox/tree-listbox.xhtml
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxNodeRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeDataModel.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeDataModel.java?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeDataModel.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeDataModel.java Fri May 10 07:59:35 2013
@@ -41,6 +41,8 @@ public abstract class TreeDataModel exte
 
   public abstract TreePath getPath();
 
+  public abstract int getDepth();
+
   public abstract boolean isFolder();
 
   @Override

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeNodeDataModel.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeNodeDataModel.java?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeNodeDataModel.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeNodeDataModel.java Fri May 10 07:59:35 2013
@@ -22,6 +22,7 @@ package org.apache.myfaces.tobago.model;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.TreeNode;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -157,6 +158,14 @@ public class TreeNodeDataModel extends T
   }
 
   @Override
+  public int getDepth() {
+    if (data instanceof DefaultMutableTreeNode) {
+      return ((DefaultMutableTreeNode) data).getDepth();
+    }
+    return -1;
+  }
+
+  @Override
   public boolean isFolder() {
     return !getRowData().isLeaf();
   }
@@ -191,7 +200,7 @@ public class TreeNodeDataModel extends T
       return showRoot;
     }
     TreeNode node = start.getParent();
-    while (node != null) {
+    while (node != null && back.get(node) != null) {
       final Data data = mapping.get(back.get(node));
       if (data.getNode().getParent() == null && !showRoot) {
         return true;
@@ -223,7 +232,7 @@ public class TreeNodeDataModel extends T
   public String getRowParentClientId() {
     if (isRowAvailable()) {
       final TreeNode parent = mapping.get(rowIndex).getNode().getParent();
-      if (parent != null) {
+      if (parent != null && back.get(parent) != null) {
         return mapping.get(back.get(parent)).getClientId();
       } else {
         return null;

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/04-listbox/tree-listbox.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/04-listbox/tree-listbox.xhtml?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/04-listbox/tree-listbox.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/04-listbox/tree-listbox.xhtml Fri May 10 07:59:35 2013
@@ -34,7 +34,8 @@
 
     <tc:treeListbox id="tree" value="#{demo.tree}" var="node">
       <tc:treeNode id="template">
-        <tc:treeLabel value="#{node.userObject.name}"/>
+        <tc:treeSelect label="#{node.userObject.name}"
+                       value="#{node.userObject.selected}"/>
       </tc:treeNode>
     </tc:treeListbox>
 

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxNodeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxNodeRenderer.java?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxNodeRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxNodeRenderer.java Fri May 10 07:59:35 2013
@@ -21,6 +21,7 @@ package org.apache.myfaces.tobago.render
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.tobago.component.UITreeNode;
+import org.apache.myfaces.tobago.component.UITreeSelect;
 import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.event.TreeExpansionEvent;
 import org.apache.myfaces.tobago.event.TreeMarkedEvent;
@@ -76,10 +77,10 @@ public class TreeListboxNodeRenderer ext
     // select
     if (tree.getSelectableAsEnum() != Selectable.NONE) { // selection
       String selected = (String) requestParameterMap.get(treeId + AbstractUITree.SELECT_STATE);
-      String searchString = ";" + nodeStateId + ";";
-      if (StringUtils.contains(selected, searchString)) {
-        // TODO: add selection to Component
-        //state.addSelection((DefaultMutableTreeNode) node.getValue());
+      String searchString = ";" + node.getClientId(facesContext) + ";";
+      UITreeSelect treeSelect = ComponentUtils.findDescendant(node, UITreeSelect.class);
+      if (treeSelect != null) {
+        treeSelect.setSubmittedValue(StringUtils.contains(selected, searchString));
       }
     }
 
@@ -119,6 +120,7 @@ public class TreeListboxNodeRenderer ext
     writer.startElement(HtmlElements.OPTION, null);
     // todo: define where to store the selection of a tree, node.getValue() seems not to be a god place.
     //        writer.writeAttribute(HtmlAttributes.VALUE, node.getValue().toString(), true); // XXX converter?
+    writer.writeAttribute(HtmlAttributes.VALUE, id, true);
     writer.writeIdAttribute(id);
     writer.writeAttribute(HtmlAttributes.SELECTED, expanded);
   }

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeListboxRenderer.java Fri May 10 07:59:35 2013
@@ -20,8 +20,8 @@
 package org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag;
 
 import org.apache.myfaces.tobago.component.RendererTypes;
-import org.apache.myfaces.tobago.component.UITreeLabel;
 import org.apache.myfaces.tobago.component.UITreeNode;
+import org.apache.myfaces.tobago.component.UITreeSelect;
 import org.apache.myfaces.tobago.internal.component.AbstractUITree;
 import org.apache.myfaces.tobago.layout.Measure;
 import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
@@ -105,18 +105,26 @@ public class TreeListboxRenderer extends
       writer.writeNameAttribute(clientId + AbstractUITree.SELECT_STATE);
       writer.writeIdAttribute(clientId + AbstractUITree.SELECT_STATE);
       writer.writeAttribute(HtmlAttributes.VALUE, ";", false);
+      writer.writeAttribute(DataAttributes.SELECTIONMODE, tree.getSelectableAsEnum().name(), false);
       writer.endElement(HtmlElements.INPUT);
     }
 
     List<Integer> thisLevel = new ArrayList<Integer>();
     thisLevel.add(0);
     List<Integer> nextLevel = new ArrayList<Integer>();
-    for (int level = 0; level < 7; level++) { // XXX not a fix value!!!
+    int depth = tree.getTreeDataModel().getDepth() != -1
+        ? tree.getTreeDataModel().getDepth()
+        : 7;  // XXX not a fix value!!!
+    // todo: use (TreeListbox ?)Layout
+    Measure currentWidth = tree.getCurrentWidth();
+    Measure width = currentWidth.divide(depth);
+    for (int level = 0; level < depth; level++) {
 
       writer.startElement(HtmlElements.DIV, null);
       writer.writeClassAttribute(Classes.create(tree, "level"));
       Style levelStyle = new Style();
-      levelStyle.setLeft(Measure.valueOf(level * 160)); // xxx 160 should be configurable
+      levelStyle.setLeft(width.multiply(level));
+      levelStyle.setWidth(width);
       writer.writeStyleAttribute(levelStyle);
       // at the start of each div there is an empty and disabled select tag to show empty area.
       // this is not needed for the 1st level.
@@ -165,8 +173,8 @@ public class TreeListboxRenderer extends
     writer.writeAttribute(HtmlAttributes.SIZE, 9); // must be > 1, but the real size comes from the layout
 //    writer.writeAttribute(HtmlAttributes.MULTIPLE, siblingMode);
 
-    final UITreeLabel label = ComponentUtils.findDescendant(tree, UITreeLabel.class);
-    final Object labelValue = label.getValue();
+    final UITreeSelect label = ComponentUtils.findDescendant(tree, UITreeSelect.class);
+    final Object labelValue = label.getLabel();
     if (labelValue != null) {
       writer.startElement(HtmlElements.OPTGROUP, tree);
       writer.writeAttribute(HtmlAttributes.LABEL, labelValue.toString(), true);

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java Fri May 10 07:59:35 2013
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.tobago.component.UITreeSelect;
 import org.apache.myfaces.tobago.internal.component.AbstractUIData;
+import org.apache.myfaces.tobago.internal.component.AbstractUITreeListbox;
 import org.apache.myfaces.tobago.internal.component.AbstractUITreeNode;
 import org.apache.myfaces.tobago.model.Selectable;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
@@ -81,6 +82,13 @@ public class TreeSelectRenderer extends 
     final AbstractUITreeNode node = ComponentUtils.findAncestor(select, AbstractUITreeNode.class);
     final AbstractUIData data = ComponentUtils.findAncestor(node, AbstractUIData.class);
 
+    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+
+    if (data instanceof AbstractUITreeListbox) {
+      writer.write(StringUtils.defaultString((String) select.getLabel()));
+      return;
+    }
+
     final String id = select.getClientId(facesContext);
     final String currentValue = getCurrentValue(facesContext, select);
     final boolean checked;
@@ -93,7 +101,6 @@ public class TreeSelectRenderer extends 
     final boolean folder = data.isFolder();
     final Selectable selectable = data.getSelectableAsEnum();
 
-    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
 
     writer.startElement(HtmlElements.SPAN, null);
     writer.writeClassAttribute(Classes.create(select));

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js?rev=1480910&r1=1480909&r2=1480910&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js Fri May 10 07:59:35 2013
@@ -104,47 +104,7 @@ Tobago.Tree.showChildren = function (nod
 };
 
 Tobago.Tree.init = function(elements) {
-
-  var listboxSelects = Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeListbox").find("select");
-
-  // find all option tags and add the dedicated select tag in its data section.
-
-  listboxSelects.children("option").each(function() {
-    var option = jQuery(this);
-    var select = option.closest(".tobago-treeListbox-level").next()
-        .find("[data-tobago-treeparent='" + option.attr("id") + "']");
-    if (select.length == 1) {
-      option.data("tobago-select", select);
-    } else {
-      var empty = option.closest(".tobago-treeListbox-level").next().children(":first");
-      option.data("tobago-select", empty);
-    }
-  });
-
-  // add on change on all select tag, all options that are not selected hide there dedicated
-  // select tag, and the selected option show its dedicated select tag.
-
-  listboxSelects.each(function() {
-
-    jQuery(this).change(function() {
-      jQuery(this).children("option:not(:selected)").each(function() {
-        jQuery(this).data("tobago-select").hide();
-      });
-      jQuery(this).children("option:selected").data("tobago-select").show();
-
-      // Deeper level (2nd and later) should only show the empty select tag.
-      // The first child is the empty selection.
-      jQuery(this).parent().nextAll(":not(:first)").children(":not(:first)").hide();
-      jQuery(this).parent().nextAll(":not(:first)").children(":first").show();
-
-    });
-
-    jQuery(this).focus(function() {
-      jQuery(this).change();
-    });
-
-  });
-
+  
   Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeNode-markup-folder .tobago-treeNode-toggle").click(function() {
     Tobago.Tree.toggleNode(jQuery(this));
     return false;
@@ -271,3 +231,73 @@ Tobago.Tree.isInSheet = function(node) {
 
 Tobago.registerListener(Tobago.Tree.init, Tobago.Phase.DOCUMENT_READY);
 Tobago.registerListener(Tobago.Tree.init, Tobago.Phase.AFTER_UPDATE);
+
+
+Tobago.TreeListbox = {};
+
+Tobago.TreeListbox.init = function(elements) {
+
+  var treeListbox = Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeListbox");
+  // hide select tags for level > root
+  treeListbox.children().find("select:not(:first)").hide();
+
+  var listboxSelects = treeListbox.find("select");
+
+  listboxSelects.children("option").each(Tobago.TreeListbox.initNextLevel);
+  listboxSelects.each(Tobago.TreeListbox.initListeners);
+};
+
+// find all option tags and add the dedicated select tag in its data section.
+Tobago.TreeListbox.initNextLevel = function() {
+  var option = jQuery(this);
+  var select = option.closest(".tobago-treeListbox-level").next()
+      .find("[data-tobago-treeparent='" + option.attr("id") + "']");
+  if (select.length == 1) {
+    option.data("tobago-select", select);
+  } else {
+    var empty = option.closest(".tobago-treeListbox-level").next().children(":first");
+    option.data("tobago-select", empty);
+  }
+};
+
+// add on change on all select tag, all options that are not selected hide there dedicated
+// select tag, and the selected option show its dedicated select tag.
+Tobago.TreeListbox.initListeners = function() {
+
+  jQuery(this).change(Tobago.TreeListbox.onChange);
+
+  jQuery(this).focus(function() {
+    jQuery(this).change();
+  });
+};
+
+Tobago.TreeListbox.onChange = function() {
+  var listbox = jQuery(this);
+  listbox.children("option:not(:selected)").each(function() {
+    jQuery(this).data("tobago-select").hide();
+  });
+  listbox.children("option:selected").data("tobago-select").show();
+  Tobago.TreeListbox.setSelected(listbox);
+
+  // Deeper level (2nd and later) should only show the empty select tag.
+  // The first child is the empty selection.
+  listbox.parent().nextAll(":not(:first)").each(function() {
+    jQuery(this).children(":not(:first)").hide();
+    jQuery(this).children(":first").show();
+  });
+
+};
+
+Tobago.TreeListbox.setSelected = function(listbox) {
+  var hidden = listbox.closest(".tobago-treeListbox").children("[data-tobago-selectionmode]");
+  if (hidden.length == 1){
+    var selectedValue = ";";
+    listbox.children("option:selected").each(function() {
+      selectedValue += jQuery(this).attr("id") + ";";
+    });
+    hidden.val(selectedValue);
+  }
+};
+
+Tobago.registerListener(Tobago.TreeListbox.init, Tobago.Phase.DOCUMENT_READY);
+Tobago.registerListener(Tobago.TreeListbox.init, Tobago.Phase.AFTER_UPDATE);
\ No newline at end of file