Coverage details for ui.panel.ICUserPanel

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.JLabel;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33 import javax.swing.JScrollPane;
34 import javax.swing.JTable;
35 import javax.swing.border.EtchedBorder;
36 import javax.swing.border.TitledBorder;
37  
38 import org.apache.log4j.Logger;
39  
40 import ui.Messages;
41 import ui.command.CommandExecutor;
42 import ui.command.creation.ShowNewUserDialogCommand;
43 import ui.command.deletion.DeleteUserCommand;
44 import ui.command.information.InfoOnUserCommand;
45 import ui.table.TableSorter;
46 import ui.table.UserTable;
47 import ui.table.model.UserTableModel;
48  
490@SuppressWarnings("serial") //$NON-NLS-1$
500public class ICUserPanel extends JPanel {
510 
520    private static final transient Logger logger = Logger
530            .getLogger(ICUserPanel.class.getName());
54  
55     private JPanel userPanel;
56  
57     private JPanel buttonPanel;
58  
59     private JButton newUserButton;
60  
61     private JButton deleteUserButton;
62  
63     private JButton infoOnUserButton;
64  
65     private JScrollPane userTableScrollPane;
66  
67     private JTable userTable;
68  
69     private TableSorter userTableSorter;
70  
71     private UserTableModel userTableModel;
720 
730    public ICUserPanel() {
740        initialize();
750    }
76  
770    protected void initialize() {
780        this.setName(Messages.getString("common.users")); //$NON-NLS-1$
790        this.setLayout(new BorderLayout());
800        this.add(getUserPanel(), BorderLayout.CENTER);
810        this.add(getButtonPanel(), BorderLayout.SOUTH);
820    }
83  
84     /**
85      * @return Returns the buttonPanel.
86      */
870    protected JPanel getButtonPanel() {
880        if (buttonPanel == null) {
890            buttonPanel = new JPanel();
900            buttonPanel.setLayout(new GridLayout(1, 5));
910            buttonPanel.setBorder(new EtchedBorder());
920            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
930            buttonPanel.add(getNewUserButton());
940            buttonPanel.add(getInfoOnUserButton());
950            buttonPanel.add(getDeleteUserButton());
960            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
97  
980        }
990        return buttonPanel;
100     }
101  
102     /**
103      * @return Returns the userPanel.
104      */
1050    protected JPanel getUserPanel() {
1060        if (userPanel == null) {
1070            userPanel = new JPanel();
1080            userPanel.setLayout(new BorderLayout());
1090            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.registeredusers")); //$NON-NLS-1$
1100            userPanel.setBorder(titledBorder);
1110            userPanel.add(getUserTableScrollPane(), BorderLayout.CENTER);
1120        }
1130        return userPanel;
114     }
115  
116     /**
117      * @return Returns the userTable.
118      */
1190    protected JTable getUserTable() {
1200        if (userTable == null) {
1210            userTable = new UserTable(getUserTableSorter());
1220            userTable
1230                    .setPreferredScrollableViewportSize(new Dimension(500, 70));
1240            // We need to place it here to avoid a ciclyc call...
1250            userTableSorter.setTableHeader(userTable.getTableHeader());
1260            // Set up tool tips for column headers.
1270            userTable
1280                    .getTableHeader()
1290                    .setToolTipText(
1300                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
1310        }
1320        return userTable;
133     }
134  
135     /**
136      * @return Returns the userTableScrollPane.
137      */
1380    protected JScrollPane getUserTableScrollPane() {
1390        if (userTableScrollPane == null) {
1400            userTableScrollPane = new JScrollPane(getUserTable());
1410        }
1420        return userTableScrollPane;
143     }
144  
145     /**
146      * @return Returns the userTableSorter.
147      */
1480    protected TableSorter getUserTableSorter() {
1490        if (userTableSorter == null) {
1500            userTableSorter = new TableSorter(getUserTableModel());
1510        }
1520        return userTableSorter;
153     }
154  
155     /**
156      * @return Returns the userTableModel.
157      */
1580    protected UserTableModel getUserTableModel() {
1590        if (userTableModel == null) {
1600            userTableModel = new UserTableModel();
1610        }
1620        return userTableModel;
163     }
164  
165     /**
166      * @return Returns the deleteUserButton.
167      */
1680    protected JButton getDeleteUserButton() {
1690        if (deleteUserButton == null) {
1700            deleteUserButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$
1710            deleteUserButton.setIcon(new ImageIcon(this.getClass().getResource(
1720                    "/icon/16x16/actions/edit-delete.png"))); //$NON-NLS-1$
1730 
1740            deleteUserButton.addActionListener(new ActionListener() {
175                 public void actionPerformed(ActionEvent arg0) {
176                     logger.debug("actionPerformed deleteButton"); //$NON-NLS-1$
177                     if (getUserTable().getSelectedRow() != -1) {
178                         int userId = Integer
179                                 .parseInt(((TableSorter) getUserTable()
180                                         .getModel()).getValueAt(
181                                         getUserTable().getSelectedRow(),
182                                         UserTableModel.USER_ID_COLUMN)
183                                         .toString());
184                         CommandExecutor.getInstance().executeCommand(
185                                 new DeleteUserCommand(userId), false);
186                     } else
187                         JOptionPane
188                                 .showMessageDialog(
189                                         null,
190                                         Messages.getString("panel.icuserpanle.message1"), //$NON-NLS-1$
191                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
192                 }
193             });
1940        }
1950        return deleteUserButton;
196     }
197  
198     /**
199      * @return Returns the infoOnUserButton.
200      */
2010    protected JButton getInfoOnUserButton() {
2020        if (infoOnUserButton == null) {
2030            infoOnUserButton = new JButton(Messages.getString("button.info")); //$NON-NLS-1$
2040            infoOnUserButton.setIcon(new ImageIcon(this.getClass().getResource(
2050                    "/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
2060 
2070            infoOnUserButton.addActionListener(new ActionListener() {
208                 public void actionPerformed(ActionEvent arg0) {
209                     logger.debug("actionPerformed infoButton"); //$NON-NLS-1$
210                     if (getUserTable().getSelectedRow() != -1) {
211                         int userId = Integer
212                                 .parseInt(((TableSorter) getUserTable()
213                                         .getModel()).getValueAt(
214                                         getUserTable().getSelectedRow(),
215                                         UserTableModel.USER_ID_COLUMN)
216                                         .toString());
217                         CommandExecutor.getInstance().executeCommand(
218                                 new InfoOnUserCommand(userId), false);
219                     } else
220                         JOptionPane
221                                 .showMessageDialog(
222                                         null,
223                                         Messages.getString("panel.icuserpanel.message1"), //$NON-NLS-1$
224                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
225                 }
226             });
2270        }
2280        return infoOnUserButton;
229     }
230  
231     /**
232      * @return Returns the newUserButton.
233      */
2340    protected JButton getNewUserButton() {
2350        if (newUserButton == null) {
2360            newUserButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$
2370            newUserButton.setIcon(new ImageIcon(this.getClass().getResource(
2380                    "/icon/16x16/actions/contact-new.png"))); //$NON-NLS-1$
2390 
2400            newUserButton.addActionListener(new ActionListener() {
241                 public void actionPerformed(ActionEvent arg0) {
242                     logger.debug("actionPerformed newUserButton"); //$NON-NLS-1$
243                     CommandExecutor.getInstance().executeCommand(
244                             new ShowNewUserDialogCommand(), false);
245                 }
246             });
2470        }
2480        return newUserButton;
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.