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

📄 cmswidgetdialogparameter.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param value the initial value of the parameter
     * @param defaultValue the default value of the parameter
     * @param name the id of the parameter
     * @param widget the widget used for this parameter
     * @param dialog the dialog this parameter is used on
     * @param minOccurs the required minimum numer of occurences of this parameter
     * @param maxOccurs the maximum allowed numer of occurences of this parameter
     * @param index the index of this parameter in the list 
     */
    public CmsWidgetDialogParameter(
        String value,
        String defaultValue,
        String name,
        I_CmsWidget widget,
        String dialog,
        int minOccurs,
        int maxOccurs,
        int index) {

        super();
        init(value, defaultValue, name, widget, dialog, minOccurs, maxOccurs, index);
    }

    /**
     * Returns a from id representation for the given widget name and id.<p> 
     * 
     * @param name the widget parameter name
     * @param index the widget parameter index
     * 
     * @return a from id representation for the given widget name and id
     */
    public static String createId(String name, int index) {

        StringBuffer result = new StringBuffer();
        result.append(name);
        result.append('.');
        result.append(index);

        return result.toString();
    }

    /**
     * "Commits" (writes) the value of this widget back to the underlying base object.<p> 
     * 
     * @param dialog the widget dialog where the parameter is used on
     * 
     * @throws CmsException in case the String value of the widget is invalid for the base Object
     */
    public void commitValue(CmsWidgetDialog dialog) throws CmsException {

        if (m_baseCollection == null) {

            PropertyUtilsBean bean = new PropertyUtilsBean();
            ConvertUtilsBean converter = new ConvertUtilsBean();
            Object value = null;
            try {
                Class type = bean.getPropertyType(m_baseObject, m_baseObjectProperty);
                value = converter.convert(m_value, type);
                bean.setNestedProperty(m_baseObject, m_baseObjectProperty, value);
                setError(null);
            } catch (InvocationTargetException e) {
                setError(e.getTargetException());
                throw new CmsWidgetException(Messages.get().container(
                    Messages.ERR_PROPERTY_WRITE_3,
                    value,
                    dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()),
                    m_baseObject.getClass().getName()), e.getTargetException(), this);
            } catch (Exception e) {
                setError(e);
                throw new CmsWidgetException(Messages.get().container(
                    Messages.ERR_PROPERTY_WRITE_3,
                    value,
                    dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()),
                    m_baseObject.getClass().getName()), e, this);
            }
        } else if (m_baseCollection instanceof SortedMap) {
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_value)) {
                int pos = m_value.indexOf('=');
                if ((pos > 0) && (pos < (m_value.length() - 1))) {
                    String key = m_value.substring(0, pos);
                    String value = m_value.substring(pos + 1);
                    SortedMap map = (SortedMap)m_baseCollection;
                    if (map.containsKey(key)) {
                        Object val = map.get(key);
                        CmsWidgetException error = new CmsWidgetException(Messages.get().container(
                            Messages.ERR_MAP_DUPLICATE_KEY_3,
                            dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()),
                            key,
                            val), this);
                        setError(error);
                        throw error;
                    }
                    map.put(key, value);
                } else {
                    CmsWidgetException error = new CmsWidgetException(Messages.get().container(
                        Messages.ERR_MAP_PARAMETER_FORM_1,
                        dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey())), this);
                    setError(error);
                    throw error;
                }
            }
        } else if (m_baseCollection instanceof List) {
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_value)) {
                List list = (List)m_baseCollection;
                list.add(m_value);
            }
        }
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getDefault(org.opencms.file.CmsObject)
     */
    public String getDefault(CmsObject cms) {

        return m_defaultValue;
    }

    /**
     * Returns the name of the dialog (or dialog page) this widget parameter is used on.<p>
     * 
     * This information can be used to create multi-page dialogs where the 
     * widgets are spread over several pages.<p>
     * 
     * @return the name of the dialog (or dialog page) this widget parameter is used on
     */
    public String getDialogPage() {

        return m_dialogPage;
    }

    /**
     * Returns the Exception caused when this parameter value was commited, or <code>null</code>
     * if error occured.<p> 
     * 
     * @return the Exception caused when this parameter value was commited
     */
    public Throwable getError() {

        return m_error;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getId()
     */
    public String getId() {

        return m_id;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getIndex()
     */
    public int getIndex() {

        return m_index;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getKey()
     */
    public String getKey() {

        StringBuffer result = new StringBuffer(128);
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_prefix)) {
            result.append(m_prefix);
            result.append('.');
        }
        result.append(getName());
        return result.toString();
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getMaxOccurs()
     */
    public int getMaxOccurs() {

        return m_maxOccurs;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getMinOccurs()
     */
    public int getMinOccurs() {

        return m_minOccurs;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getName()
     */
    public String getName() {

        return m_name;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#getStringValue(org.opencms.file.CmsObject)
     */
    public String getStringValue(CmsObject cms) throws CmsRuntimeException {

        return m_value;
    }

    /**
     * Returns the widget for this parameter.<p>
     * 
     * @return the widget for this parameter
     */
    public I_CmsWidget getWidget() {

        return m_widget;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#hasError()
     */
    public boolean hasError() {

        return m_error != null;
    }

    /**
     * Checks if a value for this widget base type with the given id is available.<p>
     * 
     * This should only be used if the base object is a collection.<p>
     * 
     * @param index the index to check
     * 
     * @return <code>true</code> if a value for this widget base type with the given id is available
     */
    public boolean hasValue(int index) {

        if (m_baseCollection instanceof List) {
            return index < ((List)m_baseCollection).size();
        } else if (m_baseCollection instanceof SortedMap) {
            return index < ((SortedMap)m_baseCollection).size();
        }
        return false;
    }

    /**
     * Returns <code>true</code> if this widget parameter is mapped to a Collection base object.<p>
     * 
     * @return <code>true</code> if this widget parameter is mapped to a Collection base object
     */
    public boolean isCollectionBase() {

        return (m_baseCollection != null)
            && ((m_baseCollection instanceof List) || (m_baseCollection instanceof SortedMap));
    }

    /**
     * Prepares this widget dialog parameter to be commited.<p>
     * 
     * This is required if the base type is mapped to a Collection object,
     * becasue the collection needs to be cleared before the new values are set.<p>
     */
    public void prepareCommit() {

        if (m_baseCollection instanceof List) {
            List list = (List)m_baseCollection;
            list.clear();
        } else if (m_baseCollection instanceof SortedMap) {
            SortedMap map = (SortedMap)m_baseCollection;
            map.clear();
        }
    }

    /**
     * Sets the error state of this widget.<p>
     *
     * If the argument is <code>null</code> then the state is set to "no error".<p>
     *
     * @param error the error state to set
     */
    public void setError(Throwable error) {

        m_error = error;
    }

    /**
     * Sets the index to the provided value.<p>
     * 
     * @param index the new index value to set
     */
    public void setindex(int index) {

        m_index = index;
        m_id = createId(m_name, m_index);
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#setKeyPrefix(java.lang.String)
     */
    public void setKeyPrefix(String prefix) {

        m_prefix = prefix;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidgetParameter#setStringValue(org.opencms.file.CmsObject, java.lang.String)
     */
    public void setStringValue(CmsObject cms, String value) throws CmsIllegalArgumentException {

        m_value = value;
    }

    /**
     * Initializes a widget parameter with the given values.<p>
     * 
     * @param value the initial value of the parameter
     * @param defaultValue the default value of the parameter
     * @param name the id of the parameter
     * @param widget the widget used for this parameter
     * @param dialog the dialog this parameter is used on
     * @param minOccurs the required minimum numer of occurences of this parameter
     * @param maxOccurs the maximum allowed numer of occurences of this parameter
     * @param index the index of this parameter in the list 
     */
    protected void init(
        String value,
        String defaultValue,
        String name,
        I_CmsWidget widget,
        String dialog,
        int minOccurs,
        int maxOccurs,
        int index) {

        if (defaultValue == null) {
            m_defaultValue = "";
        } else {
            m_defaultValue = defaultValue;
        }
        if (value == null) {
            m_value = m_defaultValue;
        } else {
            m_value = value;
        }
        m_name = name;
        m_widget = widget;
        if (maxOccurs < MAX_OCCURENCES) {
            m_maxOccurs = maxOccurs;
        } else {
            m_maxOccurs = MAX_OCCURENCES;
        }
        if (minOccurs >= 0) {
            m_minOccurs = minOccurs;
        } else {
            m_minOccurs = 0;
        }
        if (m_minOccurs > m_maxOccurs) {
            m_minOccurs = m_maxOccurs;
        }
        m_dialogPage = dialog;
        m_error = null;

        setindex(index);
    }
}

⌨️ 快捷键说明

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