Search in sources :

Example 1 with FieldComponent

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;
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 2 with FieldComponent

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);
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 3 with FieldComponent

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);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 4 with FieldComponent

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();
}
Also used : FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 5 with FieldComponent

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);
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) Optional(com.google.common.base.Optional) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) JSONException(org.json.JSONException) BigDecimal(java.math.BigDecimal)

Aggregations

FieldComponent (com.qcadoo.view.api.components.FieldComponent)443 Entity (com.qcadoo.model.api.Entity)201 FormComponent (com.qcadoo.view.api.components.FormComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)107 BigDecimal (java.math.BigDecimal)47 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)31 Date (java.util.Date)30 Optional (com.google.common.base.Optional)18 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)14 ComponentState (com.qcadoo.view.api.ComponentState)13 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)13 WindowComponent (com.qcadoo.view.api.components.WindowComponent)12 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)11 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)9 PossibleUnitConversions (com.qcadoo.model.api.units.PossibleUnitConversions)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)6 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)6 Collectors (java.util.stream.Collectors)6