]> git.mxchange.org Git - addressbook-swing.git/blob - src/org/mxchange/addressbook/menu/BaseMenu.java
This lib should only contain remote EJB interfaces for the addressbook application...
[addressbook-swing.git] / src / org / mxchange / addressbook / menu / BaseMenu.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.menu;
18
19 import java.text.MessageFormat;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23 import org.mxchange.addressbook.BaseAddressbookSystem;
24 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
25 import org.mxchange.jcore.client.Client;
26
27 /**
28  * A general menu class
29  * <p>
30  * @author Roland Haeder
31  */
32 public abstract class BaseMenu extends BaseAddressbookSystem implements Menu {
33
34         /**
35          * Menu list
36          */
37         private List<SelectableMenuItem> menuList;
38
39         /**
40          * No instance from this object
41          */
42         protected BaseMenu () {
43         }
44
45         @Override
46         public int getMenuItemsCount () {
47                 return this.menuList.size();
48         }
49
50         @Override
51         public Iterator<SelectableMenuItem> getMenuItemsIterator () {
52                 return this.menuList.iterator();
53         }
54
55         @Override
56         public void show (final Client client) {
57                 // Trace message
58                 this.getLogger().logTrace(MessageFormat.format("client={0} CALLED!", client)); //NOI18N
59
60                 // Client must not be null
61                 if (null == client) {
62                         // Abort here
63                         throw new NullPointerException("client is null"); //NOI18N
64                 }
65
66                 // Get values
67                 Iterator<SelectableMenuItem> iterator = this.menuList.iterator();
68
69                 // Debug message
70                 this.getLogger().logDebug("Showing menu with '" + this.menuList.size() + "' entries.");
71
72                 // Output all menus
73                 while (iterator.hasNext()) {
74                         // Get item
75                         SelectableMenuItem item = iterator.next();
76
77                         // Show this item
78                         item.show(client);
79                 }
80
81                 // Trace message
82                 this.getLogger().logTrace("EXIT!"); //NOI18N
83         }
84
85         /**
86          * Getter for menu list
87          * <p>
88          * @return      menuList List of menu entries
89          */
90         protected final List<SelectableMenuItem> getMenuList () {
91                 return this.menuList;
92         }
93
94         /**
95          * Initializes menu
96          * <p>
97          * @param menuType      Menu type to initialize
98          * @param client CLient to call back
99          */
100         protected void initMenu (final String menuType, final Client client) {
101                 // Trace message
102                 this.getLogger().logTrace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N
103
104                 // Init menu list
105                 this.menuList = new ArrayList<>(5);
106
107                 // Trace message
108                 this.getLogger().logTrace("EXIT!"); //NOI18N
109         }
110 }