01: package ru.emdev.EmForge.web.renderer;
02:
03: import java.io.IOException;
04: import java.util.Iterator;
05: import java.util.LinkedList;
06: import java.util.List;
07:
08: import javax.faces.component.UIComponent;
09: import javax.faces.context.FacesContext;
10: import javax.faces.context.ResponseWriter;
11:
12: import org.richfaces.component.UIToolBar;
13: import org.richfaces.component.UIToolBarGroup;
14: import org.richfaces.renderkit.html.ToolBarRenderer;
15:
16: /** This is own implemntation of ToolBar Renderer
17: * It is based on RichFaces renderer - but renders toolbar on whole width avialable
18: */
19: public class EmForgeToolBarRenderer extends ToolBarRenderer {
20:
21: @SuppressWarnings("unchecked")
22: @Override
23: public void encodeChildren(FacesContext facesContext,
24: UIComponent component) throws IOException {
25: UIToolBar toolBar = (UIToolBar) component;
26: List children = toolBar.getChildren();
27: String contentClass = (String) toolBar.getAttributes().get(
28: "contentClass");
29: if (null == contentClass)
30: contentClass = "";
31: String contentStyle = (String) toolBar.getAttributes().get(
32: "contentStyle");
33: if (children != null) {
34: List childrenToTheLeft = new LinkedList();
35: List childrenToTheRight = new LinkedList();
36: for (Iterator iter = children.iterator(); iter.hasNext();) {
37: UIComponent child = (UIComponent) iter.next();
38: if (child.isRendered()) {
39: if (child instanceof UIToolBarGroup) {
40: UIToolBarGroup group = (UIToolBarGroup) child;
41: String location = group.getLocation();
42: if (location != null
43: && location.equals("right")) {
44: childrenToTheRight.add(child);
45: } else {
46: childrenToTheLeft.add(child);
47: }
48: } else {
49: childrenToTheLeft.add(child);
50: }
51: }
52: }
53:
54: ResponseWriter writer = facesContext.getResponseWriter();
55: for (Iterator it = childrenToTheLeft.iterator(); it
56: .hasNext();) {
57: UIComponent child = (UIComponent) it.next();
58: if (!(child instanceof UIToolBarGroup)) {
59: writer.startElement("td", component);
60: writer.writeAttribute("class",
61: "dr-toolbar-int rich-toolbar-item "
62: + contentClass, null);
63: getUtils().writeAttribute(writer, "style",
64: contentStyle);
65: }
66: renderChild(facesContext, child);
67: if (!(child instanceof UIToolBarGroup)) {
68: writer.endElement("td");
69: }
70: if (it.hasNext() || !childrenToTheRight.isEmpty()) {
71: insertSeparatorIfNeed(facesContext, toolBar, writer);
72: }
73: }
74:
75: /* We need to made toolbar wide - to use whole width avialable
76:
77: writer.startElement("td", component);
78: writer.writeAttribute("width", "100%", null);
79: writer.endElement("td");
80: if (!childrenToTheLeft.isEmpty() && !childrenToTheRight.isEmpty()) {
81: insertSeparatorIfNeed(writer, facesContext, toolBar);
82: }
83: */
84:
85: for (Iterator it = childrenToTheRight.iterator(); it
86: .hasNext();) {
87: UIComponent child = (UIComponent) it.next();
88: renderChild(facesContext, child);
89: if (it.hasNext()) {
90: insertSeparatorIfNeed(facesContext, toolBar, writer);
91: }
92: }
93: }
94: }
95: }
|