2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.client;
19 import java.sql.SQLException;
20 import java.text.MessageFormat;
21 import java.util.HashMap;
23 import org.mxchange.addressbook.manager.contact.AddressbookContactManager;
24 import org.mxchange.addressbook.manager.contact.ManageableContactAddressbook;
25 import org.mxchange.addressbook.menu.Menu;
26 import org.mxchange.jcore.client.BaseClient;
27 import org.mxchange.jcore.client.Client;
30 * A general addressbook client
32 * @author Roland Haeder
33 * TODO: Find better name
35 public abstract class BaseAddressbookClient extends BaseClient implements AddressbookClient {
40 private String currentMenu;
45 private final Map<String, Menu> menus;
48 * No instances can be created of this class
50 protected BaseAddressbookClient () {
52 this.menus = new HashMap<>(10);
58 * @return the currentMenu
60 public final String getCurrentMenu () {
61 return this.currentMenu;
65 public final void setCurrentMenu (final String currentMenu) {
66 this.currentMenu = currentMenu;
70 * "Getter" for given menu type
72 * @param menuType Menu type instance to return
73 * @return Menu or null if not found
75 public Menu getMenu (final String menuType) {
76 // Default is not found
80 if (this.getMenus().containsKey(menuType)) {
82 menu = this.getMenus().get(menuType);
90 * Fills menu map with swing menus
92 protected abstract void fillMenuMap ();
95 * Getter for menus map
97 * @return Map of all menus
99 protected final Map<String, Menu> getMenus () {
104 * Initializes contact manager
106 * @throws java.sql.SQLException If any SQL error occurs
108 protected void initContactManager () throws SQLException {
110 this.getLogger().trace("CALLED!"); //NOI18N
113 this.getLogger().debug("Initializing contact manager ..."); //NOI18N
115 // Init contact manager with console client
116 // TODO Static initial amount of contacts
117 ManageableContactAddressbook manager = new AddressbookContactManager((Client) this);
120 this.setManager(manager);
123 this.getLogger().debug("Contact manager has been initialized."); //NOI18N
126 this.getLogger().trace("EXIT!"); //NOI18N
132 * @param menuType Given menu to show
134 protected void showMenu (final String menuType) {
136 this.getLogger().trace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N
138 Menu menu = this.getMenu(menuType);
141 if (!(menu instanceof Menu)) {
143 // TODO Own exception?
144 throw new NullPointerException(MessageFormat.format("Menu '{0}' not found.", menuType)); //NOI18N
151 this.getLogger().trace("EXIT!"); //NOI18N