Coverage Report - org.jtheque.films.view.impl.panels.JPanelInfosActors
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelInfosActors
0 %
0/32
0 %
0/4
1.2
 
 1  
 package org.jtheque.films.view.impl.panels;
 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.core.managers.error.JThequeError;
 22  
 import org.jtheque.core.managers.persistence.able.DataContainer;
 23  
 import org.jtheque.core.managers.view.impl.components.model.SimpleListModel;
 24  
 import org.jtheque.core.utils.ui.PanelBuilder;
 25  
 import org.jtheque.films.persistence.od.able.Film;
 26  
 import org.jtheque.films.view.able.IInfosActorsView;
 27  
 import org.jtheque.films.view.impl.actions.film.AcAddActorToList;
 28  
 import org.jtheque.films.view.impl.actions.film.AcRemoveActorFromList;
 29  
 import org.jtheque.films.view.impl.fb.IFilmFormBean;
 30  
 import org.jtheque.films.view.impl.models.list.DataCachedContainerListModel;
 31  
 import org.jtheque.primary.od.able.Person;
 32  
 import org.jtheque.primary.view.impl.listeners.ObjectChangedEvent;
 33  
 import org.jtheque.utils.ui.GridBagUtils;
 34  
 
 35  
 import javax.swing.DefaultListModel;
 36  
 import javax.swing.JButton;
 37  
 import javax.swing.JComponent;
 38  
 import javax.swing.JList;
 39  
 import javax.swing.JPanel;
 40  
 import javax.swing.ListSelectionModel;
 41  
 import java.util.Collection;
 42  
 import java.util.HashSet;
 43  
 
 44  
 /**
 45  
  * Panel to configure the actors of the film.
 46  
  *
 47  
  * @author Baptiste Wicht
 48  
  */
 49  
 public final class JPanelInfosActors extends JPanel implements IInfosActorsView {
 50  
     private final JButton buttonAdd;
 51  
     private final JButton buttonRemove;
 52  
     
 53  
     private final JList listActors;
 54  
     private final JList listActorsForFilm;
 55  
 
 56  
     private final DataCachedContainerListModel<Person> actorsModel;
 57  
     private final SimpleListModel<Person> actorsForFilmModel;
 58  
 
 59  
     private static final double AN_HALF = 0.5;
 60  
 
 61  
     /**
 62  
      * Construct a new JPanelInfosActors.
 63  
      * 
 64  
      */
 65  
     public JPanelInfosActors(){
 66  0
         super();
 67  
 
 68  0
         PanelBuilder builder = new PanelBuilder(this);
 69  
 
 70  0
         actorsModel = new DataCachedContainerListModel<Person>(
 71  
                 Managers.getManager(IBeansManager.class).<DataContainer<Person>>getBean("actorService"));
 72  
 
 73  0
         listActors = builder.addList(actorsModel, null,
 74  
                 builder.gbcSet(0, 0, GridBagUtils.BOTH, GridBagUtils.ABOVE_BASELINE_LEADING, 1, 0, AN_HALF, 1.0));
 75  0
         listActors.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 76  
 
 77  0
         actorsForFilmModel = new SimpleListModel<Person>();
 78  
 
 79  0
         listActorsForFilm = builder.addList(actorsForFilmModel, null,
 80  
                 builder.gbcSet(2, 0, GridBagUtils.BOTH, GridBagUtils.ABOVE_BASELINE_LEADING, 0, 0, AN_HALF, 1.0));
 81  0
         listActorsForFilm.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 82  
 
 83  0
         buttonAdd = builder.addButton(new AcAddActorToList(), builder.gbcSet(1, 0));
 84  0
         buttonAdd.setEnabled(false);
 85  
 
 86  0
         buttonRemove = builder.addButton(new AcRemoveActorFromList(), builder.gbcSet(1, 1));
 87  0
         buttonRemove.setEnabled(false);
 88  0
     }
 89  
 
 90  
     @Override
 91  
     public void objectChanged(ObjectChangedEvent event) {
 92  0
         actorsForFilmModel.removeAllElements();
 93  0
         actorsModel.reload();
 94  
 
 95  0
         for (Person actor : ((Film) event.getObject()).getActors()) {
 96  0
             actorsModel.removeElement(actor);
 97  0
             actorsForFilmModel.addElement(actor);
 98  
         }
 99  0
     }
 100  
 
 101  
     @Override
 102  
     public void fillFilm(IFilmFormBean fb) {
 103  0
         if (actorsForFilmModel.getSize() != 0) {
 104  0
             fb.setActors(new HashSet<Person>(actorsForFilmModel.getObjects()));
 105  
         }
 106  0
     }
 107  
 
 108  
     @Override
 109  
     public void setEnabled(boolean enabled) {
 110  0
         buttonAdd.setEnabled(enabled);
 111  0
         buttonRemove.setEnabled(enabled);
 112  
 
 113  0
         super.setEnabled(enabled);
 114  0
     }
 115  
 
 116  
     @Override
 117  
     public JComponent getImpl() {
 118  0
         return this;
 119  
     }
 120  
 
 121  
     @Override
 122  
     public DefaultListModel getActorsModel() {
 123  0
         return actorsModel;
 124  
     }
 125  
 
 126  
     @Override
 127  
     public DefaultListModel getActorsForFilmModel() {
 128  0
         return actorsForFilmModel;
 129  
     }
 130  
 
 131  
     @Override
 132  
     public int[] getSelectedActorsIndexes() {
 133  0
         return listActors.getSelectedIndices();
 134  
     }
 135  
 
 136  
     @Override
 137  
     public int[] getSelectedActorsForFilmIndexes() {
 138  0
         return listActorsForFilm.getSelectedIndices();
 139  
     }
 140  
 
 141  
     @Override
 142  
     public void validate(Collection<JThequeError> errors) {
 143  0
     }
 144  
 }