1 20 package org.enhydra.barracuda.contrib.dbroggisch.repopulation; 21 22 import java.util.List ; 23 import java.util.ArrayList ; 24 import org.enhydra.barracuda.core.forms.DefaultFormElement; 25 import org.enhydra.barracuda.core.comp.ListModel; 26 import org.enhydra.barracuda.core.comp.DefaultListModel; 27 import org.apache.log4j.Logger; 28 import org.enhydra.barracuda.core.comp.ListSelectionModel; 29 import org.enhydra.barracuda.core.forms.FormType; 30 import org.enhydra.barracuda.core.forms.FormValidator; 31 import org.enhydra.barracuda.core.comp.ItemMap; 32 import org.enhydra.barracuda.core.comp.ViewContext; 33 import org.enhydra.barracuda.core.comp.BToggleButton; 34 import org.enhydra.barracuda.core.comp.BInput; 35 import org.enhydra.barracuda.core.comp.ListModel; 36 import org.enhydra.barracuda.core.comp.ListSelectionModel; 37 import org.enhydra.barracuda.core.comp.AbstractTemplateModel; 38 import org.enhydra.barracuda.core.comp.IterativeModel; 39 40 public class GroupFormElement extends SelectFormElement implements ChildModelElement 41 { 42 public String KEY = "KEY"; 43 public String VALUE = "VALUE"; 44 45 public IterativeModel getChildModel(String parentName, String prefix) { 46 return new ChildModel(parentName, getName(), prefix); 47 } 48 49 public GroupFormElement(ListModel lm, 50 java.lang.String ikey, 51 FormType itype, 52 java.lang.Object idefaultVal, 53 FormValidator ivalidator, 54 boolean iallowMultiples) { 55 super(lm, ikey, itype, idefaultVal, ivalidator, iallowMultiples); 56 } 57 58 59 public class ChildModel extends AbstractTemplateModel implements IterativeModel { 60 61 String _name, _parent_name, _child_name, _prefix; 62 ListSelectionModel _lsm; 63 ListModel _lm; 64 int _count; 65 Object _key, _value; 66 boolean _allows_multiple; 67 68 public ChildModel(String parentName, String childName, String prefix) { 69 _parent_name = parentName; 70 _child_name = childName; 71 _name = _parent_name + "_" + _child_name; 72 if(prefix != null) { 73 _prefix = prefix; 74 } else { 75 _prefix = ""; 76 } 77 _allows_multiple = allowMultiples(); 78 } 79 80 public String getName() { 81 return _name; 82 } 83 84 85 public Object getItem(String key) { 86 if(key.equals(KEY)) { 87 return _key; 88 } else if(key.equals(VALUE)) { 89 return _value; 90 } else { 91 return super.getItem(key); 92 } 93 } 94 95 public void preIterate() { 96 _lsm = getListSelectionModel(); 97 _lm = getListModel(); 98 _count = -1; 99 } 100 101 public void postIterate() { 102 } 103 104 public boolean hasNext() { 105 return _lm.getSize() > 0 && _count < _lm.getSize() - 1; 106 } 107 108 public void loadNext() { 109 _count++; 110 Object item = _lm.getItemAt(_count); 111 BToggleButton btog = new BToggleButton(); 112 btog.setName(_child_name); 113 btog.setSelected(_lsm.isSelectedIndex(_count)); 114 if(item instanceof ItemMap) { 115 ItemMap im = (ItemMap)item; 116 btog.setValue("" + im.getKey()); 117 _value = im.getValue(); 118 } else { 119 btog.setValue("" + item); 120 _value = item; 121 } 122 if(_allows_multiple) { 123 btog.setType(BInput.CHECKBOX); 124 } else { 125 btog.setType(BInput.RADIO); 126 } 127 _key = btog; 128 } 129 } 130 131 } 132 | Popular Tags |