Coverage Report - org.jtheque.films.view.impl.panels.JPanelInfosKinds
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelInfosKinds
0 %
0/39
0 %
0/6
1.273
 
 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.persistence.able.DataContainerProvider;
 24  
 import org.jtheque.core.managers.persistence.able.DataListener;
 25  
 import org.jtheque.core.managers.view.impl.components.model.SimpleListModel;
 26  
 import org.jtheque.core.utils.ui.PanelBuilder;
 27  
 import org.jtheque.films.persistence.od.able.Film;
 28  
 import org.jtheque.films.view.able.IInfosKindsView;
 29  
 import org.jtheque.films.view.impl.actions.film.AcAddKindToList;
 30  
 import org.jtheque.films.view.impl.actions.film.AcRemoveKindFromList;
 31  
 import org.jtheque.films.view.impl.fb.IFilmFormBean;
 32  
 import org.jtheque.films.view.impl.models.list.DataCachedContainerListModel;
 33  
 import org.jtheque.primary.od.able.Kind;
 34  
 import org.jtheque.primary.services.able.IKindsService;
 35  
 import org.jtheque.primary.view.impl.actions.kind.AcNewKind;
 36  
 import org.jtheque.primary.view.impl.listeners.ObjectChangedEvent;
 37  
 import org.jtheque.utils.ui.GridBagUtils;
 38  
 
 39  
 import javax.swing.DefaultListModel;
 40  
 import javax.swing.JButton;
 41  
 import javax.swing.JComponent;
 42  
 import javax.swing.JList;
 43  
 import javax.swing.JPanel;
 44  
 import javax.swing.ListSelectionModel;
 45  
 import java.util.Collection;
 46  
 import java.util.HashSet;
 47  
 
 48  
 /**
 49  
  * @author Baptiste Wicht
 50  
  */
 51  
 public final class JPanelInfosKinds extends JPanel implements DataListener, IInfosKindsView {
 52  
     private final JButton buttonAdd;
 53  
     private final JButton buttonRemove;
 54  
     private final JButton buttonNew;
 55  
     
 56  
     private final JList listKinds;
 57  
     private final JList listKindsForFilm;
 58  
 
 59  
     private final DataCachedContainerListModel<Kind> kindsModel;
 60  
     private final SimpleListModel<Kind> kindsForFilmModel;
 61  
     
 62  
     private static final double AN_HALF = 0.5;
 63  
 
 64  
     public JPanelInfosKinds() {
 65  0
         super();
 66  
         
 67  0
         PanelBuilder builder = new PanelBuilder(this);
 68  
 
 69  0
         kindsModel = new DataCachedContainerListModel<Kind>(Managers.getManager(IBeansManager.class).<DataContainer<Kind>>getBean("kindsService"));
 70  
 
 71  0
         DataContainerProvider.getInstance().getContainerForDataType(IKindsService.DATA_TYPE).addDataListener(this);
 72  
 
 73  0
         listKinds = builder.addList(kindsModel, null,
 74  
                 builder.gbcSet(0, 0, GridBagUtils.BOTH, GridBagUtils.ABOVE_BASELINE_LEADING, 1, 0, AN_HALF, 1.0));
 75  0
         listKinds.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 76  
 
 77  0
         buttonAdd = builder.addButton(new AcAddKindToList(), builder.gbcSet(1, 0));
 78  0
         buttonAdd.setEnabled(false);
 79  
 
 80  0
         buttonRemove = builder.addButton(new AcRemoveKindFromList(), builder.gbcSet(1, 1));
 81  0
         buttonRemove.setEnabled(false);
 82  
 
 83  0
         buttonNew = builder.addButton(new AcNewKind(), builder.gbcSet(1, 2));
 84  0
         buttonNew.setEnabled(false);
 85  
 
 86  0
         kindsForFilmModel = new SimpleListModel<Kind>();
 87  
 
 88  0
         listKindsForFilm = builder.addList(kindsForFilmModel, null,
 89  
                 builder.gbcSet(2, 0, GridBagUtils.BOTH, GridBagUtils.ABOVE_BASELINE_LEADING, 1, 0, AN_HALF, 1.0));
 90  0
         listKindsForFilm.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 91  0
     }
 92  
 
 93  
     @Override
 94  
     public void objectChanged(ObjectChangedEvent event) {
 95  0
         kindsForFilmModel.removeAllElements();
 96  0
         kindsModel.reload();
 97  
 
 98  0
         for (Kind kind : ((Film) event.getObject()).getKinds()) {
 99  0
             kindsModel.removeElement(kind);
 100  0
             kindsForFilmModel.addElement(kind);
 101  
         }
 102  0
     }
 103  
 
 104  
     @Override
 105  
     public void fillFilm(IFilmFormBean fb) {
 106  0
         if (kindsForFilmModel.getSize() != 0) {
 107  0
             fb.setKinds(new HashSet<Kind>(kindsForFilmModel.getObjects()));
 108  
         }
 109  0
     }
 110  
 
 111  
     @Override
 112  
     public void setEnabled(boolean enabled) {
 113  0
         buttonAdd.setEnabled(enabled);
 114  0
         buttonRemove.setEnabled(enabled);
 115  0
         buttonNew.setEnabled(enabled);
 116  
 
 117  0
         super.setEnabled(enabled);
 118  0
     }
 119  
 
 120  
     @Override
 121  
     public DefaultListModel getKindsModel() {
 122  0
         return kindsModel;
 123  
     }
 124  
 
 125  
     @Override
 126  
     public DefaultListModel getKindsForFilmModel() {
 127  0
         return kindsForFilmModel;
 128  
     }
 129  
 
 130  
     @Override
 131  
     public int[] getSelectedKindsIndexes() {
 132  0
         return listKinds.getSelectedIndices();
 133  
     }
 134  
 
 135  
     @Override
 136  
     public int[] getSelectedKindsForFilmIndexes() {
 137  0
         return listKindsForFilm.getSelectedIndices();
 138  
     }
 139  
 
 140  
     @Override
 141  
     public void validate(Collection<JThequeError> errors) {
 142  0
     }
 143  
 
 144  
     @Override
 145  
     public void dataChanged() {
 146  0
         for (Kind o : kindsForFilmModel.getObjects()) {
 147  0
             kindsModel.removeElement(o);
 148  
         }
 149  0
     }
 150  
 
 151  
     @Override
 152  
     public JComponent getImpl() {
 153  0
         return this;
 154  
     }
 155  
 }