use of com.qcadoo.mes.timeGapsPreview.TimeGapsSearchResult in project mes by qcadoo.
the class GenerateTimeGapsListeners method generateTimeGaps.
public void generateTimeGaps(final ViewDefinitionState viewState, final ComponentState formState, final String[] args) throws ParseException {
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(TimeGapsContextFields.TIME_GAPS, Collections.<Entity>emptyList());
// Call validation
contextEntity = contextEntity.getDataDefinition().save(contextEntity);
if (!contextEntity.isValid()) {
clearSummaryFields(contextEntity);
form.setEntity(contextEntity);
return;
}
// Generate & persist results
TimeGapsSearchResult searchResult = performGeneration(contextEntity);
Entity persistedContext = persistResults(contextEntity, searchResult);
if (persistedContext.isValid()) {
// Show 'time gaps' tab
WindowComponent window = (WindowComponent) findComponentByReferenceName(viewState, QcadooViewConstants.L_WINDOW);
window.setActiveTab("timeGaps");
}
form.setEntity(persistedContext);
}
Aggregations