Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.richfaces.renderkit.html;
  
  import static org.richfaces.component.util.HtmlUtil.concatClasses;
  import static org.richfaces.renderkit.HtmlConstants.ALT_ATTRIBUTE;
  import static org.richfaces.renderkit.HtmlConstants.CLASS_ATTRIBUTE;
  import static org.richfaces.renderkit.HtmlConstants.DIV_ELEM;
  import static org.richfaces.renderkit.HtmlConstants.IMG_ELEMENT;
  import static org.richfaces.renderkit.HtmlConstants.SRC_ATTRIBUTE;
  import static org.richfaces.renderkit.HtmlConstants.TABLE_ELEMENT;
 import static org.richfaces.renderkit.HtmlConstants.TBODY_ELEMENT;
 import static org.richfaces.renderkit.HtmlConstants.TD_ELEM;
 import static org.richfaces.renderkit.HtmlConstants.TR_ELEMENT;
 
 
 import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.context.ResponseWriter;
 
 import  org.richfaces.renderkit.util.PanelIcons;
 
 public abstract class TableIconsRendererHelper<T extends UIComponent> {
     protected final String text;
     protected final String cssClassPrefix;
     protected final String cssIconsClassPrefix;
 
     protected TableIconsRendererHelper(String textString cssClassPrefixString cssIconsClassPrefix) {
         this. = text;
         this. = cssClassPrefix;
         this. = cssIconsClassPrefix;
     }
 
     protected TableIconsRendererHelper(String textString cssClassPrefix) {
         this(textcssClassPrefixcssClassPrefix + "-ico");
     }
 
     public void encodeHeader(ResponseWriter writer, FacesContext context, T componentthrows IOException {
         writer.startElement(TABLE_ELEMENT, null);
         writer.writeAttribute(CLASS_ATTRIBUTE,  + "-gr"null);
         writer.startElement(TBODY_ELEMENT, null);
         writer.startElement(TR_ELEMENT, null);
 
         encodeHeaderLeftIcon(writercontextcomponent);
         encodeHeaderText(writercontextcomponent);
         encodeHeaderRightIcon(writercontextcomponent);
 
         writer.endElement(TR_ELEMENT);
         writer.endElement(TBODY_ELEMENT);
         writer.endElement(TABLE_ELEMENT);
     }
 
     protected void encodeHeaderText(ResponseWriter writer, FacesContext context, T componentthrows IOException {
         writer.startElement(TD_ELEM, null);
         writer.writeAttribute(CLASS_ATTRIBUTE,  + "-lbl"null);
 
         encodeHeaderTextValue(writercontextcomponent);
 
         writer.endElement(TD_ELEM);
     }
 
     protected void encodeHeaderTextValue(ResponseWriter writer, FacesContext context, T componentthrows IOException {
         writeFacetOrAttr(writercontextcomponent);
     }
 
     public static void writeFacetOrAttr(ResponseWriter writer, FacesContext context, UIComponent componentString attr,
         String facetNamethrows IOException {
         writeFacetOrAttr(writercontextcomponentattrcomponent.getFacet(facetName));
     }
 
     public static void writeFacetOrAttr(ResponseWriter writer, FacesContext context, UIComponent componentString attr,
         UIComponent headerFacetthrows IOException {
         if (headerFacet != null && headerFacet.isRendered()) {
             headerFacet.encodeAll(context);
         } else {
             Object label = component.getAttributes().get(attr);
             if (label != null && !label.equals("")) {
                 writer.writeText(labelnull);
             }
         }
     }
 
     protected abstract void encodeHeaderLeftIcon(ResponseWriter writer, FacesContext context, T componentthrows IOException;
 
     protected abstract void encodeHeaderRightIcon(ResponseWriter writer, FacesContext context, T menuItemthrows IOException;
 
     protected void encodeTdIcon(ResponseWriter writer, FacesContext contextString cssClassString attrIconCollapsedValue,
         String attrIconExpandedValue, PanelIcons.State statethrows IOException {
         if (isIconRendered(attrIconCollapsedValue) || isIconRendered(attrIconExpandedValue)) {
 
             writer.startElement(TD_ELEM, null);
             writer.writeAttribute(CLASS_ATTRIBUTE, cssClassnull);
 
             if (isIconRendered(attrIconCollapsedValue)) {
                 encodeIdIcon(writercontextattrIconCollapsedValue + "-colps"state);
             }
             if (isIconRendered(attrIconExpandedValue)) {
                 encodeIdIcon(writercontextattrIconExpandedValue + "-exp"state);
             }
            writer.endElement(TD_ELEM);
        }
    }
    protected boolean isIconRendered(String attrIconValue) {
        if (attrIconValue != null && attrIconValue.trim().length() > 0 && !PanelIcons.none.toString().equals(attrIconValue)) {
            return true;
        }
        return false;
    }
    protected void encodeIdIcon(ResponseWriter writer, FacesContext contextString attrIconValueString styleClass,
        PanelIcons.State statethrows IOException {
        if (attrIconValue == null || attrIconValue.trim().length() <= 0) {
            encodeDivIcon(writer, PanelIcons.none, styleClassstate);
        } else {
            PanelIcons icon = PanelIcons.getIcon(attrIconValue);
            if (icon != null) {
                encodeDivIcon(writericonstyleClassstate);
            } else {
                encodeImage(writercontextattrIconValuestyleClass);
            }
        }
    }
    public static void encodeDivIcon(ResponseWriter writer, PanelIcons iconString styleClass, PanelIcons.State state)
        throws IOException {
        writer.startElement(DIV_ELEM, null);
        writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses(styleClassstate.getCssClass(icon)), null);
        writer.endElement(DIV_ELEM);
    }
    public static void encodeImage(ResponseWriter writer, FacesContext contextString attrIconValueString styleClass)
        throws IOException {
        writer.startElement(IMG_ELEMENT, null);
        writer.writeAttribute(ALT_ATTRIBUTE, ""null);
        writer.writeAttribute(CLASS_ATTRIBUTE, styleClassnull);
        writer.writeURIAttribute(SRC_ATTRIBUTE, RenderKitUtils.getResourceURL(attrIconValuecontext), null);
        writer.endElement(IMG_ELEMENT);
    }
New to GrepCode? Check out our FAQ X