| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Label |
|
| 1.3333333333333333;1,333 |
| 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 | ||
| 29 | package net.sf.echobinding.controls; | |
| 30 | ||
| 31 | import java.beans.PropertyChangeEvent; | |
| 32 | import java.beans.PropertyChangeListener; | |
| 33 | ||
| 34 | import net.sf.echobinding.BoundControl; | |
| 35 | import net.sf.echobinding.binding.BindingContext; | |
| 36 | import net.sf.echobinding.util.Util; | |
| 37 | import nextapp.echo2.app.Border; | |
| 38 | import nextapp.echo2.app.event.ActionListener; | |
| 39 | ||
| 40 | ||
| 41 | /** | |
| 42 | * A data bound label. | |
| 43 | * | |
| 44 | */ | |
| 45 | public class Label extends nextapp.echo2.app.Label implements BoundControl, PropertyChangeListener { | |
| 46 | ||
| 47 | private static final long serialVersionUID = 4502063417896703607L; | |
| 48 | ||
| 49 | private String _id; | |
| 50 | private BindingContext _context; | |
| 51 | ||
| 52 | /** | |
| 53 | * Creates an unbound label. | |
| 54 | * | |
| 55 | * @param text | |
| 56 | */ | |
| 57 | public Label(String text) { | |
| 58 | super(text); | |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Creates a data bound label. | |
| 63 | * | |
| 64 | * @param id | |
| 65 | * @param context | |
| 66 | */ | |
| 67 | public Label(String id, BindingContext context) { | |
| 68 | 1 | super(); |
| 69 | 1 | _id = id; |
| 70 | 1 | setBindingConext(context); |
| 71 | 1 | } |
| 72 | ||
| 73 | /* (non-Javadoc) | |
| 74 | * @see echobinding.BoundControl#setBindingConext(echobinding.BindingContext) | |
| 75 | */ | |
| 76 | public void setBindingConext(BindingContext context) { | |
| 77 | 1 | if(context == null) return; |
| 78 | 1 | if( _context != null) _context.removeControl(this); |
| 79 | 1 | context.registerControl( _id, this); |
| 80 | 1 | _context = context; |
| 81 | 1 | update(); |
| 82 | 1 | } |
| 83 | ||
| 84 | /* (non-Javadoc) | |
| 85 | * @see echobinding.BoundControl#setBindingId(java.lang.String) | |
| 86 | */ | |
| 87 | public void setAdapterId(String id) { | |
| 88 | _id = id; | |
| 89 | } | |
| 90 | ||
| 91 | /* (non-Javadoc) | |
| 92 | * @see echobinding.BoundControl#saveValues() | |
| 93 | */ | |
| 94 | public void save() { | |
| 95 | // DO NADA | |
| 96 | } | |
| 97 | ||
| 98 | /* (non-Javadoc) | |
| 99 | * @see echobinding.BoundControl#loadValues() | |
| 100 | */ | |
| 101 | public void update() { | |
| 102 | 4 | if(_context==null) // if used as a unbound label |
| 103 | return; | |
| 104 | 4 | Object value = _context.getValue(_id); |
| 105 | 4 | setText(Util.valueToString(value)); |
| 106 | 4 | } |
| 107 | ||
| 108 | /* (non-Javadoc) | |
| 109 | * @see echobinding.BoundControl#isValid() | |
| 110 | */ | |
| 111 | public boolean isValid() { | |
| 112 | return true; | |
| 113 | } | |
| 114 | ||
| 115 | /* (non-Javadoc) | |
| 116 | * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) | |
| 117 | */ | |
| 118 | public void propertyChange(PropertyChangeEvent event) { | |
| 119 | 2 | update(); // reload values |
| 120 | 2 | } |
| 121 | ||
| 122 | /* (non-Javadoc) | |
| 123 | * @see echobinding.BoundControl#validateInput() | |
| 124 | */ | |
| 125 | public void validateInput() { | |
| 126 | } | |
| 127 | ||
| 128 | /* (non-Javadoc) | |
| 129 | * @see echobinding.BoundControl#isDirty() | |
| 130 | */ | |
| 131 | public boolean isDirty() { | |
| 132 | return false; | |
| 133 | } | |
| 134 | ||
| 135 | /* (non-Javadoc) | |
| 136 | * @see echobinding.BoundControl#getValue() | |
| 137 | */ | |
| 138 | public Object getValue() { | |
| 139 | return getText(); | |
| 140 | } | |
| 141 | ||
| 142 | /* (non-Javadoc) | |
| 143 | * @see echobinding.BoundControl#setValue(java.lang.Object) | |
| 144 | */ | |
| 145 | public void setValue(Object value) { | |
| 146 | setText(Util.valueToString(value)); | |
| 147 | } | |
| 148 | ||
| 149 | /* (non-Javadoc) | |
| 150 | * @see echobinding.BoundControl#getBorder() | |
| 151 | */ | |
| 152 | public Border getBorder() { | |
| 153 | return null; | |
| 154 | } | |
| 155 | ||
| 156 | /* (non-Javadoc) | |
| 157 | * @see echobinding.BoundControl#setBorder(nextapp.echo2.app.Border) | |
| 158 | */ | |
| 159 | public void setBorder(Border border) { | |
| 160 | } | |
| 161 | ||
| 162 | /* (non-Javadoc) | |
| 163 | * @see echobinding.model.ComponentModel#addActionListener(nextapp.echo2.app.event.ActionListener) | |
| 164 | */ | |
| 165 | public void addActionListener(ActionListener listener) { | |
| 166 | } | |
| 167 | ||
| 168 | } |