Coverage details for ui.panel.TabledServerWorkstationPanel

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;
350import javax.swing.JTable;
36 import javax.swing.border.EtchedBorder;
370import javax.swing.border.TitledBorder;
38  
39 import org.apache.log4j.Logger;
40  
41 import ui.Messages;
42 import ui.command.CommandExecutor;
43 import ui.command.creation.ShowNewServerWorkstationDialogCommand;
44 import ui.command.deletion.DeleteServerWorkstationCommand;
45 import ui.command.information.InfoOnServerWorkstationCommand;
46 import ui.table.ServerWorkstationTable;
47 import ui.table.TableSorter;
48 import ui.table.model.ClientWorkstationTableModel;
49 import ui.table.model.ServerWorkstationTableModel;
50  
51 /**
52  * @author skunk
53  *
54  */
550@SuppressWarnings("serial") //$NON-NLS-1$
560public class TabledServerWorkstationPanel extends JPanel {
570 
580    private static final transient Logger logger = Logger
590            .getLogger(TabledServerWorkstationPanel.class.getName());
60  
610    private JTable workstationTable;
620 
630    private TableSorter workstationTableSorter;
640 
650    private JScrollPane workstationTableScrollPane;
660 
67     private ServerWorkstationTableModel workstationTableModel;
68  
69     private JPanel buttonPanel;
70  
71     private JButton newServerWorkstationButton;
720 
730    private JButton infoOnServerWorkstationButton;
740 
750    private JButton deleteServerWorkstationButton;
760 
770    public TabledServerWorkstationPanel() {
780        initialize();
790    }
800 
810    protected void initialize() {
820        this.setLayout(new BorderLayout());
830        TitledBorder titledBorder = new TitledBorder(Messages.getString("common.serverworkstations")); //$NON-NLS-1$
840        this.setBorder(titledBorder);
850        this.add(getWorkstationTableScrollPane(), BorderLayout.CENTER);
860        this.add(getButtonPanel(), BorderLayout.EAST);
870    }
88  
890    /**
900     * @return Returns the buttonPanel.
91      */
920    protected JPanel getButtonPanel() {
930        if (buttonPanel == null) {
940            buttonPanel = new JPanel();
950            buttonPanel.setLayout(new GridLayout(5, 1));
960            buttonPanel.setBorder(new EtchedBorder());
970            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
980            buttonPanel.add(getNewServerWorkstationButton());
990            buttonPanel.add(getInfoOnServerWorkstationButton());
1000            buttonPanel.add(getDeleteServerWorkstationButton());
1010            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1020        }
1030        return buttonPanel;
104     }
105  
106     /**
107      * @return Returns the workstationTableScrollPane.
108      */
1090    protected JScrollPane getWorkstationTableScrollPane() {
1100        if (workstationTableScrollPane == null) {
1110            workstationTableScrollPane = new JScrollPane(getWorkstationTable());
1120        }
1130        return workstationTableScrollPane;
114     }
115  
116     /**
117      * @return Returns the workstationTableSorter.
118      */
1190    protected TableSorter getWorkstationTableSorter() {
1200        if (workstationTableSorter == null) {
1210            workstationTableSorter = new TableSorter(getWorkstationTableModel());
1220        }
1230        return workstationTableSorter;
124     }
1250 
126     /**
127      * @return Returns the workstationTableModel.
1280     */
1290    protected ServerWorkstationTableModel getWorkstationTableModel() {
1300        if (workstationTableModel == null) {
1310            workstationTableModel = new ServerWorkstationTableModel();
1320        }
1330        return workstationTableModel;
134     }
135  
136     /**
137      * @return Returns the workstationTable.
138      */
1390    protected JTable getWorkstationTable() {
1400        if (workstationTable == null) {
1410            workstationTable = new ServerWorkstationTable(
1420                    getWorkstationTableSorter());
1430            workstationTable.setPreferredScrollableViewportSize(new Dimension(
1440                    500, 70));
1450            // We need to place it here to avoid a ciclyc call...
1460            workstationTableSorter.setTableHeader(workstationTable
1470                    .getTableHeader());
1480            // Set up tool tips for column headers.
1490            workstationTable
1500                    .getTableHeader()
1510                    .setToolTipText(
1520                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
1530        }
1540        return workstationTable;
155     }
156  
157     /**
158      * @return Returns the deleteServerWorkstationButton.
159      */
1600    protected JButton getDeleteServerWorkstationButton() {
1610        if (deleteServerWorkstationButton == null) {
1620            deleteServerWorkstationButton = new JButton(
1630                    Messages.getString("button.delete")); //$NON-NLS-1$
1640            deleteServerWorkstationButton.setIcon(new ImageIcon(this.getClass()
1650                    .getResource("/icon/22x22/actions/edit-delete.png"))); //$NON-NLS-1$
1660 
1670            deleteServerWorkstationButton
1680                    .addActionListener(new ActionListener() {
169                         public void actionPerformed(ActionEvent arg0) {
170                             logger
171                                     .debug("actionPerformed deleteServerWorkstationButton"); //$NON-NLS-1$
172                             if (getWorkstationTable().getSelectedRow() != -1) {
1730                                int workstationId = Integer
174                                         .parseInt(((TableSorter) getWorkstationTable()
175                                                 .getModel())
176                                                 .getValueAt(
177                                                         getWorkstationTable()
178                                                                 .getSelectedRow(),
179                                                         ClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
1800                                                .toString());
1810                                CommandExecutor.getInstance().executeCommand(
182                                         new DeleteServerWorkstationCommand(
1830                                                workstationId), false);
184                             } else
185                                 JOptionPane
1860                                        .showMessageDialog(
187                                                 null,
188                                                 Messages.getString("panel.tabledserverworkstationpanel.message1"), //$NON-NLS-1$
189                                                 Messages.getString("common.warning"), //$NON-NLS-1$
190                                                 JOptionPane.WARNING_MESSAGE);
191                         }
192                     });
1930        }
1940        return deleteServerWorkstationButton;
195     }
196  
197     /**
198      * @return Returns the infoOnServerWorkstationButton.
199      */
2000    protected JButton getInfoOnServerWorkstationButton() {
2010        if (infoOnServerWorkstationButton == null) {
2020            infoOnServerWorkstationButton = new JButton(
2030                    Messages.getString("button.info")); //$NON-NLS-1$
2040            infoOnServerWorkstationButton.setIcon(new ImageIcon(this.getClass()
2050                    .getResource("/icon/22x22/status/dialog-information.png"))); //$NON-NLS-1$
2060 
2070            infoOnServerWorkstationButton
2080                    .addActionListener(new ActionListener() {
209                         public void actionPerformed(ActionEvent arg0) {
210                             logger
211                                     .debug("actionPerformed infoOnServerWorkstationButton"); //$NON-NLS-1$
212                             if (getWorkstationTable().getSelectedRow() != -1) {
213                                 int workstationId = Integer
2140                                        .parseInt(((TableSorter) getWorkstationTable()
215                                                 .getModel())
216                                                 .getValueAt(
217                                                         getWorkstationTable()
218                                                                 .getSelectedRow(),
219                                                         ClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
220                                                 .toString());
2210                                CommandExecutor.getInstance().executeCommand(
2220                                        new InfoOnServerWorkstationCommand(
2230                                                workstationId), false);
224                             } else
225                                 JOptionPane
2260                                        .showMessageDialog(
227                                                 null,
228                                                 Messages.getString("panel.tabledserverworkstationpanel.message1"), //$NON-NLS-1$
229                                                 Messages.getString("common.warning"), //$NON-NLS-1$
230                                                 JOptionPane.WARNING_MESSAGE);
231  
232                         }
233                     });
2340        }
2350        return infoOnServerWorkstationButton;
236     }
237  
238     /**
239      * @return Returns the newServerWorkstationButton.
240      */
2410    protected JButton getNewServerWorkstationButton() {
2420        if (newServerWorkstationButton == null) {
2430            newServerWorkstationButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$
2440            newServerWorkstationButton.setIcon(new ImageIcon(this.getClass()
2450                    .getResource("/icon/22x22/places/network-server.png"))); //$NON-NLS-1$
2460 
2470            newServerWorkstationButton.addActionListener(new ActionListener() {
248                 public void actionPerformed(ActionEvent arg0) {
249                     logger.debug("actionPerformed newServerWorkstationButton"); //$NON-NLS-1$
250                     CommandExecutor.getInstance().executeCommand(
251                             new ShowNewServerWorkstationDialogCommand(), false);
252                 }
253             });
2540        }
2550        return newServerWorkstationButton;
256     }
257 }

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.