2 * Copyright 2011, The gwtquery team.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.google.gwt.query.client.plugins.widgets;
18 import com.google.gwt.dom.client.Element;
19 import com.google.gwt.dom.client.InputElement;
20 import com.google.gwt.user.client.ui.TextBoxBase;
26 public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase>
27 implements WidgetFactory<T> {
29 public T create(Element e) {
30 T textBox = createWidget();
32 if (getEquivalentTagName().equalsIgnoreCase(e.getTagName())) {
33 copyAttributes((InputElement) e.cast(),
34 (InputElement) textBox.getElement().cast());
36 textBox.setValue(e.getInnerText());
38 WidgetsUtils.replaceOrAppend(e, textBox);
43 protected String getEquivalentTagName(){
47 protected void copyAttributes(Element src, Element dest) {
48 InputElement source = src.cast();
49 InputElement destination = dest.cast();
51 destination.setAccessKey(source.getAccessKey());
52 destination.setDefaultValue(source.getDefaultValue());
53 destination.setDisabled(source.isDisabled());
54 if (source.getMaxLength() > 0) destination.setMaxLength(source.getMaxLength());
55 destination.setReadOnly(source.isReadOnly());
56 destination.setSize(source.getSize());
57 destination.setName(source.getName());
58 destination.setValue(source.getValue());
61 protected abstract T createWidget();