Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final IntegerProperty idPerson;
- private final StringProperty firstName;
- private final StringProperty lastName;
- private final StringProperty street;
- private final IntegerProperty postalCode;
- private final StringProperty city;
- private final ObjectProperty<LocalDate> birthday;
- /**
- * Default constructor.
- */
- public Person() {
- this(null,null, null);
- }
- /**
- * Constructor with some initial data.
- *
- * @param firstName
- * @param lastName
- */
- public Person(Integer idPerson, String firstName, String lastName) {
- this.idPerson = new SimpleIntegerProperty(idPerson);
- this.firstName = new SimpleStringProperty(firstName);
- this.lastName = new SimpleStringProperty(lastName);
- // Some initial dummy data, just for convenient testing.
- this.street = new SimpleStringProperty("some street");
- this.postalCode = new SimpleIntegerProperty(1234);
- this.city = new SimpleStringProperty("some city");
- this.birthday = new SimpleObjectProperty<LocalDate>(LocalDate.of(1999, 2, 21));
- }
- public Integer getIdPerson() {
- return idPerson.get();
- }
- public void setIdPerson(int postalCode) {
- this.postalCode.set(postalCode);
- }
- public IntegerProperty idPersonProperty() {
- return idPerson;
- }
- public String getFirstName() {
- return firstName.get();
- }
- public void setFirstName(String firstName) {
- this.firstName.set(firstName);
- }
- public StringProperty firstNameProperty() {
- return firstName;
- }
- public String getLastName() {
- return lastName.get();
- }
- public void setLastName(String lastName) {
- this.lastName.set(lastName);
- }
- public StringProperty lastNameProperty() {
- return lastName;
- }
- public String getStreet() {
- return street.get();
- }
- public void setStreet(String street) {
- this.street.set(street);
- }
- public StringProperty streetProperty() {
- return street;
- }
- public int getPostalCode() {
- return postalCode.get();
- }
- public void setPostalCode(int postalCode) {
- this.postalCode.set(postalCode);
- }
- public IntegerProperty postalCodeProperty() {
- return postalCode;
- }
- public String getCity() {
- return city.get();
- }
- public void setCity(String city) {
- this.city.set(city);
- }
- public StringProperty cityProperty() {
- return city;
- }
- public LocalDate getBirthday() {
- return birthday.get();
- }
- public void setBirthday(LocalDate birthday) {
- this.birthday.set(birthday);
- }
- public ObjectProperty<LocalDate> birthdayProperty() {
- return birthday;
- }
- public class PersonOverviewController {
- @FXML
- private TableView<Person> personTable;
- @FXML
- private TableColumn<Person, Number> idPersonColumn;
- @FXML
- private TableColumn<Person, String> firstNameColumn;
- @FXML
- private TableColumn<Person, String> lastNameColumn;
- @FXML
- private Label firstNameLabel;
- @FXML
- private Label lastNameLabel;
- @FXML
- private Label streetLabel;
- @FXML
- private Label postalCodeLabel;
- @FXML
- private Label cityLabel;
- @FXML
- private Label birthdayLabel;
- // Reference to the main application.
- private MainApp mainApp;
- /**
- * The constructor. The constructor is called before the initialize()
- * method.
- */
- public PersonOverviewController() {
- }
- /**
- * Initializes the controller class. This method is automatically called
- * after the fxml file has been loaded.
- */
- @FXML
- private void initialize() {
- // Initialize the person table with the two columns.
- idPersonColumn.setCellValueFactory(cellData -> cellData.getValue().idPersonProperty());
- firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
- lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
- // Clear person details.
- showPersonDetails(null);
- // Listen for selection changes and show the person details when
- // changed.
- personTable.getSelectionModel().selectedItemProperty()
- .addListener((observable, oldValue, newValue) -> showPersonDetails(newValue));
- }
- /**
- * Fills all text fields to show details about the person. If the specified
- * person is null, all text fields are cleared.
- *
- * @param person
- * the person or null
- */
- private void showPersonDetails(Person person) {
- if (person != null) {
- // Fill the labels with info from the person object.
- firstNameLabel.setText(person.getFirstName());
- lastNameLabel.setText(person.getLastName());
- streetLabel.setText(person.getStreet());
- postalCodeLabel.setText(Integer.toString(person.getPostalCode()));
- cityLabel.setText(person.getCity());
- // We need a way to convert the birthday into a String!
- birthdayLabel.setText(DateUtil.format(person.getBirthday()));
- // birthdayLabel.setText(...);
- } else {
- // Person is null, remove all the text.
- firstNameLabel.setText("");
- lastNameLabel.setText("");
- streetLabel.setText("");
- postalCodeLabel.setText("");
- cityLabel.setText("");
- birthdayLabel.setText("");
- }
- }
- /**
- * Called when the user clicks on the delete button.
- */
- @FXML
- private void handleDeletePerson() {
- int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
- //;TODO I want to retrieve the column of this line to remove this person from the database
- }`
- /**
- * Is called by the main application to give a reference back to itself.
- *
- * @param mainApp
- */
- public void setMainApp(MainApp mainApp) {
- this.mainApp = mainApp;
- // Add observable list data to the table
- personTable.setItems(mainApp.getPersonData());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement