use of com.vaadin.data.ValidationException in project v-leaflet by mstahv.
the class JtsPointFieldTest method getTestComponent.
// private Polygon polygon;
@Override
public Component getTestComponent() {
content.setMargin(true);
display.setContentMode(ContentMode.PREFORMATTED);
display.setCaption("Pojo state:");
display.setValue(pojo.toString());
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setSizeFull();
VerticalLayout editorform = new VerticalLayout();
editorform.setSizeFull();
editorform.setSpacing(true);
editorform.setCaption("Edit JTS pojo:");
TabSheet jtsFields = new TabSheet(point);
jtsFields.setCaption("JTS fiels:");
jtsFields.setSizeFull();
editorform.addComponents(new HorizontalLayout(name, date), jtsFields);
editorform.setExpandRatio(jtsFields, 1);
final Binder<JtsPojo> beanBinder = new Binder<>(JtsPojo.class);
beanBinder.readBean(pojo);
beanBinder.bindInstanceFields(this);
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.addComponent(new Button("Save", (ClickListener) event -> {
try {
beanBinder.writeBean(pojo);
display.setValue(pojo.toString());
} catch (ValidationException e) {
System.err.println("Validation errors:" + Arrays.toString(e.getBeanValidationErrors().toArray()));
}
}));
CheckBox roCheckBox = new CheckBox("Read only", false);
roCheckBox.addValueChangeListener(event -> beanBinder.setReadOnly(event.getValue()));
buttonLayout.addComponent(roCheckBox);
buttonLayout.addComponent(new Button("Assign new empty bean", (ClickListener) event -> {
pojo = new JtsPojo();
beanBinder.readBean(pojo);
display.setValue(pojo.toString());
}));
buttonLayout.addComponent(new Button("Assign bean with preset data", (ClickListener) event -> {
pojo = new JtsPojo();
pojo.setPoint(JTSUtil.toPoint(new org.vaadin.addon.leaflet.shared.Point(61, 22)));
beanBinder.readBean(pojo);
display.setValue(pojo.toString());
}));
editorform.addComponent(buttonLayout);
horizontalLayout.addComponents(editorform, display);
horizontalLayout.setExpandRatio(editorform, 1);
horizontalLayout.setExpandRatio(display, 1);
return horizontalLayout;
}
use of com.vaadin.data.ValidationException 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