--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook;\r
+\r
+/**\r
+ * This exception is thrown when the user made a valid choice but it was not\r
+ * handled by the program.\r
+ * \r
+ * @author Roland Haeder\r
+ */\r
+public class UnhandledUserChoiceException extends Exception {\r
+\r
+ public UnhandledUserChoiceException (final String message) {\r
+ super(message);\r
+ }\r
+}\r
\r
try {\r
// Ask for user input and run proper method\r
- this.getClient().doUserChoice();\r
+ this.getClient().doUserMenuChoice();\r
} catch (final Exception ex) {\r
this.getLogger().catching(ex);\r
}\r
*/\r
package org.mxchange.addressbook.client;\r
\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
import org.mxchange.addressbook.FrameworkInterface;\r
import org.mxchange.addressbook.contact.Contact;\r
import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
*/\r
public void displayOtherDataBox (final Contact contact);\r
\r
+ /**\r
+ * Let the user choose what to change on the address: [n]ame, [a]ddress,\r
+ * [o]ther\r
+ * @param contact Contact instance to let the user change data\r
+ * @throws UnhandledUserChoiceException If choice is not supported\r
+ */\r
+ public void doUserChangeAdressChoice (final Contact contact) throws UnhandledUserChoiceException;\r
+\r
/**\r
* Asks the user for a choice and proceeds accordingly\r
- * @throws java.lang.Exception\r
+ * @throws UnhandledUserChoiceException If choice is not supported\r
*/\r
- public void doUserChoice () throws Exception ;\r
+ public void doUserMenuChoice () throws UnhandledUserChoiceException ;\r
\r
/**\r
* Enables isRunning attribute which singals that the client is running\r
import java.util.HashMap;\r
import java.util.Map;\r
import java.util.Scanner;\r
+import org.mxchange.addressbook.UnhandledUserChoiceException;\r
import org.mxchange.addressbook.application.AddressbookApplication;\r
import org.mxchange.addressbook.application.Application;\r
import org.mxchange.addressbook.client.BaseClient;\r
}\r
\r
@Override\r
- public void doUserChoice () throws Exception {\r
+ public void doUserChangeAdressChoice (final Contact contact) throws UnhandledUserChoiceException {\r
+ // Ask the user for editing [name], [a]ddress or [other] data\r
+ char choice = this.enterChar(new char[]{'n', 'a', 'o', 'x'}, "Welchen Daten möchten Sie ändern? (n=Namensdaten, a=Anschriftsdaten, o=Andere, x=Zurück zur Hauptauswahl) ");\r
+\r
+ // @TODO Get rid of this ugly switch block, too\r
+ switch (choice) {\r
+ case 'n': // Name data\r
+ this.getContactManager().changeNameData(contact);\r
+ break;\r
+\r
+ case 'a': // Address data\r
+ this.getContactManager().changeAddressData(contact);\r
+ break;\r
+\r
+ case 'o': // Other data\r
+ this.getContactManager().changeOtherData(contact);\r
+ break;\r
+\r
+ case 'x': // Exit this menu\r
+ // Ignored as it should go back\r
+ break;\r
+\r
+ default:\r
+ // @TODO throw own exception\r
+ throw new UnhandledUserChoiceException("Choice '" + choice + "' not handled yet.");\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void doUserMenuChoice () throws UnhandledUserChoiceException {\r
// Get all access keys from menu\r
char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.menus, this.getCurrentMenu());\r
\r
// Output textural message and ask for a char as input\r
- char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Beenden/Zurück in's vorherhige Menü): ");\r
+ char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");\r
\r
// @TODO Rewrite this ugly switch() block\r
switch (choice) {\r
break;\r
\r
default:\r
- // @TODO throw on exception\r
- throw new Exception("choice " + choice + " invalid");\r
+ // @TODO throw own exception\r
+ throw new UnhandledUserChoiceException("Choice '" + choice + "' not handled yet.");\r
}\r
}\r
\r
throw new UnsupportedOperationException("Not supported yet.");\r
}\r
\r
+ /**\r
+ * Let the user change address data\r
+ * \r
+ * @param contact Instance to change data\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
+ }\r
+\r
+ /**\r
+ * Let the user change "name data"\r
+ * \r
+ * @param contact Instance to change data\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
+ }\r
+\r
/**\r
* Let the user change other address\r
*/\r
throw new UnsupportedOperationException("Not supported yet.");\r
}\r
\r
+ /**\r
+ * Let the user change other data\r
+ *\r
+ * @param contact Instance to change data\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
+ }\r
+\r
/**\r
* Allows the user to change his/her own data\r
*/\r
// Display contact\r
contact.show(this.getClient());\r
\r
- // @TODO Unfinished\r
- throw new UnsupportedOperationException("Method is not finished.");\r
+ try {\r
+ // Ask user what to change\r
+ this.getClient().doUserChangeAdressChoice(contact);\r
+ } catch (final Exception ex) {\r
+ this.getLogger().catching(ex);\r
+ }\r
}\r
\r
/**\r
*/\r
public void addOtherAddress ();\r
\r
+ /**\r
+ * The user can change address data, like street, ZIP code, city and country\r
+ * of given Contact instance.\r
+ * \r
+ * @param contact Instance to change data\r
+ */\r
+ public void changeAddressData (final Contact contact);\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
+ */\r
+ public void changeNameData (final Contact contact);\r
+\r
/**\r
* Let the user change other address\r
*/\r
public void changeOtherAddress ();\r
\r
+ /**\r
+ * The user can change other data, like phone numbers or comments.\r
+ * \r
+ * @param contact Instance to change data\r
+ */\r
+ public void changeOtherData (final Contact contact);\r
+\r
/**\r
* Let the user change own data\r
*/\r