Coverage Report - org.jtheque.primary.view.impl.frames.SimpleDataView
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleDataView
0 %
0/26
0 %
0/4
1.286
 
 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.SimpleData;
 24  
 import org.jtheque.primary.view.able.ISimpleDataView;
 25  
 import org.jtheque.primary.view.impl.actions.simple.ValidateSimpleDataViewAction;
 26  
 import org.jtheque.primary.view.impl.models.SimpleDataModel;
 27  
 import org.jtheque.primary.view.impl.models.able.ISimpleDataModel;
 28  
 import org.jtheque.utils.ui.GridBagUtils;
 29  
 import org.jtheque.utils.ui.SwingUtils;
 30  
 
 31  
 import javax.swing.Action;
 32  
 import javax.swing.JTextField;
 33  
 import java.util.Collection;
 34  
 
 35  
 /**
 36  
  * A view to edit simple data.
 37  
  *
 38  
  * @author Baptiste Wicht
 39  
  */
 40  0
 public final class SimpleDataView extends SwingBuildedDialogView<ISimpleDataModel> implements ISimpleDataView {
 41  
         private JTextField fieldName;
 42  
 
 43  
         private static final int NAME_LENGTH_LIMIT = 100;
 44  
         private static final int FIELD_COLUMNS = 15;
 45  
 
 46  
         /**
 47  
          * Construct a new SimpleDataView.
 48  
          */
 49  
         public SimpleDataView(){
 50  0
                 super();
 51  
 
 52  0
                 build();
 53  0
         }
 54  
 
 55  
         @Override
 56  
         protected void initView(){
 57  0
                 setModel(new SimpleDataModel());
 58  0
         }
 59  
 
 60  
         @Override
 61  
         protected void buildView(PanelBuilder builder){
 62  0
                 Action validateAction = new ValidateSimpleDataViewAction();
 63  
 
 64  0
                 builder.addI18nLabel("data.view.name", builder.gbcSet(0, 0));
 65  
 
 66  0
                 fieldName = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 0));
 67  0
                 SwingUtils.addFieldValidateAction(fieldName, validateAction);
 68  0
                 SwingUtils.addFieldLengthLimit(fieldName, NAME_LENGTH_LIMIT);
 69  
 
 70  0
                 builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1),
 71  
                                 validateAction, getCloseAction("data.view.actions.cancel"));
 72  0
         }
 73  
 
 74  
         @Override
 75  
         public void reload(){
 76  0
         SimpleData simpleData = getModel().getSimpleData();
 77  
 
 78  0
         if(simpleData.isSaved()){
 79  0
             refreshText();
 80  
         } else {
 81  0
             setTitleKey("data.view.title");
 82  
         }
 83  
 
 84  0
                 fieldName.setText(simpleData.getName());
 85  0
         }
 86  
 
 87  
         @Override
 88  
         public String getDataName(){
 89  0
                 return fieldName.getText();
 90  
         }
 91  
 
 92  
         @Override
 93  
         public void refreshText(){
 94  0
                 if (getModel().getSimpleData() != null){
 95  0
                         setTitle(getMessage("data.view.title.modify", getModel().getSimpleData().getName()));
 96  
                 }
 97  0
         }
 98  
 
 99  
         @Override
 100  
         protected void validate(Collection<JThequeError> errors){
 101  0
                 ValidationUtils.rejectIfEmpty(fieldName.getText(), "data.view.name", errors);
 102  0
                 ValidationUtils.rejectIfLongerThan(fieldName.getText(), "data.view.name", NAME_LENGTH_LIMIT, errors);
 103  0
         }
 104  
 }