use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class AbstractForm method interceptInitConfig.
protected final void interceptInitConfig() {
final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class, null);
final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class, null);
m_objectExtensions.initConfig(createLocalExtension(), new Runnable() {
@Override
public void run() {
try {
initConfig();
} catch (RuntimeException e) {
exceptionHolder.setValue(e);
} catch (PlatformError e) {
errorHolder.setValue(e);
}
}
});
if (exceptionHolder.getValue() != null) {
throw exceptionHolder.getValue();
} else if (errorHolder.getValue() != null) {
throw errorHolder.getValue();
}
}
use of org.eclipse.scout.rt.platform.holders.Holder 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.platform.holders.Holder in project scout.rt by eclipse.
the class AbstractForm method getClientPartOfExtensionOrContributionRec.
private Object getClientPartOfExtensionOrContributionRec(final Object extToSearch, Object owner) {
Object ext = getClientPartOfExtensionOrContribution(extToSearch, owner);
if (ext != null) {
return ext;
}
// search for the extension in the children
final IHolder<Object> result = new Holder<Object>(Object.class);
IFormFieldVisitor visitor = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
result.setValue(getClientPartOfExtensionOrContribution(extToSearch, field));
return result.getValue() == null;
}
};
if (owner instanceof IForm) {
((IForm) owner).visitFields(visitor);
} else if (owner instanceof IFormField) {
((IFormField) owner).acceptVisitor(visitor, 0, 0, true);
}
return result.getValue();
}
use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class CompositeFieldUtility method getFieldById.
public static <T extends IFormField> T getFieldById(ICompositeField compositeField, final String id, final Class<T> type) {
// check local moved fields
T movedField = getMovedFieldById(compositeField, id, type);
if (movedField != null) {
return movedField;
}
// visit child fields
final Holder<T> found = new Holder<T>(type);
IFormFieldVisitor v = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (type.isAssignableFrom(field.getClass()) && field.getFieldId().equals(id)) {
found.setValue(type.cast(field));
} else if (field instanceof ICompositeField) {
T movedFieldById = getMovedFieldById((ICompositeField) field, id, type);
if (movedFieldById != null) {
found.setValue(movedFieldById);
}
}
return found.getValue() == null;
}
};
compositeField.visitFields(v);
return found.getValue();
}
use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class CompositeFieldUtility method getFieldByClass.
public static <T extends IFormField> T getFieldByClass(ICompositeField compositeField, final Class<T> formFieldClass) {
// check local moved fields
IFormField movedField = getMovedFieldByClass(compositeField, formFieldClass);
if (movedField != null) {
return formFieldClass.cast(movedField);
}
// visit child fields
final Holder<T> found = new Holder<T>(formFieldClass);
IFormFieldVisitor v = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field.getClass() == formFieldClass) {
found.setValue(formFieldClass.cast(field));
} else if (field instanceof ICompositeField) {
T movedFieldByClass = getMovedFieldByClass((ICompositeField) field, formFieldClass);
if (movedFieldByClass != null) {
found.setValue(movedFieldByClass);
}
}
return found.getValue() == null;
}
};
compositeField.visitFields(v);
return found.getValue();
}
Aggregations