Coverage Report - org.jtheque.core.managers.view.impl.actions.backup.AcBackup
 
Classes in this File Line Coverage Branch Coverage Complexity
AcBackup
0 %
0/16
0 %
0/4
2.5
 
 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  
  * This file is part of JTheque.
 20  
  *
 21  
  * JTheque is free software: you can redistribute it and/or modify
 22  
  * it under the terms of the GNU General Public License as published by
 23  
  * the Free Software Foundation, either version 3 of the License.
 24  
  *
 25  
  * JTheque is distributed in the hope that it will be useful,
 26  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 27  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 28  
  * GNU General Public License for more details.
 29  
  *
 30  
  * You should have received a copy of the GNU General Public License
 31  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 32  
  */
 33  
 
 34  
 /**
 35  
  * An abstract action to backup.
 36  
  *
 37  
  * @author Baptiste Wicht
 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  
      * Construct a new AcBackup.
 54  
      *
 55  
      * @param key    The internationalization key.
 56  
      * @param filter The file filter.
 57  
      * @param type   The file type.
 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  
 }