Can't you just add a ValueUpdater handler to see when the selection changes?
On Jun 25, 4:27 am, saklig <d3andr...@gmail.com> wrote: > After a couple of tries Ive managed to write something that gets the > job done. > > My example: > > List<String> opts = new ArrayList<String>(); > opts.add("Enabled"); > opts.add("Disabled"); > > table.addColumn(new IdentityColumn<MyData>(new > ActiveSelectionCell(opts)), "Active"); > > private class ActiveSelectionCell implements Cell<MyData>{ > > private HashMap<String, Integer> indexForOption = new > HashMap<String, Integer>(); > private final List<String> options; > > public ActiveSelectionCell(List<String> options) { > this.options = new ArrayList<String>(options); > int index = 0; > for (String option : options) { > indexForOption.put(option, index++); > } > } > > @Override > public boolean consumesEvents() { > return false; > } > > @Override > public boolean dependsOnSelection() { > return false; > } > > private int getSelectedIndex(String value) { > Integer index = indexForOption.get(value); > if (index == null) { > return -1; > } > return index.intValue(); > } > > @Override > public void setValue(Element parent, MyData value, Object > viewData) > { > StringBuilder sb = new StringBuilder(); > render(value, viewData, sb); > parent.setInnerHTML(sb.toString()); > > } > > @Override > public Object onBrowserEvent(Element parent, MyData value, > Object viewData, NativeEvent event, > ValueUpdater<MyData> valueUpdater) { > String type = event.getType(); > if ("change".equals(type)) { > SelectElement select = parent.getFirstChild().cast(); > > if( options.get(select.getSelectedIndex()).equalsIgnoreCase("Enabled")) > value.setActive("1"); > else > value.setActive("0"); > System.out.println(value.getName() + " - " + > options.get(select.getSelectedIndex())); > > // valueUpdater.update(value); > } > return viewData; > } > > @Override > public void render(MyData value, Object viewData, > StringBuilder sb) > { > int selectedIndex = 0; > if(value.getActive().equalsIgnoreCase("1")){ > selectedIndex = getSelectedIndex("Enabled"); > }else{ > selectedIndex = getSelectedIndex("Disabled"); > } > > sb.append("<select>"); > int index = 0; > for (String option : options) { > if (index++ == selectedIndex) { > sb.append("<option selected='selected'>"); > } else { > sb.append("<option>"); > } > sb.append(option); > sb.append("</option>"); > } > sb.append("</select>"); > > } > > } > > If you think this was the wrong/not the best way to get an event from > a cell, pleas give me a comment. > > On Jun 22, 1:25 pm, saklig <d3andr...@gmail.com> wrote: > > > > > Hi, > > > How does one handle events from cells in a CellTable( specifically a > > SelectionCell ) ? -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.