1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.primefaces.extensions.component.layout;
23
24 import java.io.IOException;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.context.FacesContext;
28 import javax.faces.context.ResponseWriter;
29
30 import org.primefaces.extensions.util.Attrs;
31 import org.primefaces.renderkit.CoreRenderer;
32
33
34
35
36
37
38
39
40 public class LayoutPaneRenderer extends CoreRenderer {
41
42 @Override
43 public void encodeEnd(final FacesContext fc, final UIComponent component) throws IOException {
44 final ResponseWriter writer = fc.getResponseWriter();
45 final LayoutPane layoutPane = (LayoutPane) component;
46
47 final String position = layoutPane.getPosition();
48 final String combinedPosition;
49 UIComponent parent = layoutPane.getParent();
50
51 final StringBuilder combinedPositionBuilder = position == null ? null : new StringBuilder(position);
52 while (parent instanceof LayoutPane) {
53 assert combinedPositionBuilder != null;
54 combinedPositionBuilder.insert(0, ((LayoutPane) parent).getPosition() + Layout.POSITION_SEPARATOR);
55 parent = parent.getParent();
56 }
57 assert combinedPositionBuilder != null;
58 combinedPosition = combinedPositionBuilder.toString();
59
60
61 layoutPane.setCombinedPosition(combinedPosition);
62
63 boolean hasSubPanes = false;
64 for (final UIComponent subChild : layoutPane.getChildren()) {
65
66 if (hasSubPanes) {
67 break;
68 }
69
70 if (subChild instanceof LayoutPane) {
71 if (!subChild.isRendered()) {
72 continue;
73 }
74
75 hasSubPanes = true;
76 }
77 else {
78 for (final UIComponent subSubChild : subChild.getChildren()) {
79
80 if (subSubChild instanceof LayoutPane) {
81 if (!subSubChild.isRendered()) {
82 continue;
83 }
84
85 hasSubPanes = true;
86
87 break;
88 }
89 }
90 }
91 }
92
93 final UIComponent header = layoutPane.getFacet("header");
94
95 writer.startElement("div", null);
96 writer.writeAttribute("id", layoutPane.getClientId(fc), "id");
97 if (hasSubPanes) {
98 writer.writeAttribute(Attrs.CLASS, Layout.STYLE_CLASS + position + " " + Layout.STYLE_CLASS_PANE_WITH_SUBPANES, null);
99 }
100 else {
101 if (header != null) {
102 writer.writeAttribute(Attrs.CLASS, Layout.STYLE_CLASS + position + " " + Layout.STYLE_CLASS_PANE, null);
103 }
104 else {
105 if (layoutPane.getStyleClassContent() != null) {
106 writer.writeAttribute(Attrs.CLASS,
107 Layout.STYLE_CLASS + position + " " + Layout.STYLE_CLASS_PANE + " "
108 + Layout.STYLE_CLASS_PANE_CONTENT + " "
109 + layoutPane.getStyleClassContent(),
110 null);
111 }
112 else {
113 writer.writeAttribute(Attrs.CLASS,
114 Layout.STYLE_CLASS + position + " " + Layout.STYLE_CLASS_PANE + " "
115 + Layout.STYLE_CLASS_PANE_CONTENT,
116 null);
117 }
118
119 if (layoutPane.getStyleContent() != null) {
120 writer.writeAttribute(Attrs.STYLE, layoutPane.getStyleContent(), null);
121 }
122 }
123 }
124
125 writer.writeAttribute("data-combinedposition", combinedPosition, null);
126
127
128 if (header != null) {
129 String headerStyleClass = getStyleClassBuilder(fc)
130 .add(Layout.STYLE_CLASS_PANE_HEADER)
131 .add(layoutPane.getStyleClassHeader())
132 .build();
133 writer.startElement("div", null);
134 writer.writeAttribute(Attrs.CLASS, headerStyleClass, null);
135
136 if (layoutPane.getStyleHeader() != null) {
137 writer.writeAttribute(Attrs.STYLE, layoutPane.getStyleHeader(), null);
138 }
139
140 header.encodeAll(fc);
141
142 writer.endElement("div");
143 }
144
145 String contentStyleClass = getStyleClassBuilder(fc)
146 .add(Layout.STYLE_CLASS_LAYOUT_CONTENT)
147 .add(Layout.STYLE_CLASS_PANE_CONTENT)
148 .add(layoutPane.getStyleClassContent())
149 .build();
150
151
152 if (header != null) {
153 writer.startElement("div", null);
154 writer.writeAttribute(Attrs.CLASS, contentStyleClass, null);
155
156 if (layoutPane.getStyleContent() != null) {
157 writer.writeAttribute(Attrs.STYLE, "border:none; " + layoutPane.getStyleContent(), null);
158 }
159 else {
160 writer.writeAttribute(Attrs.STYLE, "border:none", null);
161 }
162
163 renderChildren(fc, layoutPane);
164
165 writer.endElement("div");
166 }
167 else {
168 renderChildren(fc, layoutPane);
169 }
170
171 writer.endElement("div");
172 }
173
174 @Override
175 public boolean getRendersChildren() {
176 return true;
177 }
178
179 @Override
180 public void encodeChildren(final FacesContext fc, final UIComponent component) {
181
182 }
183 }