Search in sources :

Example 1 with IPropertyFilter

use of org.eclipse.scout.rt.platform.reflect.IPropertyFilter in project scout.rt by eclipse.

the class AbstractForm method storeToXml.

@Override
public void storeToXml(Element root) {
    root.setAttribute("formId", getFormId());
    root.setAttribute("formQname", getClass().getName());
    // add custom properties
    Element xProps = root.getOwnerDocument().createElement("properties");
    root.appendChild(xProps);
    IPropertyFilter filter = new IPropertyFilter() {

        @Override
        public boolean accept(FastPropertyDescriptor descriptor) {
            if (descriptor.getPropertyType().isInstance(IFormField.class)) {
                return false;
            }
            if (!descriptor.getPropertyType().isPrimitive() && !Serializable.class.isAssignableFrom(descriptor.getPropertyType())) {
                return false;
            }
            if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) {
                return false;
            }
            return true;
        }
    };
    Map<String, Object> props = BeanUtility.getProperties(this, AbstractForm.class, filter);
    storePropertiesToXml(xProps, props);
    // add extension properties
    for (IExtension<?> ex : getAllExtensions()) {
        Map<String, Object> extensionProps = BeanUtility.getProperties(ex, AbstractFormExtension.class, filter);
        if (extensionProps.isEmpty()) {
            continue;
        }
        Element xExtension = root.getOwnerDocument().createElement("extension");
        xProps.appendChild(xExtension);
        xExtension.setAttribute("extensionId", ex.getClass().getSimpleName());
        xExtension.setAttribute("extensionQname", ex.getClass().getName());
        storePropertiesToXml(xExtension, extensionProps);
    }
    // add fields
    final Element xFields = root.getOwnerDocument().createElement("fields");
    root.appendChild(xFields);
    final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
    P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field.getForm() != AbstractForm.this) {
                // field is part of a wrapped form and is handled by the AbstractWrappedFormField
                return true;
            }
            Element xField = xFields.getOwnerDocument().createElement("field");
            try {
                field.storeToXml(xField);
                xFields.appendChild(xField);
            } catch (RuntimeException e) {
                exceptionHolder.setValue(e);
                return false;
            } catch (PlatformError e) {
                errorHolder.setValue(e);
                return false;
            }
            return true;
        }
    };
    visitFields(v);
    if (exceptionHolder.getValue() != null) {
        throw exceptionHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : IHtmlListElement(org.eclipse.scout.rt.platform.html.IHtmlListElement) Element(org.w3c.dom.Element) IHolder(org.eclipse.scout.rt.platform.holders.IHolder) IPropertyHolder(org.eclipse.scout.rt.shared.data.form.IPropertyHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) FastPropertyDescriptor(org.eclipse.scout.rt.platform.reflect.FastPropertyDescriptor) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) IPropertyFilter(org.eclipse.scout.rt.platform.reflect.IPropertyFilter)

Aggregations

IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)1 Holder (org.eclipse.scout.rt.platform.holders.Holder)1 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)1 IHtmlListElement (org.eclipse.scout.rt.platform.html.IHtmlListElement)1 FastPropertyDescriptor (org.eclipse.scout.rt.platform.reflect.FastPropertyDescriptor)1 IPropertyFilter (org.eclipse.scout.rt.platform.reflect.IPropertyFilter)1 IPropertyHolder (org.eclipse.scout.rt.shared.data.form.IPropertyHolder)1 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)1 Element (org.w3c.dom.Element)1