Line | Hits | Source |
---|---|---|
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") | |
48 | 0 | public class TabledRepositoryPanel extends JPanel { |
49 | ||
50 | 0 | 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.**/ | |
72 | 0 | public TabledRepositoryPanel(){ |
73 | 0 | initialize(); |
74 | 0 | } |
75 | ||
76 | /** | |
77 | * This method initializes the panel configuring and setting its components. | |
78 | */ | |
79 | protected void initialize(){ | |
80 | 0 | this.setBorder(new TitledBorder("Repository Panel")); |
81 | 0 | this.setLayout(new BorderLayout()); |
82 | 0 | this.add(getStatsPanel(),BorderLayout.NORTH); |
83 | 0 | this.add(getBackupTableScrollPane(), BorderLayout.CENTER); |
84 | 0 | this.add(getButtonPanel(), BorderLayout.SOUTH); |
85 | 0 | } |
86 | ||
87 | /** | |
88 | * @return Returns the backupTable. | |
89 | */ | |
90 | protected JTable getBackupTable() { | |
91 | 0 | if (this.backupTable == null) { |
92 | 0 | this.backupTable = new JTable(getBackupTableSorter()); |
93 | 0 | this.backupTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); |
94 | // We need to place it here to avoid a ciclyc call... | |
95 | 0 | this.backupTableSorter.setTableHeader(backupTable.getTableHeader()); |
96 | // Set up tool tips for column headers. | |
97 | 0 | this.backupTable.getTableHeader().setToolTipText("Click to specify sorting; Control-Click to specify secondary sorting."); |
98 | } | |
99 | 0 | return backupTable; |
100 | } | |
101 | ||
102 | /** | |
103 | * @return Returns the backupTableScrollPane. | |
104 | */ | |
105 | protected JScrollPane getBackupTableScrollPane() { | |
106 | 0 | if (this.backupTableScrollPane == null) { |
107 | 0 | this.backupTableScrollPane = new JScrollPane(getBackupTable()); |
108 | } | |
109 | 0 | return backupTableScrollPane; |
110 | } | |
111 | ||
112 | /** | |
113 | * @return Returns the backupTableSorter. | |
114 | */ | |
115 | protected TableSorter getBackupTableSorter() { | |
116 | 0 | if (this.backupTableSorter == null) { |
117 | 0 | this.backupTableSorter = new TableSorter(getBackupTableModel()); |
118 | } | |
119 | 0 | return backupTableSorter; |
120 | } | |
121 | ||
122 | /** | |
123 | * @return Returns the backupTableModel. | |
124 | */ | |
125 | protected TableModel getBackupTableModel() { | |
126 | 0 | if (this.backupTableModel == null) { |
127 | 0 | this.backupTableModel = new BackupDescriptorTableModel(); |
128 | } | |
129 | 0 | return backupTableModel; |
130 | } | |
131 | ||
132 | /** | |
133 | * @return the buttonPanel | |
134 | */ | |
135 | protected JPanel getButtonPanel() { | |
136 | 0 | if(this.buttonPanel == null){ |
137 | 0 | this.buttonPanel = new JPanel(); |
138 | 0 | this.buttonPanel.setLayout(new GridLayout(1,4)); |
139 | 0 | this.buttonPanel.add(this.getIndexRepositoryButton()); |
140 | 0 | this.buttonPanel.add(this.getDeleteExpiredBackupButton()); |
141 | 0 | this.buttonPanel.add(this.getRestoreBackupButton()); |
142 | 0 | this.buttonPanel.add(this.getNewBackupButton()); |
143 | ||
144 | } | |
145 | 0 | return buttonPanel; |
146 | } | |
147 | ||
148 | /** | |
149 | * @return the indexRepositoryButton | |
150 | */ | |
151 | protected JButton getIndexRepositoryButton() { | |
152 | 0 | if(this.indexRepositoryButton == null){ |
153 | 0 | this.indexRepositoryButton = new JButton("Index Repository"); |
154 | 0 | this.indexRepositoryButton.addActionListener(new IndexRepositoryActionListener()); |
155 | ||
156 | } | |
157 | 0 | return indexRepositoryButton; |
158 | } | |
159 | ||
160 | /** | |
161 | * @return Returns the restoreBackupButton. | |
162 | */ | |
163 | protected JButton getRestoreBackupButton() { | |
164 | 0 | if(this.restoreBackupButton == null){ |
165 | 0 | this.restoreBackupButton = new JButton("Restore backup"); |
166 | 0 | 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 | } | |
181 | 0 | return restoreBackupButton; |
182 | } | |
183 | ||
184 | /** | |
185 | * @return Returns the statsPanel. | |
186 | */ | |
187 | protected JPanel getStatsPanel() { | |
188 | 0 | if(this.statsPanel == null){ |
189 | 0 | this.statsPanel = new RepositoryStatisticPanel(); |
190 | } | |
191 | 0 | return statsPanel; |
192 | } | |
193 | ||
194 | /** | |
195 | * @return Returns the newBackupButton. | |
196 | */ | |
197 | protected JButton getNewBackupButton() { | |
198 | 0 | if(this.newBackupButton == null){ |
199 | 0 | this.newBackupButton = new JButton("New Backup"); |
200 | 0 | this.newBackupButton.addActionListener(new ActionListener(){ |
201 | ||
202 | public void actionPerformed(ActionEvent arg0) { | |
203 | CommandExecutor.getInstance().executeCommand(new NewBackupCommand(),false); | |
204 | }}); | |
205 | } | |
206 | 0 | return newBackupButton; |
207 | } | |
208 | ||
209 | /** | |
210 | * @return Returns the deleteExpiredBackupButton. | |
211 | */ | |
212 | protected JButton getDeleteExpiredBackupButton() { | |
213 | 0 | if(this.deleteExpiredBackupButton == null){ |
214 | 0 | this.deleteExpiredBackupButton = new JButton("Delete Expired"); |
215 | 0 | this.deleteExpiredBackupButton.addActionListener(new ActionListener(){ |
216 | ||
217 | public void actionPerformed(ActionEvent arg0) { | |
218 | CommandExecutor.getInstance().executeCommand(new DeleteExpiredBackupCommand(),false); | |
219 | }}); | |
220 | } | |
221 | 0 | return deleteExpiredBackupButton; |
222 | } | |
223 | ||
224 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |