diff --git a/JavaFXChallenge/.idea/compiler.xml b/JavaFXChallenge/.idea/compiler.xml
new file mode 100644
index 0000000..217af47
--- /dev/null
+++ b/JavaFXChallenge/.idea/compiler.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/.idea/description.html b/JavaFXChallenge/.idea/description.html
new file mode 100644
index 0000000..cc10d56
--- /dev/null
+++ b/JavaFXChallenge/.idea/description.html
@@ -0,0 +1,2 @@
+Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
+
\ No newline at end of file
diff --git a/JavaFXChallenge/.idea/encodings.xml b/JavaFXChallenge/.idea/encodings.xml
new file mode 100644
index 0000000..e206d70
--- /dev/null
+++ b/JavaFXChallenge/.idea/encodings.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/JavaFXChallenge/.idea/gradle.xml b/JavaFXChallenge/.idea/gradle.xml
new file mode 100644
index 0000000..157a0c1
--- /dev/null
+++ b/JavaFXChallenge/.idea/gradle.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/.idea/misc.xml b/JavaFXChallenge/.idea/misc.xml
new file mode 100644
index 0000000..a4e3dc8
--- /dev/null
+++ b/JavaFXChallenge/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JavaFXChallenge/.idea/modules.xml b/JavaFXChallenge/.idea/modules.xml
new file mode 100644
index 0000000..01d2d6f
--- /dev/null
+++ b/JavaFXChallenge/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JavaFXChallenge/.idea/uiDesigner.xml b/JavaFXChallenge/.idea/uiDesigner.xml
new file mode 100644
index 0000000..3b00020
--- /dev/null
+++ b/JavaFXChallenge/.idea/uiDesigner.xml
@@ -0,0 +1,125 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
diff --git a/JavaFXChallenge/.idea/vcs.xml b/JavaFXChallenge/.idea/vcs.xml
new file mode 100644
index 0000000..def6a6a
--- /dev/null
+++ b/JavaFXChallenge/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/.idea/workspace.xml b/JavaFXChallenge/.idea/workspace.xml
new file mode 100644
index 0000000..e4722a4
--- /dev/null
+++ b/JavaFXChallenge/.idea/workspace.xml
@@ -0,0 +1,963 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ localhost
+ 5050
+
+
+
+
+
+
+
+
+ 1359379246138
+
+
+ 1359379246138
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JavaFXChallenge/JavaFXChallenge.iml b/JavaFXChallenge/JavaFXChallenge.iml
new file mode 100644
index 0000000..d5c0743
--- /dev/null
+++ b/JavaFXChallenge/JavaFXChallenge.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/contacts.xml b/JavaFXChallenge/contacts.xml
new file mode 100644
index 0000000..c7d491a
--- /dev/null
+++ b/JavaFXChallenge/contacts.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/JavaFXChallenge/out/production/JavaFXChallenge/sample/contactDialog.fxml b/JavaFXChallenge/out/production/JavaFXChallenge/sample/contactDialog.fxml
new file mode 100644
index 0000000..878f9e1
--- /dev/null
+++ b/JavaFXChallenge/out/production/JavaFXChallenge/sample/contactDialog.fxml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+ Fill in the information about the Contact!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/out/production/JavaFXChallenge/sample/main.fxml b/JavaFXChallenge/out/production/JavaFXChallenge/sample/main.fxml
new file mode 100644
index 0000000..f5b087d
--- /dev/null
+++ b/JavaFXChallenge/out/production/JavaFXChallenge/sample/main.fxml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/src/sample/ContactController.java b/JavaFXChallenge/src/sample/ContactController.java
new file mode 100644
index 0000000..3cb291c
--- /dev/null
+++ b/JavaFXChallenge/src/sample/ContactController.java
@@ -0,0 +1,44 @@
+package sample;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.TextField;
+import sample.datamodel.Contact;
+
+public class ContactController {
+
+ @FXML
+ TextField firstName;
+
+ @FXML
+ TextField lastName;
+
+ @FXML
+ TextField phoneNumber;
+
+ @FXML
+ TextField notes;
+
+ public Contact processResults() {
+ Contact newContact = new Contact();
+ newContact.setFirstName(firstName.getText());
+ newContact.setLastName(lastName.getText());
+ newContact.setPhoneNumber(phoneNumber.getText());
+ newContact.setNotes(notes.getText());
+
+ return newContact;
+ }
+
+ public void fillTheGaps(Contact contact) {
+ firstName.setText(contact.getFirstName().toString());
+ lastName.setText(contact.getLastName().toString());
+ phoneNumber.setText(contact.getPhoneNumber().toString());
+ notes.setText(contact.getNotes().toString());
+ }
+
+ public void updateTheContact(Contact contact) {
+ contact.setFirstName(firstName.getText());
+ contact.setLastName(lastName.getText());
+ contact.setPhoneNumber(phoneNumber.getText());
+ contact.setNotes(notes.getText());
+ }
+}
diff --git a/JavaFXChallenge/src/sample/Controller.java b/JavaFXChallenge/src/sample/Controller.java
new file mode 100644
index 0000000..7f25746
--- /dev/null
+++ b/JavaFXChallenge/src/sample/Controller.java
@@ -0,0 +1,148 @@
+package sample;
+
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.*;
+import javafx.scene.control.cell.PropertyValueFactory;
+import javafx.scene.layout.BorderPane;
+import sample.datamodel.Contact;
+import sample.datamodel.ContactData;
+
+import java.io.IOException;
+import java.util.Optional;
+
+public class Controller {
+
+ ContactData data;
+
+ @FXML
+ TableView table;
+
+ @FXML
+ TableColumn firstNameColumn;
+
+ @FXML
+ TableColumn lastNameColumn;
+
+ @FXML
+ TableColumn phoneNumberColumn;
+
+ @FXML
+ TableColumn notesColumn;
+
+ @FXML
+ BorderPane mainBorderPane;
+
+ @FXML
+ public void handleAddEvent() {
+ Dialog dialog = new Dialog<>();
+ dialog.initOwner(mainBorderPane.getScene().getWindow());
+ dialog.setTitle("Add new contact");
+ dialog.setHeaderText("Use this dialog to create new contact");
+ FXMLLoader fxmlLoader = new FXMLLoader();
+ fxmlLoader.setLocation(getClass().getResource("contactDialog.fxml"));
+
+ try {
+ dialog.getDialogPane().setContent(fxmlLoader.load());
+ } catch(IOException e) {
+ System.out.println("Couldn't load the dialog");
+ e.printStackTrace();
+ }
+ dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
+ dialog.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
+
+ Optional result = dialog.showAndWait();
+ if(result.isPresent() && result.get() == ButtonType.OK) {
+ //Do this if OK was pressed
+ ContactController controller = fxmlLoader.getController();
+ Contact newContact = controller.processResults();
+ System.out.println(newContact);
+ data.addContact(newContact);
+ data.saveContacts();
+ }
+ }
+
+ public void handleDeleteEvent() {
+ Contact selectedContact = table.getSelectionModel().getSelectedItem();
+ if(selectedContact != null) {
+ Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
+ alert.setTitle("Confirm deliting a contact");
+ alert.setHeaderText(null);
+ alert.setContentText("Are you sure that you want to delete " + selectedContact.getFirstName() + "?");
+ Optional result = alert.showAndWait();
+ if(result.isPresent() && result.get() == ButtonType.OK) {
+ data.deleteContact(selectedContact);
+ data.saveContacts();
+ }
+ } else {
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.setHeaderText("No Contact Selected!");
+ alert.setHeaderText(null);
+ alert.setContentText("Select the contact that you want to delete");
+ alert.show();
+ return;
+ }
+ }
+
+ public void handleEditEvent() {
+ Contact selectedContact = table.getSelectionModel().getSelectedItem();
+ if(selectedContact == null) {
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.setHeaderText("No Contact Selected!");
+ alert.setHeaderText(null);
+ alert.setContentText("Select the contact that you want to edit");
+ alert.show();
+ return;
+ }
+
+
+ Dialog dialog = new Dialog<>();
+ dialog.initOwner(mainBorderPane.getScene().getWindow());
+ dialog.setTitle("Edit contact");
+ dialog.setHeaderText("Use this dialog to edit the contact");
+ FXMLLoader fxmlLoader = new FXMLLoader();
+ fxmlLoader.setLocation(getClass().getResource("contactDialog.fxml"));
+
+ try {
+ dialog.getDialogPane().setContent(fxmlLoader.load());
+ } catch(IOException e) {
+ System.out.println("Couldn't load the dialog");
+ e.printStackTrace();
+ }
+ dialog.getDialogPane().getButtonTypes().add(ButtonType.FINISH);
+ dialog.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
+
+ ContactController controller = fxmlLoader.getController();
+
+ controller.fillTheGaps(selectedContact);
+
+ Optional result = dialog.showAndWait();
+ if(result.isPresent() && result.get() == ButtonType.FINISH) {
+ controller.updateTheContact(selectedContact);
+ data.saveContacts();
+ }
+ }
+
+ public void initialize() {
+ // fills in observable list with data
+ data = new ContactData();
+ data.loadContacts();
+ table.setItems(data.getContacts());
+// firstNameColumn.setCellValueFactory(
+// new PropertyValueFactory("firstName")
+// );
+// lastNameColumn.setCellValueFactory(
+// new PropertyValueFactory("lastName")
+// );
+// phoneNumberColumn.setCellValueFactory(
+// new PropertyValueFactory("phoneNumber")
+// );
+// notesColumn.setCellValueFactory(
+// new PropertyValueFactory("notes")
+// );
+
+
+
+
+ }
+}
diff --git a/JavaFXChallenge/src/sample/Main.java b/JavaFXChallenge/src/sample/Main.java
new file mode 100644
index 0000000..5419053
--- /dev/null
+++ b/JavaFXChallenge/src/sample/Main.java
@@ -0,0 +1,37 @@
+package sample;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import sample.datamodel.ContactData;
+
+public class Main extends Application {
+
+// ContactData database = new ContactData();
+
+ @Override
+ public void start(Stage primaryStage) throws Exception{
+ Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
+ primaryStage.setTitle("My Contacts");
+ primaryStage.setScene(new Scene(root, 600, 400));
+ primaryStage.show();
+ }
+
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+// @Override
+// public void init() throws Exception {
+// database.loadContacts();
+// }
+//
+// @Override
+// public void stop() throws Exception {
+// System.out.println(database.getContacts());
+// database.saveContacts();
+// }
+}
diff --git a/JavaFXChallenge/src/sample/contactDialog.fxml b/JavaFXChallenge/src/sample/contactDialog.fxml
new file mode 100644
index 0000000..878f9e1
--- /dev/null
+++ b/JavaFXChallenge/src/sample/contactDialog.fxml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+ Fill in the information about the Contact!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JavaFXChallenge/src/sample/datamodel/Contact.java b/JavaFXChallenge/src/sample/datamodel/Contact.java
new file mode 100644
index 0000000..dbf8131
--- /dev/null
+++ b/JavaFXChallenge/src/sample/datamodel/Contact.java
@@ -0,0 +1,80 @@
+package sample.datamodel;
+
+import javafx.beans.property.SimpleStringProperty;
+
+public class Contact {
+
+ private SimpleStringProperty firstName = new SimpleStringProperty("");
+ private SimpleStringProperty lastName = new SimpleStringProperty("");
+ private SimpleStringProperty phoneNumber = new SimpleStringProperty("");
+ private SimpleStringProperty notes = new SimpleStringProperty("");
+
+ public Contact(String firstName, String lastName, String phoneNumber, String notes) {
+ this.firstName.set(firstName);
+ this.lastName.set(lastName);
+ this.phoneNumber.set(phoneNumber);
+ this.notes.set(notes);
+ }
+
+ public Contact() {
+
+ }
+
+ public String getFirstName() {
+ return firstName.get();
+ }
+
+ public SimpleStringProperty firstNameProperty() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName.set(firstName);
+ }
+
+ public String getLastName() {
+ return lastName.get();
+ }
+
+ public SimpleStringProperty lastNameProperty() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName.set(lastName);
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber.get();
+ }
+
+ public SimpleStringProperty phoneNumberProperty() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber.set(phoneNumber);
+ }
+
+ public String getNotes() {
+ return notes.get();
+ }
+
+ public SimpleStringProperty notesProperty() {
+ return notes;
+ }
+
+ public void setNotes(String notes) {
+ this.notes.set(notes);
+ }
+
+ @Override
+ public String toString() {
+ return "Contact{" +
+ "firstName=" + firstName +
+ ", lastName=" + lastName +
+ ", phoneNumber=" + phoneNumber +
+ ", notes=" + notes +
+ '}';
+ }
+}
diff --git a/JavaFXChallenge/src/sample/datamodel/ContactData.java b/JavaFXChallenge/src/sample/datamodel/ContactData.java
new file mode 100644
index 0000000..f7e4aa5
--- /dev/null
+++ b/JavaFXChallenge/src/sample/datamodel/ContactData.java
@@ -0,0 +1,204 @@
+package sample.datamodel;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import sample.datamodel.Contact;
+
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartDocument;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+
+public class ContactData {
+
+ private static final String CONTACTS_FILE = "contacts.xml";
+
+ private static final String CONTACT = "contact";
+ private static final String FIRST_NAME = "first_name";
+ private static final String LAST_NAME = "last_name";
+ private static final String PHONE_NUMBER = "phone_number";
+ private static final String NOTES = "notes";
+
+ private ObservableList contacts;
+
+ public ContactData() {
+ contacts = FXCollections.observableArrayList();
+ }
+
+ // *** Add methods to add/delete/access contacts here ***
+
+ public void addContact(Contact newContact) {
+ contacts.add(newContact);
+ }
+
+ public void deleteContact(Contact deletingContact) {
+ contacts.remove(deletingContact);
+ }
+
+ public ObservableList getContacts() {
+ return contacts;
+ }
+
+
+
+
+ public void loadContacts() {
+ try {
+ // First, create a new XMLInputFactory
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ // Setup a new eventReader
+ InputStream in = new FileInputStream(CONTACTS_FILE);
+ XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
+ // read the XML document
+ Contact contact = null;
+
+ while (eventReader.hasNext()) {
+ XMLEvent event = eventReader.nextEvent();
+
+ if (event.isStartElement()) {
+ StartElement startElement = event.asStartElement();
+ // If we have a contact item, we create a new contact
+ if (startElement.getName().getLocalPart().equals(CONTACT)) {
+ contact = new Contact();
+ continue;
+ }
+
+ if (event.isStartElement()) {
+ if (event.asStartElement().getName().getLocalPart()
+ .equals(FIRST_NAME)) {
+ event = eventReader.nextEvent();
+ contact.setFirstName(event.asCharacters().getData());
+ continue;
+ }
+ }
+ if (event.asStartElement().getName().getLocalPart()
+ .equals(LAST_NAME)) {
+ event = eventReader.nextEvent();
+ contact.setLastName(event.asCharacters().getData());
+ continue;
+ }
+
+ if (event.asStartElement().getName().getLocalPart()
+ .equals(PHONE_NUMBER)) {
+ event = eventReader.nextEvent();
+ contact.setPhoneNumber(event.asCharacters().getData());
+ continue;
+ }
+
+ if (event.asStartElement().getName().getLocalPart()
+ .equals(NOTES)) {
+ event = eventReader.nextEvent();
+ contact.setNotes(event.asCharacters().getData());
+ continue;
+ }
+ }
+
+ // If we reach the end of a contact element, we add it to the list
+ if (event.isEndElement()) {
+ EndElement endElement = event.asEndElement();
+ if (endElement.getName().getLocalPart().equals(CONTACT)) {
+ contacts.add(contact);
+ }
+ }
+ }
+ }
+ catch (FileNotFoundException e) {
+ //e.printStackTrace();
+ }
+ catch (XMLStreamException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void saveContacts() {
+
+ try {
+ // create an XMLOutputFactory
+ XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+ // create XMLEventWriter
+ XMLEventWriter eventWriter = outputFactory
+ .createXMLEventWriter(new FileOutputStream(CONTACTS_FILE));
+ // create an EventFactory
+ XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+ XMLEvent end = eventFactory.createDTD("\n");
+ // create and write Start Tag
+ StartDocument startDocument = eventFactory.createStartDocument();
+ eventWriter.add(startDocument);
+ eventWriter.add(end);
+
+ StartElement contactsStartElement = eventFactory.createStartElement("",
+ "", "contacts");
+ eventWriter.add(contactsStartElement);
+ eventWriter.add(end);
+
+ for (Contact contact: contacts) {
+ saveContact(eventWriter, eventFactory, contact);
+ }
+
+ eventWriter.add(eventFactory.createEndElement("", "", "contacts"));
+ eventWriter.add(end);
+ eventWriter.add(eventFactory.createEndDocument());
+ eventWriter.close();
+ }
+ catch (FileNotFoundException e) {
+ System.out.println("Problem with Contacts file: " + e.getMessage());
+ e.printStackTrace();
+ }
+ catch (XMLStreamException e) {
+ System.out.println("Problem writing contact: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private void saveContact(XMLEventWriter eventWriter, XMLEventFactory eventFactory, Contact contact)
+ throws FileNotFoundException, XMLStreamException {
+
+ XMLEvent end = eventFactory.createDTD("\n");
+
+ // create contact open tag
+ StartElement configStartElement = eventFactory.createStartElement("",
+ "", CONTACT);
+ eventWriter.add(configStartElement);
+ eventWriter.add(end);
+ // Write the different nodes
+ createNode(eventWriter, FIRST_NAME, contact.getFirstName());
+ createNode(eventWriter, LAST_NAME, contact.getLastName());
+ createNode(eventWriter, PHONE_NUMBER, contact.getPhoneNumber());
+ createNode(eventWriter, NOTES, contact.getNotes());
+
+ eventWriter.add(eventFactory.createEndElement("", "", CONTACT));
+ eventWriter.add(end);
+ }
+
+ private void createNode(XMLEventWriter eventWriter, String name,
+ String value) throws XMLStreamException {
+
+ XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+ XMLEvent end = eventFactory.createDTD("\n");
+ XMLEvent tab = eventFactory.createDTD("\t");
+ // create Start node
+ StartElement sElement = eventFactory.createStartElement("", "", name);
+ eventWriter.add(tab);
+ eventWriter.add(sElement);
+ // create Content
+ Characters characters = eventFactory.createCharacters(value);
+ eventWriter.add(characters);
+ // create End node
+ EndElement eElement = eventFactory.createEndElement("", "", name);
+ eventWriter.add(eElement);
+ eventWriter.add(end);
+ }
+
+}
\ No newline at end of file
diff --git a/JavaFXChallenge/src/sample/main.fxml b/JavaFXChallenge/src/sample/main.fxml
new file mode 100644
index 0000000..f5b087d
--- /dev/null
+++ b/JavaFXChallenge/src/sample/main.fxml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+