From 97955fb3d5469b50b93499a31f68adc1b6d416b8 Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Mon, 11 Feb 2019 00:46:52 +0100 Subject: [PATCH] Mobile personeditor --- .../ui/navigation/ClubhelperNavigation.java | 33 +++++++++++++++---- .../ui/navigation/PersonEditView.java | 29 ++++++++++++---- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java index 22eb9d9..ddd397b 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java @@ -53,16 +53,13 @@ public class ClubhelperNavigation { Page page = mainUI.getPage(); - MainView mainView; - if (page.getBrowserWindowWidth() < 1000) { - mainView = new MainViewMobile(personDao, groupDao, eventBusiness, securityGroupVerifier); - } else { - mainView = new MainViewDesktop(personDao, groupDao, eventBusiness, securityGroupVerifier); - } + ViewFactory factory = new ViewFactory(page); + MainView mainView = factory.createMain(); + navi.addView("", mainView); navi.addView(ClubhelperViews.MainView.name(), mainView); navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personDao, securityGroupVerifier)); - navi.addView(ClubhelperViews.PersonEditView.name(), new PersonEditView(groupDao, personDao)); + navi.addView(ClubhelperViews.PersonEditView.name(), factory.createPersonEdit()); navi.addView(ClubhelperViews.EventDetails.name(), new EventDetails(personDao, groupDao, eventBusiness, pflichtenDao, calendarAdapter)); @@ -77,6 +74,28 @@ public class ClubhelperNavigation { }); } + class ViewFactory { + + private Page page; + + public ViewFactory(Page page) { + this.page = page; + } + + public MainView createMain() { + + if (page.getBrowserWindowWidth() < 1000) { + return new MainViewMobile(personDao, groupDao, eventBusiness, securityGroupVerifier); + } else { + return new MainViewDesktop(personDao, groupDao, eventBusiness, securityGroupVerifier); + } + } + + public PersonEditView createPersonEdit() { + return new PersonEditView(groupDao, personDao, (page.getBrowserWindowWidth() >= 1000)); + } + } + public void navigateTo(String navigationState) { navi.navigateTo(navigationState); } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/PersonEditView.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/PersonEditView.java index 9fa0029..afdf557 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/PersonEditView.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/PersonEditView.java @@ -27,7 +27,7 @@ public class PersonEditView extends VerticalLayout implements View { private Navigator navigator; - public PersonEditView(GroupDao groupDao, PersonDao personDao) { + public PersonEditView(GroupDao groupDao, PersonDao personDao, boolean horizontalLayout) { setMargin(true); personGrid = new PersonGrid(groupDao, personDao); @@ -40,12 +40,11 @@ public class PersonEditView extends VerticalLayout implements View { personDetails.setSizeFull(); personDetails.setPersonChangeHandler(personGrid::refreshItem); - HorizontalLayout layout = new HorizontalLayout(); - layout.addComponents(personGrid, personDetails); - layout.setExpandRatio(personGrid, 1f); - layout.setExpandRatio(personDetails, 2f); - layout.setSizeFull(); - addComponent(layout); + if (horizontalLayout) { + addComponent(createHorizontalLayout()); + } else { + addComponent(createVerticalLayout()); + } Button addPerson = new Button("Hinzufügen"); addPerson.addClickListener(ev -> addPerson()); @@ -55,6 +54,22 @@ public class PersonEditView extends VerticalLayout implements View { addComponent(backButton); } + public HorizontalLayout createHorizontalLayout() { + HorizontalLayout layout = new HorizontalLayout(); + layout.addComponents(personGrid, personDetails); + layout.setExpandRatio(personGrid, 1f); + layout.setExpandRatio(personDetails, 2f); + layout.setSizeFull(); + return layout; + } + + public VerticalLayout createVerticalLayout() { + VerticalLayout layout = new VerticalLayout(); + layout.addComponents(personGrid, personDetails); + layout.setSizeFull(); + return layout; + } + private void addPerson() { Person person = new Person(); person.setGroups(new HashSet<>());