* @param minLength Minimum length of the string to read\r
* @param maxLength Maximum length of the string to read\r
* @param message Message to user\r
- * @return \r
+ * @param allowEmpty Whether empty strings are allowed\r
+ * @return Entered string by user or null if empty string is allowed\r
*/\r
- public String enterString (final int minLength, final int maxLength, final String message);\r
+ public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty);\r
\r
/**\r
* Setter for current menu choice\r
// @TODO Get rid of this ugly switch block, too\r
switch (choice) {\r
case 'n': // Name data\r
- this.getContactManager().changeNameData(contact);\r
+ this.getContactManager().changeNameData(contact, this);\r
break;\r
\r
case 'a': // Address data\r
- this.getContactManager().changeAddressData(contact);\r
+ this.getContactManager().changeAddressData(contact, this);\r
break;\r
\r
case 'o': // Other data\r
- this.getContactManager().changeOtherData(contact);\r
+ this.getContactManager().changeOtherData(contact, this);\r
break;\r
\r
case 'x': // Exit this menu\r
* @param minLength Minimum length of the string to read\r
* @param maxLength Maximum length of the string to read\r
* @param message Message to user\r
- * @return \r
+ * @param allowEmpty Whether to allow empty string\r
+ * @return Entered string by user or null for empty strings\r
*/\r
@Override\r
- public String enterString (final int minLength, final int maxLength, final String message) {\r
+ public String enterString (final int minLength, final int maxLength, final String message, final boolean allowEmpty) {\r
// Init input\r
String input = null;\r
\r
// Check if it is to short or to long\r
- while ((input == null) || (input.length() < minLength) || (input.length() > maxLength)) {\r
+ while (((input == null) || ((input.length() < minLength) && (!allowEmpty))) || ((input.length() > 0) && (input.length() < minLength) && (allowEmpty)) || ((input instanceof String) && (input.length() > maxLength))) {\r
// Output message\r
System.out.print(message);\r
\r
// Display other data "box"\r
client.displayOtherDataBox((Contact) this);\r
}\r
+\r
+ /**\r
+ * Updates name data in this Contact instance\r
+ * @param gender Gender (M, F, C)\r
+ * @param surname Surname\r
+ * @param familyName Family name\r
+ * @param companyName Company name\r
+ */\r
+ public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {\r
+ // Set all\r
+ this.setGender(gender);\r
+ this.setSurname(surname);\r
+ this.setFamilyName(familyName);\r
+ this.setCompanyName(companyName);\r
+ }\r
}\r
* @param client Client instance to call back\r
*/\r
public void show (final Client client);\r
+\r
+ /**\r
+ * Updates name data in this Contact instance\r
+ * @param gender Gender (M, F, C)\r
+ * @param surname Surname\r
+ * @param familyName Family name\r
+ * @param companyName Company name\r
+ */\r
+ public void updateNameData (final char gender, final String surname, final String familyName, final String companyName);\r
}\r
* @param gender Gender to be set\r
* @param surname Surname to be set\r
* @param familyName Family name to be set\r
+ * @param companyName Company name\r
* @todo Add validation of data\r
*/\r
- public UserContact (final char gender, final String surname, final String familyName) {\r
+ public UserContact (final char gender, final String surname, final String familyName, final String companyName) {\r
// Make sure all constructors are called\r
this();\r
\r
this.setGender(gender);\r
this.setSurname(surname);\r
this.setFamilyName(familyName);\r
+ this.setCompanyName(companyName);\r
}\r
\r
/**\r
import java.util.ArrayList;\r
import java.util.Iterator;\r
import java.util.List;\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
import org.mxchange.addressbook.client.Client;\r
import org.mxchange.addressbook.contact.Contact;\r
import org.mxchange.addressbook.contact.user.UserContact;\r
* Let the user change address data\r
* \r
* @param contact Instance to change data\r
+ * @param client Client instance to call back\r
*/\r
@Override\r
- public void changeAddressData (final Contact contact) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ public void changeAddressData (final Contact contact, final Client client) {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
}\r
\r
/**\r
* Let the user change "name data"\r
* \r
* @param contact Instance to change data\r
+ * @param client Client instance to call back\r
*/\r
@Override\r
- public void changeNameData (final Contact contact) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ public void changeNameData (final Contact contact, final Client client) {\r
+ // First display them again\r
+ client.displayNameBox(contact);\r
+\r
+ // Is this own data?\r
+ if (contact.isOwnContact()) {\r
+ // Re-ask own data\r
+ // Gender:\r
+ char gender = this.enterOwnGender();\r
+\r
+ // Surname\r
+ String surname = this.enterOwnSurname();\r
+\r
+ // Family name\r
+ String familyName = this.enterOwnFamilyName();\r
+\r
+ // And company\r
+ String companyName = this.enterCompanyName();\r
+\r
+ // Update contact instance\r
+ contact.updateNameData(gender, surname, familyName, companyName);\r
+ } else {\r
+ // Then re-ask them ...\r
+ throw new UnsupportedOperationException("Changing contact entries not finished.");\r
+ }\r
}\r
\r
/**\r
* Let the user change other data\r
*\r
* @param contact Instance to change data\r
+ * @param client Client instance to call back\r
*/\r
@Override\r
- public void changeOtherData (final Contact contact) {\r
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.\r
+ public void changeOtherData (final Contact contact, final Client client) {\r
+ throw new UnsupportedOperationException("Not supported yet.");\r
}\r
\r
/**\r
try {\r
// Ask user what to change\r
this.getClient().doUserChangeAdressChoice(contact);\r
- } catch (final Exception ex) {\r
+ } catch (final UnhandledUserChoiceException ex) {\r
this.getLogger().catching(ex);\r
}\r
}\r
// And 3rd for family name\r
String familyName = this.enterOwnFamilyName();\r
\r
+ // Company name ...\r
+ String companyName = this.enterCompanyName();\r
+\r
// Construct UserContact instance\r
- Contact contact = new UserContact(gender, surname, familyName);\r
+ Contact contact = new UserContact(gender, surname, familyName, companyName);\r
\r
// Mark contact as own\r
contact.enableFlagOwnContact();\r
return this.contacts.size();\r
}\r
\r
+ /**\r
+ * Asks the user for his/her company name\r
+ * @return \r
+ */\r
+ private String enterCompanyName () {\r
+ return this.getClient().enterString(5, 50, "Bitte geben Sie Ihre Firmenbezeichnung ein: ", true);\r
+ }\r
+\r
/**\r
* Asks the user for family name\r
* @return Family name of the user\r
*/\r
private String enterOwnFamilyName () {\r
- return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ");\r
+ return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Nachnamen ein: ", false);\r
}\r
\r
/**\r
* @return Surname of the user\r
*/\r
private String enterOwnSurname () {\r
- return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ");\r
+ return this.getClient().enterString(2, 50, "Bitte geben Sie Ihren Vornamen ein: ", false);\r
}\r
\r
/**\r
*/\r
package org.mxchange.addressbook.manager.contact;\r
\r
+import org.mxchange.addressbook.client.Client;\r
import org.mxchange.addressbook.contact.Contact;\r
import org.mxchange.addressbook.manager.Manageable;\r
\r
* of given Contact instance.\r
* \r
* @param contact Instance to change data\r
+ * @param client Client instance to call back\r
*/\r
- public void changeAddressData (final Contact contact);\r
+ public void changeAddressData (final Contact contact, final Client client);\r
\r
/**\r
* The user can change name data, like gender, surname, family name and\r
* company name (if business contact).\r
* \r
* @param contact Instance to change data\r
+ * @param client Client instance to call back\r
*/\r
- public void changeNameData (final Contact contact);\r
+ public void changeNameData (final Contact contact, final Client client);\r
\r
/**\r
* Let the user change other address\r
* The user can change other data, like phone numbers or comments.\r
* \r
* @param contact Instance to change data\r
+ * @param client Client instance to call back\r
*/\r
- public void changeOtherData (final Contact contact);\r
+ public void changeOtherData (final Contact contact, final Client client);\r
\r
/**\r
* Let the user change own data\r