use of com.qcadoo.view.api.components.FieldComponent in project qcadoo by qcadoo.
the class NumberGeneratorService method checkIfShouldInsertNumber.
/**
* Checks if new entity number should be generated and inserted
*
* @param state
* main view state definition
* @param formFieldReferenceName
* reference name of form
* @param numberFieldReferenceName
* reference name of field into which generated number should be inserted
* @return true if new entity number should be generated and inserted
*/
public boolean checkIfShouldInsertNumber(final ViewDefinitionState state, final String formFieldReferenceName, final String numberFieldReferenceName) {
FormComponent form = (FormComponent) state.getComponentByReference(formFieldReferenceName);
FieldComponent number = (FieldComponent) state.getComponentByReference(numberFieldReferenceName);
if (form.getEntityId() != null) {
// form is already saved
return false;
}
if (StringUtils.isNotBlank((String) number.getFieldValue())) {
// number is already chosen
return false;
}
if (number.isHasError()) {
// there is a validation message for that field
return false;
}
return true;
}
use of com.qcadoo.view.api.components.FieldComponent in project qcadoo by qcadoo.
the class ReplaceCustomTranslationsListeners method replaceCustomTranslations.
public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE);
FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM);
FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO);
String locale = (String) localeField.getFieldValue();
String replaceFrom = (String) replaceFromField.getFieldValue();
String replaceTo = (String) replaceToField.getFieldValue();
if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) {
replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE);
} else {
List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale);
if (customTranslations.isEmpty()) {
replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO);
} else {
int count = 0;
for (Entity customTranslation : customTranslations) {
String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION);
if (translation.contains(replaceFrom)) {
count++;
translation = translation.replace(replaceFrom, replaceTo);
customTranslation.setField(CUSTOM_TRANSLATION, translation);
customTranslation.getDataDefinition().save(customTranslation);
}
}
if (count > 0) {
replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS);
} else {
replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO);
}
}
}
}
use of com.qcadoo.view.api.components.FieldComponent in project qcadoo by qcadoo.
the class DictionaryItemDetailsHooks method disableNameEdit.
public void disableNameEdit(final ViewDefinitionState view) {
FormComponent dictionaryItemForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
FieldComponent nameFieldComponent = (FieldComponent) view.getComponentByReference(DictionaryItemFields.NAME);
if (dictionaryItemForm.getEntityId() == null) {
return;
} else {
nameFieldComponent.setEnabled(false);
}
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class OperationDetailsListenersTNFO method changeNextOperationAfterProducedTypeOperation.
public void changeNextOperationAfterProducedTypeOperation(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) {
FieldComponent nextOperationAfterProducedType = (FieldComponent) viewDefinitionState.getComponentByReference(TechnologyOperationComponentFieldsTNFO.NEXT_OPERATION_AFTER_PRODUCED_TYPE);
FieldComponent nextOperationAfterProducedQuantity = (FieldComponent) viewDefinitionState.getComponentByReference(TechnologyOperationComponentFieldsTNFO.NEXT_OPERATION_AFTER_PRODUCED_QUANTITY);
FieldComponent nextOperationAfterProducedQuantityUNIT = (FieldComponent) viewDefinitionState.getComponentByReference(TechnologyOperationComponentFieldsTNFO.NEXT_OPERATION_AFTER_PRODUCED_QUANTITY_UNIT);
if (nextOperationAfterProducedType.getFieldValue().equals("02specified")) {
nextOperationAfterProducedQuantity.setVisible(true);
nextOperationAfterProducedQuantityUNIT.setVisible(true);
} else {
nextOperationAfterProducedQuantity.setVisible(false);
nextOperationAfterProducedQuantityUNIT.setVisible(false);
}
nextOperationAfterProducedQuantity.requestComponentUpdateState();
}
use of com.qcadoo.view.api.components.FieldComponent in project mes by qcadoo.
the class ProductsToIssueDetailsHooks method fillQuantitiesInAdditionalUnit.
public void fillQuantitiesInAdditionalUnit(final ViewDefinitionState view) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues");
for (FormComponent form : adl.getFormComponents()) {
Entity issue = form.getPersistedEntityWithIncludedFormValues();
FieldComponent quantityField = form.findFieldComponentByName("issueQuantity");
Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse(quantityField.getFieldValue().toString(), LocaleContextHolder.getLocale());
BigDecimal conversion = issue.getDecimalField(IssueFields.CONVERSION);
if (Objects.nonNull(conversion) && maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) {
Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
String unit = product.getStringField(ProductFields.UNIT);
String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
BigDecimal issueQuantity = maybeQuantity.getRight().get();
BigDecimal issuedQuantityAdditionalUnit = calculationQuantityService.calculateAdditionalQuantity(issueQuantity, conversion, Optional.fromNullable(additionalUnit).or(unit));
issue.setField(IssueFields.ISSUE_QUANTITY_ADDITIONAL_UNIT, issuedQuantityAdditionalUnit);
form.setEntity(issue);
}
}
}
Aggregations