Skip to content

Commit 53a7f21

Browse files
committed
Create demo
1 parent 915e7a6 commit 53a7f21

File tree

3 files changed

+334
-0
lines changed

3 files changed

+334
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package software.xdev.vaadin.model;
2+
3+
public enum Department
4+
{
5+
IT,
6+
HR,
7+
ACCOUNTING
8+
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
package software.xdev.vaadin.model;
2+
3+
import java.time.LocalDate;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
8+
/**
9+
* Represents a person with attributes such as first name, last name, birthday, subscription status, and an identifier.
10+
*/
11+
public class Person
12+
{
13+
private Integer id;
14+
private String firstName;
15+
private String lastName;
16+
private LocalDate birthday;
17+
private boolean married;
18+
private double salary;
19+
private Department department;
20+
21+
/**
22+
* Constructs a new instance of the Person class with the provided attributes.
23+
*
24+
* @param id The unique identifier of the person.
25+
* @param firstName The first name of the person.
26+
* @param lastName The last name of the person.
27+
* @param birthday The birthdate of the person.
28+
* @param married Whether the person is a married (true) or not (false).
29+
* @param salary The paid salary
30+
* @param department The associated department
31+
*/
32+
public Person(
33+
final Integer id,
34+
final String firstName,
35+
final String lastName,
36+
final LocalDate birthday,
37+
final boolean married,
38+
final double salary,
39+
final Department department)
40+
{
41+
this.id = id;
42+
this.firstName = firstName;
43+
this.lastName = lastName;
44+
this.birthday = birthday;
45+
this.married = married;
46+
this.salary = salary;
47+
this.department = department;
48+
}
49+
50+
/**
51+
* Gets the first name of the person.
52+
*
53+
* @return The first name of the person.
54+
*/
55+
public String getFirstName()
56+
{
57+
return this.firstName;
58+
}
59+
60+
/**
61+
* Sets the first name of the person.
62+
*
63+
* @param firstName The new first name to set.
64+
*/
65+
public void setFirstName(final String firstName)
66+
{
67+
this.firstName = firstName;
68+
}
69+
70+
/**
71+
* Gets the last name of the person.
72+
*
73+
* @return The last name of the person.
74+
*/
75+
public String getLastName()
76+
{
77+
return this.lastName;
78+
}
79+
80+
/**
81+
* Sets the last name of the person.
82+
*
83+
* @param lastName The new last name to set.
84+
*/
85+
public void setLastName(final String lastName)
86+
{
87+
this.lastName = lastName;
88+
}
89+
90+
/**
91+
* Gets the birthdate of the person.
92+
*
93+
* @return The birthdate of the person.
94+
*/
95+
public LocalDate getBirthday()
96+
{
97+
return this.birthday;
98+
}
99+
100+
/**
101+
* Sets the birthdate of the person.
102+
*
103+
* @param birthday The new birthdate to set.
104+
*/
105+
public void setBirthday(final LocalDate birthday)
106+
{
107+
this.birthday = birthday;
108+
}
109+
110+
/**
111+
* Gets the unique identifier of the person.
112+
*
113+
* @return The unique identifier of the person.
114+
*/
115+
public Integer getId()
116+
{
117+
return this.id;
118+
}
119+
120+
/**
121+
* Sets the unique identifier of the person.
122+
*
123+
* @param id The new unique identifier to set.
124+
*/
125+
public void setId(final Integer id)
126+
{
127+
this.id = id;
128+
}
129+
130+
/**
131+
* Checks if the person is married.
132+
*
133+
* @return True if the person is married, false otherwise.
134+
*/
135+
public boolean isMarried()
136+
{
137+
return this.married;
138+
}
139+
140+
/**
141+
* Sets person's married status.
142+
*
143+
* @param married True to mark the person as married, false to mark the person as unmarried.
144+
*/
145+
public void setMarried(final boolean married)
146+
{
147+
this.married = married;
148+
}
149+
150+
/**
151+
* Gets the salary of the person.
152+
*
153+
* @return The salary of the person.
154+
*/
155+
156+
public double getSalary()
157+
{
158+
return this.salary;
159+
}
160+
161+
/**
162+
* Sets the salary of the person.
163+
*
164+
* @param salary The new salary to set.
165+
*/
166+
public void setSalary(final double salary)
167+
{
168+
this.salary = salary;
169+
}
170+
171+
/**
172+
* Gets the associated department of the person.
173+
*
174+
* @return The associated department of the person.
175+
*/
176+
public Department getDepartment()
177+
{
178+
return this.department;
179+
}
180+
181+
/**
182+
* Sets the associated department of the person.
183+
*
184+
* @param department The associated department to set.
185+
*/
186+
public void setDepartment(final Department department)
187+
{
188+
this.department = department;
189+
}
190+
191+
/**
192+
* Retrieves a list of sample Person objects.
193+
*
194+
* @return A List containing sample Person objects.
195+
*/
196+
@SuppressWarnings("checkstyle:MagicNumber")
197+
public static List<Person> getPersons()
198+
{
199+
final List<Person> lst = new ArrayList<>();
200+
201+
lst.add(new Person(0, "Siegbert", "Schmidt", LocalDate.of(1990, 12, 17), false, 1000, Department.HR));
202+
lst.add(new Person(1, "Herbert", "Maier", LocalDate.of(1967, 10, 13), false, 1000, Department.HR));
203+
lst.add(new Person(2, "Hans", "Lang", LocalDate.of(2002, 5, 9), true, 9050.60, Department.HR));
204+
lst.add(new Person(3, "Anton", "Meier", LocalDate.of(1985, 1, 24), true, 8000.75, Department.HR));
205+
lst.add(new Person(4, "Sarah", "Smith", LocalDate.of(1999, 6, 1), false, 5000, Department.IT));
206+
lst.add(new Person(5, "Niklas", "Sommer", LocalDate.of(1994, 11, 8), true, 4000.33, Department.HR));
207+
lst.add(new Person(6, "Hanna", "Neubaum", LocalDate.of(1986, 8, 15), true, 3000, Department.HR));
208+
lst.add(new Person(8, "Laura", "Fels", LocalDate.of(1996, 3, 20), true, 1000.50, Department.HR));
209+
lst.add(new Person(7, "Sofia", "Sommer", LocalDate.of(1972, 4, 14), false, 2000, Department.ACCOUNTING));
210+
211+
return lst;
212+
}
213+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package software.xdev.vaadin.ui;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
import java.util.Locale;
6+
7+
import com.vaadin.flow.component.datepicker.DatePicker;
8+
import com.vaadin.flow.component.grid.Grid;
9+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
10+
import com.vaadin.flow.data.provider.ListDataProvider;
11+
import com.vaadin.flow.router.AfterNavigationEvent;
12+
import com.vaadin.flow.router.AfterNavigationObserver;
13+
import com.vaadin.flow.router.Route;
14+
15+
import software.xdev.vaadin.FilterComponent;
16+
import software.xdev.vaadin.builder.CustomizableFilterBuilder;
17+
import software.xdev.vaadin.comparators.EqualComparator;
18+
import software.xdev.vaadin.comparators.IsBetweenComparator;
19+
import software.xdev.vaadin.comparators.NotEqualComparator;
20+
import software.xdev.vaadin.daterange_picker.business.DateRangeModel;
21+
import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges;
22+
import software.xdev.vaadin.model.Department;
23+
import software.xdev.vaadin.model.Person;
24+
import software.xdev.vaadin.model.SimpleFilterField;
25+
26+
27+
/**
28+
* Primary UI with filter component and grid.
29+
*/
30+
@Route("")
31+
public class MainView extends VerticalLayout implements AfterNavigationObserver
32+
{
33+
private final Grid<Person> dataGrid = new Grid<>(Person.class, true);
34+
35+
public MainView()
36+
{
37+
super();
38+
this.initUI();
39+
}
40+
41+
private void initUI()
42+
{
43+
// Grid configuration.
44+
this.dataGrid.setSelectionMode(Grid.SelectionMode.NONE);
45+
this.dataGrid.setSizeFull();
46+
47+
// Fill grid with dummy data.
48+
this.dataGrid.setDataProvider(new ListDataProvider<>(Person.getPersons()));
49+
50+
final DatePicker.DatePickerI18n datePickerI18n = new DatePicker.DatePickerI18n()
51+
.setDateFormat("dd.MM.yyyy");
52+
53+
// Create the FilterComponent.
54+
final FilterComponent<Person> filterComponent = new FilterComponent<>(this.dataGrid)
55+
.withFilter(new SimpleFilterField<>(Person::getLastName, "Lastname"))
56+
.withFilter(new SimpleFilterField<>(Person::getSalary, "Salary"))
57+
.withFilter(
58+
CustomizableFilterBuilder.builder()
59+
.withValueProvider(Person::getId, "Personnel number")
60+
.withEqualComparator()
61+
.withGreaterThanComparator()
62+
.withLessThanComparator()
63+
)
64+
.withFilter(
65+
CustomizableFilterBuilder.builder()
66+
.withValueProvider(Person::isMarried, "Married")
67+
.withEqualComparator()
68+
.withAvailableComparator(NotEqualComparator.getInstance())
69+
)
70+
.withFilter(
71+
CustomizableFilterBuilder.builder()
72+
.withValueProvider(Person::getDepartment, "Department", Department.values())
73+
.withContainsComparator()
74+
.withEqualComparator()
75+
)
76+
.withFilter(
77+
CustomizableFilterBuilder.builder()
78+
.withValueProvider(Person::getBirthday, "Birthday")
79+
.withIsAfterComparator()
80+
.withIsBeforeComparator()
81+
.withIsBetweenComparator()
82+
)
83+
.withDatePickerI18n(datePickerI18n)
84+
.withDateTimePickerLocale(Locale.GERMANY)
85+
.withFilterButtonText("Add filter")
86+
.withUrlParameters("filter1")
87+
.withCustomDateRangeModel(
88+
new DateRangeModel<>(LocalDate.now(), LocalDate.now().plusDays(5), SimpleDateRanges.FREE),
89+
List.of(SimpleDateRanges.allValues()))
90+
.withInitialFilter(
91+
CustomizableFilterBuilder.builder().withValueProvider(Person::getBirthday, "Birthday"),
92+
IsBetweenComparator.getInstance(), "2000-01-01#2002-08-12",
93+
true,
94+
true
95+
)
96+
.withInitialFilter(
97+
CustomizableFilterBuilder.builder().withValueProvider(Person::isMarried, "Married"),
98+
EqualComparator.getInstance(),
99+
"true",
100+
false,
101+
true
102+
);
103+
104+
this.add(filterComponent, this.dataGrid);
105+
this.setSizeFull();
106+
}
107+
108+
@Override
109+
public void afterNavigation(final AfterNavigationEvent event)
110+
{
111+
112+
}
113+
}

0 commit comments

Comments
 (0)