From 299fb72c57b0c922239fdf7f02d9bb9b4b64116c Mon Sep 17 00:00:00 2001 From: "vincent.steinman" <vincent.steinmann@etu.hesge.ch> Date: Mon, 30 Jan 2023 16:47:48 +0100 Subject: [PATCH] edit relation/workplace --- .../com/example/tpfx/HelloController.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tp/src/main/java/com/example/tpfx/HelloController.java b/tp/src/main/java/com/example/tpfx/HelloController.java index 92bbe4a..dcbd284 100644 --- a/tp/src/main/java/com/example/tpfx/HelloController.java +++ b/tp/src/main/java/com/example/tpfx/HelloController.java @@ -49,7 +49,7 @@ public class HelloController { //Fx functions /** - * Form start up. Hide and Disable unwanted component + * Form start up. Hide and Disable unwanted component */ @FXML protected void initialize() { @@ -66,6 +66,7 @@ public class HelloController { */ @FXML protected void AddCt() { + //enhanced switch, doesn't need break switch (cbxType.getValue().toString()){ //Use the combo box value case "Friend" -> AddPal(); case "Family" -> AddFam(); @@ -240,21 +241,23 @@ public class HelloController { List<String> social = SplitLine(txtSocial.getText(), " "); String job = txtJob.getText(); String other = txtOther.getText(); + int selected_id = LstCt.getSelectionModel().getSelectedIndex(); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setFirstName(firstName); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setLastName(lastName); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setAddr(address); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setPhone(phone); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setEmail(emails); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setSocial(social); - contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).setJob(job); - if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).getType().equals("Family")){ -// Family fam = (Family)contactArray.get(LstCt.getSelectionModel().getSelectedIndex()); -// fam.editRelation(other); -// int tmp = LstCt.getSelectionModel().getSelectedIndex(); -// contactArray.get(tmp) = fam; + contactArray.get(selected_id).setFirstName(firstName); + contactArray.get(selected_id).setLastName(lastName); + contactArray.get(selected_id).setAddr(address); + contactArray.get(selected_id).setPhone(phone); + contactArray.get(selected_id).setEmail(emails); + contactArray.get(selected_id).setSocial(social); + contactArray.get(selected_id).setJob(job); + if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()) instanceof Family){ + Family fam = (Family)contactArray.get(selected_id); + fam.setRelation(other); + contactArray.set(selected_id, fam); } else if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).getType().equals("Professional")){ - + Professional pro = (Professional)contactArray.get(selected_id); + pro.setWork(other); + contactArray.set(selected_id, pro); } ShowAll(); } @@ -366,7 +369,8 @@ public class HelloController { List<String> emailList = Arrays.asList(emails.split("/")); List<String> socialList = Arrays.asList(social.split("/")); - Professional pro = new Professional(first_name_list, lastName, address, phoneList, emailList, socialList, job, wp); + Professional pro = new Professional(first_name_list, lastName, address, phoneList, + emailList, socialList, job, wp); Add(pro); } /** @@ -448,11 +452,4 @@ public class HelloController { public List<String> SplitLine(String str, String splitter){ return Arrays.asList(str.split(splitter)); } - - //TODO - /* - Unit Test, - edit relation/job? - */ - } \ No newline at end of file -- GitLab