Coverage Report - org.jtheque.films.controllers.impl.state.realizer.ViewRealizerState
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewRealizerState
0 %
0/24
0 %
0/12
1.222
 
 1  
 package org.jtheque.films.controllers.impl.state.realizer;
 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.undo.IUndoRedoManager;
 21  
 import org.jtheque.films.controllers.able.IRealizerController;
 22  
 import org.jtheque.films.services.able.IRealizersService;
 23  
 import org.jtheque.films.view.impl.models.able.IRealizersModel;
 24  
 import org.jtheque.primary.controller.able.ControllerState;
 25  
 import org.jtheque.primary.controller.able.FormBean;
 26  
 import org.jtheque.primary.controller.impl.undo.DeletedPersonEdit;
 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 realizer controller state for the state "view".
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  0
 public final class ViewRealizerState implements ControllerState {
 39  
     @Resource
 40  
     private IRealizerController controller;
 41  
 
 42  
     @Resource
 43  
     private IRealizersService realizersService;
 44  
 
 45  
     /**
 46  
      * Return the model of the view.
 47  
      *
 48  
      * @return The model of the view.
 49  
      */
 50  
     private IRealizersModel getViewModel() {
 51  0
         return controller.getViewModel();
 52  
     }
 53  
 
 54  
     @Override
 55  
     public void apply() {
 56  0
         controller.getView().setEnabled(false);
 57  0
         controller.getView().getToolbarView().setDisplayMode(ViewMode.VIEW);
 58  
 
 59  0
         if (getViewModel().getCurrentRealizer() != null) {
 60  0
             controller.getView().select(getViewModel().getCurrentRealizer());
 61  
         }
 62  0
     }
 63  
 
 64  
     @Override
 65  
     public ControllerState save(FormBean bean) {
 66  
         //Do nothing
 67  
 
 68  0
         return null;
 69  
     }
 70  
 
 71  
     @Override
 72  
     public ControllerState cancel() {
 73  
         //Do nothing
 74  
 
 75  0
         return null;
 76  
     }
 77  
 
 78  
     @Override
 79  
     public ControllerState create() {
 80  0
         return controller.getNewObjectState();
 81  
     }
 82  
 
 83  
     @Override
 84  
     public ControllerState manualEdit() {
 85  0
         return controller.getModifyState();
 86  
     }
 87  
 
 88  
     @Override
 89  
     public ControllerState delete() {
 90  0
         boolean deleted = realizersService.delete(getViewModel().getCurrentRealizer());
 91  
 
 92  0
         if (deleted) {
 93  0
             Managers.getManager(IUndoRedoManager.class).addEdit(new DeletedPersonEdit(getViewModel().getCurrentRealizer()));
 94  
 
 95  0
             controller.getView().selectFirst();
 96  
         }
 97  
 
 98  0
         return null;
 99  
     }
 100  
 
 101  
     @Override
 102  
     public ControllerState autoEdit(Data data) {
 103  0
         Person realizer = (Person) data;
 104  
 
 105  0
         assert realizer.getType().equals(IRealizersService.PERSON_TYPE) : "The person must of type Actor";
 106  
 
 107  0
         getViewModel().setCurrentRealizer(realizer);
 108  
 
 109  0
         return controller.getAutoAddState();
 110  
     }
 111  
 
 112  
     @Override
 113  
     public ControllerState view(Data data) {
 114  0
         Person realizer = (Person) data;
 115  
 
 116  0
         assert realizer.getType().equals(IRealizersService.PERSON_TYPE) : "The person must of type Actor";
 117  
 
 118  0
         getViewModel().setCurrentRealizer(realizer);
 119  
 
 120  0
         return null;
 121  
     }
 122  
 }