From 381908a3a05e84e742b36140587ddd23e233ca23 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 6 Sep 2018 00:33:00 +0530 Subject: [PATCH 1/3] BAEL-8841 Merge vaadin and vaadin-spring - Moved vaadin-spring code to vaadin module --- pom.xml | 2 + vaadin/README.md | 1 + vaadin/pom.xml | 59 ++++++++---- .../main/java/com/baeldung/Application.java | 29 ++++++ .../src/main/java/com/baeldung/Employee.java | 51 +++++++++++ .../java/com/baeldung/EmployeeEditor.java | 90 +++++++++++++++++++ .../java/com/baeldung/EmployeeRepository.java | 10 +++ .../src/main/java/com/baeldung/MainView.java | 67 ++++++++++++++ 8 files changed, 290 insertions(+), 19 deletions(-) create mode 100644 vaadin/src/main/java/com/baeldung/Application.java create mode 100644 vaadin/src/main/java/com/baeldung/Employee.java create mode 100644 vaadin/src/main/java/com/baeldung/EmployeeEditor.java create mode 100644 vaadin/src/main/java/com/baeldung/EmployeeRepository.java create mode 100644 vaadin/src/main/java/com/baeldung/MainView.java diff --git a/pom.xml b/pom.xml index 0536a536c2..95c5e23e0a 100644 --- a/pom.xml +++ b/pom.xml @@ -579,6 +579,7 @@ testing-modules/mockserver testing-modules/test-containers undertow + vaadin vertx-and-rxjava saas deeplearning4j @@ -1126,6 +1127,7 @@ testing-modules/mockserver testing-modules/test-containers undertow + vaadin vertx-and-rxjava saas deeplearning4j diff --git a/vaadin/README.md b/vaadin/README.md index 0dfeea8996..43d2cc8961 100644 --- a/vaadin/README.md +++ b/vaadin/README.md @@ -1,3 +1,4 @@ ## Relevant articles: - [Introduction to Vaadin](http://www.baeldung.com/vaadin) +- [Sample Application with Spring Boot and Vaadin](https://www.baeldung.com/spring-boot-vaadin) diff --git a/vaadin/pom.xml b/vaadin/pom.xml index ce2cd592d7..c34ffa3636 100644 --- a/vaadin/pom.xml +++ b/vaadin/pom.xml @@ -8,21 +8,30 @@ war 1.0-SNAPSHOT Vaadin - - 3 - - + + parent-boot-2 com.baeldung - parent-modules - 1.0.0-SNAPSHOT + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + com.vaadin + vaadin-bom + ${vaadin.version} + pom + import + + + + javax.servlet javax.servlet-api - ${servlet.version} provided @@ -41,6 +50,25 @@ com.vaadin vaadin-themes + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.vaadin + vaadin-spring-boot-starter + ${vaadin-spring-boot-starter.version} + + + com.h2database + h2 + + + org.springframework.boot + spring-boot-starter-test + test + @@ -97,21 +125,13 @@ 2 + + org.springframework.boot + spring-boot-maven-plugin + - - - - com.vaadin - vaadin-bom - ${vaadin.version} - pom - import - - - - vaadin-addons @@ -166,6 +186,7 @@ 3.0.1 7.7.10 8.0.6 + 10.0.1 9.3.9.v20160517 UTF-8 1.8 diff --git a/vaadin/src/main/java/com/baeldung/Application.java b/vaadin/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..1d3084723a --- /dev/null +++ b/vaadin/src/main/java/com/baeldung/Application.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class Application { + + private static final Logger log = LoggerFactory.getLogger(Application.class); + + public static void main(String[] args) { + SpringApplication.run(Application.class); + } + + @Bean + public CommandLineRunner loadData(EmployeeRepository repository) { + return (args) -> { + repository.save(new Employee("Bill", "Gates")); + repository.save(new Employee("Mark", "Zuckerberg")); + repository.save(new Employee("Sundar", "Pichai")); + repository.save(new Employee("Jeff", "Bezos")); + }; + } +} diff --git a/vaadin/src/main/java/com/baeldung/Employee.java b/vaadin/src/main/java/com/baeldung/Employee.java new file mode 100644 index 0000000000..726f0838b6 --- /dev/null +++ b/vaadin/src/main/java/com/baeldung/Employee.java @@ -0,0 +1,51 @@ +package com.baeldung; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Employee { + + @Id + @GeneratedValue + private Long id; + + private String firstName; + + private String lastName; + + protected Employee() { + } + + public Employee(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Long getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format("Employee[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); + } + +} diff --git a/vaadin/src/main/java/com/baeldung/EmployeeEditor.java b/vaadin/src/main/java/com/baeldung/EmployeeEditor.java new file mode 100644 index 0000000000..ee312786d1 --- /dev/null +++ b/vaadin/src/main/java/com/baeldung/EmployeeEditor.java @@ -0,0 +1,90 @@ +package com.baeldung; + +import com.vaadin.flow.component.Key; +import com.vaadin.flow.component.KeyNotifier; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.icon.VaadinIcon; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.textfield.TextField; +import com.vaadin.flow.data.binder.Binder; +import com.vaadin.flow.spring.annotation.SpringComponent; +import com.vaadin.flow.spring.annotation.UIScope; +import org.springframework.beans.factory.annotation.Autowired; + +@SpringComponent +@UIScope +public class EmployeeEditor extends VerticalLayout implements KeyNotifier { + + private final EmployeeRepository repository; + + private Employee employee; + + TextField firstName = new TextField("First name"); + TextField lastName = new TextField("Last name"); + + Button save = new Button("Save", VaadinIcon.CHECK.create()); + Button cancel = new Button("Cancel"); + Button delete = new Button("Delete", VaadinIcon.TRASH.create()); + HorizontalLayout actions = new HorizontalLayout(save, cancel, delete); + + Binder binder = new Binder<>(Employee.class); + private ChangeHandler changeHandler; + + @Autowired + public EmployeeEditor(EmployeeRepository repository) { + this.repository = repository; + + add(firstName, lastName, actions); + + binder.bindInstanceFields(this); + + setSpacing(true); + + save.getElement().getThemeList().add("primary"); + delete.getElement().getThemeList().add("error"); + + addKeyPressListener(Key.ENTER, e -> save()); + + save.addClickListener(e -> save()); + delete.addClickListener(e -> delete()); + cancel.addClickListener(e -> editEmployee(employee)); + setVisible(false); + } + + void delete() { + repository.delete(employee); + changeHandler.onChange(); + } + + void save() { + repository.save(employee); + changeHandler.onChange(); + } + + public interface ChangeHandler { + void onChange(); + } + + public final void editEmployee(Employee c) { + if (c == null) { + setVisible(false); + return; + } + final boolean persisted = c.getId() != null; + if (persisted) { + employee = repository.findById(c.getId()).get(); + } else { + employee = c; + } + + cancel.setVisible(persisted); + binder.setBean(employee); + setVisible(true); + firstName.focus(); + } + + public void setChangeHandler(ChangeHandler h) { + changeHandler = h; + } +} diff --git a/vaadin/src/main/java/com/baeldung/EmployeeRepository.java b/vaadin/src/main/java/com/baeldung/EmployeeRepository.java new file mode 100644 index 0000000000..044160da78 --- /dev/null +++ b/vaadin/src/main/java/com/baeldung/EmployeeRepository.java @@ -0,0 +1,10 @@ +package com.baeldung; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface EmployeeRepository extends JpaRepository { + + List findByLastNameStartsWithIgnoreCase(String lastName); +} diff --git a/vaadin/src/main/java/com/baeldung/MainView.java b/vaadin/src/main/java/com/baeldung/MainView.java new file mode 100644 index 0000000000..6d4c0aaa88 --- /dev/null +++ b/vaadin/src/main/java/com/baeldung/MainView.java @@ -0,0 +1,67 @@ +package com.baeldung; + +import org.springframework.util.StringUtils; + +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.grid.Grid; +import com.vaadin.flow.component.icon.VaadinIcon; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.textfield.TextField; +import com.vaadin.flow.data.value.ValueChangeMode; +import com.vaadin.flow.router.Route; + +@Route +public class MainView extends VerticalLayout { + + private final EmployeeRepository employeeRepository; + + private final EmployeeEditor editor; + + final Grid grid; + + final TextField filter; + + private final Button addNewBtn; + + public MainView(EmployeeRepository repo, EmployeeEditor editor) { + this.employeeRepository = repo; + this.editor = editor; + this.grid = new Grid<>(Employee.class); + this.filter = new TextField(); + this.addNewBtn = new Button("New employee", VaadinIcon.PLUS.create()); + + HorizontalLayout actions = new HorizontalLayout(filter, addNewBtn); + add(actions, grid, editor); + + grid.setHeight("200px"); + grid.setColumns("id", "firstName", "lastName"); + grid.getColumnByKey("id").setWidth("50px").setFlexGrow(0); + + filter.setPlaceholder("Filter by last name"); + + filter.setValueChangeMode(ValueChangeMode.EAGER); + filter.addValueChangeListener(e -> listEmployees(e.getValue())); + + grid.asSingleSelect().addValueChangeListener(e -> { + editor.editEmployee(e.getValue()); + }); + + addNewBtn.addClickListener(e -> editor.editEmployee(new Employee("", ""))); + + editor.setChangeHandler(() -> { + editor.setVisible(false); + listEmployees(filter.getValue()); + }); + + listEmployees(null); + } + + void listEmployees(String filterText) { + if (StringUtils.isEmpty(filterText)) { + grid.setItems(employeeRepository.findAll()); + } else { + grid.setItems(employeeRepository.findByLastNameStartsWithIgnoreCase(filterText)); + } + } +} From 06cccd587b8ba3935885611a77aff27fc3647b0b Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 6 Sep 2018 00:34:59 +0530 Subject: [PATCH 2/3] BAEL-8841 Merge vaadin and vaadin-spring - Removed vaadin-spring project --- vaadin-spring/pom.xml | 64 ------------- .../main/java/com/baeldung/Application.java | 29 ------ .../src/main/java/com/baeldung/Employee.java | 51 ----------- .../java/com/baeldung/EmployeeEditor.java | 90 ------------------- .../java/com/baeldung/EmployeeRepository.java | 10 --- .../src/main/java/com/baeldung/MainView.java | 67 -------------- vaadin-spring/src/main/resources/logback.xml | 13 --- 7 files changed, 324 deletions(-) delete mode 100644 vaadin-spring/pom.xml delete mode 100644 vaadin-spring/src/main/java/com/baeldung/Application.java delete mode 100644 vaadin-spring/src/main/java/com/baeldung/Employee.java delete mode 100644 vaadin-spring/src/main/java/com/baeldung/EmployeeEditor.java delete mode 100644 vaadin-spring/src/main/java/com/baeldung/EmployeeRepository.java delete mode 100644 vaadin-spring/src/main/java/com/baeldung/MainView.java delete mode 100644 vaadin-spring/src/main/resources/logback.xml diff --git a/vaadin-spring/pom.xml b/vaadin-spring/pom.xml deleted file mode 100644 index 09f79f2676..0000000000 --- a/vaadin-spring/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - 4.0.0 - - com.baeldung - vaadin-spring - 0.1.0 - - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.vaadin - vaadin-spring-boot-starter - - - com.h2database - h2 - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - com.vaadin - vaadin-bom - 10.0.1 - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/vaadin-spring/src/main/java/com/baeldung/Application.java b/vaadin-spring/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 1d3084723a..0000000000 --- a/vaadin-spring/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class Application { - - private static final Logger log = LoggerFactory.getLogger(Application.class); - - public static void main(String[] args) { - SpringApplication.run(Application.class); - } - - @Bean - public CommandLineRunner loadData(EmployeeRepository repository) { - return (args) -> { - repository.save(new Employee("Bill", "Gates")); - repository.save(new Employee("Mark", "Zuckerberg")); - repository.save(new Employee("Sundar", "Pichai")); - repository.save(new Employee("Jeff", "Bezos")); - }; - } -} diff --git a/vaadin-spring/src/main/java/com/baeldung/Employee.java b/vaadin-spring/src/main/java/com/baeldung/Employee.java deleted file mode 100644 index 726f0838b6..0000000000 --- a/vaadin-spring/src/main/java/com/baeldung/Employee.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Employee { - - @Id - @GeneratedValue - private Long id; - - private String firstName; - - private String lastName; - - protected Employee() { - } - - public Employee(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public Long getId() { - return id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("Employee[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); - } - -} diff --git a/vaadin-spring/src/main/java/com/baeldung/EmployeeEditor.java b/vaadin-spring/src/main/java/com/baeldung/EmployeeEditor.java deleted file mode 100644 index ee312786d1..0000000000 --- a/vaadin-spring/src/main/java/com/baeldung/EmployeeEditor.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.baeldung; - -import com.vaadin.flow.component.Key; -import com.vaadin.flow.component.KeyNotifier; -import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.icon.VaadinIcon; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.component.orderedlayout.VerticalLayout; -import com.vaadin.flow.component.textfield.TextField; -import com.vaadin.flow.data.binder.Binder; -import com.vaadin.flow.spring.annotation.SpringComponent; -import com.vaadin.flow.spring.annotation.UIScope; -import org.springframework.beans.factory.annotation.Autowired; - -@SpringComponent -@UIScope -public class EmployeeEditor extends VerticalLayout implements KeyNotifier { - - private final EmployeeRepository repository; - - private Employee employee; - - TextField firstName = new TextField("First name"); - TextField lastName = new TextField("Last name"); - - Button save = new Button("Save", VaadinIcon.CHECK.create()); - Button cancel = new Button("Cancel"); - Button delete = new Button("Delete", VaadinIcon.TRASH.create()); - HorizontalLayout actions = new HorizontalLayout(save, cancel, delete); - - Binder binder = new Binder<>(Employee.class); - private ChangeHandler changeHandler; - - @Autowired - public EmployeeEditor(EmployeeRepository repository) { - this.repository = repository; - - add(firstName, lastName, actions); - - binder.bindInstanceFields(this); - - setSpacing(true); - - save.getElement().getThemeList().add("primary"); - delete.getElement().getThemeList().add("error"); - - addKeyPressListener(Key.ENTER, e -> save()); - - save.addClickListener(e -> save()); - delete.addClickListener(e -> delete()); - cancel.addClickListener(e -> editEmployee(employee)); - setVisible(false); - } - - void delete() { - repository.delete(employee); - changeHandler.onChange(); - } - - void save() { - repository.save(employee); - changeHandler.onChange(); - } - - public interface ChangeHandler { - void onChange(); - } - - public final void editEmployee(Employee c) { - if (c == null) { - setVisible(false); - return; - } - final boolean persisted = c.getId() != null; - if (persisted) { - employee = repository.findById(c.getId()).get(); - } else { - employee = c; - } - - cancel.setVisible(persisted); - binder.setBean(employee); - setVisible(true); - firstName.focus(); - } - - public void setChangeHandler(ChangeHandler h) { - changeHandler = h; - } -} diff --git a/vaadin-spring/src/main/java/com/baeldung/EmployeeRepository.java b/vaadin-spring/src/main/java/com/baeldung/EmployeeRepository.java deleted file mode 100644 index 044160da78..0000000000 --- a/vaadin-spring/src/main/java/com/baeldung/EmployeeRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface EmployeeRepository extends JpaRepository { - - List findByLastNameStartsWithIgnoreCase(String lastName); -} diff --git a/vaadin-spring/src/main/java/com/baeldung/MainView.java b/vaadin-spring/src/main/java/com/baeldung/MainView.java deleted file mode 100644 index 6d4c0aaa88..0000000000 --- a/vaadin-spring/src/main/java/com/baeldung/MainView.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung; - -import org.springframework.util.StringUtils; - -import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.grid.Grid; -import com.vaadin.flow.component.icon.VaadinIcon; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.component.orderedlayout.VerticalLayout; -import com.vaadin.flow.component.textfield.TextField; -import com.vaadin.flow.data.value.ValueChangeMode; -import com.vaadin.flow.router.Route; - -@Route -public class MainView extends VerticalLayout { - - private final EmployeeRepository employeeRepository; - - private final EmployeeEditor editor; - - final Grid grid; - - final TextField filter; - - private final Button addNewBtn; - - public MainView(EmployeeRepository repo, EmployeeEditor editor) { - this.employeeRepository = repo; - this.editor = editor; - this.grid = new Grid<>(Employee.class); - this.filter = new TextField(); - this.addNewBtn = new Button("New employee", VaadinIcon.PLUS.create()); - - HorizontalLayout actions = new HorizontalLayout(filter, addNewBtn); - add(actions, grid, editor); - - grid.setHeight("200px"); - grid.setColumns("id", "firstName", "lastName"); - grid.getColumnByKey("id").setWidth("50px").setFlexGrow(0); - - filter.setPlaceholder("Filter by last name"); - - filter.setValueChangeMode(ValueChangeMode.EAGER); - filter.addValueChangeListener(e -> listEmployees(e.getValue())); - - grid.asSingleSelect().addValueChangeListener(e -> { - editor.editEmployee(e.getValue()); - }); - - addNewBtn.addClickListener(e -> editor.editEmployee(new Employee("", ""))); - - editor.setChangeHandler(() -> { - editor.setVisible(false); - listEmployees(filter.getValue()); - }); - - listEmployees(null); - } - - void listEmployees(String filterText) { - if (StringUtils.isEmpty(filterText)) { - grid.setItems(employeeRepository.findAll()); - } else { - grid.setItems(employeeRepository.findByLastNameStartsWithIgnoreCase(filterText)); - } - } -} diff --git a/vaadin-spring/src/main/resources/logback.xml b/vaadin-spring/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/vaadin-spring/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file From 4798ba0ea235f10a3d3838baa1acc6597e2aa355 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 6 Sep 2018 22:37:01 +0530 Subject: [PATCH 3/3] BAEL-8841 Merge vaadin and vaadin-spring - Added spring-boot-maven-plugin inside plugin management for parent-boot-1 and parent-boot-2 so that it is available as a managed resource for their child projects --- parent-boot-1/pom.xml | 17 +++++++++-------- parent-boot-2/pom.xml | 16 +++++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/parent-boot-1/pom.xml b/parent-boot-1/pom.xml index c52327a42e..7742841d07 100644 --- a/parent-boot-1/pom.xml +++ b/parent-boot-1/pom.xml @@ -37,16 +37,17 @@ - - - org.springframework.boot - spring-boot-maven-plugin - 1.5.15.RELEASE - - + + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.15.RELEASE + + + - 3.1.0 diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index 86a77a90db..de6cb5d068 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -36,13 +36,15 @@ - - - org.springframework.boot - spring-boot-maven-plugin - 2.0.4.RELEASE - - + + + + org.springframework.boot + spring-boot-maven-plugin + 2.0.4.RELEASE + + +