use of com.qcadoo.view.api.components.FormComponent 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.FormComponent 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);
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class OperationDetailsHooks method disableWorkstationsTabFieldsIfOperationIsNotSaved.
private void disableWorkstationsTabFieldsIfOperationIsNotSaved(ViewDefinitionState view) {
FormComponent operationForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
GridComponent workstations = (GridComponent) view.getComponentByReference(OperationFields.WORKSTATIONS);
if (operationForm.getEntityId() == null) {
changedEnabledFields(view, L_WORKSTATIONS_TAB_FIELDS, false);
changeEnabledLookups(view, L_WORKSTATIONS_TAB_LOOKUPS, Lists.newArrayList(""));
workstations.setEnabled(false);
} else {
changedEnabledFields(view, L_WORKSTATIONS_TAB_FIELDS, true);
changeEnabledLookups(view, L_WORKSTATIONS_TAB_LOOKUPS, L_WORKSTATIONS_TAB_LOOKUPS);
workstations.setEnabled(true);
setWorkstationsTabFields(view);
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class OperationSkillDetailsHooks method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
FormComponent operationSkillForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
LookupComponent skillLookup = (LookupComponent) view.getComponentByReference(OperationSkillFields.SKILL);
Entity operationSkill = operationSkillForm.getEntity();
Entity operation = operationSkill.getBelongsToField(OperationSkillFields.OPERATION);
filterSkillLookup(skillLookup, operation);
fillMaxSkill(view, skillLookup);
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class TechnologyDetailsHooks method disableFieldTechnologyFormAndEnabledMaster.
public void disableFieldTechnologyFormAndEnabledMaster(final ViewDefinitionState view) {
FormComponent technologyForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
FieldComponent masterField = (FieldComponent) view.getComponentByReference(TechnologyFields.MASTER);
LookupComponent technologyGroupLookup = (LookupComponent) view.getComponentByReference(TechnologyFields.TECHNOLOGY_GROUP);
boolean disabled = false;
boolean masterDisabled = false;
boolean technologyGroupEnabled = false;
Long technologyId = technologyForm.getEntityId();
if (Objects.nonNull(technologyId)) {
Entity technology = getTechnologyDD().get(technologyId);
if (Objects.isNull(technology)) {
return;
}
String state = technology.getStringField(TechnologyFields.STATE);
boolean isTemplateAccepted = technology.getBooleanField(TechnologyFields.IS_TEMPLATE_ACCEPTED);
if (isTemplateAccepted || !TechnologyState.DRAFT.getStringValue().equals(state)) {
disabled = true;
}
if (TechnologyState.ACCEPTED.getStringValue().equals(state)) {
masterDisabled = true;
}
if (TechnologyState.ACCEPTED.getStringValue().equals(state) || TechnologyState.CHECKED.getStringValue().equals(state) || TechnologyState.DRAFT.getStringValue().equals(state)) {
technologyGroupEnabled = true;
}
}
technologyForm.setFormEnabled(!disabled);
masterField.setEnabled(masterDisabled);
masterField.requestComponentUpdateState();
technologyGroupLookup.setEnabled(technologyGroupEnabled);
technologyGroupLookup.requestComponentUpdateState();
}
Aggregations