⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a_cmslistdialog.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        return dialogContentEnd();
    }

    /**
     * Can be overwritten to add some code before the list.<p>
     * 
     * @return custom html code
     */
    protected String customHtmlStart() {

        return "";
    }

    /**
     * Generates the dialog starting html code.<p>
     * 
     * @return html code
     */
    protected String defaultActionHtml() {

        if (getList() != null && getList().getAllContent().isEmpty()) {
            refreshList();
        }
        StringBuffer result = new StringBuffer(2048);
        result.append(defaultActionHtmlStart());
        result.append(customHtmlStart());
        result.append(defaultActionHtmlContent());
        result.append(customHtmlEnd());
        result.append(defaultActionHtmlEnd());
        return result.toString();
    }

    /**
     * Returns the html code for the default action content.<p>
     * 
     * @return html code
     */
    protected String defaultActionHtmlContent() {

        StringBuffer result = new StringBuffer(2048);
        result.append("<form name='");
        result.append(getList().getId());
        result.append("-form' action='");
        result.append(getDialogRealUri());
        result.append("' method='post' class='nomargin'");
        if (getList().getMetadata().isSearchable()) {
            result.append(" onsubmit=\"listSearchAction('");
            result.append(getList().getId());
            result.append("', '");
            result.append(getList().getMetadata().getSearchAction().getId());
            result.append("', '");
            result.append(getList().getMetadata().getSearchAction().getConfirmationMessage().key(getLocale()));
            result.append("');\"");
        }
        result.append(">\n");
        result.append(allParamsAsHidden());
        result.append("\n");
        result.append(getList().listHtml(this));
        result.append("\n</form>\n");
        return result.toString();
    }

    /**
     * Generates the dialog ending html code.<p>
     * 
     * @return html code
     */
    protected String defaultActionHtmlEnd() {

        StringBuffer result = new StringBuffer(2048);
        result.append(dialogEnd());
        result.append(bodyEnd());
        result.append(htmlEnd());
        return result.toString();
    }

    /**
     * Generates the dialog starting html code.<p>
     * 
     * @return html code
     */
    protected String defaultActionHtmlStart() {

        StringBuffer result = new StringBuffer(2048);
        result.append(htmlStart(null));
        result.append(getList().listJs(getLocale()));
        result.append(bodyStart("dialog", null));
        result.append(dialogStart());
        result.append(dialogContentStart(getParamTitle()));
        return result.toString();
    }

    /**
     * Filter a list, given the action is set to <code>LIST_SEARCH</code> and
     * the filter text is set in the <code>PARAM_SEARCH_FILTER</code> parameter.<p>
     */
    protected void executeSearch() {

        getList().setSearchFilter(getParamSearchFilter(), getLocale());
    }

    /**
     * Select a page, given the action is set to <code>LIST_SELECT_PAGE</code> and 
     * the page to go to is set in the <code>PARAM_PAGE</code> parameter.<p>
     */
    protected void executeSelectPage() {

        int page = Integer.valueOf(getParamPage()).intValue();
        getList().setCurrentPage(page);
    }

    /**
     * Sort the list, given the action is set to <code>LIST_SORT</code> and
     * the sort column is set in the <code>PARAM_SORT_COL</code> parameter.<p>
     */
    protected void executeSort() {

        getList().setSortedColumn(getParamSortCol(), getLocale());
    }

    /**
     * Lazy initialization for detail data.<p>
     * 
     * Should fill the given detail column for every list item in <code>{@link CmsHtmlList#getAllContent()}</code>
     * 
     * Should not throw any kind of exception.<p>
     * 
     * @param detailId the id of the detail to initialize
     */
    protected abstract void fillDetails(String detailId);

    /**
     * Calls the <code>{@link #getListItems}</code> method and catches any exception.<p>
     */
    protected void fillList() {

        try {
            getList().addAllItems(getListItems());
            // initialize detail columns
            Iterator itDetails = getList().getMetadata().getItemDetailDefinitions().iterator();
            while (itDetails.hasNext()) {
                initializeDetail(((CmsListItemDetails)itDetails.next()).getId());
            }
        } catch (Exception e) {
            throw new CmsRuntimeException(Messages.get().container(
                Messages.ERR_LIST_FILL_1,
                getList().getName().key(getLocale()),
                null), e);
        }
    }

    /**
     * Should generate a list with the list items to be displayed.<p>
     * 
     * @return a list of <code>{@link CmsListItem}</code>s
     * 
     * @throws CmsException if something goes wrong
     */
    protected abstract List getListItems() throws CmsException;

    /**
     * Should generate the metadata definition for the list, and return the 
     * corresponding <code>{@link CmsListMetadata}</code> object.<p>
     * 
     * @param listDialogName the name of the class generating the list
     * @param listId the id of the list
     * 
     * @return The metadata for the given list
     */
    protected synchronized CmsListMetadata getMetadata(String listDialogName, String listId) {

        if (m_metadatas.get(listDialogName) == null || ((CmsListMetadata)m_metadatas.get(listDialogName)).isVolatile()) {
            CmsListMetadata metadata = new CmsListMetadata(listId);

            setColumns(metadata);
            // always check the search action
            setSearchAction(metadata, m_searchColId);
            setIndependentActions(metadata);
            metadata.addIndependentAction(new CmsListPrintIAction());
            setMultiActions(metadata);
            metadata.checkIds();
            m_metadatas.put(listDialogName, metadata);
        }
        return (CmsListMetadata)m_metadatas.get(listDialogName);
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        super.initWorkplaceRequestValues(settings, request);
        // set the action for the JSP switch 
        if (LIST_SEARCH.equals(getParamAction())) {
            setAction(ACTION_LIST_SEARCH);
        } else if (LIST_SORT.equals(getParamAction())) {
            setAction(ACTION_LIST_SORT);
        } else if (LIST_SELECT_PAGE.equals(getParamAction())) {
            setAction(ACTION_LIST_SELECT_PAGE);
        } else if (LIST_INDEPENDENT_ACTION.equals(getParamAction())) {
            setAction(ACTION_LIST_INDEPENDENT_ACTION);
        } else if (LIST_SINGLE_ACTION.equals(getParamAction())) {
            setAction(ACTION_LIST_SINGLE_ACTION);
        } else if (LIST_MULTI_ACTION.equals(getParamAction())) {
            setAction(ACTION_LIST_MULTI_ACTION);
        }
        setParamStyle("new");
        // test the needed parameters
        try {
            validateParamaters();
        } catch (Exception e) {
            // redirect to parent if parameters not available
            setAction(ACTION_CANCEL);
            try {
                actionCloseDialog();
            } catch (JspException e1) {
                // noop
            }
            return;
        }
    }

    /**
     * Recover the last list instance that is read from the request attributes.<p>
     * 
     * This is required for keep the whole list in memory while you browse a page.<p>
     * 
     * @param listId the id of the expected list
     */
    protected synchronized void listRecovery(String listId) {

        CmsHtmlList list = getListObject(this.getClass(), getSettings());
        if (list != null && !list.getId().equals(listId)) {
            list = null;
        }
        setList(list);
    }

    /**
     * Save the state of the list in the session.<p>
     */
    protected synchronized void listSave() {

        setListObject(this.getClass(), getList());
    }

    /**
     * Should create the columns and add them to the given list metadata object.<p>
     * 
     * This method will be just executed once, the first time the constructor is called.<p> 
     * 
     * @param metadata the list metadata
     */
    protected abstract void setColumns(CmsListMetadata metadata);

    /**
     * Should add the independent actions to the given list metadata object.<p>
     * 
     * This method will be just executed once, the first time the constructor is called.<p> 
     * 
     * @param metadata the list metadata
     */
    protected abstract void setIndependentActions(CmsListMetadata metadata);

    /**
     * Should add the multi actions to the given list metadata object.<p>
     * 
     * This method will be just executed once, the first time the constructor is called.<p> 
     * 
     * @param metadata the list metadata
     */
    protected abstract void setMultiActions(CmsListMetadata metadata);

    /**
     * Creates the default search action.<p>
     * 
     * Can be overriden for more sofisticated search.<p>
     * 
     * @param metadata the metadata of the list to do searchable
     * @param columnId the if of the column to search into
     */
    protected void setSearchAction(CmsListMetadata metadata, String columnId) {

        CmsListColumnDefinition col = metadata.getColumnDefinition(columnId);
        if (columnId != null && col != null) {
            if (metadata.getSearchAction() == null) {
                // makes the list searchable
                CmsListSearchAction searchAction = new CmsListSearchAction(col);
                searchAction.useDefaultShowAllAction();
                metadata.setSearchAction(searchAction);
            }
        }
    }

    /**
     * A convenient method to throw a list unsupported
     * action runtime exception.<p>
     * 
     * Should be triggered if your list implementation does not 
     * support the <code>{@link #getParamListAction()}</code>
     * action.<p>
     * 
     * @throws CmsRuntimeException always to signal that this operation is not supported
     */
    protected void throwListUnsupportedActionException() throws CmsRuntimeException {

        throw new CmsRuntimeException(Messages.get().container(
            Messages.ERR_LIST_UNSUPPORTED_ACTION_2,
            getList().getName().key(getLocale()),
            getParamListAction()));
    }

    /**
     * Should be overriden for parameter validation.<p>
     * 
     * @throws Exception if the parameters are not valid
     */
    protected void validateParamaters() throws Exception {

        // valid by default
    }

    /**
     * Lazzy details initialization.<p>
     * 
     * @param detailId the id of the detail column
     */
    private void initializeDetail(String detailId) {

        // if detail column visible
        if (getList().getMetadata().getItemDetailDefinition(detailId).isVisible()) {
            // if the list is not empty
            if (!getList().getAllContent().isEmpty()) {
                // if the detail column has not been previously initialized
                if (((CmsListItem)getList().getAllContent().get(0)).get(detailId) == null) {
                    fillDetails(detailId);
                }
            }
        }
    }
}

⌨️ 快捷键说明

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