-
Notifications
You must be signed in to change notification settings - Fork 82
/
ForecastDisplay.java
41 lines (33 loc) · 1.13 KB
/
ForecastDisplay.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.example;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import com.vaadin.data.ValueProvider;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import org.example.domain.Forecast;
import org.example.domain.ForecastResponse;
/**
*
* @author Matti Tahvonen <matti@vaadin.com>
*/
public class ForecastDisplay extends Grid<Forecast> {
String captionTemplate = "Tomorrow in %s there will be %s";
public void setForecast(ForecastResponse fr) {
setCaption(
String.format(captionTemplate,
fr.getCity().getName(),
fr.getList().get(0).getWeather().get(0).
getDescription())
);
removeAllColumns();
addColumn(fc -> {
int day = fr.getList().indexOf(fc);
return LocalDate.now().plusDays(day);
}).setCaption("Day");
addColumn(fc -> fc.getTemp().getDay() + "° C").setCaption("Temp");
addColumn(fc -> fc.getWeather().get(0).getDescription()).setCaption("Description");
setItems(fr.getList());
}
}