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 super();
69 _id = id;
70 setBindingConext(context);
71 }
72
73
74
75
76 public void setBindingConext(BindingContext context) {
77 if(context == null) return;
78 if( _context != null) _context.removeControl(this);
79 context.registerControl( _id, this);
80 _context = context;
81 update();
82 }
83
84
85
86
87 public void setAdapterId(String id) {
88 _id = id;
89 }
90
91
92
93
94 public void save() {
95
96 }
97
98
99
100
101 public void update() {
102 if(_context==null)
103 return;
104 Object value = _context.getValue(_id);
105 setText(Util.valueToString(value));
106 }
107
108
109
110
111 public boolean isValid() {
112 return true;
113 }
114
115
116
117
118 public void propertyChange(PropertyChangeEvent event) {
119 update();
120 }
121
122
123
124
125 public void validateInput() {
126 }
127
128
129
130
131 public boolean isDirty() {
132 return false;
133 }
134
135
136
137
138 public Object getValue() {
139 return getText();
140 }
141
142
143
144
145 public void setValue(Object value) {
146 setText(Util.valueToString(value));
147 }
148
149
150
151
152 public Border getBorder() {
153 return null;
154 }
155
156
157
158
159 public void setBorder(Border border) {
160 }
161
162
163
164
165 public void addActionListener(ActionListener listener) {
166 }
167
168 }