Search in sources :

Example 1 with AbstractForm

use of org.eclipse.scout.rt.client.ui.form.AbstractForm in project scout.rt by eclipse.

the class AbstractCompositeField method getReplacingFieldClass.

/**
 * Checks whether the form field with the given class has been replaced by another form field. If so, the replacing
 * form field's class is returned. Otherwise the given class itself.
 *
 * @param c
 * @return Returns the possibly available replacing field class for the given class.
 * @see Replace
 * @since 3.8.2
 */
private <T extends IFormField> Class<? extends T> getReplacingFieldClass(Class<T> c) {
    // 1. check local replacements
    if (m_formFieldReplacements != null) {
        @SuppressWarnings("unchecked") Class<? extends T> replacementFieldClass = (Class<? extends T>) m_formFieldReplacements.get(c);
        if (replacementFieldClass != null) {
            return replacementFieldClass;
        }
    }
    // 2. check global replacements
    IForm form = getForm();
    if (form instanceof AbstractForm) {
        Map<Class<?>, Class<? extends IFormField>> mapping = ((AbstractForm) form).getFormFieldReplacementsInternal();
        if (mapping != null) {
            @SuppressWarnings("unchecked") Class<? extends T> replacementFieldClass = (Class<? extends T>) mapping.get(c);
            if (replacementFieldClass != null) {
                return replacementFieldClass;
            }
        }
    }
    // 3. check parent field replacements (used for templates only. It is less common and therefore checked after global replacements)
    ICompositeField parentField = getParentField();
    while (parentField != null) {
        if (parentField instanceof AbstractCompositeField) {
            Map<Class<?>, Class<? extends IFormField>> parentReplacements = ((AbstractCompositeField) parentField).m_formFieldReplacements;
            if (parentReplacements != null) {
                @SuppressWarnings("unchecked") Class<? extends T> replacementFieldClass = (Class<? extends T>) parentReplacements.get(c);
                if (replacementFieldClass != null) {
                    return replacementFieldClass;
                }
            }
        }
        parentField = parentField.getParentField();
    }
    // 4. field is not replaced
    return c;
}
Also used : IForm(org.eclipse.scout.rt.client.ui.form.IForm) AbstractForm(org.eclipse.scout.rt.client.ui.form.AbstractForm)

Aggregations

AbstractForm (org.eclipse.scout.rt.client.ui.form.AbstractForm)1 IForm (org.eclipse.scout.rt.client.ui.form.IForm)1