-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rxdps93
committed
Apr 11, 2019
1 parent
5bf6820
commit 5e32d29
Showing
7 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/com/dom/freeman/components/users/dialog/EditUserDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.dom.freeman.components.users.dialog; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.dom.freeman.FileIO; | ||
import com.dom.freeman.Utility; | ||
import com.dom.freeman.obj.FileOperation; | ||
import com.dom.freeman.obj.User; | ||
import com.googlecode.lanterna.gui2.dialogs.MessageDialogBuilder; | ||
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; | ||
|
||
public class EditUserDialog extends AbstractModifyUserDialog { | ||
|
||
private User toEdit; | ||
|
||
public EditUserDialog(String title, User toEdit) { | ||
super(title); | ||
this.toEdit = toEdit; | ||
|
||
this.getFirstNameEntry().setText(this.toEdit.getFirstName()); | ||
this.getLastNameEntry().setText(this.toEdit.getLastName()); | ||
this.getDisplayNameEntry().setText(this.toEdit.getDisplayName()); | ||
} | ||
|
||
@Override | ||
public boolean validateUser() { | ||
|
||
boolean valid = true; | ||
|
||
if (this.getFirstNameEntry().getText().replaceAll(" ", "").isEmpty()) { | ||
new MessageDialogBuilder().setTitle("Create User Validation") | ||
.setText("You did not enter anything for first name. This field cannot be empty.") | ||
.setExtraWindowHints(Arrays.asList(Hint.CENTERED)) | ||
.addButton(MessageDialogButton.OK).build().showDialog(this.getTextGUI()); | ||
valid = false; | ||
} | ||
|
||
if (this.getLastNameEntry().getText().replaceAll(" ", "").isEmpty()) { | ||
new MessageDialogBuilder().setTitle("Create User Validation") | ||
.setText("You did not enter anything for last name. This field cannot be empty.") | ||
.setExtraWindowHints(Arrays.asList(Hint.CENTERED)) | ||
.addButton(MessageDialogButton.OK).build().showDialog(this.getTextGUI()); | ||
valid = false; | ||
} | ||
|
||
if (this.getDisplayNameEntry().getText().replaceAll(" ", "").isEmpty()) { | ||
new MessageDialogBuilder().setTitle("Create User Validation") | ||
.setText("You did not enter anything for display name. This field cannot be empty.") | ||
.setExtraWindowHints(Arrays.asList(Hint.CENTERED)) | ||
.addButton(MessageDialogButton.OK).build().showDialog(this.getTextGUI()); | ||
valid = false; | ||
} | ||
|
||
return valid; | ||
} | ||
|
||
@Override | ||
public void onSave() { | ||
|
||
if (this.validateUser()) { | ||
User user = new User( | ||
this.getFirstNameEntry().getText(), | ||
this.getLastNameEntry().getText(), | ||
this.getDisplayNameEntry().getText(), | ||
this.toEdit.getId()); | ||
|
||
ModifyUserSummaryDialog summary = new ModifyUserSummaryDialog( | ||
"FINAL EDIT USER SUMMARY" , FileOperation.EDIT, user, this.toEdit); | ||
summary.setHints(Arrays.asList(Hint.CENTERED)); | ||
|
||
if (summary.showDialog(this.getTextGUI())) | ||
this.saveUser(user); | ||
} | ||
} | ||
|
||
private void saveUser(User user) { | ||
|
||
boolean write = FileIO.METHODS.modifyExistingUserInFile(FileOperation.EDIT, user); | ||
|
||
if (write) { | ||
new MessageDialogBuilder().setTitle("User Edited Successfully") | ||
.setText("User successfully updated.") | ||
.setExtraWindowHints(Arrays.asList(Hint.CENTERED)) | ||
.addButton(MessageDialogButton.OK).build().showDialog(this.getTextGUI()); | ||
this.close(); | ||
Utility.METHODS.updateInventory(); | ||
Utility.METHODS.refreshViews(); | ||
} else { | ||
new MessageDialogBuilder().setTitle("Warning") | ||
.setText("Some error occurred and the user could not be updated. Please try again.") | ||
.setExtraWindowHints(Arrays.asList(Hint.CENTERED)) | ||
.addButton(MessageDialogButton.OK).build().showDialog(this.getTextGUI()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCancel() { | ||
this.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Donald,Trump,GEOTUS,3d1e48ce-a651-48b6-bd8f-e540fe8db73b, | ||
Richard,Stallman,rms.sexy,bfff8b19-b48f-41d7-b000-942646135f45, | ||
Terry,Davis,extinguisher,0a85af4c-18cb-401f-bace-efcc42de11c7, | ||
"Donald","Trump","GEOTUS","3d1e48ce-a651-48b6-bd8f-e540fe8db73b","" | ||
"Richard","Stallman","rms.sexy","bfff8b19-b48f-41d7-b000-942646135f45","" | ||
"Terry","Davis","temple","0a85af4c-18cb-401f-bace-efcc42de11c7","" |