Coverage Report - org.jtheque.films.controllers.impl.state.film.ModifyFilmState
 
Classes in this File Line Coverage Branch Coverage Complexity
ModifyFilmState
0 %
0/31
0 %
0/6
1.333
 
 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 film controller state for the state "modify".
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  0
 public final class ModifyFilmState 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.EDIT);
 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();
 67  
 
 68  0
         String oldTitle = film.getTitle();
 69  
 
 70  0
         infos.fillFilm(film);
 71  
 
 72  0
         filmsService.save(film);
 73  
 
 74  0
         if (!oldTitle.equals(film.getTitle())) {
 75  0
             controller.getView().resort();
 76  
         }
 77  
 
 78  0
         return controller.getViewState();
 79  
     }
 80  
 
 81  
     @Override
 82  
     public ControllerState cancel() {
 83  0
         getViewModel().getCurrentFilm().restoreMemento();
 84  
 
 85  0
         return controller.getViewState();
 86  
     }
 87  
 
 88  
     @Override
 89  
     public ControllerState create() {
 90  
         //Do nothing
 91  
 
 92  0
         return null;
 93  
     }
 94  
 
 95  
     @Override
 96  
     public ControllerState manualEdit() {
 97  
         //Do nothing
 98  
 
 99  0
         return null;
 100  
     }
 101  
 
 102  
     @Override
 103  
     public ControllerState delete() {
 104  
         //Do nothing
 105  
 
 106  0
         return null;
 107  
     }
 108  
 
 109  
     @Override
 110  
     public ControllerState autoEdit(Data data) {
 111  0
         Film film = (Film) data;
 112  
 
 113  0
         if (Managers.getManager(IViewManager.class).askI18nUserForConfirmation(
 114  
                 "film.dialogs.confirmSave", "film.dialogs.confirmSave.title")) {
 115  0
             controller.save();
 116  
         } else {
 117  0
             getViewModel().getCurrentFilm().restoreMemento();
 118  
         }
 119  
 
 120  0
         getViewModel().setCurrentFilm(film);
 121  
 
 122  0
         return controller.getAutoAddState();
 123  
     }
 124  
 
 125  
     @Override
 126  
     public ControllerState view(Data data) {
 127  0
         Film film = (Film) data;
 128  
 
 129  0
         if (Managers.getManager(IViewManager.class).askI18nUserForConfirmation(
 130  
                 "film.dialogs.confirmSave", "film.dialogs.confirmSave.title")) {
 131  0
             controller.save();
 132  
         } else {
 133  0
             getViewModel().getCurrentFilm().restoreMemento();
 134  
         }
 135  
 
 136  0
         getViewModel().setCurrentFilm(film);
 137  
 
 138  0
         return controller.getViewState();
 139  
     }
 140  
 }