Search in sources :

Example 1 with Person

use of com.dala.data.person.Person in project DoodleVerse by davidemarcoli.

the class CitizenManagementView method createEditor.

/**
 * Create the CRUD Editor
 * @return the CrudEditor
 */
private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    NumberField money = new NumberField("Money");
    money.setReadOnly(true);
    Double randomMoneyAmount = rand.nextDouble(100000 + 1 - 10000) + 10000;
    money.setValue(randomMoneyAmount);
    FormLayout form = new FormLayout(firstName, lastName, money);
    form.setColspan(money, 2);
    form.setMaxWidth("480px");
    form.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1), new FormLayout.ResponsiveStep("30em", 2));
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(lastName).asRequired().bind(Person::getLastName, Person::setLastName);
    binder.forField(money).asRequired().bind(Person::getMoney, Person::setMoney).setReadOnly(true);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) Person(com.dala.data.person.Person) NumberField(com.vaadin.flow.component.textfield.NumberField)

Example 2 with Person

use of com.dala.data.person.Person in project DoodleVerse by davidemarcoli.

the class CitizenManagementView method setupToolbar.

/**
 * Setup the grid toolbar
 */
private void setupToolbar() {
    Html total = new Html("<span>Total: <b>" + personRepository.count() + "</b> persons</span>");
    Button button = new Button("New person", VaadinIcon.PLUS.create());
    button.addClickListener(event -> {
        Person newPerson = new Person();
        crud.edit(newPerson, Crud.EditMode.NEW_ITEM);
    });
    button.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
    HorizontalLayout toolbar = new HorizontalLayout(total, button);
    toolbar.setAlignItems(FlexComponent.Alignment.CENTER);
    toolbar.setFlexGrow(1, toolbar);
    toolbar.setJustifyContentMode(FlexComponent.JustifyContentMode.BETWEEN);
    toolbar.setSpacing(false);
    crud.setToolbar(toolbar);
}
Also used : Button(com.vaadin.flow.component.button.Button) Html(com.vaadin.flow.component.Html) Person(com.dala.data.person.Person) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 3 with Person

use of com.dala.data.person.Person in project DoodleVerse by davidemarcoli.

the class FakeGenerator method generateDepartment.

/**
 * Generate random departments
 * @param count the number of randomly generated departments
 * @return the generated departments
 */
public ArrayList<Department> generateDepartment(int count) {
    ArrayList<Department> departments = new ArrayList<>();
    List<Person> persons = personRepository.findAll();
    for (int i = 0; i < count; i++) {
        ArrayList<Department> childDepartments = new ArrayList<>();
        List<Person> departmentWorkers = new ArrayList<>();
        for (int personCount = 0; personCount < MathUtils.getInstance().randomMinMax(1, 5); personCount++) {
            Person person = persons.get(MathUtils.getInstance().randomMinMax(0, persons.size() - 1));
            if (!departmentWorkers.contains(person)) {
                departmentWorkers.add(person);
            }
        }
        if (departmentWorkers.isEmpty()) {
            List<Person> person = personRepository.saveAllAndFlush(generateRandomPersons(MathUtils.getInstance().randomMinMax(1, 5)));
            departmentWorkers.addAll(person);
        }
        for (int j = 0; j < MathUtils.getInstance().randomMinMax(0, 5); j++) {
            departmentWorkers.clear();
            for (int personCount = 0; personCount < MathUtils.getInstance().randomMinMax(1, 5); personCount++) {
                Person person = persons.get(MathUtils.getInstance().randomMinMax(0, persons.size() - 1));
                if (!departmentWorkers.contains(person)) {
                    departmentWorkers.add(person);
                }
            }
            if (departmentWorkers.isEmpty()) {
                List<Person> person = personRepository.saveAllAndFlush(generateRandomPersons(MathUtils.getInstance().randomMinMax(1, 5)));
                departmentWorkers.addAll(person);
            }
            Department childDepartment = new Department(0L, faker.commerce().department(), departmentWorkers, null);
            System.out.println(childDepartment);
            childDepartment = departmentRepository.saveAndFlush(childDepartment);
            childDepartments.add(childDepartment);
        }
        Department department = departmentRepository.saveAndFlush(new Department(0L, faker.commerce().department(), null, childDepartments));
        departments.add(department);
    }
    return departments;
}
Also used : Department(com.dala.data.department.Department) ArrayList(java.util.ArrayList) Person(com.dala.data.person.Person)

Aggregations

Person (com.dala.data.person.Person)3 Department (com.dala.data.department.Department)1 Html (com.vaadin.flow.component.Html)1 Button (com.vaadin.flow.component.button.Button)1 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)1 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 NumberField (com.vaadin.flow.component.textfield.NumberField)1 TextField (com.vaadin.flow.component.textfield.TextField)1 Binder (com.vaadin.flow.data.binder.Binder)1 ArrayList (java.util.ArrayList)1