Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed May 26, 2017
1 parent a6a5594 commit 5604fe2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static DocumentLayoutElementDescriptor.Builder createLayoutElement(final
.addField(DocumentLayoutElementFieldDescriptor.builder(fieldDescriptor.getFieldName())
.setLookupSource(fieldDescriptor.getLookupSourceType())
.setPublicField(true)
.setSupportZoomInto(fieldDescriptor.getWidgetType().isSupportZoomInto()));
.setSupportZoomInto(fieldDescriptor.isSupportZoomInto()));
}

private static class AddressDataBindingDescriptorBuilder implements DocumentEntityDataBindingDescriptorBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private static DocumentLayoutElementDescriptor.Builder createLayoutElement(final
.addField(DocumentLayoutElementFieldDescriptor.builder(fieldDescriptor.getFieldName())
.setLookupSource(fieldDescriptor.getLookupSourceType())
.setPublicField(true)
.setSupportZoomInto(fieldDescriptor.getWidgetType().isSupportZoomInto()));
.setSupportZoomInto(fieldDescriptor.isSupportZoomInto()));
}

private static class ASIDataBindingDescriptorBuilder implements DocumentEntityDataBindingDescriptorBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public Builder addElement(final DocumentFieldDescriptor processParaDescriptor)
.addField(DocumentLayoutElementFieldDescriptor.builder(processParaDescriptor.getFieldName())
.setLookupSource(processParaDescriptor.getLookupSourceType())
.setPublicField(true)
.setSupportZoomInto(processParaDescriptor.getWidgetType().isSupportZoomInto()))
.setSupportZoomInto(processParaDescriptor.isSupportZoomInto()))
.build();

addElement(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public static final Builder builder(final String fieldName)
private final Class<?> valueClass;

private final LookupDescriptorProvider lookupDescriptorProvider;

private final boolean supportZoomInto;

private final boolean virtualField;
private final Optional<IDocumentFieldValueProvider> virtualFieldValueProvider;

Expand All @@ -114,12 +115,12 @@ public static enum Characteristic
, SpecialField_DocumentNo //
, SpecialField_DocStatus //
, SpecialField_DocAction //
// , SpecialField_DocumentSummary //
// , SpecialField_DocumentSummary //
;
};

private static final List<Characteristic> SPECIALFIELDS_ToExcludeFromLayout = ImmutableList.of(
// Characteristic.SpecialField_DocumentNo // NOP, don't exclude it (see https://github.com/metasfresh/metasfresh-webui-api/issues/291 )
// Characteristic.SpecialField_DocumentNo // NOP, don't exclude it (see https://github.com/metasfresh/metasfresh-webui-api/issues/291 )
Characteristic.SpecialField_DocStatus //
, Characteristic.SpecialField_DocAction //
// , SpecialField_DocumentSummary // NOP, don't exclude DocumentSummary because if it's layout it shall be editable at least when new (e.g. C_BPartner.Name)
Expand Down Expand Up @@ -153,9 +154,10 @@ private DocumentFieldDescriptor(final Builder builder)
valueClass = builder.getValueClass();

lookupDescriptorProvider = builder.getLookupDescriptorProvider();
supportZoomInto = builder.isSupportZoomInto();

defaultValueExpression = Preconditions.checkNotNull(builder.defaultValueExpression, "defaultValueExpression not null");

virtualField = builder.isVirtualField();
virtualFieldValueProvider = builder.getVirtualFieldValueProvider();

Expand Down Expand Up @@ -194,7 +196,7 @@ public ITranslatableString getCaption()
{
return caption;
}

public ITranslatableString getDescription()
{
return description;
Expand All @@ -219,7 +221,7 @@ public boolean isVirtualField()
{
return virtualField;
}

public Optional<IDocumentFieldValueProvider> getVirtualFieldValueProvider()
{
return virtualFieldValueProvider;
Expand All @@ -234,7 +236,7 @@ public DocumentFieldWidgetType getWidgetType()
{
return widgetType;
}

public ButtonFieldActionDescriptor getButtonActionDescriptor()
{
return buttonActionDescriptor;
Expand All @@ -244,7 +246,12 @@ public Class<?> getValueClass()
{
return valueClass;
}


public boolean isSupportZoomInto()
{
return supportZoomInto;
}

public LookupDescriptor getLookupDescriptor(final LookupScope scope)
{
return lookupDescriptorProvider.provideForScope(scope);
Expand All @@ -255,12 +262,12 @@ public LookupSource getLookupSourceType()
final LookupDescriptor lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupScope.DocumentField);
return lookupDescriptor == null ? null : lookupDescriptor.getLookupSourceType();
}

public Optional<String> getLookupTableName()
{
return extractLookupTableName(lookupDescriptorProvider);
}

private static final Optional<String> extractLookupTableName(final LookupDescriptorProvider lookupDescriptorProvider)
{
final LookupDescriptor lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupScope.DocumentField);
Expand Down Expand Up @@ -466,7 +473,7 @@ else if (Integer.class == fromType || int.class == fromType)
else if (Boolean.class == targetType)
{
final Object valueToConv;
if(value instanceof StringLookupValue)
if (value instanceof StringLookupValue)
{
// If String lookup value then consider only the Key.
// usage example 1: the Posted column which can be Y, N and some other error codes.
Expand All @@ -478,7 +485,7 @@ else if (Boolean.class == targetType)
{
valueToConv = value;
}

@SuppressWarnings("unchecked")
final T valueConv = (T)DisplayType.toBoolean(valueToConv, Boolean.FALSE);
return valueConv;
Expand All @@ -490,8 +497,8 @@ else if (IntegerLookupValue.class == targetType)
@SuppressWarnings("unchecked")
final Map<String, String> map = (Map<String, String>)value;
final IntegerLookupValue lookupValue = JSONLookupValue.integerLookupValueFromJsonMap(map);
if(Check.isEmpty(lookupValue.getDisplayName(), true) && lookupDataSource != null)

if (Check.isEmpty(lookupValue.getDisplayName(), true) && lookupDataSource != null)
{
// corner case: the frontend sent a lookup value like '{ 1234567 : "" }'
// => we need to resolve the name against the lookup
Expand Down Expand Up @@ -535,6 +542,7 @@ else if (String.class == fromType)
}
else if (StringLookupValue.class == fromType)
{
// TODO: implement https://github.com/metasfresh/metasfresh-webui-api/issues/417
final StringLookupValue stringLookupValue = (StringLookupValue)value;
@SuppressWarnings("unchecked")
final T valueConv = (T)IntegerLookupValue.of(stringLookupValue);
Expand All @@ -547,9 +555,9 @@ else if (StringLookupValue.class == targetType)
{
@SuppressWarnings("unchecked")
final Map<String, String> map = (Map<String, String>)value;
StringLookupValue lookupValue = JSONLookupValue.stringLookupValueFromJsonMap(map);
if(Check.isEmpty(lookupValue.getDisplayName(), true) && lookupDataSource != null)
final StringLookupValue lookupValue = JSONLookupValue.stringLookupValueFromJsonMap(map);

if (Check.isEmpty(lookupValue.getDisplayName(), true) && lookupDataSource != null)
{
// corner case: the frontend sent a lookup value like '{ "someKey" : "" }'
// => we need to resolve the name against the lookup
Expand Down Expand Up @@ -588,7 +596,7 @@ else if (IntegerLookupValue.class == fromType)
return valueConv;
}
}
else if(ITableRecordReference.class.isAssignableFrom(targetType))
else if (ITableRecordReference.class.isAssignableFrom(targetType))
{
@SuppressWarnings("unchecked")
final T valueConv = (T)convertToTableRecordReference(fieldName, value, widgetType, targetType, lookupDataSource);
Expand All @@ -599,29 +607,28 @@ else if(ITableRecordReference.class.isAssignableFrom(targetType))
{
throw new AdempiereException("Failed converting " + fieldName + "'s value '" + value + "' (" + fromType + ") to " + targetType
+ "\n LookupDataSource: " + lookupDataSource //
+ "\n Widget type: " + widgetType
, e);
+ "\n Widget type: " + widgetType, e);
}

throw new AdempiereException("Cannot convert " + fieldName + "'s value '" + value + "' (" + fromType + ") to " + targetType
+ "\n LookupDataSource: " + lookupDataSource //
);
}

private static final ITableRecordReference convertToTableRecordReference(
final String fieldName //
, final Object value //
, final DocumentFieldWidgetType widgetType //
, final Class<?> targetType //
, @NonNull final LookupValueByIdSupplier lookupDataSource //
)
)
{
final IntegerLookupValue lookupValue = convertToValueClass(fieldName, value, widgetType, IntegerLookupValue.class, lookupDataSource);
if(lookupValue == null)
if (lookupValue == null)
{
return null;
}

return lookupDataSource.toTableRecordReference(lookupValue.getIdAsInt());
}

Expand Down Expand Up @@ -815,14 +822,14 @@ public Builder setVirtualField(final boolean virtualField)
{
assertNotBuilt();
this.virtualField = virtualField;
this.virtualFieldValueProvider = Optional.empty();
virtualFieldValueProvider = Optional.empty();
return this;
}

public Builder setVirtualField(@NonNull final IDocumentFieldValueProvider virtualFieldValueProvider)
{
assertNotBuilt();
this.virtualField = true;
virtualField = true;
this.virtualFieldValueProvider = Optional.of(virtualFieldValueProvider);
return this;
}
Expand All @@ -831,7 +838,7 @@ public boolean isVirtualField()
{
return virtualField;
}

private Optional<IDocumentFieldValueProvider> getVirtualFieldValueProvider()
{
return virtualFieldValueProvider;
Expand All @@ -843,10 +850,10 @@ public Builder setCalculated(final boolean calculated)
this.calculated = calculated;
return this;
}

private boolean isCalculated()
{
if(isVirtualField())
if (isVirtualField())
{
return true;
}
Expand All @@ -856,7 +863,7 @@ private boolean isCalculated()
public Builder setWidgetType(final DocumentFieldWidgetType widgetType)
{
assertNotBuilt();
this._widgetType = widgetType;
_widgetType = widgetType;
return this;
}

Expand Down Expand Up @@ -896,7 +903,7 @@ public LookupSource getLookupSourceType()
final LookupDescriptor lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupScope.DocumentField);
return lookupDescriptor == null ? null : lookupDescriptor.getLookupSourceType();
}

public Optional<String> getLookupTableName()
{
return extractLookupTableName(lookupDescriptorProvider);
Expand All @@ -905,7 +912,7 @@ public Optional<String> getLookupTableName()
public Builder setValueClass(final Class<?> valueClass)
{
assertNotBuilt();
this._valueClass = valueClass;
_valueClass = valueClass;
return this;
}

Expand Down Expand Up @@ -1226,9 +1233,9 @@ private DocumentFieldDependencyMap buildDependencies()
{
dependencyMapBuilder.add(fieldName, lookupDescriptor.getDependsOnFieldNames(), DependencyType.LookupValues);
}

final IDocumentFieldValueProvider virtualFieldValueProvider = getVirtualFieldValueProvider().orElse(null);
if(virtualFieldValueProvider != null)
if (virtualFieldValueProvider != null)
{
dependencyMapBuilder.add(fieldName, virtualFieldValueProvider.getDependsOnFieldNames(), DependencyType.FieldValue);
}
Expand Down Expand Up @@ -1260,16 +1267,33 @@ private ImmutableList<IDocumentFieldCallout> buildCallouts()
{
return ImmutableList.copyOf(callouts);
}
public Builder setButtonActionDescriptor(ButtonFieldActionDescriptor buttonActionDescriptor)

public Builder setButtonActionDescriptor(final ButtonFieldActionDescriptor buttonActionDescriptor)
{
this.buttonActionDescriptor = buttonActionDescriptor;
return this;
}

public ButtonFieldActionDescriptor getButtonActionDescriptor()
{
return buttonActionDescriptor;
}

public boolean isSupportZoomInto()
{
final DocumentFieldWidgetType widgetType = getWidgetType();
if (!widgetType.isSupportZoomInto())
{
return false;
}

final String lookupTableName = getLookupTableName().orElse(null);
if (WindowConstants.TABLENAME_AD_Ref_List.equals(lookupTableName))
{
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static final Builder builder(final DocumentFieldDescriptor... fields)
.setPublicField(true)
.setLookupSource(field.getLookupSourceType())
.setLookupTableName(field.getLookupTableName())
.setSupportZoomInto(field.getWidgetType().isSupportZoomInto()));
.setSupportZoomInto(field.isSupportZoomInto()));
}

return elementBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import de.metas.logging.LogManager;
import de.metas.ui.web.quickinput.QuickInputDescriptorFactoryService;
import de.metas.ui.web.view.descriptor.ViewLayout;
import de.metas.ui.web.window.WindowConstants;
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor;
Expand Down Expand Up @@ -630,17 +629,10 @@ private final DocumentLayoutElementFieldDescriptor.Builder layoutElementField(fi
field.addCharacteristic(Characteristic.PublicField);
}

boolean supportZoomInfo = field.getWidgetType().isSupportZoomInto();
final String lookupTableName = field.getLookupTableName().orElse(null);
if (WindowConstants.TABLENAME_AD_Ref_List.equals(lookupTableName))
{
supportZoomInfo = false;
}

final DocumentLayoutElementFieldDescriptor.Builder layoutElementFieldBuilder = DocumentLayoutElementFieldDescriptor.builder(fieldName)
.setLookupSource(field.getLookupSourceType())
.setPublicField(field.hasCharacteristic(Characteristic.PublicField))
.setSupportZoomInto(supportZoomInfo)
.setSupportZoomInto(field.isSupportZoomInto())
.trackField(field);

logger.trace("Built layout element field for {}: {}", field, layoutElementFieldBuilder);
Expand Down

0 comments on commit 5604fe2

Please sign in to comment.