Search in sources :

Example 1 with AbstractValueFieldData

use of org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData 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)

Example 2 with AbstractValueFieldData

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

the class FormDataValidationTest method assertIOFailure.

private static void assertIOFailure(String fieldId, Object expectedValue) throws Exception {
    MyFormData d1 = new MyFormData();
    AbstractValueFieldData<Object> v1 = (AbstractValueFieldData<Object>) d1.getFieldById(fieldId);
    v1.setValue(expectedValue);
    // 
    ByteArrayOutputStream o = new ByteArrayOutputStream();
    ObjectOutputStream oo = new ObjectOutputStream(o);
    oo.writeObject(d1);
    oo.close();
    ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(o.toByteArray()));
    try {
        oi.readObject();
    } catch (SecurityException e) {
        // ok
        return;
    }
    fail("should have failed");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractValueFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with AbstractValueFieldData

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

the class FormDataValidationTest method assertIOSuccess.

private static void assertIOSuccess(String fieldId, Object expectedValue) throws Exception {
    MyFormData d1 = new MyFormData();
    AbstractValueFieldData<Object> v1 = (AbstractValueFieldData<Object>) d1.getFieldById(fieldId);
    v1.setValue(expectedValue);
    // 
    ByteArrayOutputStream o = new ByteArrayOutputStream();
    ObjectOutputStream oo = new ObjectOutputStream(o);
    oo.writeObject(d1);
    oo.close();
    ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(o.toByteArray()));
    MyFormData d2 = (MyFormData) oi.readObject();
    // 
    AbstractValueFieldData<Object> v2 = (AbstractValueFieldData<Object>) d2.getFieldById(fieldId);
    if (expectedValue != null && expectedValue.getClass().isArray()) {
    // nop
    } else {
        assertEquals(expectedValue, v2.getValue());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractValueFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with AbstractValueFieldData

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

the class BasicPartDefinition method accept.

/**
 * Computes whether this {@link BasicPartDefinition} takes part in building the filter criterion.
 *
 * @param formData
 *          the form data to be checked.
 * @return <code>true</code> if the properties in the form data are sufficient in order to append this part to the
 *         result statement This will result in a call to
 *         {@link BasicPartDefinition#createInstanceImpl(FormDataStatementBuilder, List, List, List, Map)} building
 *         that part.
 *         <p>
 *         Default accepts when any of the value of the valueType set is set (isValueSet) and has a non-null value in
 *         the form data
 */
public boolean accept(AbstractFormData formData) {
    Map<Integer, Map<String, AbstractFormFieldData>> fieldsBreathFirstMap = formData.getAllFieldsRec();
    Map<Integer, Map<String, AbstractPropertyData<?>>> propertiesBreathFirstMap = formData.getAllPropertiesRec();
    if (getValueTypeClassIdentifiers().length > 0) {
        for (ClassIdentifier valueType : getValueTypeClassIdentifiers()) {
            Object dataObject = formData.findFieldByClass(fieldsBreathFirstMap, valueType);
            if (dataObject instanceof AbstractFormFieldData) {
                AbstractValueFieldData<?> v = (dataObject instanceof AbstractValueFieldData<?> ? (AbstractValueFieldData<?>) dataObject : null);
                AbstractFormFieldData f = (AbstractFormFieldData) dataObject;
                if (f.isValueSet() && (v == null || v.getValue() != null)) {
                    return true;
                }
            }
            dataObject = formData.findPropertyByClass(propertiesBreathFirstMap, valueType);
            if (dataObject instanceof AbstractPropertyData<?>) {
                AbstractPropertyData<?> p = (AbstractPropertyData<?>) dataObject;
                if (p.isValueSet() && p.getValue() != null) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier) 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

AbstractValueFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Map (java.util.Map)2 ClassIdentifier (org.eclipse.scout.rt.platform.classid.ClassIdentifier)2 AbstractFormFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData)2 AbstractPropertyData (org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)2 ArrayList (java.util.ArrayList)1