Coverage Report - org.jtheque.films.view.impl.frames.AutoAddView
 
Classes in this File Line Coverage Branch Coverage Complexity
AutoAddView
0 %
0/43
0 %
0/6
1.25
 
 1  
 package org.jtheque.films.view.impl.frames;
 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.error.JThequeError;
 20  
 import org.jtheque.core.managers.view.impl.components.model.SimpleListModel;
 21  
 import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView;
 22  
 import org.jtheque.core.utils.ui.PanelBuilder;
 23  
 import org.jtheque.core.utils.ui.ValidationUtils;
 24  
 import org.jtheque.films.services.impl.utils.web.FilmResult;
 25  
 import org.jtheque.films.utils.Constants.Properties.Film;
 26  
 import org.jtheque.films.utils.Constants.Site;
 27  
 import org.jtheque.films.view.able.IAutoAddView;
 28  
 import org.jtheque.films.view.impl.actions.DisplayBeanViewAction;
 29  
 import org.jtheque.films.view.impl.actions.auto.add.AcChooseSite;
 30  
 import org.jtheque.films.view.impl.actions.auto.add.AcCloseAutoAddView;
 31  
 import org.jtheque.films.view.impl.actions.auto.add.AcValidateAutoAddView;
 32  
 import org.jtheque.films.view.impl.models.able.IAutoAddModel;
 33  
 import org.jtheque.utils.ui.GridBagUtils;
 34  
 import org.jtheque.utils.ui.SwingUtils;
 35  
 
 36  
 import javax.annotation.PostConstruct;
 37  
 import javax.swing.Action;
 38  
 import javax.swing.DefaultListModel;
 39  
 import javax.swing.JList;
 40  
 import javax.swing.JTextField;
 41  
 import javax.swing.ListSelectionModel;
 42  
 import java.awt.Container;
 43  
 import java.awt.Frame;
 44  
 import java.util.Collection;
 45  
 
 46  
 /**
 47  
  * User interface to add a film from internet.
 48  
  *
 49  
  * @author Baptiste Wicht
 50  
  */
 51  0
 public final class AutoAddView extends SwingDialogView implements IAutoAddView {
 52  
     private static final long serialVersionUID = 4633039680922071605L;
 53  
 
 54  
     private JTextField fieldTitle;
 55  
     private JList listSites;
 56  
     private JList listFilms;
 57  
 
 58  
     private DefaultListModel modelListFilms;
 59  
 
 60  0
     private int phase = PHASE_1;
 61  
 
 62  
     /**
 63  
      * Construct a new JFrameAutoAdd.
 64  
      *
 65  
      * @param parent                      The parent frame.
 66  
      */
 67  
     public AutoAddView(Frame parent) {
 68  0
         super(parent);
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Build the view.
 73  
      */
 74  
     @PostConstruct
 75  
     private void build() {
 76  0
         setTitleKey("auto.add.view.title");
 77  0
         setContentPane(buildContentPane());
 78  0
         pack();
 79  
 
 80  0
         setLocationRelativeTo(getOwner());
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Build and return the content pane.
 85  
      *
 86  
      * @return The content pane.
 87  
      */
 88  
     private Container buildContentPane() {
 89  0
         PanelBuilder builder = new PanelBuilder();
 90  
 
 91  0
         builder.addI18nLabel(Film.TITLE, builder.gbcSet(0, 0));
 92  
 
 93  0
         Action chooseSiteAction = new AcChooseSite();
 94  
         
 95  0
         fieldTitle = builder.add(new JTextField(), builder.gbcSet(1, 0));
 96  0
         SwingUtils.addFieldValidateAction(fieldTitle, chooseSiteAction);
 97  
 
 98  0
         addListsPanel(builder, chooseSiteAction);
 99  
 
 100  0
         builder.addButtonBar(builder.gbcSet(0, 2, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1),
 101  
                 new DisplayBeanViewAction("auto.add.view.actions.infos", "sitesView"), 
 102  
                 new AcValidateAutoAddView(),
 103  
                 new AcCloseAutoAddView());
 104  
 
 105  0
         return builder.getPanel();
 106  
     }
 107  
 
 108  
     /**
 109  
      * Add the list panel.
 110  
      *
 111  
      * @param parent The parent builder.
 112  
      * @param chooseSiteAction The action to choose a site. 
 113  
      */
 114  
     private void addListsPanel(PanelBuilder parent, Action chooseSiteAction) {
 115  0
         PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 1, GridBagUtils.BOTH, GridBagUtils.BASELINE_LEADING, 2, 1));
 116  
 
 117  0
         listSites = new JList(new SimpleListModel<Site>(Site.values()));
 118  0
         listSites.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 119  
 
 120  0
         builder.addScrolled(listSites, builder.gbcSet(0, 0, GridBagUtils.BOTH));
 121  
 
 122  0
         builder.addButton(chooseSiteAction, builder.gbcSet(1, 0));
 123  
 
 124  0
         modelListFilms = new DefaultListModel();
 125  
 
 126  0
         listFilms = new JList(modelListFilms);
 127  0
         listFilms.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 128  
 
 129  0
         builder.addScrolled(listFilms, builder.gbcSet(2, 0, GridBagUtils.BOTH));
 130  0
     }
 131  
 
 132  
     @Override
 133  
     public void sendMessage(String message, Object value) {
 134  0
         if ("title".equals(message)) {
 135  0
             fieldTitle.setText((String) value);
 136  
         }
 137  0
     }
 138  
 
 139  
     @Override
 140  
     public JTextField getFieldTitle() {
 141  0
         return fieldTitle;
 142  
     }
 143  
 
 144  
     @Override
 145  
     public DefaultListModel getModelListFilms() {
 146  0
         return modelListFilms;
 147  
     }
 148  
 
 149  
     @Override
 150  
     public Site getSelectedSite() {
 151  0
         return (Site) listSites.getSelectedValue();
 152  
     }
 153  
 
 154  
     @Override
 155  
     public FilmResult getSelectedFilm() {
 156  0
         return (FilmResult) listFilms.getSelectedValue();
 157  
     }
 158  
 
 159  
     @Override
 160  
     public IAutoAddModel getModel() {
 161  0
         return (IAutoAddModel) super.getModel();
 162  
     }
 163  
 
 164  
     @Override
 165  
     public boolean validateContent(int phase) {
 166  0
         this.phase = phase;
 167  
 
 168  0
         return validateContent();
 169  
     }
 170  
 
 171  
     @Override
 172  
     protected void validate(Collection<JThequeError> errors) {
 173  0
         if (PHASE_1 == phase) {
 174  0
             ValidationUtils.rejectIfEmpty(fieldTitle.getText(), "auto.view.title.film", errors);
 175  0
             ValidationUtils.rejectIfNothingSelected(listSites, "auto.view.site", errors);
 176  0
         } else if (PHASE_2 == phase) {
 177  0
             ValidationUtils.rejectIfNothingSelected(listFilms, "auto.add.view.title.film", errors);
 178  
         }
 179  0
     }
 180  
 }