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

📄 cmswidgetdialog.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }

    /**
     * Returns <code>true</code> if the dialog should be closed after the values have been committed.<p>
     * 
     * The default implementation returns <code>true</code> in case there are no 
     * commit errors.<p>
     * 
     * @return <code>true</code> if the dialog should be closed after the values have been committed
     */
    protected boolean closeDialogOnCommit() {

        return !hasCommitErrors();
    }

    /**
     * Commits all values on the dialog.<p> 
     * 
     * @return a List of all Exceptions that occured when comitting the dialog.<p>
     */
    protected List commitWidgetValues() {

        return commitWidgetValues(null);
    }

    /**
     * Commits all values on the given dialog page.<p> 
     * 
     * @param dialogPage the dialog (page) to commit
     * 
     * @return a List of all Exceptions that occured when comitting the dialog page.<p>
     */
    protected List commitWidgetValues(String dialogPage) {

        List result = new ArrayList();
        Iterator i = getWidgets().iterator();
        while (i.hasNext()) {
            // check for all widget parameters            
            CmsWidgetDialogParameter base = (CmsWidgetDialogParameter)i.next();
            if ((dialogPage == null) || (base.getDialogPage() == null) || dialogPage.equals(base.getDialogPage())) {
                // the parameter is located on the requested dialog
                base.prepareCommit();
                List params = (List)m_widgetParamValues.get(base.getName());
                Iterator j = params.iterator();
                while (j.hasNext()) {
                    CmsWidgetDialogParameter param = (CmsWidgetDialogParameter)j.next();
                    try {
                        param.commitValue(this);
                    } catch (Exception e) {
                        result.add(e);
                    }
                }
            }
        }
        setValidationErrorList(result);
        return result;
    }

    /**
     * Creates the dialog HTML for all defined widgets of this dialog.<p>  
     * 
     * @return the dialog HTML for all defined widgets of this dialog
     */
    protected String createDialogHtml() {

        return createDialogHtml(null);
    }

    /**
     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
     * 
     * To get a more complex layout variation, you have to overwrite this method in your dialog class.<p>
     * 
     * @param dialog the dialog (page) to get the HTML for
     * @return the dialog HTML for all defined widgets of the named dialog (page)
     */
    protected String createDialogHtml(String dialog) {

        StringBuffer result = new StringBuffer(1024);

        // create table
        result.append(createWidgetTableStart());

        // show error header once if there were validation errors
        result.append(createWidgetErrorHeader());

        Iterator i = getWidgets().iterator();
        // iterate the type sequence                    
        while (i.hasNext()) {
            // get the current widget base definition
            CmsWidgetDialogParameter base = (CmsWidgetDialogParameter)i.next();
            // check if the element is on the requested dialog page
            if ((dialog == null) || dialog.equals(base.getDialogPage())) {
                // add the HTML for the dialog element
                result.append(createDialogRowHtml(base));
            }
        }
        // close table
        result.append(createWidgetTableEnd());

        return result.toString();
    }

    /**
     * Creates the dialog HTML for all occurences of one widget parameter.<p>  
     * 
     * @param base the widget parameter base
     * @return the dialog HTML for one widget parameter
     */
    protected String createDialogRowHtml(CmsWidgetDialogParameter base) {

        StringBuffer result = new StringBuffer(256);

        List sequence = (List)getParameters().get(base.getName());
        int count = sequence.size();

        // check if value is optional or multiple
        boolean addValue = false;
        if (count < base.getMaxOccurs()) {
            addValue = true;
        }
        boolean removeValue = false;
        if (count > base.getMinOccurs()) {
            removeValue = true;
        }

        // check if value is present
        boolean disabledElement = false;
        if (count < 1) {
            // no parameter with the value present, but also not optional: use base as parameter
            sequence = new ArrayList();
            sequence.add(base);
            count = 1;
            if (base.getMinOccurs() == 0) {
                disabledElement = true;
            }
        }

        // loop through multiple elements
        for (int j = 0; j < count; j++) {

            // get the parameter and the widget
            CmsWidgetDialogParameter p = (CmsWidgetDialogParameter)sequence.get(j);
            I_CmsWidget widget = p.getWidget();

            // check for an error in this row
            if (p.hasError()) {
                // show error message
                result.append("<tr><td></td><td><img src=\"");
                result.append(getSkinUri()).append("editors/xmlcontent/");
                result.append("error.png");
                result.append("\" border=\"0\" alt=\"\"></td><td class=\"xmlTdError\">");
                Throwable t = p.getError();
                while (t != null) {
                    result.append(t.getLocalizedMessage());
                    t = t.getCause();
                    if (t != null) {
                        result.append("<br>");
                    }
                }
                result.append("</td><td colspan=\"2\"></td></tr>\n");
            }

            // create label and help bubble cells
            result.append("<tr>");
            result.append("<td class=\"xmlLabel");
            if (disabledElement) {
                // element is disabled, mark it with css
                result.append("Disabled");
            }

            result.append("\">");
            result.append(keyDefault(A_CmsWidget.getLabelKey(p), p.getName()));
            if (count > 1) {
                result.append(" [").append(p.getIndex() + 1).append("]");
            }
            result.append(": </td>");
            if (p.getIndex() == 0) {
                // show help bubble only on first element of each content definition 
                result.append(p.getWidget().getHelpBubble(getCms(), this, p));
            } else {
                // create empty cell for all following elements 
                result.append(dialogHorizontalSpacer(16));
            }

            // append individual widget html cell if element is enabled
            if (!disabledElement) {
                // this is a simple type, display widget
                result.append(widget.getDialogWidget(getCms(), this, p));
            } else {
                // disabled element, show message for optional element
                result.append("<td class=\"xmlTdDisabled maxwidth\">");
                result.append(key(Messages.GUI_EDITOR_WIDGET_OPTIONALELEMENT_0));
                result.append("</td>");
            }

            // append add and remove element buttons if required
            result.append(dialogHorizontalSpacer(5));
            result.append("<td>");
            if (addValue || removeValue) {
                result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");

                if (!addValue) {
                    result.append(dialogHorizontalSpacer(25));
                } else {
                    result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
                    result.append(buildAddElement(base.getName(), p.getIndex(), addValue));
                }

                if (removeValue) {
                    if (!addValue) {
                        result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
                    }
                    result.append(buildRemoveElement(base.getName(), p.getIndex(), removeValue));
                }

                result.append("</tr></table></td>");
                result.append("</tr></table>");
            }
            result.append("</td>");
            // close row
            result.append("</tr>\n");
        }

        return result.toString();
    }

    /**
     * Creates the dialog widget rows HTML for the specified widget indices.<p>
     * 
     * @param startIndex the widget index to start with
     * @param endIndex the widget index to stop at
     * @return the dialog widget rows HTML for the specified widget indices
     */
    protected String createDialogRowsHtml(int startIndex, int endIndex) {

        StringBuffer result = new StringBuffer((endIndex - startIndex) * 8);
        for (int i = startIndex; i <= endIndex; i++) {
            CmsWidgetDialogParameter base = (CmsWidgetDialogParameter)getWidgets().get(i);
            result.append(createDialogRowHtml(base));
        }
        return result.toString();
    }

    /**
     * Creates the complete widget dialog end block HTML that finishes a widget block.<p>
     * 
     * @return the complete widget dialog end block HTML that finishes a widget block
     */
    protected String createWidgetBlockEnd() {

        StringBuffer result = new StringBuffer(8);
        result.append(createWidgetTableEnd());
        result.append(dialogBlockEnd());
        return result.toString();
    }

    /**
     * Create the complete widget dialog start block HTML that begins a widget block with optional headline.<p>
     * @param headline the headline String for the block
     * @return the complete widget dialog start block HTML that begins a widget block with optional headline
     */
    protected String createWidgetBlockStart(String headline) {

        StringBuffer result = new StringBuffer(16);
        result.append(dialogBlockStart(headline));
        result.append(createWidgetTableStart());
        return result.toString();
    }

    /**
     * Creates the HTML for the error message if validation errors were found.<p>
     * 
     * @return the HTML for the error message if validation errors were found
     */
    protected String createWidgetErrorHeader() {

        StringBuffer result = new StringBuffer(8);
        if (hasValidationErrors() || hasCommitErrors()) {
            result.append("<tr><td colspan=\"5\">&nbsp;</td></tr>\n");
            result.append("<tr><td colspan=\"2\">&nbsp;</td>");
            result.append("<td class=\"xmlTdErrorHeader\">");
            result.append(key(Messages.GUI_EDITOR_WIDGET_VALIDATION_ERROR_TITLE_0));
            result.append("</td><td colspan=\"2\">&nbsp;");
            result.append("</td></tr>\n");
            result.append("<tr><td colspan=\"5\">&nbsp;</td></tr>\n");
            if (hasCommitErrors()) {
                result.append(dialogBlockStart(""));
                result.append(createWidgetTableStart());
                Iterator i = getCommitErrors().iterator();
                while (i.hasNext()) {
                    Throwable t = (Throwable)i.next();
                    result.append("<tr><td><img src=\"");
                    result.append(getSkinUri()).append("editors/xmlcontent/");
                    result.append("error.png");
                    result.append("\" border=\"0\" alt=\"\"></td><td class=\"xmlTdError maxwidth\">");
                    while (t != null) {
                        String message = "";
                        if (t instanceof I_CmsThrowable) {
                            message = ((I_CmsThrowable)t).getLocalizedMessage(getLocale());
                        } else {
                            message = t.getLocalizedMessage();
                        }
                        result.append(CmsStringUtil.escapeHtml(message));
                        t = t.getCause();
                        if (t != null) {
                            result.append("<br>");
                        }
                    }
                    result.append("</td></tr>\n");
                }
                result.append(createWidgetTableEnd());
                result.append(dialogBlockEnd());
            }
        }
        return result.toString();
    }

    /**
     * Creates the HTML for the table around the dialog widgets.<p>
     * 
     * @return the HTML for the table around the dialog widgets
     */
    protected String createWidgetTableEnd() {

        return "</table>\n";
    }

    /**
     * Creates the HTML to close the table around the dialog widgets.<p>
     * 
     * @return the HTML to close the table around the dialog widgets
     */
    protected String createWidgetTableStart() {

        return "<table cellspacing='0' cellpadding='0' class='xmlTable'>\n";
    }

    /**
     * Generates the dialog starting html code.<p>
     * 
     * @return html code
     * 
     * @throws JspException if something goes wrong
     */
    protected String defaultActionHtml() throws JspException {

        StringBuffer result = new StringBuffer(2048);
        result.append(defaultActionHtmlStart());
        result.append(defaultActionHtmlContent());
        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=\"EDITOR\" id=\"EDITOR\" method=\"post\" action=\"").append(getDialogRealUri());
        result.append("\" class=\"nomargin\" onsubmit=\"return submitAction('").append(DIALOG_OK).append(
            "', null, 'EDITOR');\">\n");
        result.append(dialogContentStart(getDialogTitle()));
        result.append(buildDialogForm());
        result.append(dialogContentEnd());
        result.append(dialogButtonsCustom());
        result.append(paramsAsHidden());
        if (getParamFramename() == null) {
            result.append("\n<input type=\"hidden\" name=\"").append(PARAM_FRAMENAME).append("\" value=\"\">\n");
        }
        result.append("</form>\n");
        result.append(getWidgetHtmlEnd());
        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
     * 
     * @throws JspException if something goes wrong
     */

⌨️ 快捷键说明

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