Coverage Report - org.jtheque.films.controllers.impl.state.film.AutoAddFilmState
 
Classes in this File Line Coverage Branch Coverage Complexity
AutoAddFilmState
0 %
0/33
0 %
0/10
1.556
 
 1  
 package org.jtheque.films.controllers.impl.state.film;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.view.able.IViewManager;
 21  
 import org.jtheque.films.controllers.able.IFilmController;
 22  
 import org.jtheque.films.persistence.od.able.Film;
 23  
 import org.jtheque.films.services.able.IFilmsService;
 24  
 import org.jtheque.films.view.impl.fb.IFilmFormBean;
 25  
 import org.jtheque.films.view.impl.models.able.IFilmsModel;
 26  
 import org.jtheque.primary.controller.able.ControllerState;
 27  
 import org.jtheque.primary.controller.able.FormBean;
 28  
 import org.jtheque.primary.od.able.Data;
 29  
 import org.jtheque.primary.view.able.ViewMode;
 30  
 
 31  
 import javax.annotation.Resource;
 32  
 
 33  
 /**
 34  
  * A state of film view correspond with an auto add.
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  0
 public final class AutoAddFilmState implements ControllerState {
 39  
     @Resource
 40  
     private IFilmController controller;
 41  
 
 42  
     @Resource
 43  
     private IFilmsService filmsService;
 44  
 
 45  
     /**
 46  
      * Return the model of the view.
 47  
      *
 48  
      * @return The model of the view.
 49  
      */
 50  
     private IFilmsModel getViewModel() {
 51  0
         return controller.getViewModel();
 52  
     }
 53  
 
 54  
     @Override
 55  
     public void apply() {
 56  0
         controller.getView().setEnabled(true);
 57  0
         controller.getView().getToolbarView().setDisplayMode(ViewMode.AUTO);
 58  
 
 59  0
         getViewModel().getCurrentFilm().saveToMemento();
 60  0
     }
 61  
 
 62  
     @Override
 63  
     public ControllerState save(FormBean bean) {
 64  0
         IFilmFormBean infos = (IFilmFormBean) bean;
 65  
 
 66  0
         Film film = getViewModel().getCurrentFilm().isSaved() ? getViewModel().getCurrentFilm() : filmsService.getEmptyFilm();
 67  
 
 68  0
         infos.fillFilm(film);
 69  
 
 70  0
         if (getViewModel().getCurrentFilm().isSaved()) {
 71  0
             filmsService.save(film);
 72  
         } else {
 73  0
             filmsService.create(film);
 74  
         }
 75  
 
 76  0
         controller.getView().resort();
 77  0
         controller.getView().select(film);
 78  
 
 79  0
         return controller.getViewState();
 80  
     }
 81  
 
 82  
     @Override
 83  
     public ControllerState cancel() {
 84  0
         if (getViewModel().getCurrentFilm().isSaved()) {
 85  0
             getViewModel().getCurrentFilm().restoreMemento();
 86  
         }
 87  
 
 88  0
         return controller.getViewState();
 89  
     }
 90  
 
 91  
     @Override
 92  
     public ControllerState create() {
 93  
         //Do nothing
 94  
 
 95  0
         return null;
 96  
     }
 97  
 
 98  
     @Override
 99  
     public ControllerState manualEdit() {
 100  
         //Do nothing
 101  
 
 102  0
         return null;
 103  
     }
 104  
 
 105  
     @Override
 106  
     public ControllerState delete() {
 107  
         //Do nothing
 108  
 
 109  0
         return null;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public ControllerState autoEdit(Data data) {
 114  0
         Film film = (Film) data;
 115  
 
 116  0
         if (Managers.getManager(IViewManager.class).askI18nUserForConfirmation(
 117  
                 "film.dialogs.confirmSave", "film.dialogs.confirmSave.title")) {
 118  0
             controller.save();
 119  
         } else {
 120  0
             getViewModel().getCurrentFilm().restoreMemento();
 121  
         }
 122  
 
 123  0
         getViewModel().setCurrentFilm(film);
 124  
 
 125  0
         return controller.getAutoAddState();
 126  
     }
 127  
 
 128  
     @Override
 129  
     public ControllerState view(Data data) {
 130  0
         Film film = (Film) data;
 131  
 
 132  0
         if (Managers.getManager(IViewManager.class).askI18nUserForConfirmation(
 133  
                 "film.dialogs.confirmSave", "film.dialogs.confirmSave.title")) {
 134  0
             controller.save();
 135  
         } else {
 136  0
             getViewModel().getCurrentFilm().restoreMemento();
 137  
         }
 138  
 
 139  0
         getViewModel().setCurrentFilm(film);
 140  
 
 141  0
         return controller.getViewState();
 142  
     }
 143  
 }