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 2010/08/16 15:20:09 UTC
svn commit: r985916 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/c...
Author: lofwyr
Date: Mon Aug 16 13:20:09 2010
New Revision: 985916
URL: http://svn.apache.org/viewvc?rev=985916&view=rev
Log:
TOBAGO-377: new tree
- adding tc:treeSelect tag for tree selection
Added:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java
- copied, changed from r985788, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIndent.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeSelectTagDeclaration.java
- copied, changed from r985788, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeIndentTagDeclaration.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java
- copied, changed from r985788, myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeIndentRenderer.java
Removed:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/TreeUtils.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Node.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-select.jsp
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java?rev=985916&r1=985915&r2=985916&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java Mon Aug 16 13:20:09 2010
@@ -84,6 +84,7 @@ public final class RendererTypes {
public static final String TREE_MENU_LABEL = "TreeMenuLabel";
public static final String TREE_MENU_NODE = "TreeMenuNode";
public static final String TREE_NODE = "TreeNode";
+ public static final String TREE_SELECT = "TreeSelect";
public static final String SHEET = "Sheet";
public static final String WIZARD = "Wizard";
Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java (from r985788, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIndent.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIndent.java&r1=985788&r2=985916&rev=985916&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIndent.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java Mon Aug 16 13:20:09 2010
@@ -19,7 +19,13 @@ package org.apache.myfaces.tobago.intern
import org.apache.myfaces.tobago.config.Configurable;
-import javax.faces.component.UIGraphic;
+import javax.faces.component.UISelectBoolean;
+import javax.faces.context.FacesContext;
-public abstract class AbstractUIIndent extends UIGraphic implements Configurable {
+public abstract class AbstractUITreeSelect extends UISelectBoolean implements Configurable {
+
+ @Override
+ public void updateModel(FacesContext context) {
+ super.updateModel(context);
+ }
}
Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeSelectTagDeclaration.java (from r985788, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeIndentTagDeclaration.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeSelectTagDeclaration.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeSelectTagDeclaration.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeIndentTagDeclaration.java&r1=985788&r2=985916&rev=985916&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeIndentTagDeclaration.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TreeSelectTagDeclaration.java Mon Aug 16 13:20:09 2010
@@ -22,26 +22,28 @@ import org.apache.myfaces.tobago.apt.ann
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasBooleanValue;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasMarkup;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasTip;
/**
- * Renders an indent beside a tree node.
+ * Makes a tree node selectable.
*/
-@Tag(name = "treeIndent")
+@Tag(name = "treeSelect")
@UIComponentTag(
- uiComponent = "org.apache.myfaces.tobago.component.UITreeIndent",
- uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUIIndent",
- rendererType = RendererTypes.TREE_INDENT,
+ uiComponent = "org.apache.myfaces.tobago.component.UITreeSelect",
+ uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUITreeSelect",
+ rendererType = RendererTypes.TREE_SELECT,
allowedChildComponenents = "NONE")
-public interface TreeIndentTagDeclaration
- extends HasIdBindingAndRendered, HasTip, HasMarkup {
+public interface TreeSelectTagDeclaration
+ extends HasIdBindingAndRendered, HasLabel, HasTip, HasMarkup, HasBooleanValue {
/**
- * Show the lines and icons which are defining the tree structure.
+ * Show a checkbox to visualize the selection state.
*/
@TagAttribute
- @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
- void setShowJunctions(String showJunctions);
+ @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
+ void setShowCheckbox(String showCheckbox);
}
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Node.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Node.java?rev=985916&r1=985915&r2=985916&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Node.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Node.java Mon Aug 16 13:20:09 2010
@@ -17,9 +17,9 @@ package org.apache.myfaces.tobago.exampl
* limitations under the License.
*/
+import org.apache.myfaces.tobago.event.TreeExpansionEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.myfaces.tobago.event.TreeExpansionEvent;
public class Node {
@@ -29,6 +29,7 @@ public class Node {
private String markup;
private boolean expanded;
private boolean disabled;
+ private boolean selected;
public Node(String name) {
this.name = name;
@@ -90,6 +91,14 @@ public class Node {
this.disabled = disabled;
}
+ public boolean isSelected() {
+ return selected;
+ }
+
+ public void setSelected(boolean selected) {
+ this.selected = selected;
+ }
+
@Override
public String toString() {
return "Node{" + "name='" + name + '\'' + '}';
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-select.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-select.jsp?rev=985916&r1=985915&r2=985916&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-select.jsp (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/tree/tree-select.jsp Mon Aug 16 13:20:09 2010
@@ -21,30 +21,20 @@
<f:view>
<tc:loadBundle basename="demo" var="bundle"/>
- <tc:page label="Sandbox - Tree" id="page"
- width="500px" height="800px">
+ <tc:page label="Tree" id="page" width="500px" height="1000px">
<f:facet name="layout">
- <tc:gridLayout margin="10px" rows="300px;*"/>
+ <tc:gridLayout margin="10px" rows="*;*"/>
</f:facet>
- <tc:tree id="sel"
- showRootJunction="true"
- showRoot="true"
- selectable="single">
- <tc:treeNode label="Root">
- <tc:treeData value="#{treeController.tree}" var="node">
- <tc:treeNode label="#{node.userObject.name}"
- markup="#{node.userObject.markup}"
- tip="#{node.userObject.tip}"/>
- </tc:treeData>
- <tc:treeNode label="Sub 1"/>
- <tc:treeNode label="Sub 2"/>
- <tc:treeNode label="Sub 3">
- <tc:treeNode label="Sub 3.1"/>
- <tc:treeNode label="Sub 3.2"/>
+ <tc:tree>
+ <tc:treeData value="#{treeController.tree}" var="node" id="data">
+ <tc:treeNode id="template" expanded="true">
+ <tc:treeIndent/>
+ <tc:treeIcon/>
+ <tc:treeSelect value="#{node.userObject.selected}"/>
+ <tc:treeCommand label="#{node.userObject.name}" action="#{node.userObject.action}"/>
</tc:treeNode>
- <tc:treeNode label="Sub 4" tip="Subnode Number 4"/>
- </tc:treeNode>
+ </tc:treeData>
</tc:tree>
<tc:cell/>
Copied: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java (from r985788, myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeIndentRenderer.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?p2=myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java&p1=myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeIndentRenderer.java&r1=985788&r2=985916&rev=985916&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeIndentRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java Mon Aug 16 13:20:09 2010
@@ -17,120 +17,40 @@ package org.apache.myfaces.tobago.render
* limitations under the License.
*/
-import org.apache.myfaces.tobago.component.UITree;
-import org.apache.myfaces.tobago.component.UITreeIndent;
-import org.apache.myfaces.tobago.component.UITreeNode;
-import org.apache.myfaces.tobago.context.Markup;
-import org.apache.myfaces.tobago.context.ResourceManagerUtils;
-import org.apache.myfaces.tobago.internal.component.AbstractUITree;
-import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
-import org.apache.myfaces.tobago.renderkit.css.Classes;
+import org.apache.myfaces.tobago.component.UITreeSelect;
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.UIComponent;
import javax.faces.context.FacesContext;
import java.io.IOException;
-import java.util.List;
-public class TreeIndentRenderer extends LayoutComponentRendererBase {
+public class TreeSelectRenderer extends SelectBooleanCheckboxRenderer {
@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
- final UITreeIndent indent = (UITreeIndent) component;
- final UITreeNode node = ComponentUtils.findAncestor(indent, UITreeNode.class);
- final AbstractUITree tree = ComponentUtils.findAncestor(indent, AbstractUITree.class);
-
- final boolean folder = node.isFolder();
- final int level = node.getLevel();
- final boolean hasNextSibling = node.isHasNextSibling();
- final List<Boolean> junctions = node.getJunctions();
-
- final boolean showRoot = ((UITree) tree).isShowRoot(); //XXX
- final boolean showJunctions = indent.isShowJunctions();
- final boolean showRootJunction = ((UITree) tree).isShowRootJunction(); //XXX
- final boolean expanded = node.isExpanded() || !showRoot && level == 0;
+ final UITreeSelect select = (UITreeSelect) component;
- TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
-
- encodeIndent(facesContext, writer, node, showJunctions, junctions);
-
- encodeTreeJunction(facesContext, writer, node, showJunctions, showRootJunction, showRoot, expanded,
- folder, level, hasNextSibling);
- }
+ final String id = select.getClientId(facesContext);
+ final String currentValue = getCurrentValue(facesContext, select);
+ final boolean checked = "true".equals(currentValue);
- private void encodeIndent(
- final FacesContext facesContext, final TobagoResponseWriter writer, final UITreeNode node,
- final boolean showJunctions, final List<Boolean> junctions)
- throws IOException {
-
- final String blank = ResourceManagerUtils.getImageWithPath(facesContext, "image/blank.gif");
- final String perpendicular = ResourceManagerUtils.getImageWithPath(facesContext, "image/I.gif");
-
- for (Boolean junction : junctions) {
- writer.startElement(HtmlElements.IMG, null);
- writer.writeClassAttribute(Classes.create(node, "junction"));
- writer.writeAttribute(HtmlAttributes.ALT, "", false);
- if (junction && showJunctions) {
- writer.writeAttribute("src", perpendicular, true);
- } else {
- writer.writeAttribute("src", blank, true);
- }
- writer.endElement(HtmlElements.IMG);
- }
+ TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+
+ writer.startElement(HtmlElements.INPUT, null);
+ writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.CHECKBOX, false);
+ writer.writeAttribute(HtmlAttributes.VALUE, "true", false);
+ writer.writeNameAttribute(id);
+ writer.writeIdAttribute(id);
+ writer.writeAttribute(HtmlAttributes.CHECKED, checked);
+ writer.endElement(HtmlElements.INPUT);
}
- private void encodeTreeJunction(
- FacesContext facesContext, TobagoResponseWriter writer, UITreeNode node,
- boolean showJunctions, boolean showRootJunction, boolean showRoot, boolean expanded, boolean folder,
- int level, boolean hasNextSibling)
- throws IOException {
- if (!(!showJunctions
- || !showRootJunction && level == 0
- || !showRootJunction && !showRoot && level == 1)) {
- writer.startElement(HtmlElements.IMG, null);
- writer.writeClassAttribute(Classes.create(node, "toggle", Markup.NULL));
-
- final String open;
- final String close;
- if (level == 0) {
- open = "Rminus.gif";
- close = "Rplus.gif";
- } else {
- if (hasNextSibling) {
- if (folder) {
- open = "Tminus.gif";
- close = "Tplus.gif";
- } else {
- open = "T.gif";
- close = "T.gif";
- }
- } else {
- if (folder) {
- open = "Lminus.gif";
- close = "Lplus.gif";
- } else {
- open = "L.gif";
- close = "L.gif";
- }
- }
- }
-
- final String srcOpen = ResourceManagerUtils.getImageWithPath(facesContext, "image/" + open);
- final String srcClose = ResourceManagerUtils.getImageWithPath(facesContext, "image/" + close);
- final String src = expanded ? srcOpen : srcClose;
- writer.writeAttribute(HtmlAttributes.SRC, src, true);
- if (folder) {
- writer.writeAttribute(HtmlAttributes.SRCOPEN, srcOpen, true);
- writer.writeAttribute(HtmlAttributes.SRCCLOSE, srcClose, true);
- }
- writer.writeAttribute(HtmlAttributes.ALT, "", false);
- writer.endElement(HtmlElements.IMG);
- }
+ @Override
+ public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
}
-
}