use of org.jooq.generated.tables.records.CountriesRecord in project jOOQ by jOOQ.
the class BarChartSample method start.
@Override
public void start(Stage stage) {
stage.setTitle("Country statistics with jOOQ and JavaFX");
Label error = new Label("");
error.setPadding(new Insets(10.0));
// Create two charts, plotting a specific metric, each.
BarChart<String, Number> chart1 = chart(COUNTRIES.GDP_PER_CAPITA, "GDP per Capita", "USD");
BarChart<String, Number> chart2 = chart(COUNTRIES.GOVT_DEBT, "Government Debt", "% of GDP");
TableView<CountriesRecord> table = table(COUNTRIES);
Runnable refresh = () -> {
table.getItems().clear();
table.getItems().addAll(ctx().fetch(COUNTRIES).sortAsc(COUNTRIES.YEAR).sortAsc(COUNTRIES.CODE));
chartRefresh(chart1);
chartRefresh(chart2);
error.setText("");
selected = ctx().newRecord(COUNTRIES);
};
refresh.run();
table.getSelectionModel().getSelectedItems().addListener((Change<? extends CountriesRecord> c) -> {
if (c.getList().isEmpty())
selected = ctx().newRecord(COUNTRIES);
else
for (CountriesRecord record : c.getList()) selected = record;
});
GridPane editPane = new GridPane();
int i = 0;
for (Field<?> field : COUNTRIES.fields()) {
Label label = new Label(field.getName());
TextField textField = new TextField();
textField.textProperty().addListener((o, oldV, newV) -> {
selected.set((Field) field, newV);
});
table.getSelectionModel().getSelectedItems().addListener((Change<? extends CountriesRecord> c) -> {
if (c.getList().isEmpty())
textField.setText("");
else
for (CountriesRecord record : c.getList()) textField.setText(record.get(field, String.class));
});
editPane.addRow(i++, label, textField);
}
Button saveButton = new Button("Save");
saveButton.setOnAction(event -> {
try {
if (selected.store() > 0)
refresh.run();
} catch (DataAccessException e) {
e.printStackTrace();
error.setText(e.sqlStateClass() + ": " + e.getCause().getMessage());
}
});
Button deleteButton = new Button("Delete");
deleteButton.setOnAction(event -> {
try {
if (selected.delete() > 0)
refresh.run();
} catch (DataAccessException e) {
e.printStackTrace();
error.setText(e.sqlStateClass() + ": " + e.getCause().getMessage());
}
});
GridPane buttonPane = new GridPane();
buttonPane.addRow(0, saveButton, deleteButton);
editPane.addRow(i++, new Label(""), buttonPane);
GridPane chartPane = new GridPane();
chartPane.addColumn(0, chart1, chart2);
grow(chartPane);
GridPane display = new GridPane();
display.addRow(0, chartPane, table, editPane);
grow(display);
GridPane displayAndStatus = new GridPane();
displayAndStatus.addColumn(0, display, error);
displayAndStatus.setGridLinesVisible(true);
grow(displayAndStatus);
Scene scene = new Scene(displayAndStatus, 1000, 800);
stage.setScene(scene);
stage.show();
}
Aggregations