diff --git a/tp/src/main/java/com/example/tpfx/Contact.java b/tp/src/main/java/com/example/tpfx/Contact.java index 577c0429c97739c873c8aac194ec7490a1ff37cf..87c0d8a5b3393cf93298537e196628f61ef38cea 100644 --- a/tp/src/main/java/com/example/tpfx/Contact.java +++ b/tp/src/main/java/com/example/tpfx/Contact.java @@ -10,6 +10,8 @@ public class Contact implements Comparable<Contact>{ protected List<String> email; protected List<String> social; protected String job; + protected int id; + static int cpt = 0; //Ctor public Contact(String type, List<String> first_name, String last_name, String addr, List<String> phone, List<String> email, @@ -22,6 +24,7 @@ public class Contact implements Comparable<Contact>{ this.email = email; this.social = social; this.job = job; + this.id = cpt++; } //Getter @@ -48,6 +51,9 @@ public class Contact implements Comparable<Contact>{ public String getJob() { return job; } + public int getId(){ + return this.id; + } //Test //Setter @@ -73,6 +79,9 @@ public class Contact implements Comparable<Contact>{ public void setJob(String job) { this.job = job; } + public void setId(int id){ + this.id = id; + } //Methodes //Type cannot be edited @@ -117,7 +126,7 @@ public class Contact implements Comparable<Contact>{ w_social += elem + " "; } - return w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + return String.valueOf(id) + " - " + w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + w_social + " - " + this.job; } @Override diff --git a/tp/src/main/java/com/example/tpfx/Family.java b/tp/src/main/java/com/example/tpfx/Family.java index cf862ba1b31bd668a9b594228a0cb75303397b3c..0b154a2e028a4ece231489014cb4ecc2f5f73a5c 100644 --- a/tp/src/main/java/com/example/tpfx/Family.java +++ b/tp/src/main/java/com/example/tpfx/Family.java @@ -36,7 +36,7 @@ public class Family extends Contact{ w_social += elem + " "; } - return w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + return String.valueOf(id) + " - " + w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + w_social + " - " + this.job + " - " + this.relation; } } diff --git a/tp/src/main/java/com/example/tpfx/HelloController.java b/tp/src/main/java/com/example/tpfx/HelloController.java index 26a1001ee3982ba08087d810c971bc58641640c0..17a79304ae3717410b466bab329a0ffed6d5c50e 100644 --- a/tp/src/main/java/com/example/tpfx/HelloController.java +++ b/tp/src/main/java/com/example/tpfx/HelloController.java @@ -131,6 +131,7 @@ public class HelloController { for (Contact c: contactArray){ List<String> str_array = SplitLine(c.toString(), " - "); writer.write(c.get_type() + "\n"); + writer.write(String.valueOf(c.getId()) + "/"); writer.write(str_array.get(0) + "/"); writer.write(str_array.get(1) + "/"); writer.write(str_array.get(2) + "/"); @@ -162,32 +163,45 @@ public class HelloController { } @FXML protected void Selected() { - selectedID = LstCt.getSelectionModel().getSelectedIndex(); lblOther.setVisible(true); - lblOther.setText(String.valueOf(selectedID) + " - " + String.valueOf(LstCt.getSelectionModel().getSelectedIndex())); btnDelete.setDisable(false); btnEdit.setDisable(false); List<String> data = SplitLine(LstCt.getSelectionModel().getSelectedItem().toString(), " - "); - txtFirst.setText(data.get(0)); - txtLast.setText(data.get(1)); - txtAdd.setText(data.get(2)); - txtPhone.setText(data.get(3)); - txtEmail.setText(data.get(4)); - txtSocial.setText(data.get(5)); - txtJob.setText(data.get(6)); - if(data.size() > 7){ + lblOther.setVisible(true); + lblOther.setText(data.get(1)); + selectedID = Integer.parseInt(data.get(0)); + txtFirst.setText(data.get(1)); + txtLast.setText(data.get(2)); + txtAdd.setText(data.get(3)); + txtPhone.setText(data.get(4)); + txtEmail.setText(data.get(5)); + txtSocial.setText(data.get(6)); + txtJob.setText(data.get(7)); + if(data.size() > 8){ txtOther.setVisible(true); lblOther.setVisible(true); txtOther.setText(data.get(7)); + if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Family")){ + //contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditRelation(other); + lblOther.setVisible(true); + lblOther.setText("Relation"); + txtOther.setVisible(true); + cbxType.setValue("Family"); + } else if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Professional")){ + lblOther.setVisible(true); + lblOther.setText("Work"); + txtOther.setVisible(true); + cbxType.setValue("Professional"); + } } else { txtOther.setVisible(false); lblOther.setVisible(false); + cbxType.setValue("Friend"); } } @FXML protected void Delete() { - lblOther.setText(String.valueOf(selectedID)); contactArray.remove(selectedID); ShowAll(); } @@ -211,14 +225,18 @@ public class HelloController { contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditJob(job); if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Family")){ //contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).EditRelation(other); - } - if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Professional")){ + } else if(contactArray.get(LstCt.getSelectionModel().getSelectedIndex()).get_type().equals("Professional")){ } ShowAll(); } @FXML protected void ShowAll() { + int cpt = 0; + for(Contact cont: contactArray){ + cont.setId(cpt); + cpt++; + } LstCt.getItems().clear(); for(Contact c: contactArray){ LstCt.getItems().add(c.toString()); @@ -292,40 +310,43 @@ public class HelloController { } public void ImportFriend(List<String> str_array){ Friend f = new Friend( - SplitArray(str_array.get(0)), - str_array.get(1), + SplitArray(str_array.get(1)), str_array.get(2), - SplitArray(str_array.get(3)), + str_array.get(3), SplitArray(str_array.get(4)), SplitArray(str_array.get(5)), - str_array.get(6) + SplitArray(str_array.get(6)), + str_array.get(7) ); + f.setId(Integer.parseInt(str_array.get(0))); Add(f); } public void ImportFamily(List<String> str_array){ Family f = new Family( - SplitArray(str_array.get(0)), - str_array.get(1), + SplitArray(str_array.get(1)), str_array.get(2), - SplitArray(str_array.get(3)), + str_array.get(3), SplitArray(str_array.get(4)), SplitArray(str_array.get(5)), - str_array.get(6), - str_array.get(7) + SplitArray(str_array.get(6)), + str_array.get(7), + str_array.get(8) ); + f.setId(Integer.parseInt(str_array.get(0))); Add(f); } public void ImportProfessional(List<String> str_array){ Professional f = new Professional( - SplitArray(str_array.get(0)), - str_array.get(1), + SplitArray(str_array.get(1)), str_array.get(2), - SplitArray(str_array.get(3)), + str_array.get(3), SplitArray(str_array.get(4)), SplitArray(str_array.get(5)), - str_array.get(6), - str_array.get(7) + SplitArray(str_array.get(6)), + str_array.get(7), + str_array.get(8) ); + f.setId(Integer.parseInt(str_array.get(0))); Add(f); } public void AddContactToList(List<String> str_array, int checker){ @@ -363,11 +384,12 @@ public class HelloController { //TODO /* - Edit family/pro - Delete/Edit with search Better toString in export - Add type for real List first names & co + Add comments + Test contact exist + Control sur les champs + Virgules dans champs text */ } \ No newline at end of file diff --git a/tp/src/main/java/com/example/tpfx/Professional.java b/tp/src/main/java/com/example/tpfx/Professional.java index 2bd675e50acd5cdf3efe90723a14f1e983de5e3f..8609131ef9142035bde5cdefb8fa0036966b7ff9 100644 --- a/tp/src/main/java/com/example/tpfx/Professional.java +++ b/tp/src/main/java/com/example/tpfx/Professional.java @@ -34,7 +34,7 @@ public class Professional extends Contact{ w_social += elem + " "; } - return w_names + " - " + last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + return String.valueOf(id) + " - " + w_names + " - " + last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - " + w_social + " - " + this.job + " - " + this.work_place; } } diff --git a/tp/src/main/resources/com/example/tpfx/hello-view.fxml b/tp/src/main/resources/com/example/tpfx/hello-view.fxml index 682a327e1c4dce96a0114ed849888b3b79fd3433..f6da7317f1456c60219c0aebd882dc542d6c6990 100644 --- a/tp/src/main/resources/com/example/tpfx/hello-view.fxml +++ b/tp/src/main/resources/com/example/tpfx/hello-view.fxml @@ -44,7 +44,7 @@ <children> <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="532.0" prefWidth="817.0" VBox.vgrow="ALWAYS"> <children> - <ListView fx:id="LstCt" layoutX="427.0" layoutY="38.0" onMouseClicked="#Selected" prefHeight="489.0" prefWidth="384.0" /> + <ListView fx:id="LstCt" layoutX="427.0" layoutY="38.0" onMouseClicked="#Selected" prefHeight="489.0" prefWidth="412.0" /> <Button fx:id="btnAdd" layoutX="229.0" layoutY="51.0" mnemonicParsing="false" onAction="#AddCt" prefHeight="24.0" prefWidth="62.0" text="Add" /> <TextField fx:id="txtFirst" layoutX="32.0" layoutY="52.0" /> <Label layoutX="230.0" layoutY="300.0" text="First Name" />