-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContactEditor.java
More file actions
137 lines (123 loc) · 6.65 KB
/
ContactEditor.java
File metadata and controls
137 lines (123 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package addressbook;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class ContactEditor {
private Contact contact;
private ContactEditorController editorController;
public ContactEditor(ObservableList<MailingList> mailingLists) throws IOException {
Stage newWindow = new Stage();
newWindow.initModality(Modality.APPLICATION_MODAL);
FXMLLoader loader = new FXMLLoader(getClass().getResource("ContactEditorForm.fxml"));
Parent form = loader.load();
editorController = loader.getController();
editorController.setMailingLists(mailingLists);
newWindow.setScene(new Scene(form));
newWindow.showAndWait();
}
public ContactEditor(ObservableList<MailingList> mailingLists, Contact contactEdit) throws IOException {
Stage newWindow = new Stage();
newWindow.initModality(Modality.APPLICATION_MODAL);
FXMLLoader loader = new FXMLLoader(getClass().getResource("ContactEditorForm.fxml"));
Parent form = loader.load();
editorController = loader.getController();
setContact(contactEdit);
editorController.setMailingLists(mailingLists);
editorController.setMailingList(contactEdit.getMailingListId());
newWindow.setScene(new Scene(form));
newWindow.showAndWait();
}
public void setContact(Contact editContact) {
contact = editContact;
editorController.setFirstNameField(contact.getFirstName());
editorController.setLastNameField(contact.getLastName());
editorController.setNameField(contact.getName());
editorController.setPseudonymField(contact.getPseudonym());
editorController.setHausePhoneNumberField(contact.getHausePhoneNumber());
editorController.setFaxPhoneNumberField(contact.getFaxPhoneNumber());
editorController.setPagerPhoneNumberField(contact.getPagerPhoneNumber());
editorController.setEmailField(contact.getEmail());
editorController.setPhoneNumberField(contact.getMobilePhoneNumber());
editorController.setWorkPhoneNumberField(contact.getWorkPhoneNumber());
editorController.setSecondEmailField(contact.getSecondEmail());
editorController.setAddressField(contact.getAddress());
editorController.setCityField(contact.getCity());
editorController.setVoivodeshipField(contact.getVoivodeship());
editorController.setPostalCodeField(contact.getPostalCode());
editorController.setCountryField(contact.getCountry());
editorController.setWebsiteField(contact.getCompanyWebsite());
editorController.setOfficeField(contact.getOffice());
editorController.setDepartamentField(contact.getDepartament());
editorController.setCompanyNameField(contact.getCompanyName());
editorController.setCompanyAddressField(contact.getCompanyAddress());
editorController.setCompanyPostalCodeField(contact.getCompanyPostalCode());
editorController.setCompanyCountryField(contact.getCompanyCountry());
editorController.setCompanyWebsiteField(contact.getCompanyWebsite());
editorController.setInfo1Field(contact.getInfo1());
editorController.setInfo2Field(contact.getInfo2());
editorController.setInfo3Field(contact.getInfo3());
editorController.setInfo4Field(contact.getInfo4());
editorController.setNotesField(contact.getNotes());
if (contact.getBirthday().isEmpty()==true) {
editorController.setBirthdayField(null);
} else {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
formatter = formatter.withLocale(Locale.ENGLISH);
LocalDate date = LocalDate.parse(contact.getBirthday(), formatter);
editorController.setBirthdayField(date);
}
editorController.setMailingList(contact.getMailingListId());
}
public Contact getContact() {
if (editorController.formStatus==false) {
return null;
}
if (contact==null) {
contact = new Contact();
}
contact.setFirstName(editorController.getFirstNameField());
contact.setLastName(editorController.getLastNameField());
contact.setName(editorController.getNameField());
contact.setPseudonym(editorController.getPseudonymField());
contact.setHausePhoneNumber(editorController.getHausePhoneNumberField());
contact.setFaxPhoneNumber(editorController.getFaxPhoneNumberField());
contact.setPagerPhoneNumber(editorController.getPagerPhoneNumberField());
contact.setEmail(editorController.getEmailField());
contact.setWebsite(editorController.getWebsiteField());
contact.setMobilePhoneNumber(editorController.getPhoneNumberField());
contact.setWorkPhoneNumber(editorController.getWorkPhoneNumberField());
contact.setSecondEmail(editorController.getSecondEmailField());
contact.setAddress(editorController.getAddressField());
contact.setCity(editorController.getCityField());
contact.setVoivodeship(editorController.getVoivodeshipField());
contact.setPostalCode(editorController.getPostalCodeField());
contact.setCountry(editorController.getCountryField());
contact.setCompanyWebsite(editorController.getWebsiteField());
contact.setDepartament(editorController.getDepartamentField());
contact.setCompanyName(editorController.getCompanyNameField());
contact.setCompanyAddress(editorController.getCompanyAddressField());
contact.setCompanyPostalCode(editorController.getCompanyPostalCodeField());
contact.setCompanyCountry(editorController.getCompanyCountryField());
contact.setCompanyWebsite(editorController.getCompanyWebsiteField());
contact.setInfo1(editorController.getInfo1Field());
contact.setInfo2(editorController.getInfo2Field());
contact.setInfo3(editorController.getInfo3Field());
contact.setInfo4(editorController.getInfo4Field());
contact.setNotes(editorController.getNotesField());
if (editorController.getBirthdayField()!=null) {
System.out.println(editorController.getBirthdayField().format(DateTimeFormatter.ISO_DATE));
contact.setBirthday(editorController.getBirthdayField().toString());
} else {
contact.setBirthday("");
}
contact.setMailingListId(editorController.getMailingList().getId());
return contact;
}
}