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 2012/07/17 10:15:27 UTC
svn commit: r1362400 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/...
Author: lofwyr
Date: Tue Jul 17 08:15:26 2012
New Revision: 1362400
URL: http://svn.apache.org/viewvc?rev=1362400&view=rev
Log:
TOBAGO-895: Support for selection of subtrees on <tc:tree>
Added:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Selectable.java
- copied, changed from r1360036, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeListboxTagDeclaration.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeTagDeclaration.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/01-select/tree-select.xhtml
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/02-editor/tree-editor.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/TreeRenderer.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/internal/component/AbstractUIData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java Tue Jul 17 08:15:26 2012
@@ -19,10 +19,13 @@ package org.apache.myfaces.tobago.intern
import org.apache.myfaces.tobago.compat.FacesUtils;
import org.apache.myfaces.tobago.compat.InvokeOnComponent;
+import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.model.ExpandedState;
+import org.apache.myfaces.tobago.model.Selectable;
import org.apache.myfaces.tobago.model.TreeDataModel;
import org.apache.myfaces.tobago.model.TreeNodeDataModel;
import org.apache.myfaces.tobago.model.TreePath;
+import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,6 +89,14 @@ public abstract class AbstractUIData ext
}
/**
+ * Will be obsolete later when selectable has the type TreeSelectable.
+ */
+ public Selectable getSelectableAsEnum() {
+ final Selectable selectable = Selectable.parse(ComponentUtils.getStringAttribute(this, Attributes.SELECTABLE));
+ return selectable != null ? selectable : Selectable.NONE; // should not happen
+ }
+
+ /**
* Creates the TreeDataModel which should be used.
* Override this method to use a custom model for an unsupported tree model.
* (Currently Tobago supports {@link TreeNode} out of the box.
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java Tue Jul 17 08:15:26 2012
@@ -26,9 +26,7 @@ import org.apache.myfaces.tobago.layout.
import org.apache.myfaces.tobago.model.ExpandedState;
import org.apache.myfaces.tobago.model.MarkedState;
import org.apache.myfaces.tobago.model.MixedTreeModel;
-import org.apache.myfaces.tobago.model.TreeSelectable;
import org.apache.myfaces.tobago.model.TreeState;
-import org.apache.myfaces.tobago.util.ComponentUtils;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
@@ -124,13 +122,6 @@ public abstract class AbstractUITree ext
return true;
}
- /**
- * Will be obsolete later when selectable has the type TreeSelectable.
- */
- public TreeSelectable getSelectableAsEnum() {
- return TreeSelectable.parse(ComponentUtils.getStringAttribute(this, Attributes.SELECTABLE));
- }
-
@Override
public void processDecodes(FacesContext facesContext) {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeListboxTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeListboxTagDeclaration.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeListboxTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeListboxTagDeclaration.java Tue Jul 17 08:15:26 2012
@@ -59,11 +59,11 @@ public interface TreeListboxTagDeclarati
* <li><strong>singleLeafOnly</strong> : a single section tree is rendered,
* only Leaf's are selectable</li>
* </ul>
- * For any other value or if this attribute is omitted the items are not selectable.
*/
@TagAttribute
- @UIComponentTagAttribute(defaultValue = "off",
- allowedValues = {"single", "multiLeafOnly", "singleLeafOnly", "off"})
+ @UIComponentTagAttribute(
+ defaultValue = "single",
+ allowedValues = {"single", "multiLeafOnly", "singleLeafOnly"})
void setSelectable(String selectable);
/**
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeTagDeclaration.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeTagDeclaration.java Tue Jul 17 08:15:26 2012
@@ -55,22 +55,22 @@ public interface TreeTagDeclaration
* Flag indicating whether or not this component should be render selectable items.
* Possible values are:
* <ul>
+ * <li><strong>multi</strong> : not selectable</li>
* <li><strong>multi</strong> : a multi section tree is rendered</li>
* <li><strong>single</strong> : a single section tree is rendered</li>
* <li><strong>multiLeafOnly</strong> : a multi section tree is rendered,
- * only Leaf's are selectable</li>
+ * only leaf's are selectable</li>
* <li><strong>singleLeafOnly</strong> : a single section tree is rendered,
- * only Leaf's are selectable</li>
+ * only leaf's are selectable</li>
* </ul>
- * For any other value or if this attribute is omitted the items are not selectable.
*/
@TagAttribute
- @UIComponentTagAttribute(defaultValue = "off",
- allowedValues = {"multi", "single", "multiLeafOnly", "singleLeafOnly", "off"})
+ @UIComponentTagAttribute(
+ defaultValue = "multi",
+ allowedValues = {"none", "multi", "single", "multiLeafOnly", "singleLeafOnly"})
void setSelectable(String selectable);
/**
- *
* <strong>ValueBindingExpression</strong> pointing to a object to save the
* component's state.
*/
Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Selectable.java (from r1360036, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Selectable.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Selectable.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java&r1=1360036&r2=1362400&rev=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Selectable.java Tue Jul 17 08:15:26 2012
@@ -22,34 +22,89 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-public enum TreeSelectable {
+public enum Selectable {
- OFF("off"),
+ /**
+ * Not selectable.
+ */
+ NONE("none"),
+
+ /**
+ * Multi selection possible. No other limitations.
+ */
MULTI("multi"),
+
+ /**
+ * Only one item is selectable.
+ */
SINGLE("single"),
+
+ /**
+ * Only one of no item is selectable.
+ */
+ SINGLE_OR_NONE("singleOrNone"),
+
+ /**
+ * Only leafs are selectable.
+ */
MULTI_LEAF_ONLY("multiLeafOnly"),
+
+ /**
+ * Only one item is selectable and it must be a leaf.
+ */
SINGLE_LEAF_ONLY("singleLeafOnly"),
+
+ /**
+ * Only siblings are selectable.
+ */
SIBLING("sibling"),
+
+ /**
+ * Only siblings are selectable and they have to be leafs.
+ */
SIBLING_LEAF_ONLY("siblingLeafOnly"),
- MULTI_SUB_TREE("multiSubTree"),
- SINGLE_SUB_TREE("singleSubTree");
+
+ /**
+ * Multi selection possible. When selecting or deselecting an item, the subtree will also
+ * be selected or unselected.
+ */
+ MULTI_CASCADE("multiCascade");
+
+ private static final Set<Selectable> SHEET_VALUES = EnumSet.of(
+ NONE,
+ MULTI,
+ SINGLE,
+ SINGLE_OR_NONE);
+
+ private static final Set<Selectable> TREE_VALUES = EnumSet.of(
+ NONE,
+ MULTI,
+ SINGLE,
+ MULTI_LEAF_ONLY,
+ SINGLE_LEAF_ONLY,
+ MULTI_CASCADE);
+
+ private static final Set<Selectable> TREE_LISTBOX_VALUES = EnumSet.of(
+ SINGLE,
+ SINGLE_LEAF_ONLY,
+ MULTI_LEAF_ONLY);
+
+ private static final Map<String, Selectable> MAPPING;
private String value;
- TreeSelectable(String value) {
+ Selectable(String value) {
this.value = value;
}
public String getValue() {
- return value;
+ return value;
}
- private static final Map<String, TreeSelectable> MAPPING;
-
static {
- MAPPING = new HashMap<String, TreeSelectable>();
+ MAPPING = new HashMap<String, Selectable>();
- for (TreeSelectable action : TreeSelectable.values()) {
+ for (Selectable action : Selectable.values()) {
MAPPING.put(action.getValue(), action);
}
}
@@ -59,8 +114,14 @@ public enum TreeSelectable {
* @return The matching tree selection (can't be null).
* @throws IllegalArgumentException When the name doesn't match any TreeSelectable.
*/
- public static TreeSelectable parse(String name) throws IllegalArgumentException {
- TreeSelectable value = MAPPING.get(name);
+ public static Selectable parse(Object name) throws IllegalArgumentException {
+ if (name == null) {
+ return null;
+ }
+ if (name instanceof Selectable) {
+ return (Selectable) name;
+ }
+ Selectable value = MAPPING.get(name.toString());
if (value != null) {
return value;
} else {
@@ -68,28 +129,23 @@ public enum TreeSelectable {
}
}
- public boolean isSupportedByTree() {
- return TREE_VALUES.contains(this);
+ public boolean isLeafOnly() {
+ return this == SINGLE_LEAF_ONLY || this == MULTI_LEAF_ONLY || this == SIBLING_LEAF_ONLY;
}
- private static final Set<TreeSelectable> TREE_VALUES = EnumSet.noneOf(TreeSelectable.class);
-
- static {
- TREE_VALUES.add(MULTI);
- TREE_VALUES.add(SINGLE);
- TREE_VALUES.add(MULTI_LEAF_ONLY);
- TREE_VALUES.add(SINGLE_LEAF_ONLY);
+ public boolean isSingle() {
+ return this == SINGLE || this == SINGLE_OR_NONE || this == SINGLE_LEAF_ONLY;
}
- public boolean isSupportedByTreeListbox() {
- return TREE_LISTBOX_VALUES.contains(this);
+ public boolean isSupportedBySheet() {
+ return SHEET_VALUES.contains(this);
}
- private static final Set<TreeSelectable> TREE_LISTBOX_VALUES = EnumSet.noneOf(TreeSelectable.class);
+ public boolean isSupportedByTree() {
+ return TREE_VALUES.contains(this);
+ }
- static {
- TREE_LISTBOX_VALUES.add(SINGLE);
- TREE_LISTBOX_VALUES.add(MULTI_LEAF_ONLY);
- TREE_LISTBOX_VALUES.add(SINGLE_LEAF_ONLY);
+ public boolean isSupportedByTreeListbox() {
+ return TREE_LISTBOX_VALUES.contains(this);
}
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreeSelectable.java Tue Jul 17 08:15:26 2012
@@ -22,6 +22,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+/**
+ * @deprecated since 1.6.0, please use {@link Selectable}
+ */
+@Deprecated
public enum TreeSelectable {
OFF("off"),
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/DataAttributes.java Tue Jul 17 08:15:26 2012
@@ -81,6 +81,11 @@ public final class DataAttributes {
public static final String RELOAD = "data-tobago-reload";
/**
+ * The selectable attribute e. g. for trees.
+ */
+ public static final String SELECTABLE = "data-tobago-selectable";
+
+ /**
* Alternate to the src attribute, to implement a hover effect.
*/
public static final String SRCHOVER = "data-tobago-srchover";
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java Tue Jul 17 08:15:26 2012
@@ -27,6 +27,7 @@ import org.apache.myfaces.tobago.example
import org.apache.myfaces.tobago.example.data.Salutation;
import org.apache.myfaces.tobago.example.data.SolarObject;
import org.apache.myfaces.tobago.model.SelectItem;
+import org.apache.myfaces.tobago.model.Selectable;
import org.apache.myfaces.tobago.model.SheetState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,17 +53,18 @@ public class OverviewController implemen
private static final Logger LOG = LoggerFactory.getLogger(OverviewController.class);
private static final String[] TREE_SELECT_MODE_KEYS = {
- "none",
- "single",
- "singleLeafOnly",
- "multi",
- "multiLeafOnly"
+ Selectable.NONE.getValue(),
+ Selectable.SINGLE.getValue(),
+ Selectable.SINGLE_LEAF_ONLY.getValue(),
+ Selectable.MULTI.getValue(),
+ Selectable.MULTI_LEAF_ONLY.getValue(),
+ Selectable.MULTI_CASCADE.getValue()
};
private static final String[] TREELISTBOX_SELECT_MODE_KEYS = {
- "single",
- "singleLeafOnly",
- "siblingLeafOnly"
+ Selectable.SINGLE.getValue(),
+ Selectable.SINGLE_LEAF_ONLY.getValue(),
+ Selectable.SIBLING_LEAF_ONLY.getValue()
};
private Salutation radioValue;
@@ -106,7 +108,7 @@ public class OverviewController implemen
public OverviewController() {
radioValue = Salutation.UNKNOWN;
singleValue = Salutation.UNKNOWN;
- treeSelectMode = TREE_SELECT_MODE_KEYS[0];
+ treeSelectMode = TREE_SELECT_MODE_KEYS[3];
treeListboxSelectMode = TREELISTBOX_SELECT_MODE_KEYS[0];
multiValue = new Salutation[0];
treeTabsState = 0;
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/01-select/tree-select.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/01-select/tree-select.xhtml?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/01-select/tree-select.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/01-select/tree-select.xhtml Tue Jul 17 08:15:26 2012
@@ -21,13 +21,12 @@
xmlns:tc="http://myfaces.apache.org/tobago/component"
xmlns:tx="http://myfaces.apache.org/tobago/extension"
xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:param name="title" value="#{overviewBundle.tree}"/>
<tc:panel id="panel">
<f:facet name="layout">
- <tc:gridLayout rows="9*;16*"/>
+ <tc:gridLayout rows="100px;*"/>
</f:facet>
<tc:out escape="false" value="(UNDER CONSTRUCTION)"/>
@@ -41,11 +40,12 @@
showRootJunction="#{demo.showRootJunction}"
showRoot="#{demo.showRoot}"
value="#{demo.tree}"
- var="node">
+ var="node"
+ selectable="#{overviewController.treeSelectMode}">
<tc:treeNode id="template">
<tc:treeIndent showJunctions="#{demo.showJunctions}"/>
<tc:treeIcon rendered="#{demo.showIcons}"/>
- <tc:treeSelect showCheckbox="true" value="#{node.userObject.selected}" label="#{node.userObject.name}" />
+ <tc:treeSelect id="select" value="#{node.userObject.selected}" label="#{node.userObject.name}"/>
</tc:treeNode>
</tc:tree>
@@ -54,9 +54,9 @@
<tc:gridLayout rows="auto;auto;auto;auto;1*;auto;auto;auto"/>
</f:facet>
- <tc:selectOneChoice value="#{overviewController.treeSelectMode}"> <!-- TODO: not implemented -->
+ <tc:selectOneRadio value="#{overviewController.treeSelectMode}">
<f:selectItems value="#{overviewController.treeSelectModeItems}"/>
- </tc:selectOneChoice>
+ </tc:selectOneRadio>
<tc:button label="#{overviewBundle.submit}" renderedPartially="panel"/>
</tc:panel>
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/02-editor/tree-editor.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/02-editor/tree-editor.xhtml?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/02-editor/tree-editor.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/03-tree/02-editor/tree-editor.xhtml Tue Jul 17 08:15:26 2012
@@ -44,7 +44,8 @@
showRootJunction="true"
showRoot="true"
value="#{treeEditor.categoryTree}"
- var="node">
+ var="node"
+ selectable="single">
<tc:treeNode id="template"
markup="#{node.userObject.markup}"
tip="#{node.userObject.tip}"
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=1362400&r1=1362399&r2=1362400&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 Tue Jul 17 08:15:26 2012
@@ -23,7 +23,7 @@ import org.apache.myfaces.tobago.context
import org.apache.myfaces.tobago.event.TreeExpansionEvent;
import org.apache.myfaces.tobago.event.TreeMarkedEvent;
import org.apache.myfaces.tobago.internal.component.AbstractUITree;
-import org.apache.myfaces.tobago.model.TreeSelectable;
+import org.apache.myfaces.tobago.model.Selectable;
import org.apache.myfaces.tobago.renderkit.CommandRendererBase;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
@@ -72,7 +72,7 @@ public class TreeListboxNodeRenderer ext
}
// select
- if (tree.getSelectableAsEnum() != TreeSelectable.OFF) { // selection
+ if (tree.getSelectableAsEnum() != Selectable.NONE) { // selection
String selected = (String) requestParameterMap.get(treeId + AbstractUITree.SELECT_STATE);
String searchString = ";" + nodeStateId + ";";
if (StringUtils.contains(selected, searchString)) {
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.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/TreeRenderer.java?rev=1362400&r1=1362399&r2=1362400&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java Tue Jul 17 08:15:26 2012
@@ -20,9 +20,11 @@ package org.apache.myfaces.tobago.render
import org.apache.myfaces.tobago.component.UITreeNode;
import org.apache.myfaces.tobago.internal.component.AbstractUIData;
import org.apache.myfaces.tobago.internal.component.AbstractUITree;
+import org.apache.myfaces.tobago.model.Selectable;
import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
import org.apache.myfaces.tobago.renderkit.css.Classes;
import org.apache.myfaces.tobago.renderkit.css.Style;
+import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
@@ -78,6 +80,11 @@ public class TreeRenderer extends Layout
writer.writeStyleAttribute(style);
writer.writeIdAttribute(clientId);
+ final Selectable selectable = tree.getSelectableAsEnum();
+ if (selectable.isSupportedByTree()) {
+ writer.writeAttribute(DataAttributes.SELECTABLE, selectable.getValue(), false);
+ }
+
writer.startElement(HtmlElements.INPUT, tree);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
final String markedId = clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_MARKED;
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=1362400&r1=1362399&r2=1362400&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 Tue Jul 17 08:15:26 2012
@@ -18,39 +18,84 @@ package org.apache.myfaces.tobago.render
*/
import org.apache.commons.lang.StringUtils;
+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.model.Selectable;
+import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.Classes;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import java.io.IOException;
-public class TreeSelectRenderer extends SelectBooleanCheckboxRenderer {
+public class TreeSelectRenderer extends RendererBase {
+
+ private static final Log LOG = LogFactory.getLog(TreeSelectRenderer.class);
+
+ public void decode(FacesContext facesContext, UIComponent component) {
+
+ final UITreeSelect select = (UITreeSelect) component;
+ final AbstractUIData data = ComponentUtils.findAncestor(select, AbstractUIData.class);
+
+ if (ComponentUtils.isOutputOnly(select)) {
+ return;
+ }
+
+ final String clientId = select.getClientId(facesContext);
+ final String name;
+ if (data.getSelectableAsEnum().isSingle()) {
+ name = getClientIdWithoutRowIndex(data, clientId);
+ } else {
+ name = clientId;
+ }
+
+ final String newValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(name);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("new value = '" + newValue + "'");
+ }
+
+ select.setSubmittedValue(clientId.equals(newValue) ? "true" : "false");
+ }
@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
final UITreeSelect select = (UITreeSelect) component;
+ final AbstractUIData data = ComponentUtils.findAncestor(select, AbstractUIData.class);
final String id = select.getClientId(facesContext);
final String currentValue = getCurrentValue(facesContext, select);
final boolean checked = "true".equals(currentValue);
+ 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));
- if (select.isShowCheckbox()) {
+ if (select.isShowCheckbox()
+ && selectable != Selectable.NONE
+ && (!selectable.isLeafOnly() || !folder)) {
writer.startElement(HtmlElements.INPUT, null);
- writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX, false);
- writer.writeAttribute(HtmlAttributes.VALUE, "true", false);
- writer.writeNameAttribute(id);
+ if (selectable.isSingle()) {
+ writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.RADIO, false);
+ writer.writeNameAttribute(getClientIdWithoutRowIndex(data, id));
+ } else {
+ writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX, false);
+ writer.writeNameAttribute(id);
+ }
+ writer.writeAttribute(HtmlAttributes.VALUE, id, false);
writer.writeIdAttribute(id);
writer.writeAttribute(HtmlAttributes.CHECKED, checked);
writer.endElement(HtmlElements.INPUT);
@@ -70,6 +115,12 @@ public class TreeSelectRenderer extends
writer.endElement(HtmlElements.SPAN);
}
+ private String getClientIdWithoutRowIndex(AbstractUIData data, String id) {
+ return id.replace(
+ "" + NamingContainer.SEPARATOR_CHAR + data.getRowIndex() + NamingContainer.SEPARATOR_CHAR,
+ "" + NamingContainer.SEPARATOR_CHAR);
+ }
+
@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
}
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=1362400&r1=1362399&r2=1362400&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 Tue Jul 17 08:15:26 2012
@@ -62,16 +62,14 @@ Tobago.Tree.toggleNode = function(elemen
* @param node A jQuery-Object as a node of the tree.
*/
Tobago.Tree.hideChildren = function (node) {
- var treeParentSelector = "[data-tobago-treeparent='" + node.attr("id") + "']";
- var children;
- if (node.parent("td").parent("tr").size() == 1) { // tree inside of a sheet
- children = node.parent("td").parent("tr").nextAll().children().children(treeParentSelector);
- children.parent().parent().hide();
- } else { // normal tree
- children = node.nextAll(treeParentSelector);
- children.hide();
- }
- children.each(function () {
+ var inSheet = Tobago.Tree.isInSheet(node);
+ var children = Tobago.Tree.findChildren(node);
+ children.each(function() {
+ if (inSheet) {
+ jQuery(this).parent().parent().hide();
+ } else {
+ jQuery(this).hide();
+ }
Tobago.Tree.hideChildren(jQuery(this));
});
};
@@ -82,21 +80,19 @@ Tobago.Tree.hideChildren = function (nod
* @return is reload needed (to get all nodes from the server)
*/
Tobago.Tree.showChildren = function (node, expanded) {
- var treeParentSelector = "[data-tobago-treeparent='" + node.attr("id") + "']";
- var children;
- if (node.parent("td").parent("tr").size() == 1) { // tree inside of a sheet
- children = node.parent("td").parent("tr").nextAll().children().children(treeParentSelector);
- children.parent().parent().show();
- } else { // normal tree
- children = node.nextAll(treeParentSelector);
- children.show();
- }
+ var inSheet = Tobago.Tree.isInSheet(node);
+ var children = Tobago.Tree.findChildren(node);
if (children.length == 0) {
// no children in DOM, reload it from the server
return true;
}
- children.each(function () {
+ children.each(function() {
var child = jQuery(this);
+ if (inSheet) {
+ child.parent().parent().show();
+ } else {
+ child.show();
+ }
if (Tobago.Tree.isExpanded(child, expanded)) {
var reload = Tobago.Tree.showChildren(child, expanded);
if (reload) {
@@ -211,6 +207,26 @@ Tobago.Tree.init = function(elements) {
});
expanded.attr("value", string);
});
+
+ // init tree selection
+ Tobago.Utils.selectWidthJQuery(elements, ".tobago-tree[data-tobago-selectable=multiCascade]").each(function() {
+ var tree = jQuery(this);
+ tree.find("input[type=checkbox]").each(function() {
+ jQuery(this).change(function(event) {
+ var node = jQuery(event.target).parents(".tobago-treeNode");
+ var checked = node.find("input[type=checkbox]").prop("checked");
+ var children = Tobago.Tree.findChildren(node);
+ children.each(function() {
+ var childsCheckbox = jQuery(this).find("input[type=checkbox]");
+ if (checked != childsCheckbox.prop("checked")) {
+ childsCheckbox.prop("checked", checked);
+ childsCheckbox.change();
+ }
+ });
+ });
+ });
+ });
+
};
Tobago.Tree.isExpanded = function(node, expanded) {
@@ -222,5 +238,20 @@ Tobago.Tree.rowIndex = function (node) {
return node.attr("id").replace(/.+\:(\d+)(\:\w+)+/, '$1');
};
+Tobago.Tree.findChildren = function (node) {
+ var treeParentSelector = "[data-tobago-treeparent='" + node.attr("id") + "']";
+ var children;
+ if (Tobago.Tree.isInSheet(node)) {
+ children = node.parent("td").parent("tr").nextAll().children().children(treeParentSelector);
+ } else { // normal tree
+ children = node.nextAll(treeParentSelector);
+ }
+ return children;
+};
+
+Tobago.Tree.isInSheet = function(node) {
+ return node.parent("td").size() == 1;
+};
+
Tobago.registerListener(Tobago.Tree.init, Tobago.Phase.DOCUMENT_READY);
Tobago.registerListener(Tobago.Tree.init, Tobago.Phase.AFTER_UPDATE);