Author: sergeyhalipov
Date: 2008-03-13 10:01:15 -0400 (Thu, 13 Mar 2008)
New Revision: 6780
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
trunk/ui/toolBar/src/main/config/component/toolBar.xml
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java
Log:
http://jira.jboss.com/jira/browse/RF-1605
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-03-13
13:44:43 UTC (rev 6779)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-03-13
14:01:15 UTC (rev 6780)
@@ -352,7 +352,7 @@
}
public void encodePassThruWithExclusionsArray(FacesContext context,
- UIComponent component, String[] exclusions) throws IOException {
+ UIComponent component, Object[] exclusions) throws IOException {
ResponseWriter writer = context.getResponseWriter();
Map<String, Object> attributes = component.getAttributes();
Arrays.sort(exclusions);
Modified: trunk/ui/toolBar/src/main/config/component/toolBar.xml
===================================================================
--- trunk/ui/toolBar/src/main/config/component/toolBar.xml 2008-03-13 13:44:43 UTC (rev
6779)
+++ trunk/ui/toolBar/src/main/config/component/toolBar.xml 2008-03-13 14:01:15 UTC (rev
6780)
@@ -90,7 +90,58 @@
</property>
&ui_component_attributes;
- &html_style_attributes;
+ &html_style_attributes;
+
+ <property>
+ <name>onitemkeydown</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemkeypress</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemkeyup</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemclick</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemdblclick</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemmousedown</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemmousemove</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemmouseover</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemmouseout</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemmouseup</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
</component>
<component>
Modified:
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java
===================================================================
---
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java 2008-03-13
13:44:43 UTC (rev 6779)
+++
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java 2008-03-13
14:01:15 UTC (rev 6780)
@@ -26,19 +26,14 @@
import java.util.Iterator;
import java.util.List;
-import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIToolBarGroup;
-import org.richfaces.renderkit.html.images.DotSeparatorImage;
-import org.richfaces.renderkit.html.images.GridSeparatorImage;
-import org.richfaces.renderkit.html.images.LineSeparatorImage;
-import org.richfaces.renderkit.html.images.SquareSeparatorImage;
-public class ToolBarGroupRenderer extends RendererBase {
+public class ToolBarGroupRenderer extends ToolBarRendererBase {
protected Class getComponentClass() {
return UIToolBarGroup.class;
@@ -51,60 +46,44 @@
public void encodeChildren(FacesContext facesContext, UIComponent component) throws
IOException {
UIToolBarGroup toolBarGroup = (UIToolBarGroup) component;
ResponseWriter writer = facesContext.getResponseWriter();
- String style = (String) toolBarGroup.getAttributes().get("style");
- String styleClass = (String) toolBarGroup.getAttributes().get("styleClass");
- if (null == styleClass) styleClass = "";
- String contentClass = (String)
toolBarGroup.getToolBar().getAttributes().get("contentClass");
- if (null == contentClass) contentClass = "";
- String contentStyle = (String)
toolBarGroup.getToolBar().getAttributes().get("contentStyle");
+ String styleClass = (String) toolBarGroup.getAttributes().get(HTML.STYLE_CLASS_ATTR);
+ String contentClass = (String)
getParentToolBar(component).getAttributes().get("contentClass");
+ String style = (String) toolBarGroup.getAttributes().get(HTML.style_ATTRIBUTE);
+ String contentStyle = (String)
getParentToolBar(component).getAttributes().get("contentStyle");
+ if (null == contentClass) {
+ contentClass = "";
+ }
+ if (null == styleClass) {
+ styleClass = "";
+ }
+ if (null == contentStyle) {
+ contentStyle = "";
+ }
+ if (null == style) {
+ style = "";
+ }
+
if (component.getChildCount() > 0) {
- List children = component.getChildren();
- for (Iterator iter = children.iterator(); iter.hasNext();) {
+ List<UIComponent> children = component.getChildren();
+ for (Iterator<UIComponent> iter = children.iterator(); iter.hasNext();) {
UIComponent child = (UIComponent) iter.next();
if(!child.isRendered()){
iter.remove();
}
}
- for (Iterator it = children.iterator(); it.hasNext();) {
+ for (Iterator<UIComponent> it = children.iterator(); it.hasNext();) {
UIComponent child = (UIComponent) it.next();
- writer.startElement("td", component);
- writer.writeAttribute("class", "dr-toolbar-int rich-toolbar-item
" + contentClass +" "+styleClass, null);
- getUtils().writeAttribute(writer, "style", contentStyle);
- getUtils().writeAttribute(writer, "style", style);
- getUtils().encodePassThruWithExclusions(facesContext, component,
"style,class");
- renderChild(facesContext, child);
- writer.endElement("td");
- if (it.hasNext()) {
- insertSeparatorIfNeed(writer, facesContext, toolBarGroup);
- }
-
- }
- }
- }
-
- protected void insertSeparatorIfNeed(ResponseWriter writer,FacesContext context,
UIToolBarGroup toolBarGroup) throws IOException {
- String itemSeparator = toolBarGroup.getItemSeparator();
- if (itemSeparator != null && itemSeparator.length()!=0 && !
itemSeparator.equalsIgnoreCase("none")){
- String uri = null;
- if (itemSeparator.equalsIgnoreCase("square")) {
- uri = getResource(SquareSeparatorImage.class.getName()).getUri(context, null);
- } else if (itemSeparator.equalsIgnoreCase("disc")) {
- uri = getResource(DotSeparatorImage.class.getName()).getUri(context, null);
- } else if (itemSeparator.equalsIgnoreCase("grid")) {
- uri = getResource(GridSeparatorImage.class.getName()).getUri(context,
toolBarGroup);
- } else if (itemSeparator.equalsIgnoreCase("line")) {
- uri = getResource(LineSeparatorImage.class.getName()).getUri(context,
toolBarGroup);
- } else throw new FacesException("Unknown type of separator -
\""+itemSeparator+"\"");
- writer.startElement("td", toolBarGroup);
- getUtils().writeAttribute(writer, "class",
toolBarGroup.getAttributes().get("separatorClass"));
- writer.writeAttribute("align", "center", null);
- writer.startElement("img", toolBarGroup);
- getUtils().writeAttribute(writer, "src", uri);
- getUtils().writeAttribute(writer, "alt", "");
- writer.endElement("img");
- writer.endElement("td");
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "dr-toolbar-int rich-toolbar-item
" + contentClass + " " + styleClass, null);
+ getUtils().writeAttribute(writer, HTML.style_ATTRIBUTE, contentStyle + ";"
+ style);
+ encodeEventsAttributes(facesContext, toolBarGroup, writer);
+ renderChild(facesContext, child);
+ writer.endElement(HTML.td_ELEM);
+ if (it.hasNext()) {
+ insertSeparatorIfNeed(facesContext, toolBarGroup, writer);
}
}
-
+ }
+ }
}
Modified:
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java
===================================================================
---
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java 2008-03-13
13:44:43 UTC (rev 6779)
+++
trunk/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java 2008-03-13
14:01:15 UTC (rev 6780)
@@ -23,9 +23,13 @@
import java.io.IOException;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
@@ -33,6 +37,7 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIToolBar;
import org.richfaces.component.UIToolBarGroup;
import org.richfaces.renderkit.html.images.DotSeparatorImage;
@@ -42,19 +47,37 @@
public class ToolBarRendererBase extends HeaderResourcesRendererBase {
-
+ private final static String[] ON_ITEM_EVENTS = new String[] {
+ "onitemkeydown",
+ "onitemkeypress",
+ "onitemkeyup",
+ "onitemclick",
+ "onitemdblclick",
+ "onitemmousedown",
+ "onitemmousemove",
+ "onitemmouseover",
+ "onitemmouseout",
+ "onitemmouseup"
+ };
public void encodeChildren(FacesContext facesContext, UIComponent component) throws
IOException {
UIToolBar toolBar = (UIToolBar) component;
- List children = toolBar.getChildren();
+ List<UIComponent> children = toolBar.getChildren();
String contentClass = (String) toolBar.getAttributes().get("contentClass");
- if (null == contentClass) contentClass = "";
String contentStyle = (String) toolBar.getAttributes().get("contentStyle");
- if(children != null){
- List childrenToTheLeft = new LinkedList();
- List childrenToTheRight = new LinkedList();
- for (Iterator iter = children.iterator(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
+
+ if (null == contentClass) {
+ contentClass = "";
+ }
+ if (null == contentStyle) {
+ contentClass = "";
+ }
+
+ if (children != null) {
+ List<UIComponent> childrenToTheLeft = new LinkedList<UIComponent>();
+ List<UIComponent> childrenToTheRight = new LinkedList<UIComponent>();
+ for (Iterator<UIComponent> iter = children.iterator(); iter.hasNext();) {
+ UIComponent child = iter.next();
if(child.isRendered()){
if (child instanceof UIToolBarGroup) {
UIToolBarGroup group = (UIToolBarGroup) child;
@@ -71,61 +94,59 @@
}
ResponseWriter writer = facesContext.getResponseWriter();
- for (Iterator it = childrenToTheLeft.iterator(); it.hasNext();) {
- UIComponent child = (UIComponent) it.next();
+ for (Iterator<UIComponent> it = childrenToTheLeft.iterator(); it.hasNext();)
{
+ UIComponent child = it.next();
if (! (child instanceof UIToolBarGroup)) {
- writer.startElement("td", component);
- writer.writeAttribute("class", "dr-toolbar-int rich-toolbar-item
" + contentClass, null);
- getUtils().writeAttribute(writer, "style", contentStyle);
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "dr-toolbar-int rich-toolbar-item
" + contentClass, null);
+ getUtils().writeAttribute(writer, HTML.style_ATTRIBUTE, contentStyle);
+ encodeEventsAttributes(facesContext, child, writer);
}
renderChild(facesContext, child);
if (! (child instanceof UIToolBarGroup)) {
- writer.endElement("td");
+ writer.endElement(HTML.td_ELEM);
}
if (it.hasNext()) {
- insertSeparatorIfNeed(writer, facesContext, toolBar);
+ insertSeparatorIfNeed(facesContext, toolBar, writer);
}
}
- writer.startElement("td", component);
- writer.writeAttribute("width", "100%", null);
- writer.endElement("td");
-// if (!childrenToTheLeft.isEmpty() && !childrenToTheRight.isEmpty()) {
-// insertSeparatorIfNeed(writer, facesContext, toolBar);
-// }
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeAttribute(HTML.width_ATTRIBUTE, "100%", null);
+ writer.endElement(HTML.td_ELEM);
- for (Iterator it = childrenToTheRight.iterator(); it.hasNext();) {
- UIComponent child = (UIComponent) it.next();
+ for (Iterator<UIComponent> it = childrenToTheRight.iterator(); it.hasNext();) {
+ UIComponent child = it.next();
renderChild(facesContext, child);
if (it.hasNext()) {
- insertSeparatorIfNeed(writer, facesContext, toolBar);
+ insertSeparatorIfNeed(facesContext, toolBar, writer);
}
}
}
}
- protected void insertSeparatorIfNeed(ResponseWriter writer,FacesContext context,
UIToolBar toolBar) throws IOException {
+ protected void insertSeparatorIfNeed(FacesContext context, UIComponent component,
ResponseWriter writer) throws IOException {
- String itemSeparator = toolBar.getItemSeparator();
+ String itemSeparator =
(String)component.getAttributes().get("itemSeparator");
if (itemSeparator != null && itemSeparator.length()!=0 && !
itemSeparator.equalsIgnoreCase("none")){
String uri = null;
if (itemSeparator.equalsIgnoreCase("square")) {
- uri = getResource(SquareSeparatorImage.class.getName()).getUri(context, null);
+ uri = getResource(SquareSeparatorImage.class.getName()).getUri(context, component);
} else if (itemSeparator.equalsIgnoreCase("disc")) {
- uri = getResource(DotSeparatorImage.class.getName()).getUri(context, null);
+ uri = getResource(DotSeparatorImage.class.getName()).getUri(context, component);
} else if (itemSeparator.equalsIgnoreCase("grid")) {
- uri = getResource(GridSeparatorImage.class.getName()).getUri(context, toolBar);
+ uri = getResource(GridSeparatorImage.class.getName()).getUri(context,
component);
} else if (itemSeparator.equalsIgnoreCase("line")) {
- uri = getResource(LineSeparatorImage.class.getName()).getUri(context, toolBar);
+ uri = getResource(LineSeparatorImage.class.getName()).getUri(context, component);
} else throw new FacesException("Unknown type of separator -
\""+itemSeparator+"\"");
- writer.startElement("td", toolBar);
- writer.writeAttribute("align", "center", null);
- getUtils().writeAttribute(writer, "class",
toolBar.getAttributes().get("separatorClass"));
- writer.startElement("img", toolBar);
- getUtils().writeAttribute(writer, "src", uri);
- getUtils().writeAttribute(writer, "alt", "");
- writer.endElement("img");
- writer.endElement("td");
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeAttribute(HTML.align_ATTRIBUTE, "center", null);
+ getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE,
component.getAttributes().get("separatorClass"));
+ writer.startElement(HTML.IMG_ELEMENT, component);
+ getUtils().writeAttribute(writer, HTML.src_ATTRIBUTE, uri);
+ getUtils().writeAttribute(writer, HTML.alt_ATTRIBUTE, "");
+ writer.endElement(HTML.IMG_ELEMENT);
+ writer.endElement(HTML.td_ELEM);
}
}
@@ -136,5 +157,42 @@
public boolean getRendersChildren() {
return true;
}
+
+ protected void encodeEventsAttributes(FacesContext facesContext, UIComponent component,
ResponseWriter writer)
+ throws IOException {
+ Map<String, Object> attributes = getParentToolBar(component).getAttributes();
+ Set<String> encodedAttributes = new HashSet<String>();
+
+ for (int i = 0; i < ON_ITEM_EVENTS.length; i++) {
+ Object value = attributes.get(ON_ITEM_EVENTS[i]);
+ if (null != value && !"".equals(value)) {
+ String eventName = ON_ITEM_EVENTS[i].replace("item", "");
+ encodedAttributes.add(eventName);
+ Object selfEvent = component.getAttributes().get(eventName);
+ if (null == selfEvent) {
+ selfEvent = "";
+ }
+ writer.writeAttribute(eventName, selfEvent + ";" + value, null);
+ }
+ }
+ encodedAttributes.add(HTML.class_ATTRIBUTE);
+ encodedAttributes.add(HTML.style_ATTRIBUTE);
+ getUtils().encodePassThruWithExclusionsArray(facesContext, component,
encodedAttributes.toArray());
+ }
+ public UIToolBar getParentToolBar(UIComponent component) {
+ if (component instanceof UIToolBar) {
+ return (UIToolBar) component;
+ } else if (component instanceof UIToolBarGroup) {
+ return ((UIToolBarGroup)component).getToolBar();
+ } else {
+ UIComponent parent = component.getParent();
+ if (!(parent instanceof UIToolBar)) {
+ return null;
+ } else {
+ return (UIToolBar) parent;
+ }
+ }
+ }
+
}