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.command.IO;
22  
23  import java.util.Date;
24  
25  import ui.Messages;
26  import ui.command.Command;
27  import ui.panel.BackupPanel;
28  import base.InternetCafe;
29  import base.InternetCafeManager;
30  import base.backup.Backup;
31  import base.backup.BackupFactory;
32  
33  public class SaveBackupCommand extends Command {
34  
35  	private final BackupPanel backupPanel;
36  
37  	private String name;
38  
39  	private String description;
40  
41  	private Date date;
42  
43  	private String dbLocationPath;
44  
45  	private String zipLocationPath;
46  
47  	/***
48  	 * @param backupPanel
49  	 */
50  	public SaveBackupCommand(BackupPanel backupPanel) {
51  		this.backupPanel = backupPanel;
52  	}
53  
54  	/*
55  	 * (non-Javadoc)
56  	 * 
57  	 * @see ui.command.Command#prologo()
58  	 */
59  	@Override
60  	protected void prologo() {
61  		InternetCafe.setStatusBarMessage(Messages.getString("command.savebackupcommand.savingbackup")); //$NON-NLS-1$
62  		this.name = getBackupPanel().getBackupName();
63  		this.description = getBackupPanel().getBackupDescription();
64  		this.dbLocationPath = getBackupPanel().getDbLocationPath();
65  		this.zipLocationPath = getBackupPanel().getZipLocationPath();
66  		this.date = getBackupPanel().getBackupDate();
67  		setStatus(EXECUTE_STATUS);
68  	}
69  
70  	/*
71  	 * (non-Javadoc)
72  	 * 
73  	 * @see ui.command.Command#execution()
74  	 */
75  	@Override
76  	protected void execution() throws Exception {
77  		switch (getStatus()) {
78  		case ERROR_STATUS:
79  			break;
80  		case VETOED_STATUS:
81  			break;
82  		case EXECUTE_STATUS:
83  			Backup backup = BackupFactory.newBackup(this.name,
84  					this.description, this.date, this.dbLocationPath,
85  					this.zipLocationPath);
86  			InternetCafeManager.getInstance().addBackup(backup);
87  			BackupFactory.backupToZipArchive(backup);
88  			setStatus(SUCCESS_STATUS);
89  			break;
90  		}
91  	}
92  
93  	/***
94  	 * @return Returns the backupPanel.
95  	 */
96  	private BackupPanel getBackupPanel() {
97  		return backupPanel;
98  	}
99  
100 }