Skip to content

Commit

Permalink
Fix formatting. Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-du committed Mar 10, 2022
1 parent 5547660 commit cc243a9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ formFactory.setFieldCreationListener("birthDate", field -> ... your own logic he

Define a `FieldProvider` to manually create a field:
```java
formFactory.setFieldProvider("groups", () -> {
formFactory.setFieldProvider("groups", user -> {
CheckboxGroup<Group> checkboxes = new CheckboxGroup<>();
checkboxes.setItems(groups);
checkboxes.setItemLabelGenerator(Group::getName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.io.Serializable;

import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.HasValueAndElement;

/**
Expand Down
3 changes: 2 additions & 1 deletion crud-ui-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
"construct-style-sheets-polyfill": "$construct-style-sheets-polyfill",
"lit": "$lit",
"@polymer/polymer": "$@polymer/polymer",
"chokidar": "$chokidar"
"chokidar": "$chokidar",
"date-fns": "$date-fns"
}
}
28 changes: 15 additions & 13 deletions crud-ui-demo/src/main/java/org/vaadin/crudui/demo/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public static void main(String[] args) {
}

@Bean
public ApplicationListener<ContextRefreshedEvent> initDatabase(GroupService groupService, UserService userService, CategoryService categoryService) {
public ApplicationListener<ContextRefreshedEvent> initDatabase(GroupService groupService, UserService userService,
CategoryService categoryService) {
return event -> {
if (groupService.count() == 0) {
createDemoData(groupService, userService,categoryService);
createDemoData(groupService, userService, categoryService);
}
};
}
Expand All @@ -56,14 +57,16 @@ private void createDemoData(GroupService groupService, UserService userService,

groupService.findAll();

String[] firstNames = "Maria,Nicole,Sandra,Brenda,Clare,Cathy,Elizabeth,Tom,John,Daniel,Edward,Hank,Arthur,Bill".split(",");
String[] firstNames = "Maria,Nicole,Sandra,Brenda,Clare,Cathy,Elizabeth,Tom,John,Daniel,Edward,Hank,Arthur,Bill"
.split(",");
String[] lastNames = "Smith,Johnson,Williams,Jones,Brown,Miller,Wilson,Wright,Thompson,Lee".split(",");

Random rand = new Random();

IntStream.rangeClosed(1, DEMO_USERS_COUNT)
.mapToObj(i -> {
String name = firstNames[rand.nextInt(firstNames.length)] + " " + lastNames[rand.nextInt(lastNames.length)];
String name = firstNames[rand.nextInt(firstNames.length)] + " "
+ lastNames[rand.nextInt(lastNames.length)];
ArrayList<Group> groups = IntStream.rangeClosed(1, 1 + rand.nextInt(2))
.mapToObj(j -> allGroups.get(rand.nextInt(allGroups.size())))
.collect(Collectors.toCollection(ArrayList::new));
Expand All @@ -78,22 +81,21 @@ private void createDemoData(GroupService groupService, UserService userService,
rand.nextInt(10) > 0,
groups.get(rand.nextInt(groups.size())),
new HashSet<>(groups),
MaritalStatus.values()[rand.nextInt(MaritalStatus.values().length)]
);
MaritalStatus.values()[rand.nextInt(MaritalStatus.values().length)]);
})
.forEach(userService::save);

String[] languages = new String[]{"Java","Javascript","Dart"};
String[][] frameworks = new String[][]{
{"Vaadin Flow","Spring","Guice"},
{"Vaadin Fusion","React","Angular"},
{"Flutter"}
String[] languages = new String[] { "Java", "Javascript", "Dart" };
String[][] frameworks = new String[][] {
{ "Vaadin", "Spring", "Guice" },
{ "Hilla", "React", "Svelte" },
{ "Flutter" }
};

for (int i = 0; i < languages.length; i++) {
Category lang = categoryService.save(new Category(languages[i],languages[i],null ));
Category language = categoryService.save(new Category(languages[i], languages[i], null));
for (int j = 0; j < frameworks[i].length; j++) {
Category lib = categoryService.save(new Category(frameworks[i][j], frameworks[i][j],lang));
categoryService.save(new Category(frameworks[i][j], frameworks[i][j], language));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static String getViewName(Class clazz) {
}

public static String getGitHubLink(Class clazz) {
return "https://github.com/alejandro-du/crudui/tree/master/demo/src/main/java/"
return "https://github.com/alejandro-du/crudui/tree/master/crud-ui-demo/src/main/java/"
+ clazz.getName().replace(".", "/")
+ ".java";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.context.ApplicationEventPublisher;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
package org.vaadin.crudui.demo.ui.view;

import javax.annotation.PostConstruct;

import com.vaadin.flow.component.HasValueAndElement;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextArea;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;
import javax.annotation.PostConstruct;

import org.vaadin.crudui.crud.impl.TreeGridCrud;
import org.vaadin.crudui.demo.entity.Category;
import org.vaadin.crudui.demo.service.CategoryService;
import org.vaadin.crudui.demo.ui.MainLayout;
import org.vaadin.crudui.layout.impl.VerticalSplitCrudLayout;

/**
* @author XakepSDK
*/
@Route(value = "simple-tree", layout = MainLayout.class)
public class SimpleTreeCrudView extends VerticalLayout {

protected final CategoryService categoryService;
protected final CategoryService categoryService;

public SimpleTreeCrudView(CategoryService categoryService) {
this.categoryService = categoryService;
}
public SimpleTreeCrudView(CategoryService categoryService) {
this.categoryService = categoryService;
}

@PostConstruct
private void build() {
TreeGridCrud<Category> crud = new TreeGridCrud<Category>(Category.class);
crud.getGrid().removeAllColumns();
crud.getGrid().addHierarchyColumn(Category::getName)
.setHeader("Name");
@PostConstruct
private void build() {
TreeGridCrud<Category> crud = new TreeGridCrud<Category>(Category.class);
crud.getGrid().removeAllColumns();
crud.getGrid().addHierarchyColumn(Category::getName)
.setHeader("Name");

crud.setChildItemProvider(category -> categoryService.findChildren(category));
crud.setChildItemProvider(category -> categoryService.findChildren(category));

crud.getCrudFormFactory().setVisibleProperties("name", "parent", "description");
crud.getCrudFormFactory().setVisibleProperties("name", "parent", "description");

crud.getCrudFormFactory().setFieldProvider("name", () -> createNameField());
crud.getCrudFormFactory().setFieldProvider("parent", () -> createParentSelector());
crud.getCrudFormFactory().setFieldProvider("description", () -> createDescriptionField());
crud.getCrudFormFactory().setFieldProvider("name", category -> createNameField());
crud.getCrudFormFactory().setFieldProvider("parent", category -> createParentSelector());
crud.getCrudFormFactory().setFieldProvider("description", category -> createDescriptionField());

crud.setFindAllOperation(() -> categoryService.findRoots());
crud.setFindAllOperation(() -> categoryService.findRoots());

crud.setAddOperation(category -> categoryService.save(category));
crud.setUpdateOperation(category -> categoryService.save(category));
crud.setDeleteOperation(category -> categoryService.delete(category));
crud.setAddOperation(category -> categoryService.save(category));
crud.setUpdateOperation(category -> categoryService.save(category));
crud.setDeleteOperation(category -> categoryService.delete(category));

crud.setChildItemProvider(category -> categoryService.findChildren(category));
crud.setChildItemProvider(category -> categoryService.findChildren(category));

crud.setShowNotifications(false);
addAndExpand(crud);
setSizeFull();
}
crud.setShowNotifications(false);
addAndExpand(crud);
setSizeFull();
}

private HasValueAndElement createNameField() {
TextField nameField = new TextField("Name");
nameField.setWidth("300px");
return nameField;
}
private HasValueAndElement createNameField() {
TextField nameField = new TextField("Name");
nameField.setWidth("300px");
return nameField;
}

private HasValueAndElement createDescriptionField() {
TextArea descriptionField = new TextArea("Description");
descriptionField.setWidth("300px");
return descriptionField;
}
private HasValueAndElement createDescriptionField() {
TextArea descriptionField = new TextArea("Description");
descriptionField.setWidth("300px");
return descriptionField;
}

private HasValueAndElement createParentSelector() {
ComboBox<Category> selector = new ComboBox<Category>("Parent", categoryService.findAll());
selector.setWidth("300px");
return selector;
}
private HasValueAndElement createParentSelector() {
ComboBox<Category> selector = new ComboBox<Category>("Parent", categoryService.findAll());
selector.setWidth("300px");
return selector;
}

}

0 comments on commit cc243a9

Please sign in to comment.