cmslistcolumndefinition.java

来自「找了很久才找到到源代码」· Java 代码 · 共 743 行 · 第 1/2 页

JAVA
743
字号

        return m_wp;
    }

    /**
     * returns the html for a cell.<p>
     * 
     * @param item the item to render the cell for
     * @param isPrintable if the list is to be printed
     * 
     * @return html code
     */
    public String htmlCell(CmsListItem item, boolean isPrintable) {

        StringBuffer html = new StringBuffer(512);
        Iterator itActions = m_directActions.iterator();
        while (itActions.hasNext()) {
            I_CmsListDirectAction action = (I_CmsListDirectAction)itActions.next();
            action.setItem(item);
            boolean enabled = action.isEnabled();
            if (isPrintable) {
                action.setEnabled(false);
            }
            html.append(action.buttonHtml());
            if (isPrintable) {
                action.setEnabled(enabled);
            }
        }
        if (!m_defaultActions.isEmpty()) {
            Iterator itDefaultActions = m_defaultActions.iterator();
            while (itDefaultActions.hasNext()) {
                CmsListDefaultAction defAction = (CmsListDefaultAction)itDefaultActions.next();
                defAction.setItem(item);
                boolean enabled = defAction.isEnabled();
                if (isPrintable) {
                    defAction.setEnabled(false);
                }
                html.append(defAction.buttonHtml());
                if (isPrintable) {
                    defAction.setEnabled(enabled);
                }
            }
        } else {
            if (m_formatter == null) {
                // unformatted output
                if (item.get(m_id) != null) {
                    // null values are not showed by default
                    html.append(item.get(m_id).toString());
                }
            } else {
                // formatted output
                html.append(m_formatter.format(item.get(m_id), getWp().getLocale()));
            }
        }
        html.append("\n");
        return html.toString();
    }

    /**
     * Returns the html code for a column header.<p>
     * 
     * @param list the list to generate the header code for
     * 
     * @return html code
     */
    public String htmlHeader(CmsHtmlList list) {

        String listId = list.getId();
        String sortedCol = list.getSortedColumn();
        CmsListOrderEnum order = list.getCurrentSortOrder();

        StringBuffer html = new StringBuffer(512);
        Locale locale = getWp().getLocale();
        CmsMessages messages = Messages.get().getBundle(locale);
        html.append("<th");
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getWidth())) {
            html.append(" width='");
            html.append(getWidth());
            html.append("'");
        }
        if (!isTextWrapping()) {
            html.append(" style='white-space: nowrap;'");
        }
        html.append(">\n");

        boolean isSorted = getId().equals(sortedCol);
        CmsListOrderEnum nextOrder = CmsListOrderEnum.ORDER_ASCENDING;
        if (isSorted && (order == CmsListOrderEnum.ORDER_ASCENDING)) {
            nextOrder = CmsListOrderEnum.ORDER_DESCENDING;
        }
        // button
        String id = listId + getId() + "Sort";
        String onClic = "listSort('" + listId + "', '" + getId() + "');";
        String helpText = null;
        if (m_helpText != null) {
            helpText = new MessageFormat(m_helpText.key(locale), locale).format(new Object[] {getName().key(locale)});
        } else {
            if (isSorteable()) {
                if (nextOrder.equals(CmsListOrderEnum.ORDER_ASCENDING)) {
                    helpText = messages.key(Messages.GUI_LIST_COLUMN_ASC_SORT_1, new Object[] {getName().key(locale)});
                } else {
                    helpText = messages.key(Messages.GUI_LIST_COLUMN_DESC_SORT_1, new Object[] {getName().key(locale)});
                }
            } else {
                helpText = messages.key(Messages.GUI_LIST_COLUMN_NO_SORT_1, new Object[] {getName().key(locale)});
            }
        }
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getWidth()) && (getWidth().indexOf('%') < 0)) {
            html.append("\t<div style='display:block; width: ");
            html.append(getWidth());
            html.append("px;'>\n");
        }
        String sortArrow = "";
        // sort order marker
        if (isSorted) {
            if (nextOrder == CmsListOrderEnum.ORDER_ASCENDING) {
                sortArrow = "<img src='" + CmsWorkplace.getSkinUri() + ICON_UP + "' alt=''>&nbsp;";
            } else {
                sortArrow = "<img src='" + CmsWorkplace.getSkinUri() + ICON_DOWN + "' alt=''>&nbsp;";
            }
        }
        html.append(A_CmsHtmlIconButton.defaultButtonHtml(
            CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
            id,
            id,
            getName().key(locale),
            helpText,
            list.isPrintable() ? false : isSorteable(),
            null,
            null,
            onClic,
            false,
            sortArrow));
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getWidth()) && (getWidth().indexOf('%') < 0)) {
            html.append("\t</div>\n");
        }
        html.append("</th>\n");
        return html.toString();
    }

    /**
     * Returns the printable  .<p>
     *
     * @return the printable flag
     */
    public boolean isPrintable() {

        return m_printable;
    }

    /**
     * Returns the sorteable.<p>
     *
     * @return the sorteable
     */
    public boolean isSorteable() {

        return getListItemComparator() != null;
    }

    /**
     * Returns the text Wrapping flag.<p>
     *
     * @return the text Wrapping flag
     */
    public boolean isTextWrapping() {

        return m_textWrapping;
    }

    /**
     * Returns the visible.<p>
     *
     * @return the visible
     */
    public boolean isVisible() {

        return m_visible;
    }

    /**
     * Removes the default action from this column by id.<p>
     * 
     * @param actionId the id of the action to remove
     * 
     * @return the action if found or <code>null</code>
     */
    public CmsListDefaultAction removeDefaultAction(String actionId) {

        Iterator it = m_defaultActions.iterator();
        while (it.hasNext()) {
            CmsListDefaultAction action = (CmsListDefaultAction)it.next();
            if (action.getId().equals(actionId)) {
                it.remove();
                return action;
            }
        }
        return null;
    }

    /**
     * Removes a direct action from this column by id.<p>
     * 
     * @param actionId the id of the action to remove
     * 
     * @return the action if found or <code>null</code>
     */
    public I_CmsListDirectAction removeDirectAction(String actionId) {

        Iterator it = m_directActions.iterator();
        while (it.hasNext()) {
            I_CmsListDirectAction action = (I_CmsListDirectAction)it.next();
            if (action.getId().equals(actionId)) {
                it.remove();
                return action;
            }
        }
        return null;
    }

    /**
     * Sets the align.<p>
     *
     * @param align the align to set
     */
    public void setAlign(CmsListColumnAlignEnum align) {

        m_align = align;
    }

    /**
     * Sets the data formatter.<p>
     *
     * @param formatter the data formatter to set
     */
    public void setFormatter(I_CmsListFormatter formatter) {

        m_formatter = formatter;
        // set the formatter for all default actions
        Iterator it = m_defaultActions.iterator();
        while (it.hasNext()) {
            CmsListDefaultAction action = (CmsListDefaultAction)it.next();
            action.setColumnForLink(this);
        }
    }

    /**
     * Sets the customized help Text.<p>
     *
     * if <code>null</code> a default help text indicating the sort actions is used.<p>
     *
     * @param helpText the customized help Text to set
     */
    public void setHelpText(CmsMessageContainer helpText) {

        m_helpText = helpText;
    }

    /**
     * Sets the comparator, used for sorting.<p>
     *
     * @param comparator the comparator to set
     */
    public void setListItemComparator(I_CmsListItemComparator comparator) {

        m_comparator = comparator;
    }

    /**
     * Sets the name.<p>
     *
     * @param name the name to set
     */
    public void setName(CmsMessageContainer name) {

        m_name = name;
    }

    /**
     * Sets the printable flag.<p>
     *
     * @param printable the printable flag to set
     */
    public void setPrintable(boolean printable) {

        m_printable = printable;
    }

    /**
     * Indicates if the current column is sorteable or not.<p>
     * 
     * if <code>true</code> a default list item comparator is used.<p>
     * 
     * if <code>false</code> any previously set list item comparator is removed.<p>
     * 
     * @param sorteable the sorteable flag
     */
    public void setSorteable(boolean sorteable) {

        if (sorteable) {
            setListItemComparator(new CmsListItemDefaultComparator());
        } else {
            setListItemComparator(null);
        }
    }

    /**
     * Sets the text Wrapping flag.<p>
     *
     * @param textWrapping the text Wrapping flag to set
     */
    public void setTextWrapping(boolean textWrapping) {

        m_textWrapping = textWrapping;
    }

    /**
     * Sets the visible.<p>
     *
     * This will set also the printable flag to <code>false</code>.<p>
     *
     * @param visible the visible to set
     */
    public void setVisible(boolean visible) {

        m_visible = visible;
        if (!m_visible) {
            setPrintable(false);
        }
    }

    /**
     * Sets the width.<p>
     *
     * @param width the width to set
     */
    public void setWidth(String width) {

        m_width = width;
    }

    /**
     * Sets the workplace dialog object.<p>
     *
     * @param wp the workplace dialog object to set
     */
    public void setWp(A_CmsListDialog wp) {

        m_wp = wp;
        Iterator itActs = getDirectActions().iterator();
        while (itActs.hasNext()) {
            I_CmsListDirectAction action = (I_CmsListDirectAction)itActs.next();
            action.setWp(wp);
        }
        Iterator itDefActs = getDefaultActions().iterator();
        while (itDefActs.hasNext()) {
            CmsListDefaultAction action = (CmsListDefaultAction)itDefActs.next();
            action.setWp(wp);
        }
    }

    /**
     * Sets the id of the list.<p>
     * 
     * @param listId the id of the list
     */
    /*package*/void setListId(String listId) {

        m_listId = listId;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?