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.DOM;
21 import com.google.gwt.user.client.ui.RadioButton;
27 public class RadioButtonWidgetFactory implements WidgetFactory<RadioButton> {
29 public static class RadioButtonOption{
33 public RadioButtonOption() {
36 public RadioButtonOption(String name){
40 public String getName() {
44 public void setName(String name) {
50 private RadioButtonOption option;
51 private String radioName;
53 public RadioButtonWidgetFactory(RadioButtonOption option) {
58 public RadioButton create(Element e) {
61 RadioButton radioButton = new RadioButton(radioName);
62 if ("input".equalsIgnoreCase(e.getTagName())){
63 copyAttributes((InputElement) e, (InputElement) radioButton.getElement().cast());
65 radioButton.setText(e.getInnerText());
68 WidgetsUtils.replaceOrAppend(e, radioButton);
74 protected void resolveName(Element e) {
75 if (radioName != null){
78 if (option.getName() != null){
79 radioName = option.getName();
80 }else if ("input".equals(e.getTagName()) && "radio".equals(((InputElement)e).getType())){
81 radioName = ((InputElement)e).getName();
83 //create an unique string via DOM.createUniqueId...
84 radioName = DOM.createUniqueId();
89 protected String getEquivalentTagName(){
93 protected void copyAttributes(InputElement source, InputElement destination) {
95 destination.setAccessKey(source.getAccessKey());
96 destination.setDisabled(source.isDisabled());
97 destination.setSize(source.getSize());
98 destination.setValue(source.getValue());