\r
import java.text.MessageFormat;\r
import java.util.Arrays;\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
* @author Roland Haeder\r
*/\r
public class ConsoleClient extends BaseClient implements Client {\r
- /**\r
- * Menu system\r
- */\r
- private final Map<String, Menu> menus;\r
-\r
/**\r
* Scanner instance for reading data from console input\r
*/\r
// Init scanner instance\r
this.scanner = new Scanner(System.in);\r
\r
- // Init menu map\r
- this.menus = new HashMap<>(10);\r
-\r
// Fill menu map\r
- this.fillConsoleMenuMap();\r
+ this.fillMenuMap();\r
}\r
\r
/**\r
this.outputMessage("Telefonnumer: " + contact.getPhoneNumber() + "\nFaxnummer: " + contact.getFaxNumber() + "\nHandy: " + contact.getCellphoneNumber() + "\nKommentar:\n" + contact.getComment());\r
}\r
\r
- @Override\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, this);\r
- break;\r
-\r
- case 'a': // Address data\r
- this.getContactManager().changeAddressData(contact, this);\r
- break;\r
-\r
- case 'o': // Other data\r
- this.getContactManager().changeOtherData(contact, this);\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
+ char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu());\r
\r
// Output textural message and ask for a char as input\r
char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): ");\r
// @TODO Rewrite this ugly switch() block\r
switch (choice) {\r
case '1': // Enter/add own data\r
- this.getContactManager().enterOwnData();\r
+ this.getContactManager().doEnterOwnData();\r
break;\r
\r
case '2': // Change own data\r
this.getContactManager().addOtherAddress();\r
break;\r
\r
- case '4': // Change other addess\r
+ case '4': // List contacts\r
+ this.getContactManager().listContacts();\r
+ break;\r
+ \r
+ case '5': // Search addresses\r
+ this.getContactManager().searchContacts();\r
+ break;\r
+\r
+ case '6': // Change other addess\r
this.getContactManager().changeOtherAddress();\r
break;\r
\r
- case '5': // Delete other address\r
+ case '7': // Delete other address\r
this.getContactManager().deleteOtherAddress();\r
break;\r
\r
this.showMenu(this.getCurrentMenu());\r
}\r
\r
+ /**\r
+ * Shows given menu entry to user\r
+ * \r
+ * @param item Menu entry\r
+ */\r
@Override\r
public void showEntry (final SelectableMenuItem item) {\r
// Access key then text\r
*/\r
@Override\r
public void showWelcome () {\r
- this.outputMessage("Welcome to " + AddressbookApplication.APP_TITLE + " v" + AddressbookApplication.APP_VERSION);\r
- this.outputMessage("");\r
- this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");\r
- \r
- // Debug message\r
- this.getLogger().debug("Intro shown to user");\r
- }\r
-\r
- /**\r
- * Fills menu map with menu entries\r
- */\r
- private void fillConsoleMenuMap () {\r
- // Initialize first (main) menu\r
- Menu menu = new ConsoleMenu("main", this);\r
-\r
- // Add it\r
- this.menus.put("main", menu);\r
+ this.outputMessage("Welcome to " + AddressbookApplication.APP_TITLE + " v" + AddressbookApplication.APP_VERSION);\r
+ this.outputMessage("");\r
+ this.outputMessage("Copyright(c) 2015 by Roland Haeder, this is free software");\r
+ \r
+ // Debug message\r
+ this.getLogger().debug("Intro shown to user");\r
}\r
\r
- /**\r
- * "Getter" for given menu type\r
- * \r
- * @param menuType Menu type instance to return\r
- * @return Menu or null if not found\r
- */\r
- private Menu getMenu (final String menuType) {\r
- // Default is not found\r
- Menu menu = null;\r
-\r
- // Check array\r
- if (this.menus.containsKey(menuType)) {\r
- // Found!\r
- menu = this.menus.get(menuType);\r
- }\r
+ @Override\r
+ public void userChooseChangeContactData (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
- // Return it\r
- return menu;\r
+ // @TODO Get rid of this ugly switch block, too\r
+ switch (choice) {\r
+ case 'n': // Name data\r
+ this.getContactManager().doChangeNameData(contact, this);\r
+ break;\r
+ \r
+ case 'a': // Address data\r
+ this.getContactManager().doChangeAddressData(contact, this);\r
+ break;\r
+ \r
+ case 'o': // Other data\r
+ this.getContactManager().doChangeOtherData(contact, this);\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
/**\r
}\r
\r
/**\r
- * Shows given menu\r
- *\r
- * @param menuType Given menu to show\r
+ * Fills menu map with menu entries\r
*/\r
- private void showMenu (final String menuType) {\r
- Menu menu = this.getMenu(menuType);\r
- \r
- // Is the menu set?\r
- if (!(menu instanceof Menu)) {\r
- // Not found\r
- // @todo Own exception?\r
- throw new NullPointerException("Menu '" + menuType + "' not found.");\r
- }\r
+ @Override\r
+ protected final void fillMenuMap () {\r
+ // Initialize first (main) menu\r
+ Menu menu = new ConsoleMenu("main", this);\r
\r
- // Show menu\r
- menu.show(this);\r
+ // Add it\r
+ this.getMenus().put("main", menu);\r
}\r
}\r