I tried using a regular selectioncell in my datagrid and the change event 
doesn't fire on it. I'm thinking it might have to do with my layout and 
maybe the events aren't bubbling all the way through? Why do the focus and 
blur methods fire, maybe those events are on the parent of the dropdown and 
not on the actual dropdown?  In onModuleLoad I have a LayoutPanel -> 
SimplePanel -> SplitLayoutPanel -> FlowPanel -> LayoutPanel -> DataGrid.? 



On Saturday, August 8, 2015 at 9:24:28 PM UTC-4, David Edelstein wrote:
>
> I can't figure out why the "change" event doesn't fire in my custom 
> selection cell, below is the code. The focus and blur events fire. Also, if 
> I change to super("click") the click event will fire but no matter what I 
> try I can not get the "change" event to fire. I add the option items 
> dynamically using the addOption(String newOp) method.  For the selection 
> model in my data grid I have : 
>
>         final SelectionModel<IssueBean> selectionModel = new 
> MultiSelectionModel<IssueBean>(keyProvider);
>         dataGrid.setSelectionModel(selectionModel, 
> DefaultSelectionEventManager.<IssueBean> createCheckboxManager());
>
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
>
> import com.google.gwt.cell.client.AbstractInputCell;
> import com.google.gwt.cell.client.ValueUpdater;
> import com.google.gwt.core.client.GWT;
> import com.google.gwt.dom.client.BrowserEvents;
> import com.google.gwt.dom.client.Element;
> import com.google.gwt.dom.client.NativeEvent;
> import com.google.gwt.dom.client.SelectElement;
> import com.google.gwt.safehtml.client.SafeHtmlTemplates;
> import com.google.gwt.safehtml.shared.SafeHtml;
> import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
> import com.google.gwt.user.client.Window;
>
> public class IssueCatagorySelectionCell extends AbstractInputCell<String, 
> String> {
>
>     interface Template extends SafeHtmlTemplates {
>         @Template("<option value=\"{0}\">{0}</option>")
>         SafeHtml deselected(String option);
>
>         @Template("<option value=\"{0}\" 
> selected=\"selected\">{0}</option>")
>         SafeHtml selected(String option);
>     }
>
>     private static Template template;
>
>     private HashMap<String, Integer> indexForOption = new HashMap<String, 
> Integer>();
>
>     private final List<String> options;
>
>     public IssueCatagorySelectionCell() {
>         super(BrowserEvents.CHANGE);
>         if (template == null) {
>             template = GWT.create(Template.class);
>         }
>         this.options = new ArrayList<String>();
>
>     }
>
>     public void addOption(String newOp){
>         String option = new String(newOp);
>         options.add(option);
>         refreshIndexes();
>     }
>
>     public void removeOption(String op){
>         String option = new String(op);
>         options.remove(indexForOption.get(option));
>         refreshIndexes();
>     }
>
>     public void removeAll() {
>         options.clear();
>         refreshIndexes();
>     }
>
>     private void refreshIndexes(){
>         int index = 0;
>         for (String option : options) {
>             indexForOption.put(option, index++);
>         }
>     }
>
>     @Override
>     public void onBrowserEvent(Context context, Element parent, String 
> value, NativeEvent event, ValueUpdater<String> valueUpdater) {
>         super.onBrowserEvent(context, parent, value, event, valueUpdater);
>         String type = event.getType();
>         Window.alert("event type = " + type);
>         if ("change".equals(type)) {
>             Object key = context.getKey();
>             SelectElement select = parent.getFirstChild().cast();
>             String newValue = options.get(select.getSelectedIndex());
>             Window.alert("newValue = " + newValue);
>             setViewData(key, newValue);
>             finishEditing(parent, newValue, key, valueUpdater);
>             if (valueUpdater != null) {
>                 valueUpdater.update(newValue);
>             }
>         }
>     }
>
>     @Override
>     public void render(com.google.gwt.cell.client.Cell.Context context, 
> String value, SafeHtmlBuilder sb) {
>         // Get the view data.
>         Object key = context.getKey();
>         String viewData = getViewData(key);
>         if (viewData != null && viewData.equals(value)) {
>             clearViewData(key);
>             viewData = null;
>         }
>
>         int selectedIndex = getSelectedIndex(viewData == null ? value : 
> viewData);
>         sb.appendHtmlConstant("<select tabindex=\"-1\">");
>         int index = 0;
>         for (String option : options) {
>             if (index++ == selectedIndex) {
>                 sb.append(template.selected(option));
>             } else {
>                 sb.append(template.deselected(option));
>             }
>         }
>         sb.appendHtmlConstant("</select>");
>     }
>
>     private int getSelectedIndex(String value) {
>         Window.alert("getSelectedIndex");
>         Integer index = indexForOption.get(value);
>         if (index == null) {
>             return -1;
>         }
>         return index.intValue();
>
>     }
>
> }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to