use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ProductionTrackingDetailsListeners method disableFields.
public void disableFields(final ViewDefinitionState viewDefinitionState, final ComponentState componentState, final String[] args) {
productionTrackingService.changeProducedQuantityFieldState(viewDefinitionState);
Object recordingTypeValue = viewDefinitionState.getComponentByReference(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING).getFieldValue();
boolean recordingTypeEqualsCumulated = TypeOfProductionRecording.CUMULATED.getStringValue().equals(recordingTypeValue);
boolean recordingTypeEqualsForEach = TypeOfProductionRecording.FOR_EACH.getStringValue().equals(recordingTypeValue);
if (recordingTypeEqualsCumulated || recordingTypeEqualsForEach) {
for (String componentName : Arrays.asList(OrderFieldsPC.REGISTER_QUANTITY_IN_PRODUCT, OrderFieldsPC.REGISTER_QUANTITY_OUT_PRODUCT, OrderFieldsPC.REGISTER_PRODUCTION_TIME, OrderFieldsPC.REGISTER_PIECEWORK)) {
ComponentState component = viewDefinitionState.getComponentByReference(componentName);
component.setEnabled(true);
}
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class AnomalyExplanationDetailsHooks method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity entity = form.getEntity();
if (view.isViewAfterRedirect()) {
initializeFormValues(view, entity);
}
boolean useWaste = ((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked();
LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
productLookup.setEnabled(!useWaste);
view.getComponentByReference("location").setEnabled(!useWaste);
ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
String givenUnit = (String) givenUnitComponent.getFieldValue();
Entity selectedProduct = productLookup.getEntity();
boolean shouldAdditionalUnitBeEnabled = true;
if (selectedProduct != null) {
String selectedProductAdditionalUnit = selectedProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
if (isNotBlank(selectedProductAdditionalUnit) && isNotBlank(givenUnit) && selectedProductAdditionalUnit.equals(givenUnit)) {
shouldAdditionalUnitBeEnabled = false;
}
}
givenUnitComponent.setEnabled(shouldAdditionalUnitBeEnabled);
}
use of com.qcadoo.view.api.ComponentState 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.ComponentState in project mes by qcadoo.
the class TechSubcontractingService method inheritSubcontractingValue.
public void inheritSubcontractingValue(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
ComponentState operationLookup = view.getComponentByReference(OPERATION_FIELD);
if (operationLookup.getFieldValue() == null) {
return;
}
Entity operation = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).get((Long) operationLookup.getFieldValue());
checkArgument(operation != null, "source entity is null");
FieldComponent isSucontractungComponent = (FieldComponent) view.getComponentByReference(IS_SUBCONTRACTING);
isSucontractungComponent.setFieldValue(operation.getField(IS_SUBCONTRACTING));
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class ProductionCountingQuantityAdvancedDetailsHooks method hideTab.
private void hideTab(ViewDefinitionState view) {
ComponentState attributesTab = view.getComponentByReference(ATTRIBUTES);
ComponentState batchesTab = view.getComponentByReference(L_BATCHES_TAB);
FieldComponent roleField = (FieldComponent) view.getComponentByReference(ProductionCountingQuantityFields.ROLE);
FieldComponent materialField = (FieldComponent) view.getComponentByReference(ProductionCountingQuantityFields.TYPE_OF_MATERIAL);
boolean isProduced = checkIfIsProduced((String) roleField.getFieldValue());
boolean isUsedMaterial = checkIfIsUsed((String) roleField.getFieldValue()) && checkIfIsComponent((String) materialField.getFieldValue());
attributesTab.setVisible(isProduced);
batchesTab.setVisible(isUsedMaterial);
}
Aggregations