use of com.vaadin.data.converter.StringToDoubleConverter in project charts by vaadin.
the class ChartWithExternalDataProviderWithChangingData method getChart.
@Override
protected Component getChart() {
HorizontalLayout lo = new HorizontalLayout();
VerticalLayout vlo = new VerticalLayout();
DataProviderSeries<Data> ds = createChartDS();
Component grid = createGrid();
TextField field = new TextField("New data value");
Binder<Data> binder = new Binder<>();
binder.forField(field).withValidator((String v) -> v != null && !v.isEmpty(), "The field cannot be empty").withConverter(new StringToDoubleConverter("Not a double")).bind(Data::getValue, Data::setValue);
binder.readBean(new Data(0.0));
Button button = new Button("Add data", e -> {
Data v = new Data(0.0);
try {
binder.writeBean(v);
data.add(v);
v = new Data(1.0);
binder.readBean(v);
} catch (ValidationException ve) {
}
});
Component chart = createChart(ds);
vlo.addComponents(field, button, grid);
vlo.setSpacing(true);
lo.addComponents(vlo, chart);
grid.setSizeFull();
chart.setSizeFull();
lo.setSizeFull();
lo.setExpandRatio(vlo, 1);
lo.setExpandRatio(chart, 3);
return lo;
}
Aggregations