X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=Addressbook%2Fsrc%2Forg%2Fmxchange%2Faddressbook%2Fmenu%2FAddressbookMenu.java;h=12257eb08d96aa8d80fbfba4cf5b53d00281e134;hb=a67280d037eb9f783695157780cbbc676e84b26f;hp=418a7cb1b784bf39c26c2618d481945ab803242a;hpb=ea30fd0dc674dcd10c3aead1acd47000a99d7334;p=addressbook-swing.git diff --git a/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java b/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java index 418a7cb..12257eb 100644 --- a/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java +++ b/Addressbook/src/org/mxchange/addressbook/menu/AddressbookMenu.java @@ -16,18 +16,20 @@ */ package org.mxchange.addressbook.menu; +import java.text.MessageFormat; import java.util.List; import org.apache.logging.log4j.Logger; -import org.mxchange.addressbook.BaseFrameworkSystem; -import org.mxchange.addressbook.client.Client; +import org.mxchange.addressbook.BaseAddressbookSystem; +import org.mxchange.addressbook.client.AddressbookClient; import org.mxchange.addressbook.menu.item.SelectableMenuItem; +import org.mxchange.jcore.client.Client; /** * Utility class for menu structure * * @author Roland Haeder */ -public class AddressbookMenu extends BaseFrameworkSystem { +public class AddressbookMenu extends BaseAddressbookSystem { /** * Copies entries for given type into the menu list @@ -40,42 +42,60 @@ public class AddressbookMenu extends BaseFrameworkSystem { // Get logger Logger log = new AddressbookMenu().getLogger(); + // Trace call + log.trace(MessageFormat.format("menuList={0},menuType={1},client={2} - CALLED!", menuList, menuType, client)); //NOI18N + + // Some instances must be set + if (menuList == null) { + // Abort here + throw new NullPointerException("menuList is null"); //NOI18N + } else if (client == null) { + // Abort here + throw new NullPointerException("contact is null"); //NOI18N + } else if (!(client instanceof AddressbookClient)) { + // Not correct instance + throw new IllegalArgumentException(MessageFormat.format("client{0} must implement AddressbookClient", client)); + } + + // Cast client to proper interface + AddressbookClient c = (AddressbookClient) client; + // Get list size int size = menuList.size(); // Debug message - log.debug("Adding menu for '" + menuType + "' (old size: '" + size + "') ..."); + log.debug(MessageFormat.format("Adding menu for '{0}' (old size: '{1}') ...", menuType, size)); //NOI18N // Depends on type switch (menuType) { - case "main": // Main menu + case "main": // Main menu //NOI18N // Enter own data - menuList.add(client.getMenuItem('1', "Eigene Adresse anlegen")); + menuList.add(c.getMenuItem('1', "Eigene Adresse anlegen")); // Change own data - menuList.add(client.getMenuItem('2', "Eigene Adresse ändern")); + menuList.add(c.getMenuItem('2', "Eigene Adresse ändern")); // Add new addess - menuList.add(client.getMenuItem('3', "Neue Adresse hinzufügen")); + menuList.add(c.getMenuItem('3', "Neue Adresse hinzufügen")); // List entries - menuList.add(client.getMenuItem('4', "Adressbuch anzeigen")); + menuList.add(c.getMenuItem('4', "Adressbuch anzeigen")); // Address search - menuList.add(client.getMenuItem('5', "Adresse suchen")); + menuList.add(c.getMenuItem('5', "Adresse suchen")); // Change other address - menuList.add(client.getMenuItem('6', "Adresse ändern")); + menuList.add(c.getMenuItem('6', "Adresse ändern")); // Delete other address - menuList.add(client.getMenuItem('7', "Adresse löschen")); + menuList.add(c.getMenuItem('7', "Adresse löschen")); // Always last line: Exit program - menuList.add(client.getMenuItem('0', "Programm verlassen")); + menuList.add(c.getMenuItem('0', "Programm verlassen")); break; default: // Not supported - log.error("Menu type '" + menuType + "' ont supported"); + log.error(MessageFormat.format("Menu type '{0}' ont supported", menuType)); //NOI18N System.exit(1); }