Author: sergeyhalipov
Date: 2008-04-02 07:02:30 -0400 (Wed, 02 Apr 2008)
New Revision: 7569
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
branches/3.1.x/ui/toolBar/src/main/config/component/toolBar.xml
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java
Log:
http://jira.jboss.com/jira/browse/RF-2731
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-04-02
09:22:20 UTC (rev 7568)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-04-02
11:02:30 UTC (rev 7569)
@@ -350,7 +350,7 @@
}
public void encodePassThruWithExclusionsArray(FacesContext context,
- UIComponent component, String[] exclusions) throws IOException {
+ UIComponent component, Object[] exclusions) throws IOException {
ResponseWriter writer = context.getResponseWriter();
Map attributes = component.getAttributes();
Arrays.sort(exclusions);
Modified: branches/3.1.x/ui/toolBar/src/main/config/component/toolBar.xml
===================================================================
--- branches/3.1.x/ui/toolBar/src/main/config/component/toolBar.xml 2008-04-02 09:22:20
UTC (rev 7568)
+++ branches/3.1.x/ui/toolBar/src/main/config/component/toolBar.xml 2008-04-02 11:02:30
UTC (rev 7569)
@@ -89,7 +89,58 @@
</property>
&ui_component_attributes;
- &html_style_attributes;
+ &html_style_attributes;
+
+ <property>
+ <name>onitemkeydown</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a key is pressed down on an
item</description>
+ </property>
+ <property>
+ <name>onitemkeypress</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a key is pressed and released on an
item</description>
+ </property>
+ <property>
+ <name>onitemkeyup</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a key is released on an
item</description>
+ </property>
+ <property>
+ <name>onitemclick</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a pointer button is clicked on an
item</description>
+ </property>
+ <property>
+ <name>onitemdblclick</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a pointer button is double-clicked on
an item</description>
+ </property>
+ <property>
+ <name>onitemmousedown</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ </property>
+ <property>
+ <name>onitemmousemove</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a pointer is moved on an
item</description>
+ </property>
+ <property>
+ <name>onitemmouseover</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a pointer is moved onto an
item</description>
+ </property>
+ <property>
+ <name>onitemmouseout</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: a script expression; a pointer is moved away from an
item</description>
+ </property>
+ <property>
+ <name>onitemmouseup</name>
+ <classname>java.lang.String</classname>
+ <description>HTML: script expression; a pointer button is released on an
item</description>
+ </property>
</component>
<component>
Modified:
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java
===================================================================
---
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java 2008-04-02
09:22:20 UTC (rev 7568)
+++
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarGroupRenderer.java 2008-04-02
11:02:30 UTC (rev 7569)
@@ -26,20 +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;
@@ -52,13 +46,24 @@
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();) {
@@ -69,43 +74,16 @@
}
for (Iterator 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");
+ 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("td");
+ writer.endElement(HTML.td_ELEM);
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");
+ insertSeparatorIfNeed(facesContext, toolBarGroup, writer);
}
}
-
+ }
+ }
}
Modified:
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java
===================================================================
---
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java 2008-04-02
09:22:20 UTC (rev 7568)
+++
branches/3.1.x/ui/toolBar/src/main/java/org/richfaces/renderkit/html/ToolBarRendererBase.java 2008-04-02
11:02:30 UTC (rev 7569)
@@ -23,9 +23,12 @@
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 javax.faces.FacesException;
import javax.faces.component.UIComponent;
@@ -33,8 +36,10 @@
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.component.util.ViewUtil;
import org.richfaces.renderkit.html.images.DotSeparatorImage;
import org.richfaces.renderkit.html.images.GridSeparatorImage;
import org.richfaces.renderkit.html.images.LineSeparatorImage;
@@ -42,7 +47,18 @@
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;
@@ -77,13 +93,14 @@
writer.startElement("td", component);
writer.writeAttribute("class", "dr-toolbar-int rich-toolbar-item
" + contentClass, null);
getUtils().writeAttribute(writer, "style", contentStyle);
+ encodeEventsAttributes(facesContext, child, writer);
}
renderChild(facesContext, child);
if (! (child instanceof UIToolBarGroup)) {
writer.endElement("td");
}
if (it.hasNext()) {
- insertSeparatorIfNeed(writer, facesContext, toolBar);
+ insertSeparatorIfNeed(facesContext, toolBar, writer);
}
}
@@ -98,34 +115,70 @@
UIComponent child = (UIComponent) 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 {
+ /**
+ * Inserts separator between toolbar items. Uses facet "itemSeparator" if it
is set
+ * and default separator implementation if facet is not set.
+ * @param context - faces context
+ * @param component - component
+ * @param writer - response writer
+ * @throws IOException - in case of IOException during writing to the ResponseWriter
+ */
+ protected void insertSeparatorIfNeed(FacesContext context, UIComponent component,
ResponseWriter writer) throws IOException {
+ UIComponent separatorFacet = component.getFacet("itemSeparator");
+ boolean isSeparatorFacetRendered = (separatorFacet != null) ?
separatorFacet.isRendered() : false;
+ if (isSeparatorFacetRendered) {
+ writer.startElement(HTML.td_ELEM, component);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-toolbar-separator", null);
+ renderChild(context, separatorFacet);
+ writer.endElement(HTML.td_ELEM);
+ }
+ else {
+ insertDefaultSeparatorIfNeed(context, component, writer);
+ }
+ }
+
+ /**
+ * Inserts default separator. Possible values are:
+ * "square", "disc", "grid", "line" - for
separators provided by component inplementation;
+ * "none" - for no separators between toolbar items;
+ * URI string value - for custom images specified by the page author.
+ *
+ * @param context - faces context
+ * @param component - component
+ * @param writer - response writer
+ * @throws IOException - in case of IOException during writing to the ResponseWriter
+ */
+ protected void insertDefaultSeparatorIfNeed(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);
- } 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");
+ uri = getResource(LineSeparatorImage.class.getName()).getUri(context, component);
+ } else {
+ // let the user specify URI to custom separator image in
"itemSeparator" attribute
+ uri = ViewUtil.getResourceURL(itemSeparator);
+ }
+ 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 +189,42 @@
public boolean getRendersChildren() {
return true;
}
+
+ protected void encodeEventsAttributes(FacesContext facesContext, UIComponent component,
ResponseWriter writer)
+ throws IOException {
+ Map attributes = getParentToolBar(component).getAttributes();
+ Set encodedAttributes = new HashSet();
+
+ 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;
+ }
+ }
+ }
+
}