• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package autotest.common.table;
2 
3 import com.google.gwt.event.logical.shared.ValueChangeEvent;
4 import com.google.gwt.event.logical.shared.ValueChangeHandler;
5 import com.google.gwt.user.client.ui.HorizontalPanel;
6 import com.google.gwt.user.client.ui.Panel;
7 import com.google.gwt.user.client.ui.RadioButton;
8 import com.google.gwt.user.client.ui.Widget;
9 
10 import java.util.Vector;
11 
12 public abstract class RadioButtonSetFilter extends Filter implements ValueChangeHandler<Boolean> {
13     private Panel panel;
14     private String name;
15     private Vector<RadioButton> buttons;
16     private int selected;
17 
RadioButtonSetFilter(String name)18     public RadioButtonSetFilter(String name) {
19         this(new HorizontalPanel(), name);
20     }
21 
RadioButtonSetFilter(Panel panel, String name)22     public RadioButtonSetFilter(Panel panel, String name) {
23         this.panel = panel;
24         this.name = name;
25         buttons = new Vector();
26     }
27 
28     @Override
getWidget()29     public Widget getWidget() {
30         return panel;
31     }
32 
addRadioButon(String label)33     public void addRadioButon(String label) {
34         RadioButton radioButton = new RadioButton(name, label);
35         int formValue = buttons.size();
36         radioButton.setFormValue(Integer.toString(formValue));
37         radioButton.addValueChangeHandler(this);
38         buttons.add(radioButton);
39         panel.add(radioButton);
40     }
41 
setSelectedButton(int index)42     public void setSelectedButton(int index) {
43         if (index < buttons.size())
44             selected = index;
45             buttons.get(index).setChecked(true);
46     }
47 
getSelectedButtonIndex()48     public int getSelectedButtonIndex() {
49         return selected;
50     }
51 
getButtonNum()52     public int getButtonNum() {
53         return buttons.size();
54     }
55 
56     @Override
onValueChange(ValueChangeEvent<Boolean> event)57     public void onValueChange(ValueChangeEvent<Boolean> event) {
58         selected = Integer.parseInt(((RadioButton) event.getSource()).getFormValue());
59         notifyListeners();
60     }
61 }