All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.mojarra.scales.component.Layout Maven / Gradle / Ivy

Go to download

This is the core for Mojarra Scales. It has everything that Scales offers minus the multi-file upload component dependencies due to their size.

The newest version!
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.mojarra.scales.component;

import com.sun.mojarra.scales.util.CssUtil;
import com.sun.mojarra.scales.util.RenderingHelper;
import com.sun.mojarra.scales.util.ScalesUtil;
import com.sun.mojarra.scales.util.YuiConstants;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

/**
 *
 * @author jasonlee
 */
public class Layout extends UIOutput {

    public static final String COMPONENT_FAMILY = "com.sun.mojarra.scales.Layout";
    public static final String COMPONENT_TYPE = COMPONENT_FAMILY;
    public static final String RENDERER_TYPE = COMPONENT_FAMILY;
    private Object[] _state = null;
    protected Boolean fullPage = Boolean.TRUE;
    private String style = "";
    private String styleClass = "";

    public Layout() {
        super();
        setRendererType(RENDERER_TYPE);

        FacesContext context = FacesContext.getCurrentInstance();
        if (context != null) {
            Links.addCss(Links.EXTERNAL_STYLESHEETS, YuiConstants.CSS_RESIZE);
            Links.addCss(Links.EXTERNAL_STYLESHEETS, YuiConstants.CSS_RESET_FONTS_GRIDS);
            Links.addCss(Links.INLINE_STYLESHEET, ".yui-skin-sam .yui-layout { background-color: #ffffff;}");
            Links.addScript(Links.EXTERNAL_SCRIPTS, YuiConstants.JS_UTILITES);
            Links.addScript(Links.EXTERNAL_SCRIPTS, YuiConstants.JS_RESIZE);
            Links.addScript(Links.EXTERNAL_SCRIPTS, YuiConstants.JS_LAYOUT);
            CssUtil.linkResizeOverrides(context);
            CssUtil.linkLayoutOverrides(context);
        }
    }

    @Override
    public String getFamily() {
        return COMPONENT_FAMILY;
    }

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        super.encodeBegin(context);

        if (!isRendered()) {
            return;
        }

        ResponseWriter writer = context.getResponseWriter();
        writer.startElement("div", this);
        writer.writeAttribute("class", "yui-skin-sam " + getAttributes().get("styleClass"), "class");
        writer.writeAttribute("style", "visibility: hidden; " + getAttributes().get("style"), "style");
        writer.writeAttribute("id", getClientId(context), "id");
    }

    @Override
    public void encodeEnd(FacesContext context) throws IOException {
        super.encodeEnd(context);
        if (!isRendered()) {
            return;
        }

        ResponseWriter writer = context.getResponseWriter();
        writer.endElement("div");
        writer.write("\n");
        RenderingHelper.writeOnDomReady(writer, "scales.createLayoutManager(" + buildLayoutConfig(context) + ");");
    }

    @Override
    public boolean getRendersChildren() {
        return false;
    }

    protected String buildLayoutConfig(FacesContext context) {
        StringBuilder builder = new StringBuilder();
        String sep = "";

        // TODO:  EL support here seems to be broken
        builder.append("'")
                .append(getClientId(context))
                .append("', ")
                .append(getAttributes().get("fullPage"))
                .append(", new Array(");
        for (UIComponent comp : getChildren()) {
            if (comp instanceof LayoutUnit) {
        	if (!comp.isRendered()) {
        	    continue;
        	}
                LayoutUnit lu = (LayoutUnit) comp;
                builder.append(sep).append("{position: '").append(lu.getPosition()).append("', body: '").append(lu.getClientId(context)).append("'");
                ScalesUtil.appendToConfigIfNotNull(builder, "header", lu.getHeader(), true, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "width",lu.getWidth(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "height", lu.getHeight(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "resize", lu.getResize(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "minWidth", lu.getMinWidth(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "maxWidth", lu.getMaxWidth(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "minHeight", lu.getMinHeight(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "maxHeight", lu.getMaxHeight(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "gutter", lu.getGutter(), true, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "footer", lu.getFooter(), true, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "collapse", lu.getCollapse(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "scroll", lu.getScroll(), false, true);
                ScalesUtil.appendToConfigIfNotNull(builder, "animate", lu.getAnimate(), false, true);
                builder.append("}");
                sep = ",";
            }
        }

        builder.append(")");

        return builder.toString();
    }

    @Override
    public Object saveState(FacesContext context) {
        if (_state == null) {
            _state = new Object[4];
        }
        _state[0] = super.saveState(context);
        _state[1] = fullPage;
        _state[2] = style;
        _state[3] = styleClass;
        return _state;
    }

    @Override
    public void restoreState(FacesContext context, Object state) {
        this._state = (Object[]) state;
        super.restoreState(context, this._state[0]);
        fullPage = (Boolean) this._state[1];
        style = (String) this._state[2];
        styleClass = (String) this._state[3];
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy