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);
}
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();
}
}
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);
}
}
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();
}
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);
}
Aggregations