Coverage Report - org.jtheque.primary.view.impl.frames.LanguageView
 
Classes in this File Line Coverage Branch Coverage Complexity
LanguageView
0 %
0/30
0 %
0/2
1.125
 
 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.error.JThequeError;
 20  
 import org.jtheque.core.managers.view.impl.frame.abstraction.SwingBuildedDialogView;
 21  
 import org.jtheque.core.utils.ui.PanelBuilder;
 22  
 import org.jtheque.core.utils.ui.ValidationUtils;
 23  
 import org.jtheque.primary.od.able.Data;
 24  
 import org.jtheque.primary.od.able.Language;
 25  
 import org.jtheque.primary.view.able.ILanguageView;
 26  
 import org.jtheque.primary.view.impl.actions.language.AcValidateLanguageView;
 27  
 import org.jtheque.primary.view.impl.models.LanguageModel;
 28  
 import org.jtheque.primary.view.impl.models.able.ILanguageModel;
 29  
 import org.jtheque.utils.ui.GridBagUtils;
 30  
 import org.jtheque.utils.ui.SwingUtils;
 31  
 
 32  
 import javax.swing.Action;
 33  
 import javax.swing.JTextField;
 34  
 import java.util.Collection;
 35  
 
 36  
 /**
 37  
  * A view to edit or add a language.
 38  
  *
 39  
  * @author Baptiste Wicht
 40  
  */
 41  
 public final class LanguageView extends SwingBuildedDialogView<ILanguageModel> implements ILanguageView {
 42  
     private JTextField fieldName;
 43  
 
 44  
     private static final int NAME_MAX_LENGTH = 150;
 45  
     private static final int FIELD_COLUMNS = 15;
 46  
 
 47  
     /**
 48  
      * Construct a new LanguageView.
 49  
      */
 50  
     public LanguageView(){
 51  0
         super();
 52  
 
 53  0
         build();
 54  0
     }
 55  
 
 56  
     @Override
 57  
     protected void initView(){
 58  0
         setModel(new LanguageModel());
 59  0
     }
 60  
 
 61  
     @Override
 62  
     protected void buildView(PanelBuilder builder){
 63  0
         builder.addI18nLabel("language.view.name", builder.gbcSet(0, 0));
 64  
 
 65  0
         Action validateAction = new AcValidateLanguageView();
 66  
 
 67  0
         fieldName = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 0));
 68  0
         SwingUtils.addFieldValidateAction(fieldName, validateAction);
 69  0
         SwingUtils.addFieldLengthLimit(fieldName, NAME_MAX_LENGTH);
 70  
 
 71  0
         builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.NONE, 2, 1), validateAction, getCloseAction("kind.actions.cancel"));
 72  
 
 73  0
         build();
 74  0
     }
 75  
 
 76  
     /**
 77  
      * Reload all the fields to do an add.
 78  
      */
 79  
     @Override
 80  
     public void reload(){
 81  0
         setTitleKey("language.view.title");
 82  
 
 83  0
         fieldName.setText("");
 84  
 
 85  0
         getModel().setLanguage(null);
 86  0
     }
 87  
 
 88  
     @Override
 89  
     public void reload(Data data){
 90  0
         Language languageObject = (Language) data;
 91  
 
 92  0
         setTitle(getMessage("language.view.title.modify") + languageObject.getName());
 93  
 
 94  0
         fieldName.setText(languageObject.getName());
 95  
 
 96  0
         getModel().setLanguage(languageObject);
 97  0
     }
 98  
 
 99  
     @Override
 100  
     public JTextField getFieldNom(){
 101  0
         return fieldName;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public void refreshText(){
 106  0
         super.refreshText();
 107  
 
 108  0
         if (getModel().getLanguage() != null){
 109  0
             setTitle(getMessage("language.view.title.modify") + getModel().getLanguage().getName());
 110  
         }
 111  0
     }
 112  
 
 113  
     @Override
 114  
     protected void validate(Collection<JThequeError> errors){
 115  0
         ValidationUtils.rejectIfEmpty(fieldName.getText(), "language.view.name", errors);
 116  0
         ValidationUtils.rejectIfLongerThan(fieldName.getText(), "language.view.name", NAME_MAX_LENGTH, errors);
 117  0
     }
 118  
 }