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.menu.Menu;
25 import org.mxchange.jcore.client.BaseClient;
26 import org.mxchange.jcore.client.Client;
27 import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
28 import org.mxchange.jcore.manager.database.ManageableDatabase;
31 * A general addressbook client
33 * @author Roland Haeder
35 public abstract class BaseAddressbookClient extends BaseClient {
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;
67 * @param currentMenu the currentMenu to set
69 public final void setCurrentMenu (final String currentMenu) {
70 this.currentMenu = currentMenu;
74 * "Getter" for given menu type
76 * @param menuType Menu type instance to return
77 * @return Menu or null if not found
79 public Menu getMenu (final String menuType) {
80 // Default is not found
84 if (this.getMenus().containsKey(menuType)) {
86 menu = this.getMenus().get(menuType);
94 * Fills menu map with swing menus
96 protected abstract void fillMenuMap ();
99 * Getter for menus map
101 * @return Map of all menus
103 protected final Map<String, Menu> getMenus () {
108 * Initializes contact manager
109 * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the database backend is not supported
110 * @throws java.sql.SQLException If any SQL error occurs
112 protected void initContactManager () throws UnsupportedDatabaseBackendException, SQLException {
114 this.getLogger().trace("CALLED!"); //NOI18N
117 this.getLogger().debug("Initializing contact manager ..."); //NOI18N
119 // Init contact manager with console client
120 // @TODO Static initial amount of contacts
121 ManageableDatabase manager = new AddressbookContactManager((Client) this);
124 this.setContactManager(manager);
127 this.getLogger().debug("Contact manager has been initialized."); //NOI18N
130 this.getLogger().trace("EXIT!"); //NOI18N
136 * @param menuType Given menu to show
138 protected void showMenu (final String menuType) {
140 this.getLogger().trace(MessageFormat.format("menuType={0} - CALLED!", menuType)); //NOI18N
142 Menu menu = this.getMenu(menuType);
145 if (!(menu instanceof Menu)) {
147 // @todo Own exception?
148 throw new NullPointerException(MessageFormat.format("Menu '{0}' not found.", menuType)); //NOI18N
155 this.getLogger().trace("EXIT!"); //NOI18N