Skip to content

Commit

Permalink
Refactored with @teosarca to better align with clean code principles
Browse files Browse the repository at this point in the history
invoice quick input #576
  • Loading branch information
metas-ts committed Sep 18, 2017
1 parent 78cf897 commit 0edfd97
Showing 1 changed file with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.metas.ui.web.window.descriptor.DetailId;
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Builder;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor;
Expand Down Expand Up @@ -69,21 +70,36 @@ public QuickInputDescriptor createQuickInputEntityDescriptor(final DocumentType
return QuickInputDescriptor.of(entityDescriptor, layout, OrderLineQuickInputProcessor.class);
}

private DocumentEntityDescriptor createEntityDescriptor(final DocumentType documentType, final DocumentId documentTypeId, final DetailId detailId)
private static DocumentEntityDescriptor createEntityDescriptor(
final DocumentType documentType,
final DocumentId documentTypeId,
final DetailId detailId)
{
final IMsgBL msgBL = Services.get(IMsgBL.class);
final DocumentEntityDescriptor.Builder descriptorBuilder = createDescriptorBuilder(documentTypeId, detailId);

descriptorBuilder.addField(createProductFieldBuilder());
descriptorBuilder.addField(createPackingInstructionFieldBuilder());
descriptorBuilder.addField(createQuantityFieldBuilder());

return descriptorBuilder.build();
}

private static DocumentEntityDescriptor.Builder createDescriptorBuilder(final DocumentId documentTypeId, final DetailId detailId)
{
final DocumentEntityDescriptor.Builder entityDescriptor = DocumentEntityDescriptor.builder()
.setDocumentType(DocumentType.QuickInput, documentTypeId)
.disableDefaultTableCallouts()
// Defaults:
.setDetailId(detailId)
.setTableName(I_C_OrderLine.Table_Name) // TODO: figure out if it's needed
//
;
return entityDescriptor;
}

entityDescriptor.addField(DocumentFieldDescriptor.builder(IOrderLineQuickInput.COLUMNNAME_M_Product_ID)
.setCaption(msgBL.translatable(IOrderLineQuickInput.COLUMNNAME_M_Product_ID))
private static Builder createProductFieldBuilder()
{
final Builder productFieldBuilder = DocumentFieldDescriptor.builder(IOrderLineQuickInput.COLUMNNAME_M_Product_ID)
.setCaption(Services.get(IMsgBL.class).translatable(IOrderLineQuickInput.COLUMNNAME_M_Product_ID))
//
.setWidgetType(DocumentFieldWidgetType.Lookup)
.setLookupDescriptorProvider(SqlLookupDescriptor.builder()
Expand All @@ -97,10 +113,29 @@ private DocumentEntityDescriptor createEntityDescriptor(final DocumentType docum
.setMandatoryLogic(ILogicExpression.TRUE)
.setDisplayLogic(ILogicExpression.TRUE)
.addCallout(OrderLineQuickInputDescriptorFactory::onProductChangedCallout)
.addCharacteristic(Characteristic.PublicField));
.addCharacteristic(Characteristic.PublicField);
return productFieldBuilder;
}

private static void onProductChangedCallout(final ICalloutField calloutField)
{
final QuickInput quickInput = QuickInput.getQuickInputOrNull(calloutField);
if (quickInput == null)
{
return;
}

final IOrderLineQuickInput quickInputModel = quickInput.getQuickInputDocumentAs(IOrderLineQuickInput.class);
final I_M_Product quickInputProduct = quickInputModel.getM_Product();

final I_C_Order order = quickInput.getRootDocumentAs(I_C_Order.class);
Services.get(IHUOrderBL.class).findM_HU_PI_Item_Product(order, quickInputProduct, quickInputModel::setM_HU_PI_Item_Product);
}

entityDescriptor.addField(DocumentFieldDescriptor.builder(IOrderLineQuickInput.COLUMNNAME_M_HU_PI_Item_Product_ID)
.setCaption(msgBL.translatable(IOrderLineQuickInput.COLUMNNAME_M_HU_PI_Item_Product_ID))
private static Builder createPackingInstructionFieldBuilder()
{
final Builder packingInstructionFieldBuilder = DocumentFieldDescriptor.builder(IOrderLineQuickInput.COLUMNNAME_M_HU_PI_Item_Product_ID)
.setCaption(Services.get(IMsgBL.class).translatable(IOrderLineQuickInput.COLUMNNAME_M_HU_PI_Item_Product_ID))
//
.setWidgetType(DocumentFieldWidgetType.Lookup)
.setLookupDescriptorProvider(SqlLookupDescriptor.builder()
Expand All @@ -113,41 +148,28 @@ private DocumentEntityDescriptor createEntityDescriptor(final DocumentType docum
.setAlwaysUpdateable(true)
.setMandatoryLogic(ILogicExpression.FALSE)
.setDisplayLogic(ILogicExpression.TRUE)
.addCharacteristic(Characteristic.PublicField));
.addCharacteristic(Characteristic.PublicField);
return packingInstructionFieldBuilder;
}

entityDescriptor.addField(DocumentFieldDescriptor.builder(IOrderLineQuickInput.COLUMNNAME_Qty)
.setCaption(msgBL.translatable(IOrderLineQuickInput.COLUMNNAME_Qty))
private static Builder createQuantityFieldBuilder()
{
final Builder qtyFieldBuilder = DocumentFieldDescriptor.builder(IOrderLineQuickInput.COLUMNNAME_Qty)
.setCaption(Services.get(IMsgBL.class).translatable(IOrderLineQuickInput.COLUMNNAME_Qty))
.setWidgetType(DocumentFieldWidgetType.Quantity)
.setReadonlyLogic(ILogicExpression.FALSE)
.setAlwaysUpdateable(true)
.setMandatoryLogic(ILogicExpression.TRUE)
.setDisplayLogic(ILogicExpression.TRUE)
.addCharacteristic(Characteristic.PublicField));

return entityDescriptor.build();
.addCharacteristic(Characteristic.PublicField);
return qtyFieldBuilder;
}

private static void onProductChangedCallout(final ICalloutField calloutField)
{
final QuickInput quickInput = QuickInput.getQuickInputOrNull(calloutField);
if (quickInput == null)
{
return;
}

final IOrderLineQuickInput quickInputModel = quickInput.getQuickInputDocumentAs(IOrderLineQuickInput.class);
final I_M_Product quickInputProduct = quickInputModel.getM_Product();

final I_C_Order order = quickInput.getRootDocumentAs(I_C_Order.class);
Services.get(IHUOrderBL.class).findM_HU_PI_Item_Product(order, quickInputProduct, quickInputModel::setM_HU_PI_Item_Product);
}

private QuickInputLayoutDescriptor createLayout(final DocumentEntityDescriptor entityDescriptor)
private static QuickInputLayoutDescriptor createLayout(final DocumentEntityDescriptor entityDescriptor)
{
return QuickInputLayoutDescriptor.build(entityDescriptor, new String[][] {
{ "M_Product_ID", "M_HU_PI_Item_Product_ID" } //
, { "Qty" }
});
}

}

0 comments on commit 0edfd97

Please sign in to comment.