Coverage Report - org.jtheque.primary.view.impl.frames.CountryView
 
Classes in this File Line Coverage Branch Coverage Complexity
CountryView
0 %
0/26
0 %
0/2
1.143
 
 1  
 package org.jtheque.primary.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.view.impl.frame.abstraction.SwingBuildedDialogView;
 20  
 import org.jtheque.core.utils.ui.PanelBuilder;
 21  
 import org.jtheque.primary.od.able.Country;
 22  
 import org.jtheque.primary.od.able.Data;
 23  
 import org.jtheque.primary.view.able.ICountryView;
 24  
 import org.jtheque.primary.view.impl.actions.country.AcValidateCountryView;
 25  
 import org.jtheque.primary.view.impl.models.CountryModel;
 26  
 import org.jtheque.primary.view.impl.models.able.ICountryModel;
 27  
 import org.jtheque.utils.ui.GridBagUtils;
 28  
 import org.jtheque.utils.ui.SwingUtils;
 29  
 
 30  
 import javax.swing.Action;
 31  
 import javax.swing.JTextField;
 32  
 
 33  
 /**
 34  
  * A view to edit country.
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  
 public final class CountryView extends SwingBuildedDialogView<ICountryModel> implements ICountryView {
 39  
     private JTextField fieldNom;
 40  
 
 41  
     private static final int NAME_LENGTH_LIMIT = 50;
 42  
 
 43  
     /**
 44  
      * Construct a new CountryView.
 45  
      */
 46  
     public CountryView(){
 47  0
         super();
 48  
 
 49  0
         build();
 50  0
     }
 51  
 
 52  
     @Override
 53  
     protected void initView(){
 54  0
         setModel(new CountryModel());
 55  0
     }
 56  
 
 57  
     @Override
 58  
     protected void buildView(PanelBuilder builder){
 59  0
         Action validateAction = new AcValidateCountryView();
 60  
 
 61  0
         builder.addI18nLabel("country.view.name", builder.gbcSet(0, 0));
 62  
 
 63  0
         fieldNom = builder.add(new JTextField(15), builder.gbcSet(1, 0));
 64  0
         SwingUtils.addFieldValidateAction(fieldNom, validateAction);
 65  0
         SwingUtils.addFieldLengthLimit(fieldNom, NAME_LENGTH_LIMIT);
 66  
 
 67  0
         builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1),
 68  
                 validateAction, getCloseAction("country.actions.cancel"));
 69  
 
 70  0
         reload();
 71  0
     }
 72  
 
 73  
     @Override
 74  
     public void reload(){
 75  0
         setTitleKey("country.view.title");
 76  
 
 77  0
         fieldNom.setText("");
 78  
 
 79  0
         getModel().setCountry(null);
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public void reload(Data data){
 84  0
         Country pays = (Country) data;
 85  
 
 86  0
         setTitle(getMessage("country.view.title.modify") + pays.getName());
 87  
 
 88  0
         fieldNom.setText(pays.getName());
 89  
 
 90  0
         getModel().setCountry(pays);
 91  0
     }
 92  
 
 93  
     @Override
 94  
     public JTextField getFieldNom(){
 95  0
         return fieldNom;
 96  
     }
 97  
 
 98  
     @Override
 99  
     public void refreshText(){
 100  0
         if (getModel().getCountry() != null){
 101  0
             setTitle(getMessage("borrower.view.title.edit") + getModel().getCountry().getName());
 102  
         }
 103  0
     }
 104  
 }