use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class ChangeTechnologyParametersListeners method onChangePerformanceNorm.
public void onChangePerformanceNorm(final ViewDefinitionState view, final ComponentState state, final String[] args) {
CheckBoxComponent changePerformanceNorm = (CheckBoxComponent) state;
FieldComponent standardPerformance = (FieldComponent) view.getComponentByReference(L_STANDARD_PERFORMANCE);
if (changePerformanceNorm.isChecked()) {
standardPerformance.setEnabled(true);
} else {
standardPerformance.setEnabled(false);
standardPerformance.setFieldValue(null);
}
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class TOCDetailsListeners method addUpTheNumberOfWorkstations.
public void addUpTheNumberOfWorkstations(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
int size = form.getPersistedEntityWithIncludedFormValues().getHasManyField(TechnologyOperationComponentFields.WORKSTATIONS).size();
FieldComponent quantityOfWorkstations = (FieldComponent) view.getComponentByReference(TechnologyOperationComponentFields.QUANTITY_OF_WORKSTATIONS);
quantityOfWorkstations.setFieldValue(size);
quantityOfWorkstations.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class OPICDetailsListeners method calculateQuantity.
private void calculateQuantity(final ViewDefinitionState view, final Entity operationProductInComponent) {
Entity technologyInputProductType = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
Entity product = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.PRODUCT);
String givenUnit = operationProductInComponent.getStringField(OperationProductInComponentFields.GIVEN_UNIT);
FieldComponent unitField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.UNIT);
FieldComponent givenQuantityField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.GIVEN_QUANTITY);
if ((Objects.isNull(technologyInputProductType) && Objects.isNull(product)) || Objects.isNull(givenUnit) || givenUnit.isEmpty() || Objects.isNull(givenQuantityField.getFieldValue())) {
return;
}
Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse((String) givenQuantityField.getFieldValue(), view.getLocale());
if (maybeQuantity.isRight()) {
if (maybeQuantity.getRight().isPresent()) {
BigDecimal givenQuantity = maybeQuantity.getRight().get();
if (Objects.nonNull(product)) {
String baseUnit = product.getStringField(ProductFields.UNIT);
if (baseUnit.equals(givenUnit)) {
operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, givenQuantity);
} else {
PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(givenUnit, searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));
if (unitConversions.isDefinedFor(baseUnit)) {
BigDecimal convertedQuantity = unitConversions.convertTo(givenQuantity, baseUnit);
operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, convertedQuantity);
} else {
operationProductInComponent.addError(operationProductInComponent.getDataDefinition().getField(OperationProductInComponentFields.GIVEN_QUANTITY), "technologies.operationProductInComponent.validate.error.missingUnitConversion");
operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, null);
}
}
} else {
operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, givenQuantity);
operationProductInComponent.setField(OperationProductInComponentFields.UNIT, givenUnit);
unitField.setFieldValue(givenUnit);
unitField.requestComponentUpdateState();
}
} else {
operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, null);
}
} else {
operationProductInComponent.setField(OperationProductInComponentFields.QUANTITY, null);
}
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class OPICDetailsListeners method fillUnitForTechnologyType.
private void fillUnitForTechnologyType(ViewDefinitionState view) {
LookupComponent technologyInputProductTypeLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
FieldComponent unitField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.UNIT);
FieldComponent givenUnitField = (FieldComponent) view.getComponentByReference(OperationProductInComponentFields.GIVEN_UNIT);
Entity technologyInputProductType = technologyInputProductTypeLookup.getEntity();
String givenUnit = (String) givenUnitField.getFieldValue();
LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.PRODUCT);
if (productLookup.isEmpty() && Objects.nonNull(technologyInputProductType) && StringUtils.isNoneEmpty(givenUnit)) {
unitField.setFieldValue(givenUnit);
unitField.requestComponentUpdateState();
}
unitService.fillProductUnitBeforeRenderIfEmpty(view, OperationProductInComponentFields.UNIT);
unitService.fillProductUnitBeforeRenderIfEmpty(view, OperationProductInComponentFields.GIVEN_UNIT);
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class OperationDetailsListeners method addUpTheNumberOfWorkstations.
public void addUpTheNumberOfWorkstations(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
int size = form.getPersistedEntityWithIncludedFormValues().getHasManyField(OperationFields.WORKSTATIONS).size();
FieldComponent quantityOfWorkstations = (FieldComponent) view.getComponentByReference(OperationFields.QUANTITY_OF_WORKSTATIONS);
quantityOfWorkstations.setFieldValue(size);
quantityOfWorkstations.requestComponentUpdateState();
}
Aggregations