Skip to content

Commit

Permalink
Merge pull request #102 from XakepSDK/master
Browse files Browse the repository at this point in the history
Pass domain object instance to a FieldProvider
  • Loading branch information
alejandro-du authored Mar 10, 2022
2 parents d54cfa4 + 26b7068 commit 5547660
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected List<HasValueAndElement> buildFields(CrudOperation operation, T domain

if (propertyType != null) {

HasValueAndElement field = buildField(configuration, property, propertyType);
HasValueAndElement field = buildField(configuration, property, propertyType, domainObject);

if (field != null) {
configureField(field, property, fieldCaption, readOnly, configuration);
Expand Down Expand Up @@ -187,18 +187,18 @@ protected List<HasValueAndElement> buildFields(CrudOperation operation, T domain
return fields;
}

protected HasValueAndElement buildField(CrudFormConfiguration configuration, String property, Class<?> propertyType) throws InstantiationException, IllegalAccessException {
protected HasValueAndElement buildField(CrudFormConfiguration configuration, String property, Class<?> propertyType, T domainObject) throws InstantiationException, IllegalAccessException {
HasValueAndElement<?, ?> field;
FieldProvider<?, ?> provider = configuration.getFieldProviders().get(property);
FieldProvider<?, T> provider = (FieldProvider<?, T>) configuration.getFieldProviders().get(property);

if (provider != null) {
field = provider.buildField();
field = provider.buildField(domainObject);
} else {
Class<? extends HasValueAndElement<?, ?>> fieldType = configuration.getFieldTypes().get(property);
if (fieldType != null) {
field = fieldType.newInstance();
} else {
field = new DefaultFieldProvider(propertyType).buildField();
field = new DefaultFieldProvider(propertyType).buildField(domainObject);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
@FunctionalInterface
public interface FieldProvider<C extends Component, T> extends Serializable {

HasValueAndElement buildField();
HasValueAndElement buildField(T t);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public AbstractListingProvider(String caption, Collection<T> items, ComponentRen
}

@Override
public HasValueAndElement<ComponentValueChangeEvent<C, T>, T> buildField() {
public HasValueAndElement<ComponentValueChangeEvent<C, T>, T> buildField(T t) {
C field = buildAbstractListing();
field.setItems(items);
return field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DefaultFieldProvider(Class<?> type) {
}

@Override
public HasValueAndElement buildField() {
public HasValueAndElement buildField(Object t) {
if (Boolean.class.isAssignableFrom(type) || boolean.class == type) {
return new Checkbox();
}
Expand Down

0 comments on commit 5547660

Please sign in to comment.