use of com.qcadoo.view.api.components.FieldComponent 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.FieldComponent 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.FieldComponent 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();
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class SkillOperationDetailsHooks method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity opSkill = form.getEntity();
FieldComponent maxSkillLevelField = (FieldComponent) view.getComponentByReference(MAX_LEVEL);
maxSkillLevelField.setFieldValue(opSkill.getBelongsToField(OperationSkillFields.SKILL).getIntegerField(SkillFields.MAXIMUM_LEVEL));
LookupComponent operationLookup = (LookupComponent) view.getComponentByReference(OperationSkillFields.OPERATION);
FilterValueHolder filterValueHolder = operationLookup.getFilterValue();
Long skillId = opSkill.getBelongsToField(StaffSkillsFields.SKILL).getId();
if (Objects.isNull(skillId)) {
filterValueHolder.remove(L_SKILL_ID);
} else {
filterValueHolder.put(L_SKILL_ID, skillId);
}
operationLookup.setFilterValue(filterValueHolder);
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class TechnologicalProcessComponentDetailsHooks method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
CheckBoxComponent extendedTimeForSizeGroupField = (CheckBoxComponent) view.getComponentByReference(EXTENDED_TIME_FOR_SIZE_GROUP);
FieldComponent increasePercentField = (FieldComponent) view.getComponentByReference(INCREASE_PERCENT);
LookupComponent sizeGroupLookup = (LookupComponent) view.getComponentByReference(SIZE_GROUP);
if (extendedTimeForSizeGroupField.isChecked()) {
increasePercentField.setEnabled(true);
increasePercentField.setRequired(true);
sizeGroupLookup.setEnabled(true);
sizeGroupLookup.setRequired(true);
} else {
increasePercentField.setEnabled(false);
increasePercentField.setFieldValue(null);
increasePercentField.setRequired(false);
sizeGroupLookup.setEnabled(false);
sizeGroupLookup.setFieldValue(null);
sizeGroupLookup.setRequired(false);
}
increasePercentField.requestComponentUpdateState();
sizeGroupLookup.requestComponentUpdateState();
}
Aggregations