Coverage Report - org.jtheque.films.controllers.impl.state.actor.ModifyActorState
 
Classes in this File Line Coverage Branch Coverage Complexity
ModifyActorState
0 %
0/32
0 %
0/14
1.333
 
 1  
 package org.jtheque.films.controllers.impl.state.actor;
 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.IActorController;
 22  
 import org.jtheque.films.services.able.IActorService;
 23  
 import org.jtheque.films.view.impl.fb.IPersonFormBean;
 24  
 import org.jtheque.films.view.impl.models.able.IActorsModel;
 25  
 import org.jtheque.primary.controller.able.ControllerState;
 26  
 import org.jtheque.primary.controller.able.FormBean;
 27  
 import org.jtheque.primary.od.able.Data;
 28  
 import org.jtheque.primary.od.able.Person;
 29  
 import org.jtheque.primary.view.able.ViewMode;
 30  
 
 31  
 import javax.annotation.Resource;
 32  
 
 33  
 /**
 34  
  * A actor controller state for the state "modify".
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  0
 public final class ModifyActorState implements ControllerState {
 39  
     @Resource
 40  
     private IActorController controller;
 41  
 
 42  
     @Resource
 43  
     private IActorService actorService;
 44  
 
 45  
     /**
 46  
      * Return the model of the view.
 47  
      *
 48  
      * @return The model of the view.
 49  
      */
 50  
     private IActorsModel 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().getCurrentActor().saveToMemento();
 60  0
     }
 61  
 
 62  
     @Override
 63  
     public ControllerState save(FormBean bean) {
 64  0
         IPersonFormBean infos = (IPersonFormBean) bean;
 65  
 
 66  0
         String oldName = getViewModel().getCurrentActor().getDisplayableText();
 67  
 
 68  0
         actorService.edit(getViewModel().getCurrentActor(), infos);
 69  
 
 70  0
         if (!oldName.equals(getViewModel().getCurrentActor().getDisplayableText())) {
 71  0
             controller.getView().resort();
 72  0
             controller.getView().select(getViewModel().getCurrentActor());
 73  
         }
 74  
 
 75  0
         return controller.getViewState();
 76  
     }
 77  
 
 78  
     @Override
 79  
     public ControllerState cancel() {
 80  0
         getViewModel().getCurrentActor().restoreMemento();
 81  
 
 82  0
         return controller.getViewState();
 83  
     }
 84  
 
 85  
     @Override
 86  
     public ControllerState create() {
 87  
         //Do nothing
 88  
 
 89  0
         return null;
 90  
     }
 91  
 
 92  
     @Override
 93  
     public ControllerState manualEdit() {
 94  
         //Do nothing
 95  
 
 96  0
         return null;
 97  
     }
 98  
 
 99  
     @Override
 100  
     public ControllerState delete() {
 101  
         //Do nothing
 102  
 
 103  0
         return null;
 104  
     }
 105  
 
 106  
     @Override
 107  
     public ControllerState autoEdit(Data data) {
 108  0
         Person actor = (Person) data;
 109  
 
 110  0
         assert actor.getType().equals(IActorService.PERSON_TYPE) : "The person must of type Actor";
 111  
 
 112  0
         if (Managers.getManager(IViewManager.class).askI18nUserForConfirmation(
 113  
                 "actor.dialogs.confirmSave", "actor.dialogs.confirmSave.title")) {
 114  0
             controller.save();
 115  
         } else {
 116  0
             getViewModel().getCurrentActor().restoreMemento();
 117  
         }
 118  
 
 119  0
         getViewModel().setCurrentActor(actor);
 120  
 
 121  0
         return controller.getAutoAddState();
 122  
     }
 123  
 
 124  
     @Override
 125  
     public ControllerState view(Data data) {
 126  0
         Person actor = (Person) data;
 127  
 
 128  0
         assert actor.getType().equals(IActorService.PERSON_TYPE) : "The person must of type Actor";
 129  
 
 130  0
         if (Managers.getManager(IViewManager.class).askUserForConfirmation(
 131  
                 "actor.dialogs.confirmSave", "actor.dialogs.confirmSave.title")) {
 132  0
             controller.save();
 133  
         } else {
 134  0
             getViewModel().getCurrentActor().restoreMemento();
 135  
         }
 136  
 
 137  0
         getViewModel().setCurrentActor(actor);
 138  
 
 139  0
         return controller.getViewState();
 140  
     }
 141  
 }