| 52 | | // Boolean field |
| 53 | | if (Boolean.class.isAssignableFrom(type)) { |
| 54 | | final CheckBox checkbox = new CheckBox(); |
| 55 | | checkbox.setSwitchMode(true); |
| 56 | | checkbox.setImmediate(true); |
| 57 | | return checkbox; |
| 58 | | } |
| 59 | | return super.createField(type, uiContext); |
| | 68 | // Let the BaseFieldFactory create the fields |
| | 69 | Field field = super.createField(type, uiContext); |
| | 70 | |
| | 71 | // ...and just set them as immediate |
| | 72 | ((AbstractField)field).setImmediate(true); |
| | 73 | |
| | 74 | return field; |
| 62 | | |
| 63 | | public class MyTable extends Table { |
| 64 | | /** Really adds an item and not just an item id. */ |
| 65 | | public void addItem(Item item, Object itemId) { |
| 66 | | |
| | 77 | |
| | 78 | /** |
| | 79 | * This is a custom container that allows adding BeanItems inside it. The |
| | 80 | * BeanItem objects must be bound to a MyBean object. The item ID is an |
| | 81 | * Integer from 0 to 99. |
| | 82 | * |
| | 83 | * Most of the interface methods are implemented with just dummy |
| | 84 | * implementations, as they are not needed in this example. |
| | 85 | */ |
| | 86 | public class MyContainer implements Container { |
| | 87 | Item[] items; |
| | 88 | int current = 0; |
| | 89 | |
| | 90 | public MyContainer() { |
| | 91 | items = new Item[100]; // Yeah this is just a test |
| | 93 | |
| | 94 | public boolean addContainerProperty(Object propertyId, Class type, |
| | 95 | Object defaultValue) throws UnsupportedOperationException { |
| | 96 | throw new UnsupportedOperationException(); |
| | 97 | } |
| | 98 | |
| | 99 | public Item addItem(Object itemId) throws UnsupportedOperationException { |
| | 100 | throw new UnsupportedOperationException(); |
| | 101 | } |
| | 102 | |
| | 103 | public Object addItem() throws UnsupportedOperationException { |
| | 104 | throw new UnsupportedOperationException(); |
| | 105 | } |
| | 106 | |
| | 107 | /** |
| | 108 | * This addItem method is specific for this container and allows adding |
| | 109 | * BeanItem objects. The BeanItems must be bound to MyBean objects. |
| | 110 | */ |
| | 111 | public void addItem(BeanItem item) throws UnsupportedOperationException { |
| | 112 | items[current++] = item; |
| | 113 | } |
| | 114 | |
| | 115 | public boolean containsId(Object itemId) { |
| | 116 | if (itemId instanceof Integer) { |
| | 117 | int pos = ((Integer)itemId).intValue(); |
| | 118 | if (pos >= 0 && pos < 100) |
| | 119 | return items[pos] != null; |
| | 120 | } |
| | 121 | return false; |
| | 122 | } |
| | 123 | |
| | 124 | /** |
| | 125 | * The Table will call this method to get the property objects for the |
| | 126 | * columns. It uses the property objects to determine the data types of |
| | 127 | * the columns. |
| | 128 | */ |
| | 129 | public Property getContainerProperty(Object itemId, Object propertyId) { |
| | 130 | if (itemId instanceof Integer) { |
| | 131 | int pos = ((Integer)itemId).intValue(); |
| | 132 | if (pos >= 0 && pos < 100) { |
| | 133 | Item item = items[pos]; |
| | 134 | |
| | 135 | // The BeanItem provides the property objects for the items. |
| | 136 | return item.getItemProperty(propertyId); |
| | 137 | } |
| | 138 | } |
| | 139 | return null; |
| | 140 | } |
| | 141 | |
| | 142 | /** Table calls this to get the column names. */ |
| | 143 | public Collection getContainerPropertyIds() { |
| | 144 | // This container can contain only BeanItems bound to MyBeans. |
| | 145 | Item item = new BeanItem(new MyBean()); |
| | 146 | |
| | 147 | // The BeanItem knows how to get the property names from the bean. |
| | 148 | return item.getItemPropertyIds(); |
| | 149 | } |
| | 150 | |
| | 151 | public Item getItem(Object itemId) { |
| | 152 | if (itemId instanceof Integer) { |
| | 153 | int pos = ((Integer)itemId).intValue(); |
| | 154 | if (pos >= 0 && pos < 100) |
| | 155 | return items[pos]; |
| | 156 | } |
| | 157 | return null; |
| | 158 | } |
| | 159 | |
| | 160 | public Collection getItemIds() { |
| | 161 | Vector ids = new Vector(); |
| | 162 | for (int i=0; i<100; i++) |
| | 163 | ids.add(Integer.valueOf(i)); |
| | 164 | return ids; |
| | 165 | } |
| | 166 | |
| | 167 | public Class getType(Object propertyId) { |
| | 168 | return BeanItem.class; |
| | 169 | } |
| | 170 | |
| | 171 | public boolean removeAllItems() throws UnsupportedOperationException { |
| | 172 | throw new UnsupportedOperationException(); |
| | 173 | } |
| | 174 | |
| | 175 | public boolean removeContainerProperty(Object propertyId) |
| | 176 | throws UnsupportedOperationException { |
| | 177 | throw new UnsupportedOperationException(); |
| | 178 | } |
| | 179 | |
| | 180 | public boolean removeItem(Object itemId) |
| | 181 | throws UnsupportedOperationException { |
| | 182 | throw new UnsupportedOperationException(); |
| | 183 | } |
| | 184 | |
| | 185 | public int size() { |
| | 186 | return current; |
| | 187 | } |
| | 188 | |