use of com.kyj.fx.voeditor.visual.component.grid.EditableTableView in project Gargoyle by callakrsos.
the class EditableTableViewExam method start.
@Override
public void start(Stage primaryStage) throws Exception {
Button btnExec = new Button("Exec.");
Button btnAdd = new Button("Add ");
Button btnRemove = new Button("Remove");
Button btnSave = new Button("Save");
btnAdd.setDisable(true);
TextField textField = new TextField();
HBox hBox = new HBox(5, textField, btnExec, btnAdd, btnRemove, btnSave);
EditableTableView editableTableView = new EditableTableView(new Supplier<Connection>() {
@Override
public Connection get() {
try {
return DbUtil.getConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
});
editableTableView.tableNameProperty().addListener((oba, oldval, newval) -> {
btnAdd.setDisable(false);
});
// editableTableView.execute("tbm_sm_realtime_search");
btnExec.setOnAction(e -> {
String tableName = textField.getText();
try {
editableTableView.readByTableName("select * from " + tableName, tableName);
} catch (Exception e1) {
e1.printStackTrace();
}
});
btnAdd.setOnAction(ev -> {
editableTableView.getItems().add(new HashMap<>());
editableTableView.getSelectionModel().selectLast();
editableTableView.scrollTo(editableTableView.getItems().size() - 1);
});
btnRemove.setOnAction(ev -> {
editableTableView.getItems().removeAll(editableTableView.getSelectionModel().getSelectedItems());
});
btnSave.setOnAction(ev -> {
try {
editableTableView.save();
} catch (Exception e1) {
e1.printStackTrace();
}
});
editableTableView.setOnMouseClicked(ev -> {
Map<ColumnExpression, ObjectProperty<ValueExpression>> selectedItem = editableTableView.getSelectionModel().getSelectedItem();
System.out.println(selectedItem);
});
BorderPane root = new BorderPane(editableTableView);
root.setTop(hBox);
Scene value = new Scene(root);
// ".table-row{ -fx-background-color: red; }"
// value.getStylesheets().add(EditableTableViewExam.class.getResource("EditableTableViewExam.css").toExternalForm());
primaryStage.setScene(value);
primaryStage.show();
}
Aggregations