Search in sources :

Example 1 with FormDataPropertyFilter

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

the class AbstractForm method exportFormData.

@Override
public void exportFormData(final AbstractFormData target) {
    // locally declared form properties
    Map<String, Object> properties = BeanUtility.getProperties(this, AbstractForm.class, new FormDataPropertyFilter());
    BeanUtility.setProperties(target, properties, false, null);
    // properties in extensions of form
    exportExtensionProperties(this, target);
    final Set<IFormField> exportedFields = new HashSet<IFormField>();
    // all fields
    Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
    breadthFirstMap = target.getAllFieldsRec();
    for (Map<String, AbstractFormFieldData> /* qualified field id */
    targetMap : breadthFirstMap.values()) {
        for (Map.Entry<String, AbstractFormFieldData> e : targetMap.entrySet()) {
            String fieldQId = e.getKey();
            AbstractFormFieldData data = e.getValue();
            FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
            visitFields(v);
            IFormField f = v.getField();
            if (f != null) {
                // field properties
                properties = BeanUtility.getProperties(f, AbstractFormField.class, new FormDataPropertyFilter());
                BeanUtility.setProperties(data, properties, false, null);
                exportExtensionProperties(f, data);
                // field state
                f.exportFormFieldData(data);
                // remember exported fields
                exportedFields.add(f);
            } else {
                LOG.warn("Cannot find field with id '{}' in form '{}' for DTO '{}'.", fieldQId, getClass().getName(), data.getClass().getName());
            }
        }
    }
    // visit remaining fields (there could be an extension with properties e.g. on a groupbox)
    final Holder<RuntimeException> exHolder = new Holder<>(RuntimeException.class);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
    visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (exportedFields.contains(field)) {
                // already exported -> skip
                return true;
            }
            final IForm formOfField = field.getForm();
            if (formOfField == null) {
                // either form has not been initialized or the field is part of a composite field, that does not override setForminternal -> skip
                LOG.info("Extension properties are not exported for fields on which getForm() returns null. " + "Ensure that the form is initialized and that the field's parent invokes field.setFormInternal(IForm) [exportingForm={}, field={}]", AbstractForm.this.getClass().getName(), field.getClass().getName());
                return true;
            }
            if (formOfField != AbstractForm.this) {
                // field belongs to another form -> skip
                return true;
            }
            try {
                exportExtensionProperties(field, target);
            } catch (RuntimeException e) {
                exHolder.setValue(e);
            } catch (PlatformError e) {
                errorHolder.setValue(e);
            }
            return exHolder.getValue() == null && errorHolder.getValue() == null;
        }
    });
    if (exHolder.getValue() != null) {
        throw exHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : AbstractFormField(org.eclipse.scout.rt.client.ui.form.fields.AbstractFormField) AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) 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) FormDataPropertyFilter(org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) FindFieldByFormDataIdVisitor(org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with FormDataPropertyFilter

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

the class AbstractForm method importFormData.

@Override
public void importFormData(AbstractFormData source, boolean valueChangeTriggersEnabled, IPropertyFilter filter, IFormFieldFilter formFieldFilter) {
    Assertions.assertNotNull(source, "source form data must not be null");
    if (filter == null) {
        filter = new FormDataPropertyFilter();
    }
    // form properties
    importProperties(source, this, AbstractFormData.class, filter);
    // sort fields, first non-slave fields, then slave fields in transitive order
    LinkedList<IFormField> masterList = new LinkedList<IFormField>();
    LinkedList<IFormField> slaveList = new LinkedList<IFormField>();
    HashMap<IFormField, AbstractFormFieldData> dataMap = new HashMap<IFormField, AbstractFormFieldData>();
    // collect fields and split them into masters/slaves
    Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
    breadthFirstMap = source.getAllFieldsRec();
    for (Map<String, AbstractFormFieldData> /* qualified field id */
    sourceMap : breadthFirstMap.values()) {
        for (Map.Entry<String, AbstractFormFieldData> e : sourceMap.entrySet()) {
            String fieldQId = e.getKey();
            AbstractFormFieldData data = e.getValue();
            FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
            visitFields(v);
            IFormField f = v.getField();
            if (f != null) {
                if (formFieldFilter == null || formFieldFilter.accept(f)) {
                    dataMap.put(f, data);
                    if (f.getMasterField() != null) {
                        int index = slaveList.indexOf(f.getMasterField());
                        if (index >= 0) {
                            slaveList.add(index + 1, f);
                        } else {
                            slaveList.addFirst(f);
                        }
                    } else {
                        masterList.add(f);
                    }
                }
            } else {
                LOG.warn("cannot find field data for '{}' in form '{}'.", fieldQId, getClass().getName());
            }
        }
    }
    for (IFormField f : masterList) {
        importFormField(f, dataMap, valueChangeTriggersEnabled, filter);
    }
    for (IFormField f : slaveList) {
        importFormField(f, dataMap, valueChangeTriggersEnabled, filter);
    }
}
Also used : AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) HashMap(java.util.HashMap) FormDataPropertyFilter(org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter) LinkedList(java.util.LinkedList) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) FindFieldByFormDataIdVisitor(org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with FormDataPropertyFilter

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

the class AbstractForm method exportExtensionProperties.

private void exportExtensionProperties(Object o, IPropertyHolder target) {
    if (!(o instanceof IExtensibleObject)) {
        return;
    }
    for (IExtension<?> ex : ((IExtensibleObject) o).getAllExtensions()) {
        Class<?> dto = getDataAnnotationValue(ex.getClass());
        if (dto != null && !Object.class.equals(dto)) {
            Object propertyTarget = target.getContribution(dto);
            Map<String, Object> fieldProperties = BeanUtility.getProperties(ex, AbstractFormField.class, new FormDataPropertyFilter());
            BeanUtility.setProperties(propertyTarget, fieldProperties, false, null);
        }
    }
}
Also used : IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) FormDataPropertyFilter(org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject)

Aggregations

FormDataPropertyFilter (org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)2 FindFieldByFormDataIdVisitor (org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor)2 AbstractFormFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData)2 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 AbstractFormField (org.eclipse.scout.rt.client.ui.form.fields.AbstractFormField)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 IPropertyHolder (org.eclipse.scout.rt.shared.data.form.IPropertyHolder)1