Search in sources :

Example 1 with BalanceGenerationStrategy

use of com.qcadoo.mes.productionPerShift.BalanceGenerationStrategy in project mes by qcadoo.

the class GenerateBalanceListeners method generateBalance.

public void generateBalance(final ViewDefinitionState viewState, final ComponentState formState, final String[] args) {
    FormComponent form = (FormComponent) formState;
    Entity contextEntity = form.getPersistedEntityWithIncludedFormValues();
    // We don't want to reuse contexts - in case of the user working with many browser tabs to compare a couple of results
    contextEntity.setId(null);
    contextEntity.setField(BalanceContextFields.BALANCES, Collections.<Entity>emptyList());
    // Call validation
    contextEntity = contextEntity.getDataDefinition().save(contextEntity);
    if (!contextEntity.isValid()) {
        form.setEntity(contextEntity);
        return;
    }
    BalanceGenerationStrategy strategy = resolveBalanceGenerationStrategy(contextEntity);
    List<Entity> balances = productionBalancePerShiftGenerator.generate(strategy);
    contextEntity.setField(BalanceContextFields.BALANCES, balances);
    Entity persistedContext = contextEntity.getDataDefinition().save(contextEntity);
    if (persistedContext.isValid()) {
        // Show 'balances' tab
        WindowComponent window = (WindowComponent) viewState.getComponentByReference(QcadooViewConstants.L_WINDOW);
        window.setActiveTab("balances");
    }
    form.setEntity(persistedContext);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) BalanceGenerationStrategy(com.qcadoo.mes.productionPerShift.BalanceGenerationStrategy) WindowComponent(com.qcadoo.view.api.components.WindowComponent)

Aggregations

BalanceGenerationStrategy (com.qcadoo.mes.productionPerShift.BalanceGenerationStrategy)1 Entity (com.qcadoo.model.api.Entity)1 FormComponent (com.qcadoo.view.api.components.FormComponent)1 WindowComponent (com.qcadoo.view.api.components.WindowComponent)1