Coverage details for ui.panel.ICSessionPanel

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.ShowNewSessionDialogCommand;
43 import ui.command.deletion.DeleteSessionCommand;
44 import ui.command.information.InfoOnSessionCommand;
45 import ui.table.SessionTable;
46 import ui.table.TableSorter;
47 import ui.table.model.SessionTableModel;
48  
490@SuppressWarnings("serial") //$NON-NLS-1$
500public class ICSessionPanel extends JPanel {
510 
520    private static final transient Logger logger = Logger
530            .getLogger(ICSessionPanel.class.getName());
54  
55     private JPanel sortPanel;
56  
57     private JPanel sessionPanel;
58  
59     private JPanel buttonPanel;
60  
61     private JButton newSessionButton;
62  
63     private JButton infoOnSessionButton;
64  
65     private JButton deleteSessionButton;
66  
67     private JTable sessionTable;
68  
69     private JScrollPane sessionTableScrollPane;
70  
71     private TableSorter sessionTableSorter;
72  
73     private SessionTableModel sessionTableModel;
740 
750    public ICSessionPanel() {
760        initialize();
770    }
78  
790    protected void initialize() {
800        this.setName(Messages.getString("common.sessions")); //$NON-NLS-1$
810        this.setLayout(new BorderLayout());
820        this.add(getSortPanel(), BorderLayout.NORTH);
830        this.add(getSessionPanel(), BorderLayout.CENTER);
840        this.add(getButtonPanel(), BorderLayout.SOUTH);
850    }
86  
87     /**
88      * @return Returns the buttonPanel.
89      */
900    protected JPanel getButtonPanel() {
910        if (buttonPanel == null) {
920            buttonPanel = new JPanel();
930            buttonPanel.setLayout(new GridLayout(1, 5));
940            buttonPanel.setBorder(new EtchedBorder());
950            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
960            buttonPanel.add(getNewSessionButton());
970            buttonPanel.add(getInfoOnSessionButton());
980            buttonPanel.add(getDeleteSessionButton());
990            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1000        }
1010        return buttonPanel;
102     }
103  
104     /**
105      * @return Returns the sessionPanel.
106      */
1070    protected JPanel getSessionPanel() {
1080        if (sessionPanel == null) {
1090            sessionPanel = new JPanel();
1100            sessionPanel.setLayout(new BorderLayout());
1110            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.sessions")); //$NON-NLS-1$
1120            sessionPanel.setBorder(titledBorder);
1130            sessionPanel.add(getSessionTableScrollPane(), BorderLayout.CENTER);
114  
1150        }
1160        return sessionPanel;
117     }
118  
119     /**
120      * @return Returns the sortPanel.
121      */
1220    protected JPanel getSortPanel() {
1230        if (sortPanel == null) {
1240            sortPanel = new SessionSearchPanel(getSessionTableModel());
1250        }
1260        return sortPanel;
127     }
128  
129     /**
130      * @return Returns the sessionTableScrollPane.
131      */
1320    protected JScrollPane getSessionTableScrollPane() {
1330        if (sessionTableScrollPane == null) {
1340            sessionTableScrollPane = new JScrollPane(getSessionTable());
1350        }
1360        return sessionTableScrollPane;
137     }
138  
139     /**
140      * @return Returns the sessionTableSorter.
141      */
1420    protected TableSorter getSessionTableSorter() {
1430        if (sessionTableSorter == null) {
1440            sessionTableSorter = new TableSorter(getSessionTableModel());
1450        }
1460        return sessionTableSorter;
147     }
148  
149     /**
150      * @return Returns the sessionTableModel.
151      */
1520    protected SessionTableModel getSessionTableModel() {
1530        if (sessionTableModel == null) {
1540            sessionTableModel = new SessionTableModel();
1550        }
1560        return sessionTableModel;
157     }
158  
159     /**
160      * @return Returns the sessionTable.
161      */
1620    protected JTable getSessionTable() {
1630        if (sessionTable == null) {
1640            sessionTable = new SessionTable(getSessionTableSorter());
1650            sessionTable.setPreferredScrollableViewportSize(new Dimension(500,
1660                    70));
1670            // We need to place it here to avoid a ciclyc call...
1680            sessionTableSorter.setTableHeader(sessionTable.getTableHeader());
1690            // Set up tool tips for column headers.
1700            sessionTable
1710                    .getTableHeader()
1720                    .setToolTipText(
1730                            Messages.getString("tablesorte.header.tooltip")); //$NON-NLS-1$
1740        }
1750        return sessionTable;
176     }
177  
178     /**
179      * @return Returns the deleteSessionButton.
180      */
1810    protected JButton getDeleteSessionButton() {
1820        if (deleteSessionButton == null) {
1830            deleteSessionButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$
1840            deleteSessionButton.setIcon(new ImageIcon(this.getClass()
1850                    .getResource("/icon/16x16/actions/edit-delete.png"))); //$NON-NLS-1$
1860 
1870            deleteSessionButton.addActionListener(new ActionListener() {
188                 public void actionPerformed(ActionEvent arg0) {
189                     logger.debug("actionPerformed deleteButton"); //$NON-NLS-1$
190                     if (getSessionTable().getSelectedRow() != -1) {
191                         int sessionId = Integer
192                                 .parseInt(((TableSorter) getSessionTable()
193                                         .getModel()).getValueAt(
194                                         getSessionTable().getSelectedRow(),
195                                         SessionTableModel.SESSION_ID_COLUMN)
196                                         .toString());
197                         CommandExecutor.getInstance().executeCommand(
198                                 new DeleteSessionCommand(sessionId), false);
199                     } else
200                         JOptionPane
201                                 .showMessageDialog(
202                                         null,
203                                         Messages.getString("panel.icsessionpanel.message1"), //$NON-NLS-1$
204                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
205                 }
206             });
2070        }
2080        return deleteSessionButton;
209     }
210  
211     /**
212      * @return Returns the infoOnSessionButton.
213      */
2140    protected JButton getInfoOnSessionButton() {
2150        if (infoOnSessionButton == null) {
2160            infoOnSessionButton = new JButton(Messages.getString("button.info")); //$NON-NLS-1$
2170            infoOnSessionButton.setIcon(new ImageIcon(this.getClass()
2180                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
2190            infoOnSessionButton.addActionListener(new ActionListener() {
220                 public void actionPerformed(ActionEvent arg0) {
221                     logger.debug("actionPerformed infoButton"); //$NON-NLS-1$
222                     if (getSessionTable().getSelectedRow() != -1) {
223                         int sessionId = Integer
224                                 .parseInt(((TableSorter) getSessionTable()
225                                         .getModel()).getValueAt(
226                                         getSessionTable().getSelectedRow(),
227                                         SessionTableModel.SESSION_ID_COLUMN)
228                                         .toString());
229                         CommandExecutor.getInstance().executeCommand(
230                                 new InfoOnSessionCommand(sessionId), false);
231                     } else
232                         JOptionPane
233                                 .showMessageDialog(
234                                         null,
235                                         Messages.getString("panel.icsessionpanel.message1"), //$NON-NLS-1$
236                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
237                 }
238             });
2390        }
2400        return infoOnSessionButton;
241     }
242  
243     /**
244      * @return Returns the newSessionButton.
245      */
2460    protected JButton getNewSessionButton() {
2470        if (newSessionButton == null) {
2480            newSessionButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$
2490            newSessionButton.setIcon(new ImageIcon(this.getClass().getResource(
2500                    "/icon/16x16/actions/window-new.png"))); //$NON-NLS-1$
2510            newSessionButton.addActionListener(new ActionListener() {
252                 public void actionPerformed(ActionEvent arg0) {
253                     CommandExecutor.getInstance().executeCommand(
254                             new ShowNewSessionDialogCommand(), false);
255                     logger.debug("actionPerformed newButton"); //$NON-NLS-1$
256                 }
257             });
258  
2590        }
2600        return newSessionButton;
261     }
262  
263 }

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.