Coverage details for ui.panel.TabledBackupPanel

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 import java.io.File;
29  
30 import javax.swing.ImageIcon;
31 import javax.swing.JButton;
32 import javax.swing.JLabel;
330import javax.swing.JOptionPane;
34 import javax.swing.JPanel;
350import javax.swing.JScrollPane;
36 import javax.swing.JTable;
37 import 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.IO.LoadBackupCommand;
44 import ui.command.creation.ShowNewBackupCommand;
45 import ui.command.deletion.DeleteBackupCommand;
46 import ui.table.BackupTable;
47 import ui.table.TableSorter;
48 import ui.table.model.BackupTableModel;
49 import base.ConfigurationManager;
50 import base.InternetCafeManager;
51 import base.backup.Backup;
52  
530@SuppressWarnings("serial") //$NON-NLS-1$
540public class TabledBackupPanel extends JPanel {
550 
560    private static final transient Logger logger = Logger
570            .getLogger(TabledBackupPanel.class.getName());
580 
59     private JTable backUpHistoryTable;
60  
610    private JScrollPane backUpHistoryTableScrollPane;
620 
630    private TableSorter backUpHistoryTableSorter;
640 
650    private BackupTableModel backUpHistoryTableModel;
660 
67     private JPanel backUpButtonPanel;
68  
69     private JButton newBackUpButton;
70  
71     private JButton restoreBackUpButton;
720 
730    private JButton loadBackUpButton;
740 
75     private JButton deleteBackUpButton;
760 
770    public TabledBackupPanel() {
780        initialize();
790    }
800 
810    protected void initialize() {
820        TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.backuppanel.backuphistory")); //$NON-NLS-1$
830        this.setBorder(titledBorder);
840        this.setLayout(new BorderLayout());
850        this.add(getBackUpHistoryTableScrollPane(), BorderLayout.CENTER);
860        this.add(getBackUpButtonPanel(), BorderLayout.EAST);
870    }
88  
89     /**
90      * @return Returns the backUpHistoryTable.
91      */
920    protected JTable getBackUpHistoryTable() {
930        if (backUpHistoryTable == null) {
940            backUpHistoryTable = new BackupTable(getUserTableSorter());
950            backUpHistoryTable
960                    .setPreferredScrollableViewportSize(new Dimension(500, 70));
970            // We need to place it here to avoid a ciclyc call...
980            backUpHistoryTableSorter.setTableHeader(backUpHistoryTable
990                    .getTableHeader());
1000            // Set up tool tips for column headers.
1010            backUpHistoryTable
1020                    .getTableHeader()
1030                    .setToolTipText(
1040                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
1050        }
1060        return backUpHistoryTable;
1070    }
108  
109     /**
110      * @return Returns the backUpHistoryTableScrollPane.
111      */
1120    protected JScrollPane getBackUpHistoryTableScrollPane() {
1130        if (backUpHistoryTableScrollPane == null) {
1140            backUpHistoryTableScrollPane = new JScrollPane(
1150                    getBackUpHistoryTable());
1160        }
1170        return backUpHistoryTableScrollPane;
118     }
119  
120     /**
121      * @return Returns the backUpHistoryTableSorter.
122      */
1230    protected TableSorter getUserTableSorter() {
1240        if (backUpHistoryTableSorter == null) {
1250            backUpHistoryTableSorter = new TableSorter(
1260                    getBackUpHistoryTableModel());
1270        }
1280        return backUpHistoryTableSorter;
1290    }
1300 
1310    /**
1320     * @return Returns the backUpHistoryTableModel.
133      */
1340    protected BackupTableModel getBackUpHistoryTableModel() {
1350        if (backUpHistoryTableModel == null) {
1360            backUpHistoryTableModel = new BackupTableModel();
1370        }
1380        return backUpHistoryTableModel;
139     }
140  
1410    /**
1420     * @return Returns the backUpButtonPanel.
1430     */
1440    protected JPanel getBackUpButtonPanel() {
1450        if (backUpButtonPanel == null) {
1460            backUpButtonPanel = new JPanel();
1470            backUpButtonPanel.setLayout(new GridLayout(6, 1));
1480            backUpButtonPanel.add(new JLabel("")); //$NON-NLS-1$
1490            backUpButtonPanel.add(getNewBackUpButton());
1500            backUpButtonPanel.add(getLoadBackUpButton());
1510            backUpButtonPanel.add(getRestoreBackUpButton());
1520            backUpButtonPanel.add(getDeleteBackUpButton());
1530            backUpButtonPanel.add(new JLabel("")); //$NON-NLS-1$
1540        }
1550        return backUpButtonPanel;
156     }
157  
158     /**
159      * @return Returns the deleteBackUpButton.
160      */
1610    protected JButton getDeleteBackUpButton() {
1620        if (deleteBackUpButton == null) {
1630            deleteBackUpButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$
1640            deleteBackUpButton.setIcon(new ImageIcon(this.getClass()
1650                    .getResource("/icon/22x22/actions/edit-delete.png"))); //$NON-NLS-1$
1660 
1670            deleteBackUpButton.addActionListener(new ActionListener() {
1680                public void actionPerformed(ActionEvent arg0) {
169                     logger.debug("actionPerformed deleteBackUpButton"); //$NON-NLS-1$
170                     if (getBackUpHistoryTable().getSelectedRow() != -1) {
171                         int backupId = Integer
172                                 .parseInt(((TableSorter) getBackUpHistoryTable()
173                                         .getModel()).getValueAt(
174                                         getBackUpHistoryTable()
1750                                                .getSelectedRow(),
1760                                        BackupTableModel.BACKUP_ID_COLUMN)
1770                                        .toString());
178                         CommandExecutor.getInstance().executeCommand(
179                                 new DeleteBackupCommand(backupId), false);
1800                    } else
181                         JOptionPane
182                                 .showMessageDialog(
183                                         null,
184                                         Messages.getString("panel.tabledbackuppanel.message1"), //$NON-NLS-1$
185                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
186                 }
187             });
1880        }
1890        return deleteBackUpButton;
190     }
191  
192     /**
193      * @return Returns the loadBackUpButton.
194      */
1950    protected JButton getLoadBackUpButton() {
1960        if (loadBackUpButton == null) {
1970            loadBackUpButton = new JButton(Messages.getString("button.load")); //$NON-NLS-1$
1980            loadBackUpButton.setIcon(new ImageIcon(this.getClass().getResource(
1990                    "/icon/22x22/actions/document-open.png"))); //$NON-NLS-1$
2000 
2010            loadBackUpButton.addActionListener(new ActionListener() {
202                 public void actionPerformed(ActionEvent arg0) {
203                     logger.debug("actionPerformed loadBackUpButton"); //$NON-NLS-1$
204                     CommandExecutor.getInstance().executeCommand(
205                             new LoadBackupCommand(), false);
206                 }
207             });
2080        }
2090        return loadBackUpButton;
210     }
211  
212     /**
213      * @return Returns the newBackUpButton.
214      */
2150    protected JButton getNewBackUpButton() {
2160        if (newBackUpButton == null) {
2170            newBackUpButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$
2180            newBackUpButton.setIcon(new ImageIcon(this.getClass().getResource(
2190                    "/icon/22x22/actions/document-new.png"))); //$NON-NLS-1$
2200 
2210            newBackUpButton.addActionListener(new ActionListener() {
222                 public void actionPerformed(ActionEvent arg0) {
223                     logger.debug("actionPerformed newBackUpButton"); //$NON-NLS-1$
224                     CommandExecutor.getInstance().executeCommand(
225                             new ShowNewBackupCommand(), false);
226                 }
227             });
2280        }
2290        return newBackUpButton;
230     }
231  
232     /**
233      * @return Returns the restoreBackUpButton.
234      */
2350    protected JButton getRestoreBackUpButton() {
2360        if (restoreBackUpButton == null) {
2370            restoreBackUpButton = new JButton(Messages.getString("button.restore")); //$NON-NLS-1$
2380            restoreBackUpButton.setIcon(new ImageIcon(this.getClass()
2390                    .getResource("/icon/22x22/actions/view-refresh.png"))); //$NON-NLS-1$
2400 
2410            restoreBackUpButton.addActionListener(new ActionListener() {
242                 public void actionPerformed(ActionEvent arg0) {
243                     logger.debug("actionPerformed restoreBackUpButton"); //$NON-NLS-1$
244                     if (getBackUpHistoryTable().getSelectedRow() != -1) {
245                         Object[] options = { Messages.getString("TabledBackupPanel.19"), //$NON-NLS-1$
246                                 Messages.getString("TabledBackupPanel.20") }; //$NON-NLS-1$
247                         int result = JOptionPane
248                                 .showOptionDialog(
249                                         null,
250                                         Messages.getString("panel.tabledbackuppanel.message2"), //$NON-NLS-1$
251                                         Messages.getString("panel.tabledbackuppanel.backuprestore"), //$NON-NLS-1$
252                                         JOptionPane.YES_NO_OPTION,
253                                         JOptionPane.QUESTION_MESSAGE, null,
254                                         options, options[1]);
255                         if (result == JOptionPane.YES_OPTION) {
256                             int backupId = Integer
257                                     .parseInt(((TableSorter) getBackUpHistoryTable()
258                                             .getModel()).getValueAt(
259                                             getBackUpHistoryTable()
260                                                     .getSelectedRow(),
261                                             BackupTableModel.BACKUP_ID_COLUMN)
262                                             .toString());
263                             Backup backup = InternetCafeManager.getInstance()
264                                     .getBackupById(backupId);
265                             if (backup != null) {
266                                 if (new File(backup.getDbLocationPath())
267                                         .exists()) {
268                                     ConfigurationManager.getInstance()
269                                             .setDataBasePath(
270                                                     backup.getDbLocationPath());
271                                     InternetCafeManager.getInstance().clear();
272                                     InternetCafeManager.getInstance()
2730                                            .retrieve();
274                                 } else
275                                     JOptionPane
276                                             .showMessageDialog(
277                                                     null,
278                                                     Messages.getString("panel.tabledbackuppanel.message3"), //$NON-NLS-1$
279                                                     Messages.getString("common.error"), //$NON-NLS-1$
280                                                     JOptionPane.ERROR_MESSAGE);
281                             } else
282                                 logger.error(Messages.getString("BIG PROBLEM HERE!")); //$NON-NLS-1$
283                         }
284                     } else
285                         JOptionPane
286                                 .showMessageDialog(
287                                         null,
288                                         Messages.getString("panel.tabledbackuppanel.message1"), //$NON-NLS-1$
289                                         Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
290                 }
291             });
292  
2930        }
2940        return restoreBackUpButton;
295     }
296  
297 }

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.