Author: amarkhel
Date: 2010-12-16 05:27:39 -0500 (Thu, 16 Dec 2010)
New Revision: 20603
Added:
trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java
Modified:
trunk/core/api/src/main/java/org/richfaces/renderkit/util/HtmlDimensions.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ToolbarRendererBase.java
trunk/ui/output/ui/src/main/templates/toolbar.template.xml
Log:
RF-9976 Toolbar group: attributes itemStyle and itemClass ignored
- formatSize method was added into HtmlDimensions.
- Markup of Toolbar was changed in order to support particular width for column through
style attribute.
Modified: trunk/core/api/src/main/java/org/richfaces/renderkit/util/HtmlDimensions.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/renderkit/util/HtmlDimensions.java 2010-12-16
10:22:22 UTC (rev 20602)
+++
trunk/core/api/src/main/java/org/richfaces/renderkit/util/HtmlDimensions.java 2010-12-16
10:27:39 UTC (rev 20603)
@@ -87,4 +87,17 @@
return v;
}
+
+ public static String formatSize(String size) {
+ if (size != null) {
+ String incomingSize = size.trim();
+ if (!incomingSize.isEmpty()) {
+ char lastChar = incomingSize.charAt(incomingSize.length() - 1);
+ if (Character.isDigit(lastChar)) {
+ return incomingSize + "px";
+ }
+ }
+ }
+ return size;
+ }
}
Added: trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java
===================================================================
--- trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java
(rev 0)
+++
trunk/core/api/src/test/java/org/richfaces/renderkit/util/HtmlDimensionsTest.java 2010-12-16
10:27:39 UTC (rev 20603)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author amarkhel
+ *
+ */
+public class HtmlDimensionsTest {
+
+ @Test
+ public void testFormatSize() {
+ Assert.assertEquals("100px",
HtmlDimensions.formatSize("100"));
+ Assert.assertEquals("100px", HtmlDimensions.formatSize("100
"));
+ Assert.assertEquals("100px", HtmlDimensions.formatSize("
100"));
+ Assert.assertEquals("100px", HtmlDimensions.formatSize(" 100
"));
+ Assert.assertEquals("t100px",
HtmlDimensions.formatSize("t100"));
+ Assert.assertEquals("r100px", HtmlDimensions.formatSize("r100
"));
+ Assert.assertEquals("100px ", HtmlDimensions.formatSize("100px
"));
+ Assert.assertEquals(" 100px", HtmlDimensions.formatSize("
100px"));
+ Assert.assertEquals(" 100px ", HtmlDimensions.formatSize(" 100px
"));
+ Assert.assertEquals("100px",
HtmlDimensions.formatSize("100px"));
+ Assert.assertEquals("100 px", HtmlDimensions.formatSize("100
px"));
+ Assert.assertEquals("99%",
HtmlDimensions.formatSize("99%"));
+ Assert.assertEquals("99 %", HtmlDimensions.formatSize("99
%"));
+ Assert.assertEquals("100em",
HtmlDimensions.formatSize("100em"));
+ Assert.assertEquals("size",
HtmlDimensions.formatSize("size"));
+ Assert.assertEquals("", HtmlDimensions.formatSize(""));
+ Assert.assertEquals(" ", HtmlDimensions.formatSize("
"));
+ }
+}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ToolbarRendererBase.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ToolbarRendererBase.java 2010-12-16
10:22:22 UTC (rev 20602)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ToolbarRendererBase.java 2010-12-16
10:27:39 UTC (rev 20603)
@@ -40,6 +40,7 @@
import org.richfaces.renderkit.HtmlConstants;
import org.richfaces.renderkit.RenderKitUtils;
import org.richfaces.renderkit.RendererBase;
+import org.richfaces.renderkit.util.HtmlDimensions;
@ResourceDependency(library = "org.richfaces", name =
"toolbar.ecss")
@@ -88,18 +89,93 @@
public enum Locations {
RIGHT, LEFT
}
+
+ private void writeColElement(ResponseWriter writer, UIComponent component) throws
IOException {
+ writer.startElement(HtmlConstants.COL_ELEMENT, component);
+ writer.writeAttribute(HtmlConstants.WIDTH_ATTRIBUTE, "1px", null);
+ writer.endElement(HtmlConstants.COL_ELEMENT);
+ }
+
+ private boolean isSeparatorFacetRendered(UIComponent component) {
+ UIComponent separatorFacet = component.getFacet("itemSeparator");
+ return (separatorFacet != null) ? separatorFacet.isRendered() : false;
+ }
+
+ private boolean isSeparatorAttributeRendered(UIComponent component) {
+ String itemSeparator = (String)
component.getAttributes().get("itemSeparator");
+
+ if (itemSeparator != null && itemSeparator.trim().length() != 0
+ &&
!itemSeparator.equalsIgnoreCase(ItemSeparators.NONE.toString())) {
+ return true;
+ }
+ return false;
+ }
+
+
+ private int getColumnCount(List<UIComponent> components) {
+ int result = 0;
+ for (UIComponent component : components) {
+ if (component instanceof AbstractToolbarGroup) {
+ result += component.getChildren().size();
+ } else {
+ result++;
+ }
+ }
+
+ return result;
+ }
+
+ private int getCountSeparators(AbstractToolbar toolBar, List<UIComponent>
components) {
+ int result = 0;
+ if (components != null && (isSeparatorFacetRendered(toolBar) ||
isSeparatorAttributeRendered(toolBar))) {
+ result += components.size() - 1;
+ }
+
+ for (UIComponent component : components) {
+ if (component instanceof AbstractToolbarGroup) {
+ result += getCountSeparators((AbstractToolbarGroup) component,
component.getChildren());
+ }
+ }
+
+ return result;
+ }
+
+ private int getCountSeparators(AbstractToolbarGroup toolBarGroup,
List<UIComponent> components) {
+ if (components != null && (isSeparatorFacetRendered(toolBarGroup) ||
isSeparatorAttributeRendered(toolBarGroup))) {
+ return components.size() - 1;
+ }
+ return 0;
+ }
+
+ protected void renderColElements(FacesContext context, UIComponent component) throws
IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ List<UIComponent> childrenToTheLeft = new LinkedList<UIComponent>();
+ List<UIComponent> childrenToTheRight = new
LinkedList<UIComponent>();
+
+ getChildrenToLeftAndRight(context, component, childrenToTheLeft,
childrenToTheRight);
+ int columnAmount = getCountSeparators((AbstractToolbar) component,
childrenToTheLeft) +
+ getColumnCount(childrenToTheLeft);
+ for (int i = 0; i < columnAmount; i++) {
+ writeColElement(writer, component);
+ }
+
+ writer.startElement(HtmlConstants.COL_ELEMENT, component);
+ writer.writeAttribute(HtmlConstants.WIDTH_ATTRIBUTE, "*", null);
+ writer.endElement(HtmlConstants.COL_ELEMENT);
+
+ columnAmount = getCountSeparators((AbstractToolbar) component,
childrenToTheRight) +
+ getColumnCount(childrenToTheRight);
+ for (int i = 0; i < columnAmount; i++) {
+ writeColElement(writer, component);
+ }
+ }
- @Override
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ private void getChildrenToLeftAndRight(FacesContext context, UIComponent component,
+ final List<UIComponent> childrenToTheLeft, final List<UIComponent>
childrenToTheRight) {
+
AbstractToolbar toolbar = (AbstractToolbar) component;
- String itemClass = (String) toolbar.getAttributes().get("itemClass");
- String itemStyle = (String) toolbar.getAttributes().get("itemStyle");
-
List<UIComponent> children = toolbar.getChildren();
-
if (children != null) {
- List<UIComponent> childrenToTheLeft = new
LinkedList<UIComponent>();
- List<UIComponent> childrenToTheRight = new
LinkedList<UIComponent>();
for (UIComponent child : children) {
if (child.isRendered()) {
if (child instanceof AbstractToolbarGroup) {
@@ -115,7 +191,23 @@
}
}
}
+ }
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ AbstractToolbar toolbar = (AbstractToolbar) component;
+ String itemClass = (String) toolbar.getAttributes().get("itemClass");
+ String itemStyle = (String) toolbar.getAttributes().get("itemStyle");
+ List<UIComponent> children = toolbar.getChildren();
+
+ if (children != null) {
+ List<UIComponent> childrenToTheLeft = new
LinkedList<UIComponent>();
+ List<UIComponent> childrenToTheRight = new
LinkedList<UIComponent>();
+
+ getChildrenToLeftAndRight(context, component, childrenToTheLeft,
childrenToTheRight);
+
ResponseWriter writer = context.getResponseWriter();
for (Iterator<UIComponent> it = childrenToTheLeft.iterator();
it.hasNext();) {
@@ -135,16 +227,14 @@
if (!(child instanceof AbstractToolbarGroup)) {
writer.endElement(HtmlConstants.TD_ELEM);
}
-
-
-
+
if (it.hasNext()) {
insertSeparatorIfNeed(context, toolbar, writer);
}
}
writer.startElement(HtmlConstants.TD_ELEM, component);
- writer.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, "width:100%",
null);
+ writer.write(" ");
writer.endElement(HtmlConstants.TD_ELEM);
for (Iterator<UIComponent> it = childrenToTheRight.iterator();
it.hasNext();) {
@@ -257,4 +347,20 @@
protected boolean isPropertyRendered(String property) {
return (null != property && !"".equals(property));
}
+
+ protected String getWidthToolbar(UIComponent component) {
+ if (component instanceof AbstractToolbar) {
+ return HtmlDimensions.formatSize(((AbstractToolbar)component).getWidth());
+ } else {
+ return "";
+ }
+ }
+
+ protected String getHeightToolbar(UIComponent component) {
+ if (component instanceof AbstractToolbar) {
+ return HtmlDimensions.formatSize(((AbstractToolbar)component).getHeight());
+ } else {
+ return "";
+ }
+ }
}
Modified: trunk/ui/output/ui/src/main/templates/toolbar.template.xml
===================================================================
--- trunk/ui/output/ui/src/main/templates/toolbar.template.xml 2010-12-16 10:22:22 UTC
(rev 20602)
+++ trunk/ui/output/ui/src/main/templates/toolbar.template.xml 2010-12-16 10:27:39 UTC
(rev 20603)
@@ -14,11 +14,14 @@
</cc:interface>
<cc:implementation>
- <table border="0" cellpadding="0"
cellspacing="0" id="#{clientId}"
width="#{component.attributes['width']}"
- height="#{component.attributes['height']}" class="rf-tb
#{component.attributes['styleClass']}"
- style="#{component.attributes['style']}"
+ <table border="0" cellpadding="0"
cellspacing="0" id="#{clientId}"
+ width="#{getWidthToolbar(component)}"
+ height="#{getHeightToolbar(component)}"
+ class="rf-tb #{component.attributes['styleClass']}"
+ style="#{ component.attributes['style']}"
cdk:passThroughWithExclusions="">
- <cdk:call expression="encodeEventsAttributes(facesContext,
component)" />
+ <cdk:call expression="encodeEventsAttributes(facesContext,
component)" />
+ <cdk:call expression="renderColElements(facesContext,
component)" />
<tr class="rf-tb-cntr">
<cdk:body />
</tr>