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