Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. private final IntegerProperty idPerson;
  2. private final StringProperty firstName;
  3. private final StringProperty lastName;
  4. private final StringProperty street;
  5. private final IntegerProperty postalCode;
  6. private final StringProperty city;
  7. private final ObjectProperty<LocalDate> birthday;
  8.  
  9. /**
  10. * Default constructor.
  11. */
  12. public Person() {
  13. this(null,null, null);
  14. }
  15.  
  16. /**
  17. * Constructor with some initial data.
  18. *
  19. * @param firstName
  20. * @param lastName
  21. */
  22. public Person(Integer idPerson, String firstName, String lastName) {
  23. this.idPerson = new SimpleIntegerProperty(idPerson);
  24. this.firstName = new SimpleStringProperty(firstName);
  25. this.lastName = new SimpleStringProperty(lastName);
  26.  
  27. // Some initial dummy data, just for convenient testing.
  28. this.street = new SimpleStringProperty("some street");
  29. this.postalCode = new SimpleIntegerProperty(1234);
  30. this.city = new SimpleStringProperty("some city");
  31. this.birthday = new SimpleObjectProperty<LocalDate>(LocalDate.of(1999, 2, 21));
  32. }
  33.  
  34. public Integer getIdPerson() {
  35. return idPerson.get();
  36. }
  37.  
  38. public void setIdPerson(int postalCode) {
  39. this.postalCode.set(postalCode);
  40. }
  41.  
  42. public IntegerProperty idPersonProperty() {
  43. return idPerson;
  44. }
  45.  
  46. public String getFirstName() {
  47. return firstName.get();
  48. }
  49.  
  50. public void setFirstName(String firstName) {
  51. this.firstName.set(firstName);
  52. }
  53.  
  54. public StringProperty firstNameProperty() {
  55. return firstName;
  56. }
  57.  
  58. public String getLastName() {
  59. return lastName.get();
  60. }
  61.  
  62. public void setLastName(String lastName) {
  63. this.lastName.set(lastName);
  64. }
  65.  
  66. public StringProperty lastNameProperty() {
  67. return lastName;
  68. }
  69.  
  70. public String getStreet() {
  71. return street.get();
  72. }
  73.  
  74. public void setStreet(String street) {
  75. this.street.set(street);
  76. }
  77.  
  78. public StringProperty streetProperty() {
  79. return street;
  80. }
  81.  
  82. public int getPostalCode() {
  83. return postalCode.get();
  84. }
  85.  
  86. public void setPostalCode(int postalCode) {
  87. this.postalCode.set(postalCode);
  88. }
  89.  
  90. public IntegerProperty postalCodeProperty() {
  91. return postalCode;
  92. }
  93.  
  94. public String getCity() {
  95. return city.get();
  96. }
  97.  
  98. public void setCity(String city) {
  99. this.city.set(city);
  100. }
  101.  
  102. public StringProperty cityProperty() {
  103. return city;
  104. }
  105.  
  106. public LocalDate getBirthday() {
  107. return birthday.get();
  108. }
  109.  
  110. public void setBirthday(LocalDate birthday) {
  111. this.birthday.set(birthday);
  112. }
  113.  
  114. public ObjectProperty<LocalDate> birthdayProperty() {
  115. return birthday;
  116. }
  117.  
  118. public class PersonOverviewController {
  119. @FXML
  120. private TableView<Person> personTable;
  121. @FXML
  122. private TableColumn<Person, Number> idPersonColumn;
  123. @FXML
  124. private TableColumn<Person, String> firstNameColumn;
  125. @FXML
  126. private TableColumn<Person, String> lastNameColumn;
  127.  
  128. @FXML
  129. private Label firstNameLabel;
  130. @FXML
  131. private Label lastNameLabel;
  132. @FXML
  133. private Label streetLabel;
  134. @FXML
  135. private Label postalCodeLabel;
  136. @FXML
  137. private Label cityLabel;
  138. @FXML
  139. private Label birthdayLabel;
  140.  
  141. // Reference to the main application.
  142. private MainApp mainApp;
  143.  
  144. /**
  145. * The constructor. The constructor is called before the initialize()
  146. * method.
  147. */
  148. public PersonOverviewController() {
  149. }
  150.  
  151. /**
  152. * Initializes the controller class. This method is automatically called
  153. * after the fxml file has been loaded.
  154. */
  155. @FXML
  156. private void initialize() {
  157. // Initialize the person table with the two columns.
  158. idPersonColumn.setCellValueFactory(cellData -> cellData.getValue().idPersonProperty());
  159. firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
  160. lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
  161.  
  162. // Clear person details.
  163. showPersonDetails(null);
  164.  
  165. // Listen for selection changes and show the person details when
  166. // changed.
  167. personTable.getSelectionModel().selectedItemProperty()
  168. .addListener((observable, oldValue, newValue) -> showPersonDetails(newValue));
  169.  
  170. }
  171.  
  172. /**
  173. * Fills all text fields to show details about the person. If the specified
  174. * person is null, all text fields are cleared.
  175. *
  176. * @param person
  177. * the person or null
  178. */
  179. private void showPersonDetails(Person person) {
  180. if (person != null) {
  181. // Fill the labels with info from the person object.
  182. firstNameLabel.setText(person.getFirstName());
  183. lastNameLabel.setText(person.getLastName());
  184. streetLabel.setText(person.getStreet());
  185. postalCodeLabel.setText(Integer.toString(person.getPostalCode()));
  186. cityLabel.setText(person.getCity());
  187.  
  188. // We need a way to convert the birthday into a String!
  189. birthdayLabel.setText(DateUtil.format(person.getBirthday()));
  190. // birthdayLabel.setText(...);
  191. } else {
  192. // Person is null, remove all the text.
  193. firstNameLabel.setText("");
  194. lastNameLabel.setText("");
  195. streetLabel.setText("");
  196. postalCodeLabel.setText("");
  197. cityLabel.setText("");
  198. birthdayLabel.setText("");
  199. }
  200. }
  201.  
  202. /**
  203. * Called when the user clicks on the delete button.
  204. */
  205. @FXML
  206. private void handleDeletePerson() {
  207. int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
  208. //;TODO I want to retrieve the column of this line to remove this person from the database
  209.  
  210. }`
  211.  
  212. /**
  213. * Is called by the main application to give a reference back to itself.
  214. *
  215. * @param mainApp
  216. */
  217. public void setMainApp(MainApp mainApp) {
  218. this.mainApp = mainApp;
  219.  
  220. // Add observable list data to the table
  221. personTable.setItems(mainApp.getPersonData());
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement