Coverage Report - net.sf.echobinding.model.AbstractPresentationModel
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractPresentationModel
100%
11/11
N/A
0
 
 1  
 /**
 2  
  * Copyright (C) 2006 Philipp Mpalampanis
 3  
  *
 4  
  * License: MPL 1.1/GPL 2.0/LGPL 2.1
 5  
  *
 6  
  * The contents of this file are subject to the Mozilla Public License Version
 7  
  * 1.1 (the "License"); you may not use this file except in compliance with
 8  
  * the License. You may obtain a copy of the License at
 9  
  * http://www.mozilla.org/MPL/
 10  
  *
 11  
  * Software distributed under the License is distributed on an "AS IS" basis,
 12  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 13  
  * for the specific language governing rights and limitations under the
 14  
  * License.
 15  
  *
 16  
  * Alternatively, the contents of this file may be used under the terms of
 17  
  * either the GNU General Public License Version 2 or later (the "GPL"), or
 18  
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 19  
  * in which case the provisions of the GPL or the LGPL are applicable instead
 20  
  * of those above. If you wish to allow use of your version of this file only
 21  
  * under the terms of either the GPL or the LGPL, and not to allow others to
 22  
  * use your version of this file under the terms of the MPL, indicate your
 23  
  * decision by deleting the provisions above and replace them with the notice
 24  
  * and other provisions required by the GPL or the LGPL. If you do not delete
 25  
  * the provisions above, a recipient may use your version of this file under
 26  
  * the terms of any one of the MPL, the GPL or the LGPL.
 27  
  */
 28  
 package net.sf.echobinding.model;
 29  
 
 30  
 import net.sf.echobinding.BoundControl;
 31  
 import net.sf.echobinding.binding.BindingContext;
 32  
 
 33  
 /**
 34  
  *
 35  
  */
 36  3
 public abstract class AbstractPresentationModel implements PresentationModel {
 37  
 
 38  
         private BindingContext _context;
 39  
         
 40  
         /**
 41  
          * Returns the control for the given adapter id.
 42  
          *  
 43  
          */
 44  
         public BoundControl getControl(String id) {
 45  5
                 if(getContext() == null)
 46  
                         throw new NullPointerException("Binding context is null!");
 47  
                 
 48  5
                 return getContext().getControl(id);
 49  
         }
 50  
 
 51  
         /**
 52  
          * @return Returns the binding context.
 53  
          */
 54  
         public BindingContext getContext() {
 55  22
                 return _context;
 56  
         }
 57  
 
 58  
         public void setContext(BindingContext context) {
 59  3
                 _context = context;
 60  3
         }
 61  
         
 62  
         /**
 63  
          * Convenience method for getContext.getValue()
 64  
          * 
 65  
          * @param adapterId
 66  
          * @return the value
 67  
          */
 68  
         public Object getValue(String adapterId) {
 69  3
                 return getContext().getValue(adapterId);
 70  
         }
 71  
         
 72  
         /**
 73  
          * Convenience method for getContext.setValue(...)
 74  
          * @param adapterId
 75  
          * @param value
 76  
          */
 77  
         public void setValue(String adapterId, Object value) {
 78  
                 getContext().setValue(adapterId, value);
 79  
         }
 80  
         
 81  
         /**
 82  
          * Configures the presentation model (by calling the configue() method) and
 83  
          * initializes all components that belong to the binding context.
 84  
          */
 85  
         public void init() {
 86  
                 
 87  1
                 configure();
 88  
                 
 89  7
                 for( BoundControl control: getContext().getControls() ) {
 90  5
                         control.update();
 91  
                 }
 92  1
         }
 93  
 }