Skip to content

Instantly share code, notes, and snippets.

@fge
Created March 17, 2015 21:06
Show Gist options
  • Save fge/f15872468682bfd91cd2 to your computer and use it in GitHub Desktop.
Save fge/f15872468682bfd91cd2 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Controller;
import com.gemtastic.carshop.tables.records.CustomerRecord;
import com.gemtastic.carshop.utils.JavafxUtils;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import java.net.URL;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.util.ResourceBundle;
import static com.gemtastic.carshop.tables.Customer.CUSTOMER;
/**
*
* @author Gemtastic
*/
public class ListCustomerController implements Initializable {
@FXML
public TableView<CustomerRecord> customers;
@FXML
public TableColumn<CustomerRecord, String> firstname;
@FXML
private TableColumn<CustomerRecord, String> lastname;
@FXML
private TableColumn<CustomerRecord, String> address;
@FXML
private TableColumn<CustomerRecord, String> phone;
@FXML
private TableColumn<CustomerRecord, Integer> customerID;
@FXML
private TableColumn<CustomerRecord, Date> dateOfBirth;
// public void populateTable(ObservableList<Customer> customer){
// customers.setItems(customer);
// }
@Override
public void initialize(URL location, ResourceBundle resources) {
JavafxUtils.setColumnValue(firstname, CustomerRecord::getFirstName);
JavafxUtils.setColumnValue(lastname, CustomerRecord::getLastName);
JavafxUtils.setColumnValue(phone, CustomerRecord::getPhone);
JavafxUtils.setColumnValue(customerID, CustomerRecord::getId);
JavafxUtils.setColumnValue(dateOfBirth, CustomerRecord::getDateOfBirth);
ObservableList<CustomerRecord> l = FXCollections.observableArrayList();
try(Connection con = DriverManager.getConnection("jdbc:postgresql:postgres", "postgres", "g3mt45t1c")){
DSLContext jooq = DSL.using(con, SQLDialect.POSTGRES);
jooq.selectFrom(CUSTOMER).fetch()
.forEach(customers.getItems()::add);
}catch(Exception e){
e.printStackTrace();
}
}
}
@basith374
Copy link

hi. where can i find the source for JavafxUtils file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment