Search in sources :

Example 1 with AbstractPropertyData

use of org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData 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 AbstractPropertyData

use of org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData in project scout.rt by eclipse.

the class AbstractFormData method collectAllPropertiesRec.

private void collectAllPropertiesRec(AbstractFormFieldData field, Map<Integer, /* level */
Map<String, /* qualified field id */
AbstractPropertyData<?>>> breadthFirstMap, int level, String prefix) {
    Map<String, AbstractPropertyData<?>> /* qualified field id */
    subMap = breadthFirstMap.get(level);
    if (subMap == null) {
        subMap = new HashMap<String, /* qualified field id */
        AbstractPropertyData<?>>();
        breadthFirstMap.put(level, subMap);
    }
    for (AbstractPropertyData<?> prop : field.getAllProperties()) {
        subMap.put(prefix + prop.getClass().getSimpleName(), prop);
    }
    for (AbstractFormFieldData child : field.getFields()) {
        collectAllPropertiesRec(child, breadthFirstMap, level + 1, prefix + child.getFieldId() + FIELD_PATH_DELIM);
    }
}
Also used : AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) AbstractPropertyData(org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)

Example 3 with AbstractPropertyData

use of org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData in project scout.rt by eclipse.

the class AbstractFormFieldData method initConfig.

@Override
protected void initConfig() {
    // add properties
    List<Class<AbstractPropertyData>> configuredPropertyDatas = getConfiguredPropertyDatas();
    Map<Class<? extends AbstractPropertyData>, AbstractPropertyData> propMap = new HashMap<Class<? extends AbstractPropertyData>, AbstractPropertyData>(configuredPropertyDatas.size());
    for (Class<AbstractPropertyData> propertyDataClazz : configuredPropertyDatas) {
        AbstractPropertyData p = ConfigurationUtility.newInnerInstance(this, propertyDataClazz);
        propMap.put(p.getClass(), p);
    }
    // add fields
    List<Class<? extends AbstractFormFieldData>> fieldDataClasses = getConfiguredFieldDatas();
    Map<Class<? extends AbstractFormFieldData>, AbstractFormFieldData> map = new HashMap<Class<? extends AbstractFormFieldData>, AbstractFormFieldData>(fieldDataClasses.size());
    for (Class<? extends AbstractFormFieldData> formFieldDataClazz : fieldDataClasses) {
        AbstractFormFieldData f = ConfigurationUtility.newInnerInstance(this, formFieldDataClazz);
        map.put(f.getClass(), f);
    }
    if (!propMap.isEmpty()) {
        m_propertyMap = propMap;
    }
    if (!map.isEmpty()) {
        m_fieldMap = map;
        Map<Class<?>, Class<? extends AbstractFormFieldData>> replacements = ConfigurationUtility.getReplacementMapping(fieldDataClasses);
        if (!replacements.isEmpty()) {
            m_fieldDataReplacements = replacements;
        }
    }
}
Also used : HashMap(java.util.HashMap) AbstractPropertyData(org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)

Example 4 with AbstractPropertyData

use of org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData in project scout.rt by eclipse.

the class AbstractForm method removeNotSetProperties.

private void removeNotSetProperties(IPropertyHolder dto, Map<String, Object> properties) {
    for (Iterator<String> it = properties.keySet().iterator(); it.hasNext(); ) {
        String propertyId = it.next();
        AbstractPropertyData pd = dto.getPropertyById(propertyId);
        if (pd != null && !pd.isValueSet()) {
            it.remove();
        }
    }
}
Also used : AbstractPropertyData(org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)

Example 5 with AbstractPropertyData

use of org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData 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

AbstractPropertyData (org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)7 AbstractFormFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 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 TreeMap (java.util.TreeMap)1