1 29 30 package nextapp.echo2.app.button; 31 32 import java.io.Serializable ; 33 import java.util.HashSet ; 34 import java.util.Iterator ; 35 import java.util.Set ; 36 37 import nextapp.echo2.app.ApplicationInstance; 38 import nextapp.echo2.app.RenderIdSupport; 39 import nextapp.echo2.app.RadioButton; 40 41 45 public class ButtonGroup 46 implements RenderIdSupport, Serializable { 47 48 private static final RadioButton[] EMPTY = new RadioButton[0]; 49 50 private String id = ApplicationInstance.generateSystemId(); 51 private Set buttons; 52 53 61 public void addButton(RadioButton radioButton) { 62 if (buttons == null) { 63 buttons = new HashSet (); 64 } 65 buttons.add(radioButton); 66 updateSelection(radioButton); 67 } 68 69 74 public RadioButton[] getButtons() { 75 if (buttons == null) { 76 return EMPTY; 77 } else { 78 return (RadioButton[]) buttons.toArray(new RadioButton[buttons.size()]); 79 } 80 } 81 82 85 public String getRenderId() { 86 return id; 87 } 88 89 97 public void removeButton(RadioButton radioButton) { 98 if (buttons != null) { 99 buttons.remove(radioButton); 100 } 101 } 102 103 109 public void updateSelection(RadioButton changedButton) { 110 if (buttons == null || !changedButton.isSelected()) { 111 return; 112 } 113 Iterator buttonIt = buttons.iterator(); 114 while (buttonIt.hasNext()) { 115 RadioButton button = (RadioButton) buttonIt.next(); 116 if (!button.equals(changedButton)) { 117 button.setSelected(false); 118 } 119 } 120 } 121 } 122 | Popular Tags |