Coverage details for ui.panel.TabledPhoneNumberPanel

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20 package ui.panel;
21  
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.GridLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27  
28 import javax.swing.ImageIcon;
29 import javax.swing.JButton;
30 import javax.swing.JOptionPane;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.JTable;
34 import javax.swing.border.TitledBorder;
35  
36 import org.apache.log4j.Logger;
37  
38 import ui.Messages;
39 import ui.command.CommandExecutor;
40 import ui.command.creation.ShowNewPhoneNumberDialogCommand;
41 import ui.command.deletion.DeletePhoneNumberCommand;
42 import ui.command.information.InfoOnPhoneNumberCommand;
43 import ui.table.PhoneNumberTable;
44 import ui.table.TableSorter;
45 import ui.table.model.PhoneNumberTableModel;
46 import base.user.User;
47  
480@SuppressWarnings("serial") //$NON-NLS-1$
490public class TabledPhoneNumberPanel extends JPanel {
500 
510    private static final transient Logger logger = Logger
520            .getLogger(TabledPhoneNumberPanel.class.getName());
53  
54     private JTable phoneNumberTable;
55  
56     private TableSorter phoneNumberTableSorter;
57  
58     private JScrollPane phoneNumberTableScrollPane;
59  
60     private PhoneNumberTableModel phoneNumberTableModel;
61  
62     private JPanel phoneNumberButtonPanel;
63  
64     private JButton newPhoneNumberButton;
65  
66     private JButton infoOnPhoneNumberButton;
67  
68     private JButton deletePhoneNumberButton;
69  
70     private final User user;
710 
720    public TabledPhoneNumberPanel(User user) {
730        this.user = user;
740        initialize();
750    }
76  
770    protected void initialize() {
780        this.setBorder(new TitledBorder(Messages.getString("common.phonenumbers"))); //$NON-NLS-1$
790        this.setLayout(new BorderLayout());
800        this.add(getPhoneNumberTableScrollPane(), BorderLayout.CENTER);
810        this.add(getPhoneNumberButtonPanel(), BorderLayout.EAST);
820    }
83  
84     /**
85      * @return Returns the phoneNumberTable.
86      */
870    protected JTable getPhoneNumberTable() {
880        if (phoneNumberTable == null) {
890            phoneNumberTable = new PhoneNumberTable(getPhoneNumberTableSorter());
900            phoneNumberTable.setPreferredScrollableViewportSize(new Dimension(
910                    500, 70));
920            // We need to place it here to avoid a ciclyc call...
930            phoneNumberTableSorter.setTableHeader(phoneNumberTable
940                    .getTableHeader());
950            // Set up tool tips for column headers.
960            phoneNumberTable
970                    .getTableHeader()
980                    .setToolTipText(
990                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
1000        }
1010        return phoneNumberTable;
102     }
103  
104     /**
105      * @return Returns the phoneNumberTableScrollPane.
106      */
1070    protected JScrollPane getPhoneNumberTableScrollPane() {
1080        if (phoneNumberTableScrollPane == null) {
1090            phoneNumberTableScrollPane = new JScrollPane(getPhoneNumberTable());
1100        }
1110        return phoneNumberTableScrollPane;
112     }
113  
114     /**
115      * @return Returns the phoneNumberTableSorter.
116      */
1170    protected TableSorter getPhoneNumberTableSorter() {
1180        if (phoneNumberTableSorter == null) {
1190            phoneNumberTableSorter = new TableSorter(getPhoneNumberTableModel());
1200        }
1210        return phoneNumberTableSorter;
122     }
123  
124     /**
125      * @return Returns the phoneNumberTableModel.
126      */
1270    protected PhoneNumberTableModel getPhoneNumberTableModel() {
1280        if (phoneNumberTableModel == null) {
1290            phoneNumberTableModel = new PhoneNumberTableModel(getUser());
1300        }
1310        return phoneNumberTableModel;
132     }
133  
134     /**
135      * @return Returns the phoneNumberButtonPanel.
136      */
1370    protected JPanel getPhoneNumberButtonPanel() {
1380        if (phoneNumberButtonPanel == null) {
1390            phoneNumberButtonPanel = new JPanel();
1400            phoneNumberButtonPanel.setLayout(new GridLayout(3, 1));
1410            phoneNumberButtonPanel.add(getNewPhoneNumberButton());
1420            phoneNumberButtonPanel.add(getDeletePhoneNumberButton());
1430            phoneNumberButtonPanel.add(getInfoOnPhoneNumberButton());
1440        }
1450        return phoneNumberButtonPanel;
146     }
147  
148     /**
149      * @return Returns the deletePhoneNumberButton.
150      */
1510    protected JButton getDeletePhoneNumberButton() {
1520        if (deletePhoneNumberButton == null) {
1530            deletePhoneNumberButton = new JButton();
1540            deletePhoneNumberButton.setIcon(new ImageIcon(this.getClass()
1550                    .getResource("/icon/16x16/actions/list-remove.png"))); //$NON-NLS-1$
1560 
1570            deletePhoneNumberButton.addActionListener(new ActionListener() {
158                 public void actionPerformed(ActionEvent arg0) {
159                     logger.debug("actionPerformed deletePhoneNumberButton"); //$NON-NLS-1$
160                     if (getPhoneNumberTable().getSelectedRow() != -1) {
161                         int phoneNumberId = Integer
162                                 .parseInt(((TableSorter) getPhoneNumberTable()
163                                         .getModel())
164                                         .getValueAt(
165                                                 getPhoneNumberTable()
166                                                         .getSelectedRow(),
167                                                 PhoneNumberTableModel.PHONENUMBER_ID_COLUMN)
168                                         .toString());
169                         CommandExecutor.getInstance().executeCommand(
170                                 new DeletePhoneNumberCommand(getUser(),
171                                         phoneNumberId,
172                                         getPhoneNumberTableModel()), false);
173                     } else
174                         JOptionPane
175                                 .showMessageDialog(
176                                         null,
177                                         Messages.getString("panel.tabledphonenumberpanel.message1"), //$NON-NLS-1$
178                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
179                 }
180             });
181  
1820        }
1830        return deletePhoneNumberButton;
184     }
185  
186     /**
187      * @return Returns the infoOnPhoneNumberButton.
188      */
1890    protected JButton getInfoOnPhoneNumberButton() {
1900        if (infoOnPhoneNumberButton == null) {
1910            infoOnPhoneNumberButton = new JButton();
1920            infoOnPhoneNumberButton.setIcon(new ImageIcon(this.getClass()
1930                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
1940 
1950            infoOnPhoneNumberButton.addActionListener(new ActionListener() {
196                 public void actionPerformed(ActionEvent arg0) {
197                     logger.debug("actionPerformed infoOnPhoneNumberButton"); //$NON-NLS-1$
198                     if (getPhoneNumberTable().getSelectedRow() != -1) {
199                         int phoneNumberId = Integer
200                                 .parseInt(((TableSorter) getPhoneNumberTable()
201                                         .getModel())
202                                         .getValueAt(
203                                                 getPhoneNumberTable()
204                                                         .getSelectedRow(),
205                                                 PhoneNumberTableModel.PHONENUMBER_ID_COLUMN)
206                                         .toString());
207                         CommandExecutor.getInstance().executeCommand(
208                                 new InfoOnPhoneNumberCommand(getUser(),
209                                         phoneNumberId), false);
210                     } else
211                         JOptionPane
212                                 .showMessageDialog(
213                                         null,
214                                         Messages.getString("panel.tabledphonenumberpanel.message1"), //$NON-NLS-1$
215                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
216                 }
217             });
2180        }
2190        return infoOnPhoneNumberButton;
220     }
221  
222     /**
223      * @return Returns the newPhoneNumberButton.
224      */
2250    protected JButton getNewPhoneNumberButton() {
2260        if (newPhoneNumberButton == null) {
2270            newPhoneNumberButton = new JButton();
2280            newPhoneNumberButton.setIcon(new ImageIcon(this.getClass()
2290                    .getResource("/icon/16x16/actions/list-add.png"))); //$NON-NLS-1$
2300 
2310            newPhoneNumberButton.addActionListener(new ActionListener() {
232                 public void actionPerformed(ActionEvent arg0) {
233                     logger.debug("actionPerformed newPhoneNumberButton"); //$NON-NLS-1$
234                     ShowNewPhoneNumberDialogCommand showNewPhoneNumberDialogCommand = new ShowNewPhoneNumberDialogCommand(
235                             getUser(), getPhoneNumberTableModel());
236                     CommandExecutor.getInstance().executeCommand(
237                             showNewPhoneNumberDialogCommand, false);
238                 }
239             });
2400        }
2410        return newPhoneNumberButton;
242     }
243  
244     /**
245      * @return Returns the user.
246      */
2470    protected User getUser() {
2480        return user;
249     }
250  
251 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.