View Javadoc

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.GridLayout;
25  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;
27  import java.util.Date;
28  
29  import javax.swing.ImageIcon;
30  import javax.swing.JButton;
31  import javax.swing.JFileChooser;
32  import javax.swing.JPanel;
33  import javax.swing.JTextField;
34  import javax.swing.border.TitledBorder;
35  
36  import org.apache.log4j.Logger;
37  
38  import ui.Messages;
39  import base.ConfigurationManager;
40  
41  /***
42   * @author skunk
43   * 
44   */
45  @SuppressWarnings("serial") //$NON-NLS-1$
46  public class BackupPanel extends JPanel {
47  
48  	private static final transient Logger logger = Logger
49  			.getLogger(BackupPanel.class.getName());
50  
51  	/*
52  	 * private final int id; private String name; private String description;
53  	 * private Date date; private String originalBackupDestinationPath; private
54  	 * String currentBackupLocationPath="";
55  	 */
56  
57  	private JPanel namePanel;
58  
59  	private JTextField nameTextField;
60  
61  	private JPanel descriptionPanel;
62  
63  	private JTextField descriptionTextField;
64  
65  	private JPanel datePanel;
66  
67  	private Date currentDate;
68  
69  	private JTextField dateTextField;
70  
71  	private JPanel dbLocationPathPanel;
72  
73  	private JTextField dbLocationPathTextField;
74  
75  	private JPanel zipLocationPathPanel;
76  
77  	private JTextField zipLocationPathTextField;
78  
79  	private JButton chooseZipLocationPathButton;
80  
81  	public BackupPanel() {
82  		initialize();
83  	}
84  
85  	protected void initialize() {
86  		this.setLayout(new GridLayout(5, 1));
87  		this.add(getNamePanel());
88  		this.add(getDatePanel());
89  		this.add(getDescriptionPanel());
90  		this.add(getDbLocationPathPanel());
91  		this.add(getZipLocationPathPanel());
92  	}
93  
94  	/***
95  	 * @return Returns the datePanel.
96  	 */
97  	protected JPanel getDatePanel() {
98  		if (datePanel == null) {
99  			datePanel = new JPanel();
100 			datePanel.setBorder(new TitledBorder(Messages.getString("common.date"))); //$NON-NLS-1$
101 			datePanel.setLayout(new BorderLayout());
102 			datePanel.add(getDateTextField(), BorderLayout.CENTER);
103 		}
104 		return datePanel;
105 	}
106 
107 	/***
108 	 * @return Returns the dateTextField.
109 	 */
110 	protected JTextField getDateTextField() {
111 		if (dateTextField == null) {
112 			dateTextField = new JTextField();
113 			dateTextField.setText(getCurrentDate().toString());
114 			dateTextField.setEditable(false);
115 		}
116 		return dateTextField;
117 	}
118 
119 	/***
120 	 * @return Returns the descriptionPanel.
121 	 */
122 	protected JPanel getDescriptionPanel() {
123 		if (descriptionPanel == null) {
124 			descriptionPanel = new JPanel();
125 			descriptionPanel.setBorder(new TitledBorder(Messages.getString("common.description"))); //$NON-NLS-1$
126 			descriptionPanel.setLayout(new BorderLayout());
127 			descriptionPanel
128 					.add(getDescriptionTextField(), BorderLayout.CENTER);
129 		}
130 		return descriptionPanel;
131 	}
132 
133 	/***
134 	 * @return Returns the descriptionTextField.
135 	 */
136 	protected JTextField getDescriptionTextField() {
137 		if (descriptionTextField == null) {
138 			descriptionTextField = new JTextField();
139 		}
140 		return descriptionTextField;
141 	}
142 
143 	/***
144 	 * @return Returns the zipLocationPathPanel.
145 	 */
146 	protected JPanel getZipLocationPathPanel() {
147 		if (zipLocationPathPanel == null) {
148 			zipLocationPathPanel = new JPanel();
149 			zipLocationPathPanel.setBorder(new TitledBorder(
150 					Messages.getString("panel.backuppanel.zippedarchivedestinationpath"))); //$NON-NLS-1$
151 			zipLocationPathPanel.setLayout(new BorderLayout());
152 			zipLocationPathPanel.add(getZipLocationPathTextField(),
153 					BorderLayout.CENTER);
154 			zipLocationPathPanel.add(getChooseZipLocationPathButton(),
155 					BorderLayout.EAST);
156 		}
157 		return zipLocationPathPanel;
158 	}
159 
160 	/***
161 	 * @return Returns the zipLocationPathTextField.
162 	 */
163 	protected JTextField getZipLocationPathTextField() {
164 		if (zipLocationPathTextField == null) {
165 			zipLocationPathTextField = new JTextField();
166 			zipLocationPathTextField.setEditable(false);
167 		}
168 		return zipLocationPathTextField;
169 	}
170 
171 	/***
172 	 * @return Returns the dbLocationPathPanel.
173 	 */
174 	protected JPanel getDbLocationPathPanel() {
175 		if (dbLocationPathPanel == null) {
176 			dbLocationPathPanel = new JPanel();
177 			dbLocationPathPanel
178 					.setBorder(new TitledBorder(Messages.getString("panel.backuppanel.envolveddatabase"))); //$NON-NLS-1$
179 			dbLocationPathPanel.setLayout(new BorderLayout());
180 			dbLocationPathPanel.add(getDbLocationPathTextField(),
181 					BorderLayout.CENTER);
182 		}
183 		return dbLocationPathPanel;
184 	}
185 
186 	/***
187 	 * @return Returns the dbLocationPathTextField.
188 	 */
189 	protected JTextField getDbLocationPathTextField() {
190 		if (dbLocationPathTextField == null) {
191 			dbLocationPathTextField = new JTextField();
192 			dbLocationPathTextField.setText(ConfigurationManager.getInstance()
193 					.getDataBasePath());
194 			dbLocationPathTextField.setEditable(false);
195 		}
196 		return dbLocationPathTextField;
197 	}
198 
199 	/***
200 	 * @return Returns the namePanel.
201 	 */
202 	protected JPanel getNamePanel() {
203 		if (namePanel == null) {
204 			namePanel = new JPanel();
205 			namePanel.setBorder(new TitledBorder(Messages.getString("common.name"))); //$NON-NLS-1$
206 			namePanel.setLayout(new BorderLayout());
207 			namePanel.add(getNameTextField(), BorderLayout.CENTER);
208 		}
209 		return namePanel;
210 	}
211 
212 	/***
213 	 * @return Returns the nameTextField.
214 	 */
215 	protected JTextField getNameTextField() {
216 		if (nameTextField == null) {
217 			nameTextField = new JTextField();
218 			nameTextField.setText(Messages.getString("common.backup")); //$NON-NLS-1$
219 		}
220 		return nameTextField;
221 	}
222 
223 	/***
224 	 * @return Returns the chooseZipLocationPathButton.
225 	 */
226 	protected JButton getChooseZipLocationPathButton() {
227 		if (chooseZipLocationPathButton == null) {
228 			chooseZipLocationPathButton = new JButton();
229 			chooseZipLocationPathButton.setToolTipText(Messages.getString("common.choosefolder")); //$NON-NLS-1$
230 			chooseZipLocationPathButton.setIcon(new ImageIcon(this.getClass()
231 					.getResource("/icon/16x16/actions/document-open.png"))); //$NON-NLS-1$
232 			chooseZipLocationPathButton.addActionListener(new ActionListener() {
233 				public void actionPerformed(ActionEvent arg0) {
234 					logger.debug("actionPerformed chooseZipLocationPathButton"); //$NON-NLS-1$
235 					JFileChooser chooser = new JFileChooser();
236 					chooser
237 							.setDialogTitle(Messages.getString("panel.backuppanel.message1")); //$NON-NLS-1$
238 					chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
239 					chooser.setApproveButtonText(Messages.getString("button.select")); //$NON-NLS-1$
240 					if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
241 						getZipLocationPathTextField().setText(
242 								chooser.getSelectedFile().getPath());
243 					}
244 				}
245 			});
246 		}
247 		return chooseZipLocationPathButton;
248 	}
249 
250 	/***
251 	 * @return The backup's date.
252 	 */
253 	public Date getBackupDate() {
254 		return this.getCurrentDate();
255 	}
256 
257 	/***
258 	 * @return The backup's name.
259 	 */
260 	public String getBackupName() {
261 		return this.getNameTextField().getText();
262 	}
263 
264 	/***
265 	 * @return The backup's description.
266 	 */
267 	public String getBackupDescription() {
268 		return this.getDescriptionTextField().getText();
269 	}
270 
271 	/***
272 	 * @return The backup's database location path.
273 	 */
274 	public String getDbLocationPath() {
275 		return this.getDbLocationPathTextField().getText();
276 	}
277 
278 	/***
279 	 * @return The compressed backup file's path.
280 	 */
281 	public String getZipLocationPath() {
282 		return this.getZipLocationPathTextField().getText();
283 	}
284 
285 	/***
286 	 * @return Returns the currentDate.
287 	 */
288 	protected Date getCurrentDate() {
289 		if (currentDate == null) {
290 			currentDate = new Date();
291 		}
292 		return currentDate;
293 	}
294 }