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 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 && !disabled);
  37. op.addClickListener(this);
  38. optionsToKeys.put(op, opUidl.getStringAttribute("key"));
  39. panel.add(op);
  40. }
  41. }
  42. protected Object[] getSelectedItems() {
  43. return selectedKeys.toArray();
  44. }
  45. public void onClick(Widget sender) {
  46. super.onClick(sender);
  47. if(sender instanceof CheckBox) {
  48. boolean selected = ((CheckBox) sender).isChecked();
  49. String key = (String) optionsToKeys.get(sender);
  50. if(!multiselect) selectedKeys.clear();
  51. if(selected) selectedKeys.add(key);
  52. else selectedKeys.remove(key);
  53. client.updateVariable(id, "selected", getSelectedItems(), immediate);
  54. }
  55. }
  56. }