alright so now that we can add contacts
let's so go ahead and add the code to alright so now that we can add contacts
edit a contact so the first thing we let's so go ahead and add the code to
need to do is to add and edit item to edit a contact so the first thing we
our contact menu I'm going to look at need to do is to add and edit item to
the contact dialogue to do that and our contact menu I'm going to look at
let's add an entry in a menu so I said the contact dialogue to do that and
contact dialogue but of course menu is let's add an entry in a menu so I said
in main .fxml so we want contact dialogue but of course menu is
to add it here in main .fxml so we want
as another menu item below the add to add it here
we're going to come along here and put as another menu item below the add
our items again and we're going to put we're going to come along here and put
... our items again and we're going to put
... ...
now what we're going to do is reuse the ...
UI that we use for adding a contact now now what we're going to do is reuse the
we want to change the header text of the UI that we use for adding a contact now
dialogue we also want to fill the field we want to change the header text of the
with existing values of a contact that we are dialogue we also want to fill the field
editing when the user presses ok we with existing values of a contact that we are
don't want to add a new contact we want editing when the user presses ok we
to actually update the values in the don't want to add a new contact we want
existing contact instance but first we to actually update the values in the
need to know which contact the user existing contact instance but first we
wants to edit so we want to know which need to know which contact the user
contact the user has selected in the wants to edit so we want to know which
table then if nothing is selected show a contact the user has selected in the
message box that tells the user to table then if nothing is selected show a
select the item that they want to edit message box that tells the user to
that's what we're going to do so we'll select the item that they want to edit
go back to our controller class and that's what we're going to do so we'll
will actually add this function this method go back to our controller class and
... will actually add this function this method
alright so the method is going to be ...
public void alright so the method is going to be
... public void
... ...
alright so we get the selected item from ...
the table if it's null it means alright so we get the selected item from
that nothing selected we're going to the table if it's null it means
show this alert that was just coded up that nothing selected we're going to
and then return now alerts can have a show this alert that was just coded up
header text or can have header text just and then return now alerts can have a
like dialogues but we don't need it and header text or can have header text just
that's why I've set it to null so let's like dialogues but we don't need it and
run this and try it out and that's why I've set it to null so let's
obviously to check this code we need to run this and try it out and
run it without actually selecting an obviously to check this code we need to
item from the table and we actually run it without actually selecting an
got an error here so let's check out what I've item from the table and we actually
done wrong with ok so i don't think it's got an error here so let's check out what I've
anything to do with the code that we done wrong with ok so i don't think it's
change... anything to do with the code that we
...and we go back change...
to our controller that looks ...and we go back
ok to me just looking at data again our to our controller that looks
contacts xml and that's the problem ok to me just looking at data again our
you remember that i didn't add anything contacts xml and that's the problem
for notes we haven't got any validation you remember that i didn't add anything
and we're assuming that all the fields for notes we haven't got any validation
will actually have some information and we're assuming that all the fields
that's so i'm suspecting I changes this will actually have some information
some notes by editing the xml directly that's so i'm suspecting I changes this
then go back and run this again we some notes by editing the xml directly
should find that it works so that was my bad then go back and run this again we
for actually not putting any data should find that it works so that was my bad
in there we go so it's actually working for actually not putting any data
again in there we go so it's actually working
alright so let's do what I was again
going to originally do and going click alright so let's do what I was
on contacts and click on edit to see going to originally do and going click
with that dialog box pops up that we on contacts and click on edit to see
just created the alert I should say no with that dialog box pops up that we
contact selected please select the just created the alert I should say no
content you want to edit just contact selected please select the
confirming right then select one and content you want to edit just
click on edit again we don't get the confirming right then select one and
pop-up this time because we've actually click on edit again we don't get the
got a selected contact pop-up this time because we've actually
alright so that's working well alright got a selected contact
so we've got the code obviously we go alright so that's working well alright
back to our controller in the case of so we've got the code obviously we go
the selected contact being null back to our controller in the case of
in other words if there wasn't a the selected contact being null
selected contact so let us now write the in other words if there wasn't a
code in a situation where there was a selected contact so let us now write the
valid one selected so I'm gonna start code in a situation where there was a
down here and what we're going to do is valid one selected so I'm gonna start
create that dialogue so that we can pop down here and what we're going to do is
up the dialogue containing the fields and create that dialogue so that we can pop
enable the user to edit so start... up the dialogue containing the fields and
... enable the user to edit so start...
... ...
and ...
interesting enough intellij is smart enough and
figure out that we've got some interesting enough intellij is smart enough
duplicated code in this file so we could figure out that we've got some
have made a method or done this and some duplicated code in this file so we could
other way but I'll leave that for now we have made a method or done this and some
know that this code is duplicated from the other way but I'll leave that for now we
code that we added up here we work on know that this code is duplicated from the
the show add contact but leave that code that we added up here we work on
for now for the simplicity as we go through the show add contact but leave that
alright so again we just add for now for the simplicity as we go through
the rest of the code so... alright so again we just add
... the rest of the code so...
... ...
....i'm going ...
to touch on the changes from the add ....i'm going
method and most of these occur after to touch on the changes from the add
we've added the buttons to the dialogue so method and most of these occur after
first i'm setting the title of the dialog we've added the buttons to the dialogue so
to add contact on line 74 the second first i'm setting the title of the dialog
rather than getting a reference to the to add contact on line 74 the second
contact controller when the user presses rather than getting a reference to the
ok i'm actually getting up front because contact controller when the user presses
we want the contact controller to ok i'm actually getting up front because
populate the dialogue values with the we want the contact controller to
existing value for the contact to do so populate the dialogue values with the
i'm calling the edit contact method existing value for the contact to do so
which we're going to be adding to the i'm calling the edit contact method
contact controller in a minute and third which we're going to be adding to the
and last if the user presses ok we call contact controller in a minute and third
the update contact method from the and last if the user presses ok we call
contact controller again and we'll be the update contact method from the
adding that method shortly as well contact controller again and we'll be
alright so let's go back to the contact adding that method shortly as well
control and add those methods so the alright so let's go back to the contact
first one control and add those methods so the
... first one
.... ...
.... ....
...so you can ....
see what we're doing here just purely ...so you can
populating the fields on screen in our see what we're doing here just purely
dialogue with the contents from our populating the fields on screen in our
content contact object get last name... dialogue with the contents from our
... content contact object get last name...
... ...
...now the update to ...
contact we need to do the opposite ...now the update to
we need to get the data in the contact we need to do the opposite
dialogue and actually populate the we need to get the data in the
contact objects so... dialogue and actually populate the
... contact objects so...
... ...
....now once again we would ...
normally be doing some verification in a ....now once again we would
real world application but I'm keeping normally be doing some verification in a
things really simple so real world application but I'm keeping
go back to our controller again the things really simple so
main controller those errors disappeared go back to our controller again the
and the other thing to note here is that main controller those errors disappeared
saving the contacts to the file after the and the other thing to note here is that
Edit just as we're doing when we add a saving the contacts to the file after the
new record Edit just as we're doing when we add a
alright so let's actually try running new record
this just to see whether it works so i'm alright so let's actually try running
going to run this so let's start first this just to see whether it works so i'm
to check the Edit if nothing selected going to run this so let's start first
that's correct we get an alert if we to check the Edit if nothing selected
choose something like this fourth record that's correct we get an alert if we
contacts edit got the field showing their choose something like this fourth record
lets actually just try click ok contacts edit got the field showing their
without making any changes to make sure lets actually just try click ok
that the same values are present without making any changes to make sure
and just be really sure we stop the that the same values are present
app running again even though we're not and just be really sure we stop the
suspecting there any problems a good app running again even though we're not
thing to check still got the original suspecting there any problems a good
values there thing to check still got the original
alright so let's actually try editing it values there
will change last name from smith and alright so let's actually try editing it
will change phone number... will change last name from smith and
...click on ok we got Zane Smith new will change phone number...
phone number a few notes just to be ...click on ok we got Zane Smith new
sure phone number a few notes just to be
also change the first entries well make sure
it Bob instead of zane and you can see also change the first entries well make
the form is being updated and we'll just it Bob instead of zane and you can see
run it again and we still got the right the form is being updated and we'll just
values coming back when the applications run it again and we still got the right
reloaded now remember that our quick and values coming back when the applications
dirty save load code expects all values reloaded now remember that our quick and
to be present dirty save load code expects all values
you saw what happened when i to be present
accidentally forgot to put something in you saw what happened when i
the notes field for a particular accidentally forgot to put something in
record we got it to crash at startup so you the notes field for a particular
may not notice that when you doing that record we got it to crash at startup so you
when you're adding a new record until you may not notice that when you doing that
get to the stage of reloading the data when you're adding a new record until you
so if that's the case just gonna come get to the stage of reloading the data
over here to the contacts . xml edit and so if that's the case just gonna come
put some values in there and obviously over here to the contacts . xml edit and
in a real-world application you wouldn't put some values in there and obviously
allow that to happen you would actually in a real-world application you wouldn't
you want to make sure that you've got allow that to happen you would actually
the ability to enter null values or have some you want to make sure that you've got
sort of verification validation to avoid the ability to enter null values or have some
that sort of verification validation to avoid
alright I'm going to finish the video that
here now we're just about done in the alright I'm going to finish the video
next video what we're going to do is go here now we're just about done in the
ahead and add the code to delete a next video what we're going to do is go
contact and then there's a few little ahead and add the code to delete a
minor things will do in terms of contact and then there's a few little
resizing and so forth for the table i'll see minor things will do in terms of
you in the next video resizing and so forth for the table i'll see