Coverage details for ui.panel.TabledClientWorkstationPanel

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  
21 package ui.panel;
22  
23 import java.awt.BorderLayout;
24 import java.awt.Dimension;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28  
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JLabel;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTable;
36 import javax.swing.border.EtchedBorder;
370import javax.swing.border.TitledBorder;
38  
390import org.apache.log4j.Logger;
40  
41 import ui.Messages;
42 import ui.command.CommandExecutor;
43 import ui.command.creation.ShowNewClientWorkstationDialogCommand;
44 import ui.command.deletion.DeleteClientWorkstationCommand;
45 import ui.command.information.InfoOnClientWorkstationCommand;
46 import ui.table.ClientWorkstationTable;
47 import ui.table.TableSorter;
48 import ui.table.model.ClientWorkstationTableModel;
49  
50 /**
51  * @author skunk
52  *
53  */
540@SuppressWarnings("serial") //$NON-NLS-1$
550public class TabledClientWorkstationPanel extends JPanel {
560 
570    private static final transient Logger logger = Logger
580            .getLogger(TabledClientWorkstationPanel.class.getName());
59  
600    private JTable workstationTable;
610 
620    private TableSorter workstationTableSorter;
63  
64     private JScrollPane workstationTableScrollPane;
650 
660    private ClientWorkstationTableModel workstationTableModel;
670 
680    private JPanel buttonPanel;
690 
700    private JButton newClientWorkstationButton;
71  
72     private JButton infoOnClientWorkstationButton;
73  
74     private JButton snapshotOfClientWorkstationButton;
75  
760    private JButton deleteClientWorkstationButton;
770 
780    public TabledClientWorkstationPanel() {
790        initialize();
800    }
810 
820    protected void initialize() {
830        this.setLayout(new BorderLayout());
840        TitledBorder titledBorder = new TitledBorder(Messages.getString("common.clientworkstations")); //$NON-NLS-1$
850        this.setBorder(titledBorder);
860        this.add(getWorkstationTableScrollPane(), BorderLayout.CENTER);
870        this.add(getButtonPanel(), BorderLayout.EAST);
880    }
89  
90     /**
91      * @return Returns the buttonPanel.
92      */
930    protected JPanel getButtonPanel() {
940        if (buttonPanel == null) {
950            buttonPanel = new JPanel();
960            buttonPanel.setLayout(new GridLayout(6, 1));
970            buttonPanel.setBorder(new EtchedBorder());
980            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
990            buttonPanel.add(getNewClientWorkstationButton());
1000            buttonPanel.add(getInfoOnClientWorkstationButton());
1010            buttonPanel.add(getSnapshotOfClientWorkstationButton());
1020            buttonPanel.add(getDeleteClientWorkstationButton());
1030            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1040        }
1050        return buttonPanel;
106     }
1070 
108     /**
109      * @return Returns the workstationTableScrollPane.
110      */
1110    protected JScrollPane getWorkstationTableScrollPane() {
1120        if (workstationTableScrollPane == null) {
1130            workstationTableScrollPane = new JScrollPane(getWorkstationTable());
1140        }
1150        return workstationTableScrollPane;
116     }
1170 
118     /**
119      * @return Returns the workstationTableSorter.
120      */
1210    protected TableSorter getWorkstationTableSorter() {
1220        if (workstationTableSorter == null) {
1230            workstationTableSorter = new TableSorter(getWorkstationTableModel());
1240        }
1250        return workstationTableSorter;
126     }
1270 
128     /**
129      * @return Returns the workstationTableModel.
1300     */
1310    protected ClientWorkstationTableModel getWorkstationTableModel() {
1320        if (workstationTableModel == null) {
1330            workstationTableModel = new ClientWorkstationTableModel();
1340        }
1350        return workstationTableModel;
136     }
137  
1380    /**
139      * @return Returns the workstationTable.
140      */
1410    protected JTable getWorkstationTable() {
1420        if (workstationTable == null) {
1430            workstationTable = new ClientWorkstationTable(
1440                    getWorkstationTableSorter());
1450            workstationTable.setPreferredScrollableViewportSize(new Dimension(
1460                    500, 70));
1470            // We need to place it here to avoid a ciclyc call...
1480            workstationTableSorter.setTableHeader(workstationTable
1490                    .getTableHeader());
1500            // Set up tool tips for column headers.
1510            workstationTable
1520                    .getTableHeader()
1530                    .setToolTipText(
1540                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
1550        }
1560        return workstationTable;
157     }
158  
159     /**
160      * @return Returns the deleteClientWorkstationButton.
161      */
1620    protected JButton getDeleteClientWorkstationButton() {
1630        if (deleteClientWorkstationButton == null) {
1640            deleteClientWorkstationButton = new JButton(
1650                    Messages.getString("button.delete")); //$NON-NLS-1$
1660            deleteClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
1670                    .getResource("/icon/22x22/actions/edit-delete.png"))); //$NON-NLS-1$
1680 
1690            deleteClientWorkstationButton
1700                    .addActionListener(new ActionListener() {
171                         public void actionPerformed(ActionEvent arg0) {
172                             logger
173                                     .debug("actionPerformed deleteClientWorkstationButton"); //$NON-NLS-1$
174                             if (getWorkstationTable().getSelectedRow() != -1) {
175                                 int workstationId = Integer
176                                         .parseInt(((TableSorter) getWorkstationTable()
177                                                 .getModel())
1780                                                .getValueAt(
179                                                         getWorkstationTable()
180                                                                 .getSelectedRow(),
181                                                         ClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
182                                                 .toString());
183                                 CommandExecutor.getInstance().executeCommand(
184                                         new DeleteClientWorkstationCommand(
1850                                                workstationId), false);
1860                            } else
187                                 JOptionPane
1880                                        .showMessageDialog(
189                                                 null,
190                                                 Messages.getString("panel.tabledclientworkstationpanel.message1"), //$NON-NLS-1$
1910                                                Messages.getString("common.warning"), //$NON-NLS-1$
192                                                 JOptionPane.WARNING_MESSAGE);
193                         }
194                     });
1950        }
1960        return deleteClientWorkstationButton;
197     }
198  
199     /**
200      * @return Returns the infoOnClientWorkstationButton.
201      */
2020    protected JButton getInfoOnClientWorkstationButton() {
2030        if (infoOnClientWorkstationButton == null) {
2040            infoOnClientWorkstationButton = new JButton(
2050                    Messages.getString("button.info")); //$NON-NLS-1$
2060            infoOnClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
2070                    .getResource("/icon/22x22/status/dialog-information.png"))); //$NON-NLS-1$
2080 
2090            infoOnClientWorkstationButton
2100                    .addActionListener(new ActionListener() {
211                         public void actionPerformed(ActionEvent arg0) {
212                             logger
213                                     .debug("actionPerformed infoOnClientWorkstationButton"); //$NON-NLS-1$
214                             if (getWorkstationTable().getSelectedRow() != -1) {
215                                 int workstationId = Integer
216                                         .parseInt(((TableSorter) getWorkstationTable()
217                                                 .getModel())
218                                                 .getValueAt(
219                                                         getWorkstationTable()
2200                                                                .getSelectedRow(),
221                                                         ClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
222                                                 .toString());
223                                 CommandExecutor.getInstance().executeCommand(
224                                         new InfoOnClientWorkstationCommand(
225                                                 workstationId), false);
226  
2270                            } else
2280                                JOptionPane
2290                                        .showMessageDialog(
230                                                 null,
231                                                 Messages.getString("panel.tabledclientworkstationpanel.message1"), //$NON-NLS-1$
2320                                                Messages.getString("common.warning"), //$NON-NLS-1$
233                                                 JOptionPane.WARNING_MESSAGE);
234  
235                         }
236                     });
2370        }
2380        return infoOnClientWorkstationButton;
239     }
2400 
241     /**
242      * @return Returns the newClientWorkstationButton.
243      */
2440    protected JButton getNewClientWorkstationButton() {
2450        if (newClientWorkstationButton == null) {
2460            newClientWorkstationButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$
2470            newClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
2480                    .getResource("/icon/22x22/devices/computer.png"))); //$NON-NLS-1$
2490 
2500            newClientWorkstationButton.addActionListener(new ActionListener() {
251                 public void actionPerformed(ActionEvent arg0) {
252                     logger.debug("actionPerformed newClientWorkstationButton"); //$NON-NLS-1$
253                     CommandExecutor.getInstance().executeCommand(
2540                            new ShowNewClientWorkstationDialogCommand(), false);
255                 }
256             });
2570        }
2580        return newClientWorkstationButton;
259     }
260  
261     /**
262      * @return Returns the snapshotOfClientWorkstationButton.
263      */
2640    protected JButton getSnapshotOfClientWorkstationButton() {
2650        if (snapshotOfClientWorkstationButton == null) {
2660            snapshotOfClientWorkstationButton = new JButton(
2670                    Messages.getString("button.snapshot")); //$NON-NLS-1$
2680            snapshotOfClientWorkstationButton.setIcon(new ImageIcon(this
2690                    .getClass().getResource(
2700                            "/icon/22x22/devices/camera-photo.png"))); //$NON-NLS-1$
2710 
2720            snapshotOfClientWorkstationButton
2730                    .addActionListener(new ActionListener() {
274                         public void actionPerformed(ActionEvent arg0) {
275                             logger
276                                     .debug("actionPerformed snapshotOfClientWorkstationButton"); //$NON-NLS-1$
277                             // CommandExecutor.getInstance().executeCommand(new
278                             // ShowNewClientWorkstationDialogCommand(), false);
279                         }
280                     });
2810        }
2820        return snapshotOfClientWorkstationButton;
283     }
284  
285 }

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.