Search in sources :

Example 1 with AbstractCheckList

use of com.storedobject.core.AbstractCheckList in project SODevelopment by syampillai.

the class ProcessCheckList method process.

@Override
protected boolean process() {
    ArrayList<AbstractCheckList> modified = new ArrayList<>();
    AbstractCheckList node;
    Date date;
    boolean completed;
    for (Object[] row : items) {
        if (((DateField) row[1]).isReadOnly()) {
            continue;
        }
        node = (AbstractCheckList) row[0];
        completed = ((Checkbox) row[2]).getValue();
        date = ((DateField) row[1]).getValue();
        if (node.getCompleted() == completed && date.compareTo(node.getCompletedOn()) == 0) {
            continue;
        }
        node.setCompletedOn(date);
        node.setCompleted(completed);
        modified.add(node);
    }
    if (modified.isEmpty()) {
        message("No changes done");
        return true;
    }
    completed = transact(t -> {
        for (AbstractCheckList m : modified) {
            m.save(t);
        }
    });
    if (!completed) {
        return true;
    }
    // noinspection SuspiciousMethodCalls
    items.removeIf(r -> modified.contains(r[0]));
    modified.clear();
    items.removeIf(r -> {
        AbstractCheckList item = (AbstractCheckList) r[0];
        if (item.getCompleted() == item.checkCompleteness()) {
            return true;
        }
        modified.add(item);
        return false;
    });
    transact(t -> {
        for (AbstractCheckList m : modified) {
            m.save(t);
        }
    });
    return true;
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) DateUtility(com.storedobject.core.DateUtility) com.storedobject.ui(com.storedobject.ui) DateField(com.storedobject.vaadin.DateField) GridLayout(com.storedobject.vaadin.GridLayout) AbstractCheckList(com.storedobject.core.AbstractCheckList) HasComponents(com.vaadin.flow.component.HasComponents) DataForm(com.storedobject.vaadin.DataForm) Date(java.sql.Date) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) DateField(com.storedobject.vaadin.DateField) AbstractCheckList(com.storedobject.core.AbstractCheckList) Date(java.sql.Date)

Aggregations

AbstractCheckList (com.storedobject.core.AbstractCheckList)1 DateUtility (com.storedobject.core.DateUtility)1 com.storedobject.ui (com.storedobject.ui)1 DataForm (com.storedobject.vaadin.DataForm)1 DateField (com.storedobject.vaadin.DateField)1 GridLayout (com.storedobject.vaadin.GridLayout)1 HasComponents (com.vaadin.flow.component.HasComponents)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 Date (java.sql.Date)1 ArrayList (java.util.ArrayList)1