Skip to content
This repository was archived by the owner on Sep 24, 2022. It is now read-only.

Commit 9bf59e4

Browse files
RenlarRenlar
authored andcommitted
Closed #6 fixed list sorting and updating again.
1 parent 52d44a5 commit 9bf59e4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/awana/database/DirectoryPage.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,33 @@ public void saveCurrentRecord() {
220220

221221
public void updateListings() {
222222
int index = masterListModel.indexOf(selectedRecord.createListing());
223-
Listing l = masterListModel.get(index);
224-
if (l.getFirstName() != null && l.getLastName() != null && (!l.getFirstName().equals(selectedRecord.get("First Name").getData()) || !l.getLastName().equals(selectedRecord.get("Last Name").getData()))) {
223+
if(nameChanged()){
225224
masterListModel.remove(index);
226225
addListing(selectedRecord.createListing());
227226
}
228227
}
229228

229+
public boolean nameChanged(){
230+
int index = masterListModel.indexOf(selectedRecord.createListing());
231+
Listing l = masterListModel.get(index);
232+
if(!stringsEqual(l.getFirstName(), selectedRecord.get("First Name").getData())){
233+
return true;
234+
}else if(!stringsEqual(l.getLastName(), selectedRecord.get("Last Name").getData())){
235+
return true;
236+
}
237+
return false;
238+
}
239+
240+
public boolean stringsEqual(String a, String b){
241+
if(b == null && a == null){
242+
return true;
243+
}else if(b == null || a == null){
244+
return false;
245+
}else{
246+
return a.equals(b);
247+
}
248+
}
249+
230250
public void updateRecordData() {
231251
clearRecordData();
232252
selectedRecord = databaseWrapper.getRecord(((Listing) recordItemList.getSelectedValue()).getID());

0 commit comments

Comments
 (0)