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.query.client.GQuery;
21 import com.google.gwt.user.client.ui.TextBoxBase;
27 public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase>
28 implements WidgetFactory<T> {
30 public T create(Element e) {
31 T textBox = createWidget();
33 if (getEquivalentTagName().equalsIgnoreCase(e.getTagName())) {
34 copyAttributes((InputElement) e.cast(),
35 (InputElement) textBox.getElement().cast());
37 textBox.setValue(e.getInnerText());
39 WidgetsUtils.replaceOrAppend(e, textBox);
44 protected String getEquivalentTagName(){
48 protected void copyAttributes(Element src, Element dest) {
49 InputElement source = src.cast();
50 InputElement destination = dest.cast();
52 destination.setAccessKey(source.getAccessKey());
53 destination.setDefaultValue(source.getDefaultValue());
54 destination.setDisabled(source.isDisabled());
55 if (source.getMaxLength() > 0) destination.setMaxLength(source.getMaxLength());
56 destination.setReadOnly(source.isReadOnly());
57 destination.setSize(source.getSize());
58 destination.setName(source.getName());
59 destination.setValue(source.getValue());
62 protected abstract T createWidget();