Coverage details for ui.panel.TabledNAddressPanel

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.ShowNewNAddressDialogCommand;
41 import ui.command.deletion.DeleteNAddressCommand;
42 import ui.command.information.InfoOnNAddressCommand;
43 import ui.table.NAddressTable;
44 import ui.table.TableSorter;
45 import ui.table.model.NAddressTableModel;
46 import base.user.User;
47  
480@SuppressWarnings("serial") //$NON-NLS-1$
490public class TabledNAddressPanel extends JPanel {
500 
510    private static final transient Logger logger = Logger
520            .getLogger(TabledNAddressPanel.class.getName());
53  
54     private JTable nAddressTable;
55  
56     private TableSorter nAddressTableSorter;
57  
58     private JScrollPane nAddressTableScrollPane;
59  
60     private NAddressTableModel nAddressTableModel;
61  
62     private JPanel nAddressButtonPanel;
63  
64     private JButton newNAddressButton;
65  
66     private JButton infoOnNAddressButton;
67  
68     private JButton deleteNAddressButton;
69  
70     private final User user;
710 
720    public TabledNAddressPanel(User user) {
730        this.user = user;
740        initialize();
750    }
76  
770    protected void initialize() {
780        this.setBorder(new TitledBorder(Messages.getString("common.normalmailaddresses"))); //$NON-NLS-1$
790        this.setLayout(new BorderLayout());
800        this.add(getNAddressTableScrollPane(), BorderLayout.CENTER);
810        this.add(getNAddressButtonPanel(), BorderLayout.EAST);
820    }
83  
84     /**
85      * @return Returns the nAddressTable.
86      */
870    protected JTable getNAddressTable() {
880        if (nAddressTable == null) {
890            nAddressTable = new NAddressTable(getNAddressTableSorter());
900            nAddressTable.setPreferredScrollableViewportSize(new Dimension(500,
910                    70));
920            // We need to place it here to avoid a ciclyc call...
930            nAddressTableSorter.setTableHeader(nAddressTable.getTableHeader());
940            // Set up tool tips for column headers.
950            nAddressTable
960                    .getTableHeader()
970                    .setToolTipText(
980                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
990        }
1000        return nAddressTable;
101     }
102  
103     /**
104      * @return Returns the nAddressTableScrollPane.
105      */
1060    protected JScrollPane getNAddressTableScrollPane() {
1070        if (nAddressTableScrollPane == null) {
1080            nAddressTableScrollPane = new JScrollPane(getNAddressTable());
1090        }
1100        return nAddressTableScrollPane;
111     }
112  
113     /**
114      * @return Returns the nAddressTableSorter.
115      */
1160    protected TableSorter getNAddressTableSorter() {
1170        if (nAddressTableSorter == null) {
1180            nAddressTableSorter = new TableSorter(getNAddressTableModel());
1190        }
1200        return nAddressTableSorter;
121     }
122  
123     /**
124      * @return Returns the nAddressTableModel.
125      */
1260    protected NAddressTableModel getNAddressTableModel() {
1270        if (nAddressTableModel == null) {
1280            nAddressTableModel = new NAddressTableModel(getUser());
1290        }
1300        return nAddressTableModel;
131     }
132  
133     /**
134      * @return Returns the nAddressButtonPanel.
135      */
1360    protected JPanel getNAddressButtonPanel() {
1370        if (nAddressButtonPanel == null) {
1380            nAddressButtonPanel = new JPanel();
1390            nAddressButtonPanel.setLayout(new GridLayout(3, 1));
1400            nAddressButtonPanel.add(getNewNAddressButton());
1410            nAddressButtonPanel.add(getDeleteNAddressButton());
1420            nAddressButtonPanel.add(getInfoOnNAddressButton());
1430        }
1440        return nAddressButtonPanel;
145     }
146  
147     /**
148      * @return Returns the deleteNAddressButton.
149      */
1500    protected JButton getDeleteNAddressButton() {
1510        if (deleteNAddressButton == null) {
1520            deleteNAddressButton = new JButton();
1530            deleteNAddressButton.setIcon(new ImageIcon(this.getClass()
1540                    .getResource("/icon/16x16/actions/list-remove.png"))); //$NON-NLS-1$
1550 
1560            deleteNAddressButton.addActionListener(new ActionListener() {
157                 public void actionPerformed(ActionEvent arg0) {
158                     logger.debug("actionPerformed deleteNAddressButton"); //$NON-NLS-1$
159                     if (getNAddressTable().getSelectedRow() != -1) {
160                         int nAddressId = Integer
161                                 .parseInt(((TableSorter) getNAddressTable()
162                                         .getModel()).getValueAt(
163                                         getNAddressTable().getSelectedRow(),
164                                         NAddressTableModel.NADDRESS_ID_COLUMN)
165                                         .toString());
166                         CommandExecutor.getInstance().executeCommand(
167                                 new DeleteNAddressCommand(getUser(),
168                                         nAddressId, getNAddressTableModel()),
169                                 false);
170                     } else
171                         JOptionPane
172                                 .showMessageDialog(
173                                         null,
174                                         Messages.getString("panel.tablednaddresspanel.message1"), //$NON-NLS-1$
175                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
176                 }
177             });
1780        }
1790        return deleteNAddressButton;
180     }
181  
182     /**
183      * @return Returns the infoOnNAddressButton.
184      */
1850    protected JButton getInfoOnNAddressButton() {
1860        if (infoOnNAddressButton == null) {
1870            infoOnNAddressButton = new JButton();
1880            infoOnNAddressButton.setIcon(new ImageIcon(this.getClass()
1890                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
1900 
1910            infoOnNAddressButton.addActionListener(new ActionListener() {
192                 public void actionPerformed(ActionEvent arg0) {
193                     logger.debug("actionPerformed infoOnNAddressButton"); //$NON-NLS-1$
194                     if (getNAddressTable().getSelectedRow() != -1) {
195                         int nAddressId = Integer
196                                 .parseInt(((TableSorter) getNAddressTable()
197                                         .getModel()).getValueAt(
198                                         getNAddressTable().getSelectedRow(),
199                                         NAddressTableModel.NADDRESS_ID_COLUMN)
200                                         .toString());
201                         CommandExecutor.getInstance()
202                                 .executeCommand(
203                                         new InfoOnNAddressCommand(getUser(),
204                                                 nAddressId), false);
205                     } else
206                         JOptionPane
207                                 .showMessageDialog(
208                                         null,
209                                         Messages.getString("panel.tablednaddresspanel.message1"), //$NON-NLS-1$
210                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
211                 }
212             });
2130        }
2140        return infoOnNAddressButton;
215     }
216  
217     /**
218      * @return Returns the newNAddressButton.
219      */
2200    protected JButton getNewNAddressButton() {
2210        if (newNAddressButton == null) {
2220            newNAddressButton = new JButton();
2230            newNAddressButton.setIcon(new ImageIcon(this.getClass()
2240                    .getResource("/icon/16x16/actions/list-add.png"))); //$NON-NLS-1$
2250 
2260            newNAddressButton.addActionListener(new ActionListener() {
227                 public void actionPerformed(ActionEvent arg0) {
228                     logger.debug("actionPerformed newNAddressButton"); //$NON-NLS-1$
229                     ShowNewNAddressDialogCommand showNewNAddressDialogCommand = new ShowNewNAddressDialogCommand(
230                             getUser(), getNAddressTableModel());
231                     CommandExecutor.getInstance().executeCommand(
232                             showNewNAddressDialogCommand, false);
233                 }
234             });
2350        }
2360        return newNAddressButton;
237     }
238  
239     /**
240      * @return Returns the user.
241      */
2420    protected User getUser() {
2430        return user;
244     }
245  
246 }

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.