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