use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class AnomalyExplanationDetailsHooks method initializeFormValues.
private void initializeFormValues(ViewDefinitionState view, Entity entity) {
LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
if (entity.getId() == null) {
Entity anomaly = entity.getBelongsToField(AnomalyExplanationFields.ANOMALY);
Entity anomalyProduct = anomaly.getBelongsToField(AnomalyFields.PRODUCT);
productLookup.setFieldValue(anomalyProduct.getId());
String selectedProductUnit = anomalyProduct.getStringField(ProductFields.UNIT);
String additionalSelectedProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
if (isNotBlank(additionalSelectedProductUnit)) {
givenUnitComponent.setFieldValue(additionalSelectedProductUnit);
} else {
givenUnitComponent.setFieldValue(selectedProductUnit);
}
BigDecimal anomalyUsedQuantity = anomaly.getDecimalField(AnomalyFields.USED_QUANTITY);
view.getComponentByReference("usedQuantity").setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
String additionalAnomalyProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
ComponentState givenQuantityComponent = view.getComponentByReference("givenQuantity");
if (isNotBlank(additionalAnomalyProductUnit)) {
productUnitsConversionService.forProduct(anomalyProduct).fromPrimaryUnit().to(additionalAnomalyProductUnit).convertValue(anomalyUsedQuantity).ifPresent(convertedValue -> {
givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(convertedValue, 0));
});
} else {
givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
}
Entity anomalyLocation = anomaly.getBelongsToField(AnomalyFields.LOCATION);
view.getComponentByReference("location").setFieldValue(ofNullable(anomalyLocation).map(Entity::getId).orElse(null));
}
Entity selectedProduct = productLookup.getEntity();
ComponentState productUnit = view.getComponentByReference("productUnit");
ComponentState usedQuantity = view.getComponentByReference("usedQuantity");
if (selectedProduct != null) {
productUnit.setFieldValue(selectedProduct.getStringField(ProductFields.UNIT));
usedQuantity.setEnabled(true);
} else {
if (((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked()) {
productUnit.setFieldValue(entity.getStringField(AnomalyExplanationFields.GIVEN_UNIT));
} else {
productUnit.setFieldValue(null);
}
usedQuantity.setEnabled(false);
}
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class ProdOutResourceAttrValDetailsHooks method setValueBold.
private void setValueBold(ViewDefinitionState view) {
LookupComponent attributeValueLookup = (LookupComponent) view.getComponentByReference(ProdOutResourceAttrValFields.ATTRIBUTE_VALUE);
attributeValueLookup.setRequired(true);
attributeValueLookup.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class ProdOutResourceAttrValDetailsHooks method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
setValueBold(view);
setFilters(view);
LookupComponent attributeLookup = (LookupComponent) view.getComponentByReference(ProdOutResourceAttrValFields.ATTRIBUTE);
LookupComponent attributeValueLookup = (LookupComponent) view.getComponentByReference(ProdOutResourceAttrValFields.ATTRIBUTE_VALUE);
FieldComponent valueField = (FieldComponent) view.getComponentByReference(ProdOutResourceAttrValFields.VALUE);
if (Objects.nonNull(attributeLookup.getEntity())) {
Entity attribute = attributeLookup.getEntity();
FieldComponent unitField = (FieldComponent) view.getComponentByReference(L_UNIT);
unitField.setFieldValue(attribute.getStringField(AttributeFields.UNIT));
unitField.requestComponentUpdateState();
if (AttributeDataType.CONTINUOUS.getStringValue().equals(attribute.getStringField(AttributeFields.DATA_TYPE))) {
valueField.setVisible(true);
attributeValueLookup.setVisible(false);
} else {
valueField.setVisible(false);
attributeValueLookup.setVisible(true);
}
} else {
valueField.setVisible(false);
attributeValueLookup.setVisible(false);
}
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class WorkstationDetailsListenersPL method clearProductionLine.
public void clearProductionLine(final ViewDefinitionState view, final ComponentState state, final String[] args) {
LookupComponent productionLineLookup = (LookupComponent) view.getComponentByReference("productionLinesLookup");
productionLineLookup.setFieldValue(null);
productionLineLookup.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class UserDetailsHooksPL method setFieldsEnabledForAdmin.
public void setFieldsEnabledForAdmin(final ViewDefinitionState view) {
if (securityService.hasCurrentUserRole("ROLE_ADMIN")) {
LookupComponent lookupComponent = (LookupComponent) view.getComponentByReference(UserFieldsPL.PRODUCTION_LINE);
lookupComponent.setEnabled(true);
lookupComponent.requestComponentUpdateState();
}
}
Aggregations