use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class OrderedProductDetailsHooksSN method disabledFieldWhenOfferIsSelected.
public void disabledFieldWhenOfferIsSelected(final ViewDefinitionState view) {
LookupComponent offerLookup = (LookupComponent) view.getComponentByReference(OrderedProductFieldsSN.OFFER);
Entity offer = offerLookup.getEntity();
FieldComponent pricePerUnitField = (FieldComponent) view.getComponentByReference(OrderedProductFields.PRICE_PER_UNIT);
FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(OrderedProductFields.TOTAL_PRICE);
if (offer == null) {
pricePerUnitField.setEnabled(true);
totalPriceField.setEnabled(true);
} else {
pricePerUnitField.setEnabled(false);
totalPriceField.setEnabled(false);
}
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class ProductionTrackingDetailsHooksTSFPC method disabledSubcontractorFieldForState.
public void disabledSubcontractorFieldForState(final ViewDefinitionState view) {
FormComponent productionTrackingForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
LookupComponent subcontractorLookup = (LookupComponent) view.getComponentByReference(ProductionTrackingFieldsTSFPC.SUBCONTRACTOR);
if (productionTrackingForm.getEntityId() == null) {
return;
}
Entity productionTracking = getProductionTrackingFromDB(productionTrackingForm.getEntityId());
String state = productionTracking.getStringField(ProductionTrackingFields.STATE);
boolean isDraft = ProductionTrackingStateStringValues.DRAFT.equals(state);
boolean isExternalSynchronized = productionTracking.getBooleanField(ProductionTrackingFields.IS_EXTERNAL_SYNCHRONIZED);
subcontractorLookup.setEnabled(isDraft && isExternalSynchronized);
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class TechnologyService method generateTechnologyNumber.
public void generateTechnologyNumber(final ViewDefinitionState view, final ComponentState state, final String[] args) {
if (!(state instanceof FieldComponent)) {
throw new IllegalStateException("Component is not FieldComponentState");
}
FieldComponent numberField = (FieldComponent) view.getComponentByReference(TechnologyFields.NUMBER);
LookupComponent productLookup = (LookupComponent) state;
Entity product = productLookup.getEntity();
if (Objects.isNull(product) || StringUtils.isNotEmpty(Objects.toString(numberField.getFieldValue(), ""))) {
return;
}
numberField.setFieldValue(technologyNameAndNumberGenerator.generateNumber(product));
numberField.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class ModifyTechnologyDetailsHooks method onBeforeRender.
public final void onBeforeRender(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
if (view.isViewAfterRedirect()) {
Entity mt = form.getEntity().getDataDefinition().get(form.getEntityId());
LookupComponent replaceProductLookup = (LookupComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT);
replaceProductLookup.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getId());
replaceProductLookup.requestComponentUpdateState();
String selectedEntities = mt.getStringField(ModifyTechnologyHelperFields.SELECTED_ENTITIES);
List<Long> ids = Lists.newArrayList(selectedEntities.split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
boolean sizeProduct = mt.getBooleanField("sizeProduct");
if (sizeProduct) {
List<Entity> producstBySize = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_PRODUCT_BY_SIZE_GROUP).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
Set<BigDecimal> quantities = producstBySize.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
if (quantities.size() == 1) {
FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
qnt.setFieldValue(quantities.stream().findFirst().get());
qnt.requestComponentUpdateState();
}
} else {
List<Entity> opicDtos = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT_DTO).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
Set<BigDecimal> quantities = opicDtos.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
if (quantities.size() == 1) {
FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
qnt.setFieldValue(quantities.stream().findFirst().get());
qnt.requestComponentUpdateState();
}
}
FieldComponent replaceProductUnit = (FieldComponent) view.getComponentByReference(L_REPLACE_PRODUCT_UNIT);
replaceProductUnit.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getStringField(ProductFields.UNIT));
}
setForm(view);
}
use of com.qcadoo.view.api.components.LookupComponent in project mes by qcadoo.
the class OPICDetailsHooks method setAttributeTabState.
private void setAttributeTabState(ViewDefinitionState view) {
FormComponent operationProductInComponentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
LookupComponent attributeLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.ATTRIBUTE);
if (Objects.isNull(attributeLookup)) {
return;
}
LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OperationProductInComponentFields.PRODUCT);
Entity operationProductInComponent = operationProductInComponentForm.getEntity();
Entity operationComponent = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT);
Entity technology = null;
if (Objects.isNull(operationComponent)) {
technology = operationProductInComponent.getBelongsToField(OperationProductInComponentFields.TECHNOLOGY);
} else {
technology = operationComponent.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
}
Entity technologyProduct = technology.getBelongsToField(TechnologyFields.PRODUCT);
if (ProductFamilyElementType.PRODUCTS_FAMILY.getStringValue().equals(technologyProduct.getField(ProductFields.ENTITY_TYPE)) && Objects.nonNull(productLookup.getEntity()) && ProductFamilyElementType.PRODUCTS_FAMILY.getStringValue().equals(productLookup.getEntity().getField(ProductFields.ENTITY_TYPE))) {
attributeLookup.setEnabled(true);
} else {
attributeLookup.setFieldValue(null);
attributeLookup.setEnabled(false);
}
}
Aggregations