Coverage details for ui.panel.TabledEAddressPanel

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.ShowNewEAddressDialogCommand;
41 import ui.command.deletion.DeleteEAddressCommand;
42 import ui.command.information.InfoOnEAddressCommand;
43 import ui.table.EAddressTable;
44 import ui.table.TableSorter;
45 import ui.table.model.EAddressTableModel;
46 import base.user.User;
47  
480@SuppressWarnings("serial") //$NON-NLS-1$
490public class TabledEAddressPanel extends JPanel {
500 
510    private static final transient Logger logger = Logger
520            .getLogger(TabledEAddressPanel.class.getName());
53  
54     private JTable eAddressTable;
55  
56     private TableSorter eAddressTableSorter;
57  
58     private JScrollPane eAddressTableScrollPane;
59  
60     private EAddressTableModel eAddressTableModel;
61  
62     private JPanel eAddressButtonPanel;
63  
64     private JButton newEAddressButton;
65  
66     private JButton infoOnEAddressButton;
67  
68     private JButton deleteEAddressButton;
69  
70     private final User user;
710 
720    public TabledEAddressPanel(User user) {
730        this.user = user;
740        initialize();
750    }
76  
770    protected void initialize() {
780        this.setBorder(new TitledBorder(Messages.getString("common.elettronicmailaddresses"))); //$NON-NLS-1$
790        this.setLayout(new BorderLayout());
800        this.add(getEAddressTableScrollPane(), BorderLayout.CENTER);
810        this.add(getEAddressButtonPanel(), BorderLayout.EAST);
820    }
83  
84     /**
85      * @return Returns the eAddressTable.
86      */
870    protected JTable getEAddressTable() {
880        if (eAddressTable == null) {
890            eAddressTable = new EAddressTable(getEAddressTableSorter());
900            eAddressTable.setPreferredScrollableViewportSize(new Dimension(500,
910                    70));
920            // We need to place it here to avoid a ciclyc call...
930            eAddressTableSorter.setTableHeader(eAddressTable.getTableHeader());
940            // Set up tool tips for column headers.
950            eAddressTable
960                    .getTableHeader()
970                    .setToolTipText(
980                            Messages.getString("tablesoreter.header.tooltip")); //$NON-NLS-1$
990        }
1000        return eAddressTable;
101     }
102  
103     /**
104      * @return Returns the eAddressTableScrollPane.
105      */
1060    protected JScrollPane getEAddressTableScrollPane() {
1070        if (eAddressTableScrollPane == null) {
1080            eAddressTableScrollPane = new JScrollPane(getEAddressTable());
1090        }
1100        return eAddressTableScrollPane;
111     }
112  
113     /**
114      * @return Returns the eAddressTableSorter.
115      */
1160    protected TableSorter getEAddressTableSorter() {
1170        if (eAddressTableSorter == null) {
1180            eAddressTableSorter = new TableSorter(getEAddressTableModel());
1190        }
1200        return eAddressTableSorter;
121     }
122  
123     /**
124      * @return Returns the eAddressTableModel.
125      */
1260    protected EAddressTableModel getEAddressTableModel() {
1270        if (eAddressTableModel == null) {
1280            eAddressTableModel = new EAddressTableModel(getUser());
1290        }
1300        return eAddressTableModel;
131     }
132  
133     /**
134      * @return Returns the eAddressButtonPanel.
135      */
1360    protected JPanel getEAddressButtonPanel() {
1370        if (eAddressButtonPanel == null) {
1380            eAddressButtonPanel = new JPanel();
1390            eAddressButtonPanel.setLayout(new GridLayout(3, 1));
1400            eAddressButtonPanel.add(getNewEAddressButton());
1410            eAddressButtonPanel.add(getDeleteEAddressButton());
1420            eAddressButtonPanel.add(getInfoOnEAddressButton());
1430        }
1440        return eAddressButtonPanel;
145     }
146  
147     /**
148      * @return Returns the deleteEAddressButton.
149      */
1500    protected JButton getDeleteEAddressButton() {
1510        if (deleteEAddressButton == null) {
1520            deleteEAddressButton = new JButton();
1530            deleteEAddressButton.setIcon(new ImageIcon(this.getClass()
1540                    .getResource("/icon/16x16/actions/list-remove.png"))); //$NON-NLS-1$
1550            deleteEAddressButton.addActionListener(new ActionListener() {
156                 public void actionPerformed(ActionEvent arg0) {
157                     logger.debug("actionPerformed deleteEAddressButton"); //$NON-NLS-1$
158                     if (getEAddressTable().getSelectedRow() != -1) {
159                         int eAddressId = Integer
160                                 .parseInt(((TableSorter) getEAddressTable()
161                                         .getModel()).getValueAt(
162                                         getEAddressTable().getSelectedRow(),
163                                         EAddressTableModel.EADDRESS_ID_COLUMN)
164                                         .toString());
165                         CommandExecutor.getInstance().executeCommand(
166                                 new DeleteEAddressCommand(getUser(),
167                                         eAddressId, getEAddressTableModel()),
168                                 false);
169                     } else
170                         JOptionPane
171                                 .showMessageDialog(
172                                         null,
173                                         Messages.getString("panel.tabledeaddresspanel.message1"), //$NON-NLS-1$
174                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
175                 }
176             });
1770        }
1780        return deleteEAddressButton;
179     }
180  
181     /**
182      * @return Returns the infoOnEAddressButton.
183      */
1840    protected JButton getInfoOnEAddressButton() {
1850        if (infoOnEAddressButton == null) {
1860            infoOnEAddressButton = new JButton();
1870            infoOnEAddressButton.setIcon(new ImageIcon(this.getClass()
1880                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
1890            infoOnEAddressButton.addActionListener(new ActionListener() {
190                 public void actionPerformed(ActionEvent arg0) {
191                     logger.debug("actionPerformed infoOnEAddressButton"); //$NON-NLS-1$
192                     if (getEAddressTable().getSelectedRow() != -1) {
193                         int eAddressId = Integer
194                                 .parseInt(((TableSorter) getEAddressTable()
195                                         .getModel()).getValueAt(
196                                         getEAddressTable().getSelectedRow(),
197                                         EAddressTableModel.EADDRESS_ID_COLUMN)
198                                         .toString());
199                         CommandExecutor.getInstance()
200                                 .executeCommand(
201                                         new InfoOnEAddressCommand(getUser(),
202                                                 eAddressId), false);
203                     } else
204                         JOptionPane
205                                 .showMessageDialog(
206                                         null,
207                                         Messages.getString("panel.tabledeaddresspanel.message1"), //$NON-NLS-1$
208                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
209                 }
210             });
211  
2120        }
2130        return infoOnEAddressButton;
214     }
215  
216     /**
217      * @return Returns the newEAddressButton.
218      */
2190    protected JButton getNewEAddressButton() {
2200        if (newEAddressButton == null) {
2210            newEAddressButton = new JButton();
2220            newEAddressButton.setIcon(new ImageIcon(this.getClass()
2230                    .getResource("/icon/16x16/actions/list-add.png"))); //$NON-NLS-1$
2240 
2250            newEAddressButton.addActionListener(new ActionListener() {
226                 public void actionPerformed(ActionEvent arg0) {
227                     logger.debug("actionPerformed newEAddressButton"); //$NON-NLS-1$
228                     ShowNewEAddressDialogCommand showNewEAddressDialogCommand = new ShowNewEAddressDialogCommand(
229                             getUser(), getEAddressTableModel());
230                     CommandExecutor.getInstance().executeCommand(
231                             showNewEAddressDialogCommand, false);
232                 }
233             });
2340        }
2350        return newEAddressButton;
236     }
237  
238     /**
239      * @return Returns the user.
240      */
2410    protected User getUser() {
2420        return user;
243     }
244  
245 }

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.