use of org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor 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.client.ui.form.internal.FindFieldByFormDataIdVisitor 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);
}
}
Aggregations