Coverage details for ui.panel.ICServicePanel

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.ShowNewServiceDialogCommand;
43 import ui.command.deletion.DeleteServiceCommand;
44 import ui.command.information.InfoOnServiceCommand;
45 import ui.table.ServiceTable;
46 import ui.table.TableSorter;
47 import ui.table.model.ServiceTableModel;
48 import ui.table.model.SessionTableModel;
49  
500@SuppressWarnings("serial") //$NON-NLS-1$
510public class ICServicePanel extends JPanel {
520 
530    private static final transient Logger logger = Logger
540            .getLogger(ICServicePanel.class.getName());
55  
56     private JPanel contentPanel;
57  
58     private JPanel buttonPanel;
59  
60     private JButton newServiceButton;
61  
62     private JButton deleteServiceButton;
63  
64     private JButton infoOnServiceButton;
65  
66     private JTable serviceTable;
67  
68     private TableSorter serviceTableSorter;
69  
70     private JScrollPane serviceTableScrollPane;
71  
72     private ServiceTableModel serviceTableModel;
730 
740    public ICServicePanel() {
750        initialize();
760    }
77  
780    protected void initialize() {
790        this.setLayout(new BorderLayout());
800        this.add(getContentPanel(), 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.setBorder(new EtchedBorder());
910            buttonPanel.setLayout(new GridLayout(1, 5));
920            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
930            buttonPanel.add(getNewServiceButton());
940            buttonPanel.add(getInfoOnServiceButton());
950            buttonPanel.add(getDeleteServiceButton());
960            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
97  
980        }
990        return buttonPanel;
100     }
101  
102     /**
103      * @return Returns the contentPanel.
104      */
1050    protected JPanel getContentPanel() {
1060        if (contentPanel == null) {
1070            contentPanel = new JPanel();
1080            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.services")); //$NON-NLS-1$
1090            contentPanel.setBorder(titledBorder);
1100            contentPanel.setLayout(new BorderLayout());
1110            contentPanel.add(getServiceTableScrollPane(), BorderLayout.CENTER);
1120        }
1130        return contentPanel;
114     }
115  
116     /**
117      * @return Returns the deleteServiceButton.
118      */
1190    protected JButton getDeleteServiceButton() {
1200        if (deleteServiceButton == null) {
1210            deleteServiceButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$
1220            deleteServiceButton.setIcon(new ImageIcon(this.getClass()
1230                    .getResource("/icon/16x16/actions/edit-delete.png"))); //$NON-NLS-1$
1240 
1250            deleteServiceButton.addActionListener(new ActionListener() {
126                 public void actionPerformed(ActionEvent arg0) {
127                     logger.debug("actionPerformed deleteServiceButton"); //$NON-NLS-1$
128                     if (getServiceTable().getSelectedRow() != -1) {
129                         int serviceId = Integer
130                                 .parseInt(((TableSorter) getServiceTable()
131                                         .getModel()).getValueAt(
132                                         getServiceTable().getSelectedRow(),
133                                         SessionTableModel.SESSION_ID_COLUMN)
134                                         .toString());
135                         CommandExecutor.getInstance().executeCommand(
136                                 new DeleteServiceCommand(serviceId), false);
137                     } else
138                         JOptionPane
139                                 .showMessageDialog(
140                                         null,
141                                         Messages.getString("panel.icservicepanel.message1"), //$NON-NLS-1$
142                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
143                 }
144             });
1450        }
1460        return deleteServiceButton;
147     }
148  
149     /**
150      * @return Returns the infoOnServiceButton.
151      */
1520    protected JButton getInfoOnServiceButton() {
1530        if (infoOnServiceButton == null) {
1540            infoOnServiceButton = new JButton(Messages.getString("button.info")); //$NON-NLS-1$
1550            infoOnServiceButton.setIcon(new ImageIcon(this.getClass()
1560                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
1570 
1580            infoOnServiceButton.addActionListener(new ActionListener() {
159                 public void actionPerformed(ActionEvent arg0) {
160                     logger.debug("actionPerformed infoOnServiceButton"); //$NON-NLS-1$
161                     if (getServiceTable().getSelectedRow() != -1) {
162                         int serviceId = Integer
163                                 .parseInt(((TableSorter) getServiceTable()
164                                         .getModel()).getValueAt(
165                                         getServiceTable().getSelectedRow(),
166                                         SessionTableModel.SESSION_ID_COLUMN)
167                                         .toString());
168                         CommandExecutor.getInstance().executeCommand(
169                                 new InfoOnServiceCommand(serviceId), false);
170                     } else
171                         JOptionPane
172                                 .showMessageDialog(
173                                         null,
174                                         Messages.getString("panel.icservicepanel.message1"), //$NON-NLS-1$
175                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
176  
177                 }
178             });
1790        }
1800        return infoOnServiceButton;
181     }
182  
183     /**
184      * @return Returns the newServiceButton.
185      */
1860    protected JButton getNewServiceButton() {
1870        if (newServiceButton == null) {
1880            newServiceButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$
1890            newServiceButton
1900                    .setIcon(new ImageIcon(
1910                            this
1920                                    .getClass()
1930                                    .getResource(
1940                                            "/icon/16x16/apps/preferences-desktop-remote-desktop.png"))); //$NON-NLS-1$
1950 
1960            newServiceButton.addActionListener(new ActionListener() {
197                 public void actionPerformed(ActionEvent arg0) {
198                     logger.debug("actionPerformed newServiceButton"); //$NON-NLS-1$
199                     CommandExecutor.getInstance().executeCommand(
200                             new ShowNewServiceDialogCommand(), false);
201                 }
202             });
2030        }
2040        return newServiceButton;
205     }
206  
207     /**
208      * @return Returns the serviceTableScrollPane.
209      */
2100    protected JScrollPane getServiceTableScrollPane() {
2110        if (serviceTableScrollPane == null) {
2120            serviceTableScrollPane = new JScrollPane(getServiceTable());
2130        }
2140        return serviceTableScrollPane;
215     }
216  
217     /**
218      * @return Returns the serviceTableSorter.
219      */
2200    protected TableSorter getServiceTableSorter() {
2210        if (serviceTableSorter == null) {
2220            serviceTableSorter = new TableSorter(getServiceTableModel());
2230        }
2240        return serviceTableSorter;
225     }
226  
227     /**
228      * @return Returns the serviceTableModel.
229      */
2300    protected ServiceTableModel getServiceTableModel() {
2310        if (serviceTableModel == null) {
2320            serviceTableModel = new ServiceTableModel();
2330        }
2340        return serviceTableModel;
235     }
236  
237     /**
238      * @return Returns the serviceTable.
239      */
2400    protected JTable getServiceTable() {
2410        if (serviceTable == null) {
2420            serviceTable = new ServiceTable(getServiceTableSorter());
2430            serviceTable.setPreferredScrollableViewportSize(new Dimension(500,
2440                    70));
2450            // We need to place it here to avoid a ciclyc call...
2460            serviceTableSorter.setTableHeader(serviceTable.getTableHeader());
2470            // Set up tool tips for column headers.
2480            serviceTable
2490                    .getTableHeader()
2500                    .setToolTipText(
2510                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
2520        }
2530        return serviceTable;
254     }
255  
256 }

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.