| 1 | |
package org.jtheque.core.managers.view.impl.actions.backup; |
| 2 | |
|
| 3 | |
import org.jtheque.core.managers.Managers; |
| 4 | |
import org.jtheque.core.managers.error.IErrorManager; |
| 5 | |
import org.jtheque.core.managers.file.IFileManager; |
| 6 | |
import org.jtheque.core.managers.file.able.FileType; |
| 7 | |
import org.jtheque.core.managers.log.IJThequeLogger; |
| 8 | |
import org.jtheque.core.managers.log.Logger; |
| 9 | |
import org.jtheque.core.managers.view.able.IViewManager; |
| 10 | |
import org.jtheque.core.managers.view.impl.actions.JThequeAction; |
| 11 | |
import org.jtheque.utils.io.FileException; |
| 12 | |
import org.jtheque.utils.io.SimpleFilter; |
| 13 | |
|
| 14 | |
import javax.annotation.Resource; |
| 15 | |
import java.awt.event.ActionEvent; |
| 16 | |
import java.io.File; |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public abstract class AcBackup extends JThequeAction { |
| 40 | |
private final SimpleFilter filter; |
| 41 | |
private final FileType type; |
| 42 | |
|
| 43 | |
@Resource |
| 44 | |
private IFileManager fileManager; |
| 45 | |
|
| 46 | |
@Resource |
| 47 | |
private IViewManager viewManager; |
| 48 | |
|
| 49 | |
@Logger |
| 50 | |
private IJThequeLogger logger; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
AcBackup(String key, SimpleFilter filter, FileType type) { |
| 60 | 0 | super(key); |
| 61 | |
|
| 62 | 0 | this.filter = filter; |
| 63 | 0 | this.type = type; |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public final void actionPerformed(ActionEvent e) { |
| 68 | 0 | if (fileManager.isBackupPossible(type)) { |
| 69 | 0 | final boolean yes = viewManager.askI18nUserForConfirmation( |
| 70 | |
"dialogs.confirm.backup", "dialogs.confirm.backup.title"); |
| 71 | |
|
| 72 | 0 | if (yes) { |
| 73 | 0 | File file = new File(viewManager.chooseFile(filter)); |
| 74 | |
|
| 75 | |
try { |
| 76 | 0 | fileManager.backup(type, file); |
| 77 | 0 | } catch (FileException e1) { |
| 78 | 0 | logger.error(e1); |
| 79 | 0 | Managers.getManager(IErrorManager.class).addInternationalizedError("error.backup.error"); |
| 80 | 0 | } |
| 81 | |
} |
| 82 | 0 | } else { |
| 83 | 0 | viewManager.displayI18nText("error.backup.nothing"); |
| 84 | |
} |
| 85 | 0 | } |
| 86 | |
} |