Coverage details for base.jdbs.ui.panel.TabledRepositoryPanel

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 base.jdbs.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.JButton;
29 import javax.swing.JOptionPane;
30 import javax.swing.JPanel;
31 import javax.swing.JScrollPane;
32 import javax.swing.JTable;
33 import javax.swing.border.TitledBorder;
34 import javax.swing.table.TableModel;
35  
36 import org.apache.log4j.Logger;
37  
38 import ui.command.CommandExecutor;
39 import ui.table.TableSorter;
40 import ui.table.model.BackupTableModel;
41 import base.jdbs.ui.BackupDescriptorTableModel;
42 import base.jdbs.ui.action.IndexRepositoryActionListener;
43 import base.jdbs.ui.command.DeleteExpiredBackupCommand;
44 import base.jdbs.ui.command.NewBackupCommand;
45 import base.jdbs.ui.command.RestoreBackupArtifactCommand;
46  
47 @SuppressWarnings("serial")
480public class TabledRepositoryPanel extends JPanel {
49  
500    private static final transient Logger logger = Logger.getLogger(TabledRepositoryPanel.class.getName());
51  
52     /**The table where the local backups artifacts must be shown.**/
53     private JTable backupTable;
54     /**This is needed to scroll the backups artifacts displayed in the backupTable.**/
55     private JScrollPane backupTableScrollPane;
56     /**This is needed to sort the content of the backupTable.**/
57     private TableSorter backupTableSorter;
58     /**This is the model for the backupTable.**/
59     private TableModel backupTableModel;
60     /**The button panel is needed to offer some functions to the user.**/
61     private JPanel buttonPanel;
62     /**This is the panel where some statistics about the Repository usage must be shown.**/
63     private JPanel statsPanel;
64     
65     private JButton indexRepositoryButton;
66     private JButton restoreBackupButton;
67     private JButton newBackupButton;
68     private JButton deleteExpiredBackupButton;
69     
70     
71     /**This is the default constructor.**/
720    public TabledRepositoryPanel(){
730        initialize();
740    }
75     
76     /**
77      * This method initializes the panel configuring and setting its components.
78      */
79     protected void initialize(){
800        this.setBorder(new TitledBorder("Repository Panel"));
810        this.setLayout(new BorderLayout());
820        this.add(getStatsPanel(),BorderLayout.NORTH);
830        this.add(getBackupTableScrollPane(), BorderLayout.CENTER);
840        this.add(getButtonPanel(), BorderLayout.SOUTH);
850    }
86     
87     /**
88      * @return Returns the backupTable.
89      */
90     protected JTable getBackupTable() {
910        if (this.backupTable == null) {
920            this.backupTable = new JTable(getBackupTableSorter());
930            this.backupTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
94             // We need to place it here to avoid a ciclyc call...
950            this.backupTableSorter.setTableHeader(backupTable.getTableHeader());
96             // Set up tool tips for column headers.
970            this.backupTable.getTableHeader().setToolTipText("Click to specify sorting; Control-Click to specify secondary sorting.");
98         }
990        return backupTable;
100     }
101  
102     /**
103      * @return Returns the backupTableScrollPane.
104      */
105     protected JScrollPane getBackupTableScrollPane() {
1060        if (this.backupTableScrollPane == null) {
1070            this.backupTableScrollPane = new JScrollPane(getBackupTable());
108         }
1090        return backupTableScrollPane;
110     }
111  
112     /**
113      * @return Returns the backupTableSorter.
114      */
115     protected TableSorter getBackupTableSorter() {
1160        if (this.backupTableSorter == null) {
1170            this.backupTableSorter = new TableSorter(getBackupTableModel());
118         }
1190        return backupTableSorter;
120     }
121     
122     /**
123      * @return Returns the backupTableModel.
124      */
125     protected TableModel getBackupTableModel() {
1260        if (this.backupTableModel == null) {
1270            this.backupTableModel = new BackupDescriptorTableModel();
128         }
1290        return backupTableModel;
130     }
131  
132     /**
133      * @return the buttonPanel
134      */
135     protected JPanel getButtonPanel() {
1360        if(this.buttonPanel == null){
1370            this.buttonPanel = new JPanel();
1380            this.buttonPanel.setLayout(new GridLayout(1,4));
1390            this.buttonPanel.add(this.getIndexRepositoryButton());
1400            this.buttonPanel.add(this.getDeleteExpiredBackupButton());
1410            this.buttonPanel.add(this.getRestoreBackupButton());
1420            this.buttonPanel.add(this.getNewBackupButton());
143             
144         }
1450        return buttonPanel;
146     }
147  
148     /**
149      * @return the indexRepositoryButton
150      */
151     protected JButton getIndexRepositoryButton() {
1520        if(this.indexRepositoryButton == null){
1530            this.indexRepositoryButton = new JButton("Index Repository");
1540            this.indexRepositoryButton.addActionListener(new IndexRepositoryActionListener());
155             
156         }
1570        return indexRepositoryButton;
158     }
159  
160     /**
161      * @return Returns the restoreBackupButton.
162      */
163     protected JButton getRestoreBackupButton() {
1640        if(this.restoreBackupButton == null){
1650            this.restoreBackupButton = new JButton("Restore backup");
1660            this.restoreBackupButton.addActionListener(new ActionListener() {
167                 public void actionPerformed(ActionEvent arg0) {
168                     logger.debug("actionPerformed restoreBackupButton");
169                     if (getBackupTable().getSelectedRow() != -1) {
170                         String guId = ((TableSorter) getBackupTable().getModel()).getValueAt(getBackupTable().getSelectedRow(),BackupTableModel.BACKUP_ID_COLUMN).toString();
171                         CommandExecutor.getInstance().executeCommand(new RestoreBackupArtifactCommand(guId), false);
172                     } else
173                         JOptionPane
174                                 .showMessageDialog(
175                                         null,
176                                         "You must select a Backup before to try this action!",
177                                         "Warning", JOptionPane.WARNING_MESSAGE);
178                 }
179             });
180         }
1810        return restoreBackupButton;
182     }
183  
184     /**
185      * @return Returns the statsPanel.
186      */
187     protected JPanel getStatsPanel() {
1880        if(this.statsPanel == null){
1890            this.statsPanel = new RepositoryStatisticPanel();
190         }
1910        return statsPanel;
192     }
193  
194     /**
195      * @return Returns the newBackupButton.
196      */
197     protected JButton getNewBackupButton() {
1980        if(this.newBackupButton == null){
1990            this.newBackupButton = new JButton("New Backup");
2000            this.newBackupButton.addActionListener(new ActionListener(){
201  
202                 public void actionPerformed(ActionEvent arg0) {
203                     CommandExecutor.getInstance().executeCommand(new NewBackupCommand(),false);
204                 }});
205         }
2060        return newBackupButton;
207     }
208  
209     /**
210      * @return Returns the deleteExpiredBackupButton.
211      */
212     protected JButton getDeleteExpiredBackupButton() {
2130        if(this.deleteExpiredBackupButton == null){
2140            this.deleteExpiredBackupButton = new JButton("Delete Expired");
2150            this.deleteExpiredBackupButton.addActionListener(new ActionListener(){
216  
217                 public void actionPerformed(ActionEvent arg0) {
218                     CommandExecutor.getInstance().executeCommand(new DeleteExpiredBackupCommand(),false);
219                 }});
220         }
2210        return deleteExpiredBackupButton;
222     }
223         
224 }

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.