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);
}
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);
}
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;
}
Aggregations