You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IOptionGroup.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.itmill.toolkit.terminal.gwt.client.ui;
  2. import java.util.HashMap;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import com.google.gwt.user.client.ui.CheckBox;
  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. import com.itmill.toolkit.terminal.gwt.client.UIDL;
  10. public class IOptionGroup extends IOptionGroupBase {
  11. public static final String CLASSNAME = "i-select-optiongroup";
  12. private Panel panel;
  13. private Map optionsToKeys;
  14. public IOptionGroup() {
  15. super(CLASSNAME);
  16. panel = (Panel) optionsContainer;
  17. optionsToKeys = new HashMap();
  18. }
  19. /*
  20. * Return true if no elements were changed, false otherwise.
  21. */
  22. protected void buildOptions(UIDL uidl) {
  23. panel.clear();
  24. for (Iterator it = uidl.getChildIterator(); it.hasNext();) {
  25. UIDL opUidl = (UIDL) it.next();
  26. CheckBox op;
  27. if (multiselect) {
  28. op = new ICheckBox();
  29. op.setText(opUidl.getStringAttribute("caption"));
  30. } else {
  31. op = new RadioButton(id, opUidl.getStringAttribute("caption"));
  32. op.setStyleName("i-radiobutton");
  33. }
  34. op.addStyleName(CLASSNAME_OPTION);
  35. op.setChecked(opUidl.getBooleanAttribute("selected"));
  36. op.setEnabled(!opUidl.getBooleanAttribute("disabled") && !readonly
  37. && !disabled);
  38. op.addClickListener(this);
  39. optionsToKeys.put(op, opUidl.getStringAttribute("key"));
  40. panel.add(op);
  41. }
  42. }
  43. protected Object[] getSelectedItems() {
  44. return selectedKeys.toArray();
  45. }
  46. public void onClick(Widget sender) {
  47. super.onClick(sender);
  48. if (sender instanceof CheckBox) {
  49. boolean selected = ((CheckBox) sender).isChecked();
  50. String key = (String) optionsToKeys.get(sender);
  51. if (!multiselect)
  52. selectedKeys.clear();
  53. if (selected)
  54. selectedKeys.add(key);
  55. else
  56. selectedKeys.remove(key);
  57. client
  58. .updateVariable(id, "selected", getSelectedItems(),
  59. immediate);
  60. }
  61. }
  62. }