Coverage Report - org.jtheque.primary.controller.impl.SimpleController
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleController
0 %
0/24
0 %
0/2
1.2
 
 1  
 package org.jtheque.primary.controller.impl;
 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.core.managers.view.able.controller.AbstractController;
 22  
 import org.jtheque.primary.controller.able.ISimpleController;
 23  
 import org.jtheque.primary.controller.impl.undo.GenericDataCreatedEdit;
 24  
 import org.jtheque.primary.od.able.SimpleData;
 25  
 import org.jtheque.primary.services.able.ISimpleDataService;
 26  
 import org.jtheque.primary.view.able.ISimpleDataView;
 27  
 import org.jtheque.primary.view.able.ViewMode;
 28  
 
 29  
 import javax.annotation.Resource;
 30  
 
 31  
 /**
 32  
  * A Country Controller.
 33  
  *
 34  
  * @author Baptiste Wicht
 35  
  */
 36  0
 public final class SimpleController extends AbstractController implements ISimpleController {
 37  0
         private ViewMode state = ViewMode.NEW;
 38  
 
 39  
         private final ISimpleDataService simpleService;
 40  
     private final String id;
 41  
 
 42  
         @Resource
 43  
         private ISimpleDataView simpleDataView;
 44  
 
 45  
         /**
 46  
          * Construct a new SimpleController.
 47  
          *
 48  
          * @param simpleService The simple service to use
 49  
          * @param id The bean identifier of this controller. 
 50  
          */
 51  
         public SimpleController(ISimpleDataService simpleService, String id){
 52  0
                 super();
 53  
 
 54  0
                 this.simpleService = simpleService;
 55  0
         this.id = id;
 56  0
     }
 57  
 
 58  
         @Override
 59  
         public void create(){
 60  0
                 state = ViewMode.NEW;
 61  
 
 62  0
         simpleDataView.getModel().setCurrentController(id);
 63  0
         simpleDataView.getModel().setSimpleData(simpleService.getEmptySimpleData());
 64  0
                 simpleDataView.reload();
 65  0
         }
 66  
 
 67  
         @Override
 68  
         public void edit(SimpleData data){
 69  0
                 state = ViewMode.EDIT;
 70  
 
 71  0
         simpleDataView.getModel().setCurrentController(id);
 72  0
         simpleDataView.getModel().setSimpleData(data);
 73  0
                 simpleDataView.reload();
 74  
 
 75  0
                 displayView();
 76  0
         }
 77  
 
 78  
         @Override
 79  
         public void save(String name){
 80  0
                 simpleDataView.getModel().getSimpleData().setName(name);
 81  
 
 82  0
                 if (state == ViewMode.NEW){
 83  0
                         simpleService.create(simpleDataView.getModel().getSimpleData());
 84  
 
 85  0
                         Managers.getManager(IUndoRedoManager.class).addEdit(
 86  
                                         new GenericDataCreatedEdit<SimpleData>("simpleService", simpleDataView.getModel().getSimpleData()));
 87  
                 } else {
 88  0
                         simpleService.save(simpleDataView.getModel().getSimpleData());
 89  
                 }
 90  0
         }
 91  
 
 92  
         @Override
 93  
         public ISimpleDataView getView(){
 94  0
                 return simpleDataView;
 95  
         }
 96  
 }