1 | /** |
2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.deduced.viewer.web.shared; |
17 | |
18 | import com.google.gwt.i18n.client.HasDirection.Direction; |
19 | import com.google.gwt.user.client.ui.TextBox; |
20 | import com.google.gwt.user.client.ui.UIObject; |
21 | |
22 | /** |
23 | * TextBox Model |
24 | * |
25 | * @author Steve McDuff |
26 | * |
27 | */ |
28 | public class TextBoxModel extends TextBoxBaseModel |
29 | { |
30 | |
31 | /** |
32 | * serialVersionUID |
33 | */ |
34 | private static final long serialVersionUID = 2054086279715557895L; |
35 | |
36 | /** |
37 | * visible length of the text box. If null, the default text box length is |
38 | * used. |
39 | */ |
40 | private Integer visibleLength; |
41 | |
42 | /** |
43 | * maximum length of the text box. If null, the default text box length is |
44 | * used. |
45 | */ |
46 | private Integer maximumLength; |
47 | |
48 | /** |
49 | * |
50 | * TextBoxModel constructor |
51 | */ |
52 | public TextBoxModel() |
53 | { |
54 | |
55 | } |
56 | |
57 | /** |
58 | * (non-JSDoc) |
59 | * |
60 | * @see org.deduced.viewer.web.shared.WidgetModel#createUIObject() |
61 | */ |
62 | @Override |
63 | public UIObject createUIObject() |
64 | { |
65 | TextBox textBox = new TextBox(); |
66 | textBox.addValueChangeHandler(this); |
67 | textBox.addKeyUpHandler(this); |
68 | textBox.addMouseUpHandler(this); |
69 | |
70 | createTextBoxBaseDropController(textBox); |
71 | return textBox; |
72 | } |
73 | |
74 | /** |
75 | * get TextBox |
76 | * |
77 | * @return the text box |
78 | */ |
79 | public TextBox getTextBox() |
80 | { |
81 | return (TextBox) getUIObject(); |
82 | } |
83 | |
84 | /** |
85 | * (non-JSDoc) |
86 | * |
87 | * @see org.deduced.viewer.web.shared.TextBoxBaseModel#internalSynchronizeWithUI() |
88 | */ |
89 | @Override |
90 | public void internalSynchronizeWithUI() |
91 | { |
92 | TextBox label = getTextBox(); |
93 | Direction setDirection = getDirectionConstant(); |
94 | if (setDirection != null) |
95 | { |
96 | label.setDirection(setDirection); |
97 | } |
98 | |
99 | if (getVisibleLength() != null) |
100 | { |
101 | label.setVisibleLength(getVisibleLength().intValue()); |
102 | } |
103 | if (getMaximumLength() != null) |
104 | { |
105 | label.setMaxLength(getMaximumLength().intValue()); |
106 | } |
107 | |
108 | super.internalSynchronizeWithUI(); |
109 | } |
110 | |
111 | /** |
112 | * (non-JSDoc) |
113 | * |
114 | * @see org.deduced.viewer.web.shared.TextBoxBaseModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
115 | */ |
116 | @Override |
117 | public void propertyChanged( |
118 | ChangeEvent event) |
119 | { |
120 | if (Utilities.equals(event.getName(), "visible length")) |
121 | { |
122 | setVisibleLength((Integer) event.getSerializableValue()); |
123 | synchronizeWithUI(); |
124 | } |
125 | else if (Utilities.equals(event.getName(), "maximum length")) |
126 | { |
127 | setMaximumLength((Integer) event.getSerializableValue()); |
128 | synchronizeWithUI(); |
129 | } |
130 | else |
131 | { |
132 | super.propertyChanged(event); |
133 | } |
134 | } |
135 | |
136 | /** |
137 | * @param setMaximumLength the maximumLength to set |
138 | */ |
139 | public void setMaximumLength( |
140 | Integer setMaximumLength) |
141 | { |
142 | maximumLength = setMaximumLength; |
143 | } |
144 | |
145 | /** |
146 | * @return the maximumLength |
147 | */ |
148 | public Integer getMaximumLength() |
149 | { |
150 | return maximumLength; |
151 | } |
152 | |
153 | /** |
154 | * @param setVisibleLength the visibleLength to set |
155 | */ |
156 | public void setVisibleLength( |
157 | Integer setVisibleLength) |
158 | { |
159 | visibleLength = setVisibleLength; |
160 | } |
161 | |
162 | /** |
163 | * @return the visibleLength |
164 | */ |
165 | public Integer getVisibleLength() |
166 | { |
167 | return visibleLength; |
168 | } |
169 | |
170 | } |