Search in sources :

Example 1 with IDataContainer

use of org.alfresco.web.data.IDataContainer in project acs-community-packaging by Alfresco.

the class UIDataPager method encodeBegin.

// ------------------------------------------------------------------------------
// Component implementation
/**
 * @see javax.faces.component.UIComponent#encodeBegin(javax.faces.context.FacesContext)
 */
public void encodeBegin(FacesContext context) throws IOException {
    IDataContainer dataContainer = getDataContainer();
    if (dataContainer == null) {
        throw new IllegalStateException("Must nest UISortLink inside component implementing IDataContainer!");
    }
    // with a valid "pageSize" property
    if (isRendered() == false || dataContainer.getPageSize() == -1) {
        return;
    }
    final String formClientId = Utils.getParentForm(context, this).getClientId(context);
    final String pageInputId = getPageInputId();
    final String hiddenFieldName = getHiddenFieldName();
    ResponseWriter out = context.getResponseWriter();
    ResourceBundle bundle = Application.getBundle(context);
    StringBuilder buf = new StringBuilder(512);
    int currentPage = dataContainer.getCurrentPage();
    int pageCount = dataContainer.getPageCount();
    Object displayInput = getAttributes().get("displayInput");
    String beginTag = "<span";
    String endTag = "</span>";
    String divStyle = "";
    String inputStyle = "height:13px;";
    String imageVericalAlign = null;
    String imageStyle = "margin-top:0px;";
    StringBuilder inputPageNumber = new StringBuilder(128);
    if (displayInput != null && ((Boolean) displayInput) == false) {
        imageStyle = null;
        inputPageNumber.append(currentPage + 1);
    } else {
        final boolean isIE = Utils.USER_AGENT_MSIE.equals(Utils.getUserAgent(context));
        if (isIE) {
            beginTag = "<div";
            endTag = "</div>";
            divStyle = "padding:1px;";
            inputStyle = "height:13px; vertical-align:middle;";
            imageVericalAlign = "middle";
            imageStyle = "margin-top:0px;";
            inputPageNumber.append("<input type=\"text\" maxlength=\"3\" value=\"").append(currentPage + 1).append("\" style=\"width: 24px; margin-left: 4px;").append(inputStyle).append("\" ");
            inputPageNumber.append("onkeydown=\"").append(generateIE6InputOnkeydownScript(pageInputId, formClientId, hiddenFieldName)).append("\" ");
            inputPageNumber.append("id=\"").append(pageInputId).append("\" />");
        } else {
            inputPageNumber.append("<input type=\"text\" maxlength=\"3\" value=\"").append(currentPage + 1).append("\" style=\"width: 24px; margin-left: 4px;").append(inputStyle).append("\" ");
            inputPageNumber.append("onkeypress=\"").append(generateInputOnkeyPressScript(pageInputId, formClientId, hiddenFieldName)).append("\" ");
            inputPageNumber.append("onkeydown=\"").append(generateInputOnkeydownScript()).append("\" ");
            inputPageNumber.append("id=\"").append(pageInputId).append("\" />");
        }
    }
    buf.append(beginTag);
    if (getAttributes().get("style") != null) {
        buf.append(" style=\"").append(getAttributes().get("style")).append(divStyle).append('"');
    }
    if (getAttributes().get("styleClass") != null) {
        buf.append(" class=").append(getAttributes().get("styleClass"));
    }
    buf.append('>');
    // output Page X of Y text
    buf.append(MessageFormat.format(bundle.getString(MSG_PAGEINFO), new Object[] { // current page can be zero if no data present
    inputPageNumber.toString(), Integer.toString(pageCount) }));
    buf.append("&nbsp;&nbsp;");
    // first page
    if (currentPage != 0) {
        buf.append("<a href='#' onclick=\"");
        buf.append(generateEventScript(0, hiddenFieldName));
        buf.append("\">");
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_FIRSTPAGE, 16, 16, bundle.getString(FIRST_PAGE), null, imageVericalAlign, imageStyle));
        buf.append("</a>");
    } else {
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_FIRSTPAGE_NONE, 16, 16, null, null, imageVericalAlign, imageStyle));
    }
    buf.append("&nbsp;");
    // previous page
    if (currentPage != 0) {
        buf.append("<a href='#' onclick=\"");
        buf.append(generateEventScript(currentPage - 1, hiddenFieldName));
        buf.append("\">");
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_PREVIOUSPAGE, 16, 16, bundle.getString(PREVIOUS_PAGE), null, imageVericalAlign, imageStyle));
        buf.append("</a>");
    } else {
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_PREVIOUSPAGE_NONE, 16, 16, null, null, imageVericalAlign, imageStyle));
    }
    buf.append("&nbsp;");
    Object objType = getAttributes().get("dataPagerType");
    PagerType type = PagerType.TRACKPAGE;
    if (objType instanceof String) {
        try {
            type = PagerType.valueOf((String) objType);
        } catch (Throwable ex) {
            s_logger.warn("DataPager id:" + this.getId() + " with incorrect 'numberPageType' attribute");
        }
    }
    switch(type) {
        case STANDARD:
            encodeType0(buf, currentPage, pageCount);
            break;
        case DECADES:
            encodeType1(buf, currentPage, pageCount);
            break;
        case TRACKPAGE:
            encodeType2(buf, currentPage, pageCount);
            break;
        default:
            encodeType2(buf, currentPage, pageCount);
    }
    // next page
    if ((dataContainer.getCurrentPage() < dataContainer.getPageCount() - 1) == true) {
        buf.append("<a href='#' onclick=\"");
        buf.append(generateEventScript(currentPage + 1, hiddenFieldName));
        buf.append("\">");
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_NEXTPAGE, 16, 16, bundle.getString(NEXT_PAGE), null, imageVericalAlign, imageStyle));
        buf.append("</a>");
    } else {
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_NEXTPAGE_NONE, 16, 16, null, null, imageVericalAlign, imageStyle));
    }
    buf.append("&nbsp;");
    // last page
    if ((dataContainer.getCurrentPage() < dataContainer.getPageCount() - 1) == true) {
        buf.append("<a href='#' onclick=\"");
        buf.append(generateEventScript(dataContainer.getPageCount() - 1, hiddenFieldName));
        buf.append("\">");
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_LASTPAGE, 16, 16, bundle.getString(LAST_PAGE), null, imageVericalAlign, imageStyle));
        buf.append("</a>");
    } else {
        buf.append(Utils.buildImageTag(context, WebResources.IMAGE_LASTPAGE_NONE, 16, 16, null, null, imageVericalAlign, imageStyle));
    }
    buf.append(endTag);
    out.write(buf.toString());
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) IDataContainer(org.alfresco.web.data.IDataContainer) ResourceBundle(java.util.ResourceBundle)

Example 2 with IDataContainer

use of org.alfresco.web.data.IDataContainer in project acs-community-packaging by Alfresco.

the class UISortLink method encodeBegin.

/**
 * @see javax.faces.component.UIComponent#encodeBegin(javax.faces.context.FacesContext)
 */
public void encodeBegin(FacesContext context) throws IOException {
    ResponseWriter out = context.getResponseWriter();
    IDataContainer dataContainer = getDataContainer();
    if (dataContainer == null) {
        throw new IllegalStateException("Must nest UISortLink inside component implementing IDataContainer!");
    }
    // swap sort direction if we were last sorted column
    boolean bPreviouslySorted = false;
    boolean descending = true;
    String lastSortedColumn = dataContainer.getCurrentSortColumn();
    if (lastSortedColumn != null && lastSortedColumn.equals(getValue())) {
        descending = !dataContainer.isCurrentSortDescending();
        bPreviouslySorted = true;
    }
    // render sort link
    StringBuilder buf = new StringBuilder(256);
    buf.append("<nobr><a href='#' onclick=\"");
    // generate some JavaScript to set a hidden form field and submit
    // a form which request attributes that we can decode
    buf.append(Utils.generateFormSubmit(context, this, getHiddenFieldName(context), getClientId(context)));
    buf.append('"');
    if (getAttributes().get("style") != null) {
        buf.append(" style=\"").append(getAttributes().get("style")).append('"');
    }
    if (getAttributes().get("styleClass") != null) {
        buf.append(" class=").append(getAttributes().get("styleClass"));
    }
    if (getAttributes().get("tooltip") != null) {
        buf.append(" title=\"").append(getAttributes().get("tooltip")).append('"');
    }
    buf.append('>');
    // output column label
    buf.append(Utils.encode((String) getAttributes().get("label")));
    if (bPreviouslySorted == true) {
        if (descending == true) {
            buf.append(" ").append(Utils.buildImageTag(context, WebResources.IMAGE_SORTUP, 10, 6, null));
        } else {
            buf.append(" ").append(Utils.buildImageTag(context, WebResources.IMAGE_SORTDOWN, 10, 6, null));
        }
    } else {
        buf.append(" ").append(Utils.buildImageTag(context, WebResources.IMAGE_SORTNONE, 10, 7, null));
    }
    buf.append("</a></nobr>");
    out.write(buf.toString());
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) IDataContainer(org.alfresco.web.data.IDataContainer)

Aggregations

ResponseWriter (javax.faces.context.ResponseWriter)2 IDataContainer (org.alfresco.web.data.IDataContainer)2 ResourceBundle (java.util.ResourceBundle)1