Advertisement
Guest User

Untitled

a guest
Jul 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. package at.nisteria.nisteria;
  2.  
  3. import java.util.List;
  4.  
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Repository;
  7.  
  8. import com.vaadin.data.Binder;
  9. import com.vaadin.server.VaadinRequest;
  10. import com.vaadin.spring.annotation.SpringUI;
  11. import com.vaadin.ui.Grid.SelectionMode;
  12. import com.vaadin.ui.UI;
  13.  
  14. @SpringUI
  15. @Repository
  16. public class MandantUI extends UI{
  17.  
  18. private static final long serialVersionUID = 2179686694654113128L;
  19.  
  20. MandantList mandantlist;
  21.  
  22. private Mandant mandant;
  23.  
  24. private Binder<Mandant> binder = new Binder<>(Mandant.class);
  25.  
  26. @Autowired
  27. private MandantService service;
  28.  
  29. @Override
  30. protected void init(VaadinRequest request) {
  31. setContent(mandantlist);
  32. updateGrid();
  33. mandantlist.grid.setSelectionMode(SelectionMode.SINGLE);
  34.  
  35. mandantlist.grid.addSelectionListener(e -> updateForm());
  36. /* mandantlist.grid.addSelectionListener(new SelectionListener<Mandant>() {
  37.  
  38. private static final long serialVersionUID = 1656189879017373025L;
  39.  
  40. @Override
  41. public void selectionChange(SelectionEvent<Mandant> event) {
  42. updateForm();
  43. }
  44. });*/
  45. mandantlist.save.addClickListener(e -> saveCustomer());
  46.  
  47.  
  48. binder.bindInstanceFields(this);
  49.  
  50.  
  51. }
  52.  
  53. private void updateGrid() {
  54. List<Mandant> customers = service.findAll();
  55. mandantlist.grid.setItems(customers);
  56. setFormVisible(false);
  57. }
  58.  
  59. private void updateForm() {
  60. if (mandantlist.grid.asSingleSelect().isEmpty()) {
  61. setFormVisible(false);
  62. } else {
  63. mandant = mandantlist.grid.asSingleSelect().getValue();
  64. binder.setBean(mandant);
  65. setFormVisible(true);
  66. }
  67. }
  68.  
  69. private void setFormVisible(boolean visible) {
  70. mandantlist.name.setVisible(visible);
  71. mandantlist.anmerkung.setVisible(visible);
  72. mandantlist.save.setVisible(visible);
  73. }
  74.  
  75. private void saveCustomer() {
  76. service.update(mandant);
  77. updateGrid();
  78. }
  79.  
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement