Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright ${year}, Red Hat, Inc. and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.richfaces.renderkit.html;
 
 import static org.richfaces.renderkit.HtmlConstants.CLASS_ATTRIBUTE;
 import static org.richfaces.renderkit.HtmlConstants.DIV_ELEM;
 import static org.richfaces.renderkit.HtmlConstants.ID_ATTRIBUTE;
 import static org.richfaces.renderkit.HtmlConstants.STYLE_ATTRIBUTE;
 
 import java.util.Map;
 
 import  javax.faces.application.ResourceDependencies;
 import  javax.faces.application.ResourceDependency;
 import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.context.ResponseWriter;
 
 import  org.ajax4jsf.javascript.JSObject;

Author(s):
akolonitsky
Since:
2010-08-27
 
 @ResourceDependencies({ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
         @ResourceDependency(name = "jquery.js"),
         @ResourceDependency(name = "richfaces.js"),
         @ResourceDependency(library = "org.richfaces", name = "richfaces-queue.reslib"),
         @ResourceDependency(name = "richfaces-base-component.js"),
         @ResourceDependency(name = "richfaces-event.js"),
         @ResourceDependency(library = "org.richfaces", name = "togglePanel.js"),
         @ResourceDependency(library = "org.richfaces", name = "togglePanelItem.js"),
         @ResourceDependency(library = "org.richfaces", name = "collapsiblePanel.js"),
         @ResourceDependency(library = "org.richfaces", name = "collapsiblePanelItem.js"),
         @ResourceDependency(library = "org.richfaces", name = "icons.ecss"),
         @ResourceDependency(library = "org.richfaces", name = "collapsiblePanel.ecss") })
 @JsfRenderer(type = "org.richfaces.CollapsiblePanelRenderer", family = .)
 public class CollapsiblePanelRenderer extends TogglePanelRenderer {
     public static final String SWITCH = "switch";
     public static final String BEFORE_SWITCH = "beforeswitch";
         "header""rf-cp") {
         protected void encodeHeaderLeftIcon(ResponseWriter writer, FacesContext contextAbstractCollapsiblePanel panel)
             throws IOException {
             String leftCollapsedIcon = panel.getLeftCollapsedIcon();
             if (leftCollapsedIcon == null || leftCollapsedIcon.trim().length() == 0) {
                 leftCollapsedIcon = ..toString();
             }
             String leftExpandedIcon = panel.getLeftExpandedIcon();
             if (leftExpandedIcon == null || leftExpandedIcon.trim().length() == 0) {
                 leftExpandedIcon = ..toString();
             }
 
             encodeTdIcon(writercontext + "-ico"leftCollapsedIconleftExpandedIcon..);
         }
 
         protected void encodeHeaderRightIcon(ResponseWriter writer, FacesContext contextAbstractCollapsiblePanel panel)
             throws IOException {
             // TODO nick - should this be "-ico-exp"? also why expanded icon state is connected with right icon alignment?
             encodeTdIcon(writercontext + "-exp-ico"panel.getRightCollapsedIcon(),
                 panel.getRightExpandedIcon(), ..);
         }
 
         @Override
         protected void encodeHeaderTextValue(ResponseWriter writer, FacesContext contextAbstractCollapsiblePanel component)
             throws IOException {
             writer.startElement(DIV_ELEM, null);
             writer.writeAttribute(CLASS_ATTRIBUTE,  + "-lbl-exp"null);
             writeFacetOrAttr(writercontextcomponent + "Expanded");
             writer.endElement(DIV_ELEM);
 
             writer.startElement(DIV_ELEM, null);
             writer.writeAttribute(CLASS_ATTRIBUTE,  + "-lbl-colps"null);
             writeFacetOrAttr(writercontextcomponent + "Collapsed");
             writer.endElement(DIV_ELEM);
        }
    };
    @Override
    protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
        super.doEncodeBegin(writercontextcomponent);
        encodeHeader(writercontext, (AbstractCollapsiblePanelcomponent);
    }
    @Override
    protected String getStyleClass(UIComponent component) {
        return concatClasses("rf-cp"super.getStyleClass(component));
    }
    @Override
    protected JSObject getScriptObject(FacesContext context, UIComponent component) {
        return new JSObject("RichFaces.ui.CollapsiblePanel"component.getClientId(context), getScriptObjectOptions(context,
            component));
    }
    @Override
    protected Map<StringObjectgetScriptObjectOptions(FacesContext context, UIComponent component) {
        AbstractTogglePanel panel = (AbstractTogglePanelcomponent;
        Map<StringObjectoptions = new HashMap<StringObject>();
        options.put("activeItem"panel.getActiveItem());
        options.put("ajax"getAjaxOptions(contextpanel));
        options.put("switchMode"panel.getSwitchType());
        TogglePanelRenderer.addEventOption(contextpaneloptions);
        TogglePanelRenderer.addEventOption(contextpaneloptions);
        return options;
    }
    private void encodeHeader(ResponseWriter writer, FacesContext contextAbstractCollapsiblePanel component)
        throws IOException {
        writer.startElement(DIV_ELEM, null);
        writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) + ":header"null);
        writer.writeAttribute(
            CLASS_ATTRIBUTE,
            concatClasses("rf-cp-hdr""rf-cp-hdr-" + (component.isExpanded() ? "exp" : "colps"),
                attributeAsString(component"headerClass")), null);
        .encodeHeader(writercontextcomponent);
        writer.endElement(DIV_ELEM);
    }
    @Override
    protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent componentthrows IOException {
        AbstractCollapsiblePanel panel = (AbstractCollapsiblePanelcomponent;
        encodeContentChild(writercontextcomponentpanel);
        encodeEmptyChild(writercontextcomponentpanel);
    }
    private void encodeContentChild(ResponseWriter writer, FacesContext context, UIComponent component,
        AbstractCollapsiblePanel panelthrows IOException {
        if (panel.isExpanded()) {
            encodeContent(writercontextcomponenttrue);
        } else {
            switch (panel.getSwitchType()) {
                case :
                    encodeContent(writercontextcomponentfalse);
                    break;
                case :
                    context.getResponseWriter().write(getPlaceHolder(panel.getClientId(context) + ":content"));
                    break;
                case :
                    // Do nothing.
                    break;
                default:
                    throw new IllegalStateException("Unknown switch type : " + panel.getSwitchType());
            }
        }
    }
    private void encodeEmptyChild(ResponseWriter writer, FacesContext context, UIComponent component,
        AbstractCollapsiblePanel panelthrows IOException {
        if (!panel.isExpanded()) {
            encodeEmptyDiv(writercontextcomponenttrue);
        } else {
            switch (panel.getSwitchType()) {
                case :
                    encodeEmptyDiv(writercontextcomponentfalse);
                    break;
                case :
                    writer.write(getPlaceHolder(panel.getClientId(context) + ":empty"));
                    break;
                case :
                    // Do nothing.
                    break;
                default:
                    throw new IllegalStateException("Unknown switch type : " + panel.getSwitchType());
            }
        }
    }
    private String getPlaceHolder(String id) {
        return "<div id=\"" + id + "\" style=\"display:none\" ></div>";
    }
    private void encodeContent(ResponseWriter writer, FacesContext context, UIComponent componentboolean visible)
        throws IOException {
        writer.startElement(DIV_ELEM, component);
        writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) + ":content"null);
        writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses("rf-cp-b"attributeAsString(component"bodyClass")), null);
        writer.writeAttribute(STYLE_ATTRIBUTE, styleElement("display"visible ? "block" : "none"), null);
        renderChildren(contextcomponent);
        writer.endElement(DIV_ELEM);
    }
    private void encodeEmptyDiv(ResponseWriter writer, FacesContext context, UIComponent componentboolean visible)
        throws IOException {
        writer.startElement(DIV_ELEM, component);
        writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) + ":empty"null);
        writer.writeAttribute(CLASS_ATTRIBUTE, "rf-cp-empty"null);
        writer.writeAttribute(STYLE_ATTRIBUTE, styleElement("display"visible ? "block" : "none"), null);
        writer.endElement(DIV_ELEM);
    }
    @Override
    protected Class<? extends UIComponent> getComponentClass() {
        return AbstractCollapsiblePanel.class;
    }
New to GrepCode? Check out our FAQ X