Coverage Report - org.jtheque.primary.view.impl.frames.KindView
 
Classes in this File Line Coverage Branch Coverage Complexity
KindView
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.Kind;
 25  
 import org.jtheque.primary.view.able.IKindView;
 26  
 import org.jtheque.primary.view.impl.actions.kind.AcValidateKindView;
 27  
 import org.jtheque.primary.view.impl.models.KindModel;
 28  
 import org.jtheque.primary.view.impl.models.able.IKindModel;
 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  
  * The view for kind.
 38  
  *
 39  
  * @author Baptiste Wicht
 40  
  */
 41  
 public final class KindView extends SwingBuildedDialogView<IKindModel> implements IKindView {
 42  
     private JTextField fieldName;
 43  
 
 44  
     private static final int NAME_MAX_LENGTH = 150;
 45  
 
 46  
     /**
 47  
      * Construct a new JFrameKind modal to his parent view.
 48  
      */
 49  
     public KindView(){
 50  0
         super();
 51  
 
 52  0
         build();
 53  0
     }
 54  
 
 55  
     @Override
 56  
     protected void initView(){
 57  0
         setModel(new KindModel());
 58  0
     }
 59  
 
 60  
     @Override
 61  
     protected void buildView(PanelBuilder builder){
 62  0
         builder.addI18nLabel("kind.view.name", builder.gbcSet(0, 0));
 63  
 
 64  0
         Action validateAction = new AcValidateKindView();
 65  
 
 66  0
         fieldName = builder.add(new JTextField(15), builder.gbcSet(1, 0, GridBagUtils.HORIZONTAL));
 67  0
         SwingUtils.addFieldLengthLimit(fieldName, NAME_MAX_LENGTH);
 68  0
         SwingUtils.addFieldValidateAction(fieldName, validateAction);
 69  
 
 70  0
         builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL), validateAction, getCloseAction("language.actions.cancel"));
 71  
 
 72  0
         reload();
 73  0
     }
 74  
 
 75  
     @Override
 76  
     public void reload(){
 77  0
         setTitleKey("kind.view.title");
 78  
 
 79  0
         getModel().setKind(null);
 80  
 
 81  0
         fieldName.setText("");
 82  0
     }
 83  
 
 84  
 
 85  
     @Override
 86  
     public void reload(Data data){
 87  0
         Kind kind = (Kind) data;
 88  
 
 89  0
         getModel().setKind(kind);
 90  
 
 91  0
         setTitle(getMessage("kind.view.title.modify") + kind.getDisplayableText());
 92  
 
 93  0
         fieldName.setText(kind.getName());
 94  0
     }
 95  
 
 96  
     @Override
 97  
     public JTextField getFieldName(){
 98  0
         return fieldName;
 99  
     }
 100  
 
 101  
     @Override
 102  
     public void refreshText(){
 103  0
         super.refreshText();
 104  
 
 105  0
         if (getModel().getKind() != null){
 106  0
             setTitle(getMessage("kind.view.title.modify") + getModel().getKind().getDisplayableText());
 107  
         }
 108  0
     }
 109  
 
 110  
     @Override
 111  
     protected void validate(Collection<JThequeError> errors){
 112  0
         ValidationUtils.rejectIfEmpty(fieldName.getText(), "kind.view.name", errors);
 113  0
         ValidationUtils.rejectIfLongerThan(fieldName.getText(), "kind.view.name", NAME_MAX_LENGTH, errors);
 114  0
     }
 115  
 }