X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=Addressbook%2Fsrc%2Forg%2Fmxchange%2Faddressbook%2Fclient%2Fconsole%2FConsoleClient.java;h=5249c5f9fecd2a958f884821f6a1323b0ef9b048;hb=d16c6288f14c09b779d9d8f395529d411cdd156e;hp=841b7b65d8a9d979f17dbc6f75ebba978c3eac83;hpb=8c199926b3d45121755468737d863958abd9322a;p=jaddressbook-lib.git diff --git a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java index 841b7b65..5249c5f9 100644 --- a/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java +++ b/Addressbook/src/org/mxchange/addressbook/client/console/ConsoleClient.java @@ -18,8 +18,6 @@ package org.mxchange.addressbook.client.console; import java.text.MessageFormat; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; import java.util.Scanner; import org.mxchange.addressbook.UnhandledUserChoiceException; import org.mxchange.addressbook.application.AddressbookApplication; @@ -39,11 +37,6 @@ import org.mxchange.addressbook.menu.item.console.ConsoleMenuItem; * @author Roland Haeder */ public class ConsoleClient extends BaseClient implements Client { - /** - * Menu system - */ - private final Map menus; - /** * Scanner instance for reading data from console input */ @@ -65,11 +58,8 @@ public class ConsoleClient extends BaseClient implements Client { // Init scanner instance this.scanner = new Scanner(System.in); - // Init menu map - this.menus = new HashMap<>(10); - // Fill menu map - this.fillConsoleMenuMap(); + this.fillMenuMap(); } /** @@ -123,7 +113,7 @@ public class ConsoleClient extends BaseClient implements Client { @Override public void doUserMenuChoice () throws UnhandledUserChoiceException { // Get all access keys from menu - char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.menus, this.getCurrentMenu()); + char[] accessKeys = MenuTools.getAccessKeysFromMenuMap(this.getMenus(), this.getCurrentMenu()); // Output textural message and ask for a char as input char choice = this.enterChar(accessKeys, "Bitte Auswahl eingeben (0=Programm beenden): "); @@ -142,11 +132,19 @@ public class ConsoleClient extends BaseClient implements Client { this.getContactManager().addOtherAddress(); break; - case '4': // Change other addess + case '4': // List contacts + this.getContactManager().listContacts(); + break; + + case '5': // Search addresses + this.getContactManager().searchContacts(); + break; + + case '6': // Change other addess this.getContactManager().changeOtherAddress(); break; - case '5': // Delete other address + case '7': // Delete other address this.getContactManager().deleteOtherAddress(); break; @@ -276,6 +274,11 @@ public class ConsoleClient extends BaseClient implements Client { this.showMenu(this.getCurrentMenu()); } + /** + * Shows given menu entry to user + * + * @param item Menu entry + */ @Override public void showEntry (final SelectableMenuItem item) { // Access key then text @@ -293,7 +296,7 @@ public class ConsoleClient extends BaseClient implements Client { // Debug message this.getLogger().debug("Intro shown to user"); - } + } @Override public void userChooseChangeContactData (final Contact contact) throws UnhandledUserChoiceException { @@ -324,37 +327,6 @@ public class ConsoleClient extends BaseClient implements Client { } } - /** - * Fills menu map with menu entries - */ - private void fillConsoleMenuMap () { - // Initialize first (main) menu - Menu menu = new ConsoleMenu("main", this); - - // Add it - this.menus.put("main", menu); - } - - /** - * "Getter" for given menu type - * - * @param menuType Menu type instance to return - * @return Menu or null if not found - */ - private Menu getMenu (final String menuType) { - // Default is not found - Menu menu = null; - - // Check array - if (this.menus.containsKey(menuType)) { - // Found! - menu = this.menus.get(menuType); - } - - // Return it - return menu; - } - /** * Reads one character * @@ -408,21 +380,14 @@ public class ConsoleClient extends BaseClient implements Client { } /** - * Shows given menu - * - * @param menuType Given menu to show + * Fills menu map with menu entries */ - private void showMenu (final String menuType) { - Menu menu = this.getMenu(menuType); - - // Is the menu set? - if (!(menu instanceof Menu)) { - // Not found - // @todo Own exception? - throw new NullPointerException("Menu '" + menuType + "' not found."); - } + @Override + protected final void fillMenuMap () { + // Initialize first (main) menu + Menu menu = new ConsoleMenu("main", this); - // Show menu - menu.show(this); + // Add it + this.getMenus().put("main", menu); } }