Coverage Report - org.jtheque.films.view.impl.models.FilmsModel
 
Classes in this File Line Coverage Branch Coverage Complexity
FilmsModel
0 %
0/19
0 %
0/4
1.286
 
 1  
 package org.jtheque.films.view.impl.models;
 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.beans.IBeansManager;
 21  
 import org.jtheque.films.persistence.od.able.Film;
 22  
 import org.jtheque.films.services.able.IFilmsService;
 23  
 import org.jtheque.films.view.impl.models.able.IFilmsModel;
 24  
 import org.jtheque.primary.view.impl.listeners.ObjectChangedEvent;
 25  
 import org.jtheque.primary.view.impl.models.PrincipalDataModel;
 26  
 
 27  
 import java.util.Collection;
 28  
 
 29  
 /**
 30  
  * A model for the films view.
 31  
  *
 32  
  * @author Baptiste Wicht
 33  
  */
 34  
 public final class FilmsModel extends PrincipalDataModel<Film> implements IFilmsModel {
 35  
     private Film currentFilm;
 36  
 
 37  
     private Collection<Film> displayList;
 38  
 
 39  
     /**
 40  
      * Init the view.
 41  
      */
 42  
     public FilmsModel() {
 43  0
         super();
 44  
 
 45  0
         getFilmsService().addDataListener(this);
 46  0
     }
 47  
 
 48  
     @Override
 49  
     @SuppressWarnings("unchecked")
 50  
     public void updateDisplayList(Collection<Film> films) {
 51  0
         getDisplayList().clear();
 52  
 
 53  0
         if (films == null) {
 54  0
             getDisplayList().addAll(getFilmsService().getFilms());
 55  
         } else {
 56  0
             getDisplayList().addAll(films);
 57  
         }
 58  
 
 59  0
         fireDisplayListChanged();
 60  0
     }
 61  
 
 62  
     @Override
 63  
     public void updateDisplayList() {
 64  0
         updateDisplayList(null);
 65  0
     }
 66  
 
 67  
     @Override
 68  
     public Collection<Film> getDisplayList() {
 69  0
         if (displayList == null) {
 70  0
             displayList = getFilmsService().getFilms();
 71  
         }
 72  
 
 73  0
         return displayList;
 74  
     }
 75  
 
 76  
     @Override
 77  
     public Film getCurrentFilm() {
 78  0
         return currentFilm;
 79  
     }
 80  
 
 81  
     @Override
 82  
     public void setCurrentFilm(Film currentFilm) {
 83  0
         this.currentFilm = currentFilm;
 84  
 
 85  0
         fireCurrentObjectChanged(new ObjectChangedEvent(this, currentFilm));
 86  0
     }
 87  
     
 88  
     /**
 89  
      * Return the service for the films.
 90  
      *
 91  
      * @return The service for the films.
 92  
      */
 93  
     private static IFilmsService getFilmsService() {
 94  0
         return Managers.getManager(IBeansManager.class).getBean("filmsService");
 95  
     }
 96  
 }