Group loaded into combobox

master
Markus Kreth 7 years ago
parent d43ce6b7ac
commit 93a99676c1
  1. 35
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDaoImpl.java
  2. 7
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/GroupDao.java
  3. 16
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/GroupDaoImpl.java
  4. 25
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoImpl.java
  5. 24
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/GroupDef.java
  6. 16
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
  7. 66
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
  8. 3
      src/main/resources/application.properties
  9. 12
      src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/addons.scss
  10. 15583
      src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/styles.css
  11. 9
      src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/styles.scss
  12. 40
      src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/vaadin-clubhelpertheme.scss

@ -0,0 +1,35 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class AbstractDaoImpl<T> implements IDao<T> {
@Autowired
EntityManager em;
private final Class<T> entityClass;
public AbstractDaoImpl(Class<T> entityClass) {
super();
this.entityClass = entityClass;
}
@Override
public void save(T obj) {
em.persist(obj);
}
@Override
public List<T> list() {
TypedQuery<T> query = em.createNamedQuery(
entityClass.getSimpleName() + ".findAll", entityClass);
return query.getResultList();
}
}

@ -0,0 +1,7 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
public interface GroupDao extends IDao<GroupDef> {
}

@ -0,0 +1,16 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
import org.springframework.stereotype.Repository;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
@Repository
public class GroupDaoImpl extends AbstractDaoImpl<GroupDef>
implements
GroupDao {
public GroupDaoImpl() {
super(GroupDef.class);
}
}

@ -1,31 +1,16 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
@Repository
public class PersonDaoImpl implements PersonDao {
@Autowired
EntityManager em;
@Override
public void save(Person obj) {
em.persist(obj);
}
public class PersonDaoImpl extends AbstractDaoImpl<Person>
implements
PersonDao {
@Override
public List<Person> list() {
TypedQuery<Person> query = em.createNamedQuery(Person.QUERY_FINDALL,
Person.class);
return query.getResultList();
public PersonDaoImpl() {
super(Person.class);
}
}

@ -1,20 +1,31 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* The persistent class for the groupDef database table.
*
*/
@Entity
@Entity(name = "groupDef")
@Table(name = "groupDef")
@NamedQuery(name="GroupDef.findAll", query="SELECT g FROM GroupDef g")
@NamedQuery(name = GroupDef.QUERY_FINDALL, query = "SELECT g FROM groupDef g")
public class GroupDef implements Serializable {
private static final long serialVersionUID = 1L;
public final static String QUERY_FINDALL = "GroupDef.findAll";
private static final long serialVersionUID = -2827542956463449518L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -100,4 +111,9 @@ public class GroupDef implements Serializable {
return persongroup;
}
@Override
public String toString() {
return "GroupDef [id=" + id + ", name=" + name + "]";
}
}

@ -12,6 +12,7 @@ import org.vaadin.addon.calendar.Calendar;
import org.vaadin.addon.calendar.item.BasicItemProvider;
import org.vaadin.addon.calendar.ui.CalendarComponentEvents;
import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.HorizontalLayout;
@ -20,17 +21,24 @@ import com.vaadin.ui.UI;
import de.kreth.clubhelperbackend.google.calendar.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.EventBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.EventGrid;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid;
@Theme("vaadin-clubhelpertheme")
@SpringUI
public class MainUi extends UI {
private static final long serialVersionUID = 7581634188909841919L;
@Autowired
PersonDao personDao;
@Autowired
PersonDao dao;
GroupDao groupDao;
private ClubEventProvider dataProvider;
private PersonGrid personGrid;
private EventGrid eventGrid;
@ -40,8 +48,8 @@ public class MainUi extends UI {
HorizontalLayout layout = new HorizontalLayout();
List<Person> persons = dao.list();
personGrid = new PersonGrid();
List<Person> persons = personDao.list();
personGrid = new PersonGrid(groupDao);
personGrid.setItems(persons);
personGrid.setCaption("Personen");
personGrid.setVisible(false);
@ -79,6 +87,8 @@ public class MainUi extends UI {
private void showDetails(ClubEvent ev) {
eventGrid.setVisible(false);
personGrid.setVisible(true);
personGrid.setCaption(ev.getCaption());
personGrid.setTitle(ev.getCaption());
Notification.show("" + ev);
}

@ -1,18 +1,27 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.event.selection.SingleSelectionEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Persongroup;
public class PersonGrid extends CustomComponent {
@ -21,18 +30,36 @@ public class PersonGrid extends CustomComponent {
private final DateFormat birthFormat = DateFormat
.getDateInstance(DateFormat.MEDIUM);
private final Grid<Person> grid = new Grid<>();
private final Grid<Person> grid;
private CheckBox checkIncluded;
private ComboBox<GroupDef> comboGroups;
private final CheckBox checkIncluded;
private final ComboBox<GroupDef> comboGroups;
private final TextField textTitle;
private final ListDataProvider<Person> dataProvider;
public PersonGrid(GroupDao groupDao) {
textTitle = new TextField();
textTitle.setStyleName("title_label");
textTitle.setCaption("Veranstaltung");
textTitle.setEnabled(false);
public PersonGrid() {
checkIncluded = new CheckBox("Nur gemeldete");
checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev));
comboGroups = new ComboBox<>("Gruppenfilter");
comboGroups.setEmptySelectionAllowed(true);
comboGroups.setEmptySelectionCaption("Alle");
comboGroups.setItemCaptionGenerator(GroupDef::getName);
comboGroups.addSelectionListener(ev -> onGroupSelected(ev));
comboGroups.setItems(groupDao.list());
HorizontalLayout filters = new HorizontalLayout();
filters.addComponents(checkIncluded, comboGroups);
dataProvider = new ListDataProvider<>(new ArrayList<>());
grid = new Grid<>();
grid.setDataProvider(dataProvider);
grid.addColumn(Person::getPrename).setCaption("Vorname");
grid.addColumn(Person::getSurname).setCaption("Nachname");
grid.addColumn(Person::getBirth,
@ -41,10 +68,37 @@ public class PersonGrid extends CustomComponent {
grid.setSelectionMode(SelectionMode.MULTI);
VerticalLayout panel = new VerticalLayout();
panel.addComponents(filters, grid);
panel.addComponents(textTitle, filters, grid);
setCompositionRoot(panel);
}
private void onSelectedOnly(ValueChangeEvent<Boolean> ev) {
dataProvider.clearFilters();
Set<Person> selected = grid.getSelectedItems();
dataProvider.addFilter(p -> selected.contains(p));
}
private void onGroupSelected(SingleSelectionEvent<GroupDef> ev) {
dataProvider.clearFilters();
final Set<GroupDef> groups = ev.getAllSelectedItems();
dataProvider.addFilter(p -> {
List<Persongroup> pgs = p.getPersongroups();
for (Persongroup pg : pgs) {
if (groups.contains(pg.getGroupDef())) {
return true;
}
}
return false;
});
}
public void setTitle(String value) {
if (value == null) {
value = "";
}
textTitle.setValue(value);
}
public void setItems(Collection<Person> items) {
grid.setItems(items);
}

@ -4,3 +4,6 @@ spring.datasource.password=0773
security.ignored=/**
security.basic.enable: false
management.security.enabled: false
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

@ -0,0 +1,12 @@
/* This file is automatically managed and will be overwritten from time to time. */
/* Do not manually edit this file. */
/* Provided by calendar-component-2.0-BETA4.jar */
@import "../../../VAADIN/addons/calendar/calendar-addon.scss";
/* Import and include this mixin into your project theme to include the addon themes */
@mixin addons {
@include calendar-addon;
}

@ -0,0 +1,9 @@
@import "addons.scss";
@import "vaadin-clubhelpertheme.scss";
/* This file prefixes all rules with the theme name to avoid causing conflicts with other themes. */
/* The actual styles should be defined in vaadin-clubhelpertheme.scss */
.vaadin-clubhelpertheme {
@include addons;
@include vaadin-clubhelpertheme;
}

@ -0,0 +1,40 @@
// Global variable overrides. Must be declared before importing Valo.
// Defines the plaintext font size, weight and family. Font size affects general component sizing.
//$v-font-size: 16px;
//$v-font-weight: 300;
//$v-font-family: "Open Sans", sans-serif;
// Defines the border used by all components.
//$v-border: 1px solid (v-shade 0.7);
//$v-border-radius: 4px;
// Affects the color of some component elements, e.g Button, Panel title, etc
//$v-background-color: hsl(210, 0%, 98%);
// Affects the color of content areas, e.g Panel and Window content, TextField input etc
//$v-app-background-color: $v-background-color;
// Affects the visual appearance of all components
//$v-gradient: v-linear 8%;
//$v-bevel-depth: 30%;
//$v-shadow-opacity: 5%;
// Defines colors for indicating status (focus, success, failure)
//$v-focus-color: valo-focus-color(); // Calculates a suitable color automatically
//$v-friendly-color: #2c9720;
//$v-error-indicator-color: #ed473b;
// For more information, see: https://vaadin.com/book/-/page/themes.valo.html
// Example variants can be copy/pasted from https://vaadin.com/wiki/-/wiki/Main/Valo+Examples
@import "../valo/valo.scss";
@mixin vaadin-clubhelpertheme {
@include valo;
// Insert your own theme rules here
.title_label {
font-weight: bold;
font-size: large;
}
}
Loading…
Cancel
Save