001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.panelstack;
035:
036: import com.icesoft.faces.component.util.CustomComponentUtils;
037: import com.icesoft.faces.context.DOMContext;
038: import com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer;
039: import com.icesoft.faces.renderkit.dom_html_basic.HTML;
040: import com.icesoft.faces.renderkit.dom_html_basic.PassThruAttributeRenderer;
041: import com.icesoft.faces.application.D2DViewHandler;
042: import org.w3c.dom.Element;
043:
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import java.io.IOException;
047:
048: public class PanelStackRenderer extends DomBasicRenderer {
049: public boolean getRendersChildren() {
050: return true;
051: }
052:
053: public void encodeChildren(FacesContext facesContext,
054: UIComponent uiComponent) throws IOException {
055: validateParameters(facesContext, uiComponent, PanelStack.class);
056: DOMContext domContext = DOMContext.attachDOMContext(
057: facesContext, uiComponent);
058:
059: if (!domContext.isInitialized()) {
060: Element panelStackTable = domContext
061: .createRootElement(HTML.TABLE_ELEM);
062: setRootElementId(facesContext, panelStackTable, uiComponent);
063: if (PassThruAttributeRenderer
064: .passThruAttributeExists(uiComponent)) {
065: PassThruAttributeRenderer.renderAttributes(
066: facesContext, uiComponent, null);
067: }
068: }
069: Element panelStackTable = (Element) domContext.getRootNode();
070: DOMContext.removeChildren(panelStackTable);
071: panelStackTable.setAttribute(HTML.CLASS_ATTR,
072: ((PanelStack) uiComponent).getStyleClass());
073: String style = ((PanelStack) uiComponent).getStyle();
074: if (style != null && style.length() > 0)
075: panelStackTable.setAttribute(HTML.STYLE_ATTR, style);
076: else
077: panelStackTable.removeAttribute(HTML.STYLE_ATTR);
078: Element tr = domContext.createElement(HTML.TR_ELEM);
079: panelStackTable.appendChild(tr);
080: tr.setAttribute(HTML.CLASS_ATTR, ((PanelStack) uiComponent)
081: .getRowClass());
082: Element td = domContext.createElement(HTML.TD_ELEM);
083: tr.appendChild(td);
084: td.setAttribute(HTML.CLASS_ATTR, ((PanelStack) uiComponent)
085: .getColumnClass());
086: domContext.setCursorParent(td);
087: PanelStack panelStack = (PanelStack) uiComponent;
088: String selectedPanel = panelStack.getSelectedPanel();
089: UIComponent childToRender = null;
090:
091: if (selectedPanel == null) {
092: // render the first child
093: if (panelStack.getChildCount() > 0) {
094: childToRender = (UIComponent) panelStack.getChildren()
095: .get(0);
096: }
097: } else {
098: // render the selected child
099: //childToRender = panelStack.findComponent(selectedPanel);
100: childToRender = D2DViewHandler.findComponent(selectedPanel,
101: panelStack);
102: if (childToRender == null) {
103: // if not found, render the first child
104: if (panelStack.getChildCount() > 0) {
105: childToRender = (UIComponent) panelStack
106: .getChildren().get(0);
107: }
108: }
109: }
110:
111: if (childToRender != null) {
112: domContext.streamWrite(facesContext, uiComponent,
113: domContext.getRootNode(), td);
114: CustomComponentUtils.renderChild(facesContext,
115: childToRender);
116: }
117:
118: domContext.stepOver();
119: domContext.streamWrite(facesContext, uiComponent);
120: facesContext.getExternalContext().getRequestMap().put(
121: PanelStack.LAST_SELECTED_PANEL
122: + uiComponent.getClientId(facesContext),
123: selectedPanel);
124: }
125:
126: }
|