Search in sources :

Example 1 with AbstractFormFieldData

use of org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData in project scout.rt by eclipse.

the class AbstractForm method importFormField.

private void importFormField(IFormField f, Map<IFormField, AbstractFormFieldData> dataMap, boolean valueChangeTriggersEnabled, IPropertyFilter filter) {
    AbstractFormFieldData data = dataMap.get(f);
    // form field properties
    importProperties(data, f, getFieldStopClass(data), filter);
    // field state
    f.importFormFieldData(data, valueChangeTriggersEnabled);
}
Also used : AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData)

Example 2 with AbstractFormFieldData

use of org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData 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 3 with AbstractFormFieldData

use of org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData 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 4 with AbstractFormFieldData

use of org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData in project scout.rt by eclipse.

the class FormDataStatementBuilder method build.

@SuppressWarnings("cast")
public String build(AbstractFormData formData) {
    m_where = new StringBuilder();
    // build constraints for fields
    for (BasicPartDefinition def : m_basicDefs) {
        if (def.accept(formData)) {
            Map<String, String> parentAliasMap = getAliasMapper().getRootAliases();
            EntityContribution contrib = def.createInstance(this, formData, parentAliasMap);
            String cons = createWhereConstraint(contrib);
            if (cons != null) {
                addWhere(" AND " + cons);
            }
        }
    }
    // build constraints for composer trees
    Map<Integer, Map<String, AbstractFormFieldData>> fieldsBreathFirstMap = formData.getAllFieldsRec();
    for (Map<String, AbstractFormFieldData> map : fieldsBreathFirstMap.values()) {
        for (AbstractFormFieldData f : map.values()) {
            if (f.isValueSet() && f instanceof AbstractTreeFieldData) {
                // composer tree with entity, attribute
                EntityContribution contrib = buildTreeNodes(((AbstractTreeFieldData) f).getRoots(), EntityStrategy.BuildConstraints, AttributeStrategy.BuildConstraintOfAttributeWithContext);
                String cons = createWhereConstraint(contrib);
                if (cons != null) {
                    addWhere(" AND " + cons);
                }
            }
        }
    }
    return getWhereConstraints();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractTreeFieldData(org.eclipse.scout.rt.shared.data.form.fields.treefield.AbstractTreeFieldData) AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AbstractFormFieldData

use of org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData in project scout.rt by eclipse.

the class BasicPartDefinition method createInstance.

/**
 * Override this method to intercept and change part instance properties such as values, operation type, etc.<br>
 * Sometimes it is convenient to set the operation to {@link DataModelConstants#OPERATOR_NONE} which uses the
 * attribute itself as the complete statement part.
 *
 * @param builder
 * @param formData
 *          the form data to be checked.
 * @return the result EntityContribution. null if that part is to be ignored
 *         <p>
 *         normally calls
 *         {@link FormDataStatementBuilder#createSqlPart(Integer, String, int, List, List, boolean, Map)}
 *         <p>
 *         Can make use of alias markers such as @Person@.LAST_NAME, these are resolved in the
 *         {@link FormDataStatementBuilder}
 *         <p>
 *         Only additional bind values - other than the bindValues passed to createStatementPart - must be added using
 *         {@link FormDataStatementBuilder#addBind(String, Object)}
 */
public EntityContribution createInstance(FormDataStatementBuilder builder, AbstractFormData formData, Map<String, String> parentAliasMap) {
    Map<Integer, Map<String, AbstractFormFieldData>> fieldsBreathFirstMap = formData.getAllFieldsRec();
    Map<Integer, Map<String, AbstractPropertyData<?>>> propertiesBreathFirstMap = formData.getAllPropertiesRec();
    ClassIdentifier[] valueTypes = getValueTypeClassIdentifiers();
    /**
     * the form data objects containing the runtime values {@link AbstractFormFieldData} and
     * {@link AbstractPropertyData}
     */
    ArrayList<Object> valueDatas = new ArrayList<Object>(valueTypes.length);
    /**
     * by default the names "a", "b", "c", ... represent the bindValues in the same order as the values
     */
    ArrayList<String> bindNames = new ArrayList<String>(valueTypes.length);
    /**
     * the values of the {@link AbstractFormFieldData}s and {@link AbstractPropertyData}s in the same order
     */
    ArrayList<Object> bindValues = new ArrayList<Object>(valueTypes.length);
    for (int i = 0; i < valueTypes.length; i++) {
        if (AbstractFormFieldData.class.isAssignableFrom(valueTypes[i].getLastSegment())) {
            AbstractFormFieldData field = formData.findFieldByClass(fieldsBreathFirstMap, valueTypes[i]);
            valueDatas.add(field);
            bindNames.add("" + (char) (('a') + i));
            if (field instanceof AbstractValueFieldData<?>) {
                bindValues.add(((AbstractValueFieldData<?>) field).getValue());
            } else {
                bindValues.add(null);
            }
        } else if (AbstractPropertyData.class.isAssignableFrom(valueTypes[i].getLastSegment())) {
            AbstractPropertyData<?> property = formData.findPropertyByClass(propertiesBreathFirstMap, valueTypes[i]);
            valueDatas.add(property);
            bindNames.add("" + (char) (('a') + i));
            bindValues.add(property.getValue());
        } else {
            valueDatas.add(null);
            bindNames.add("" + (char) (('a') + i));
            bindValues.add(null);
        }
    }
    // 
    String wherePart = createInstanceImpl(builder, valueDatas, bindNames, bindValues, parentAliasMap);
    return EntityContribution.create(wherePart);
}
Also used : AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier) ArrayList(java.util.ArrayList) AbstractValueFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData) AbstractPropertyData(org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData) Map(java.util.Map)

Aggregations

AbstractFormFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData)12 Map (java.util.Map)7 HashMap (java.util.HashMap)6 AbstractPropertyData (org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)5 TreeMap (java.util.TreeMap)2 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)2 FindFieldByFormDataIdVisitor (org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor)2 FormDataPropertyFilter (org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter)2 ClassIdentifier (org.eclipse.scout.rt.platform.classid.ClassIdentifier)2 AbstractValueFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AbstractFormField (org.eclipse.scout.rt.client.ui.form.fields.AbstractFormField)1 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)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