0

I have a CellTable with a few rows for which I use MultiSelectionModel. The first column is a column of checkbox cells. When the user checks one of the checkboxes the row becomes selected (as per the example in the site) and when the user clicks a row a function "doActionOnRow()" is called.

My problem is that when the user checks a checkbox the "doActionOnRow()" is also called. How can I make the CheckboxCell consume the click event so it wont be triggered on the celltable as well ?

EDIT:

This is my code:

table.addCellPreviewHandler(new Handler<Patient>() {
        @Override
        public void onCellPreview(CellPreviewEvent<Patient> event) {
            boolean isClick = "click".equals(event.getNativeEvent().getType());
                if (isClick) {
                    doSomething();
                }
            }});

Column<Patient, Boolean> checkColumn = new Column<Patient, Boolean>(new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(Patient object) {
            // Get the value from the selection model.
            return sm.isSelected(object);
        }

        @Override
        public void onBrowserEvent(Context context, Element elem, Patient patient, NativeEvent event) {
            if ("click".equals(event.getType()))
                event.stopPropagation();

            super.onBrowserEvent(context, elem, patient, event);
        }
    };

table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));

Even when I add event.stopPropagation(); doSomething(); is called when I click the checkbox.

Any idea why ?

Oberon
  • 93
  • 1
  • 7

1 Answers1

0

You need to check where the event happens first (on the cell or on the row: I forgot that point). then you just call event.stopPropagation()

You can also decide in your column whether you want to do something with the click this way (snippet from my project)

    productColumn = new Column<ProductProxy, ProductProxy>(productCoreCell) {
        @Override
        public ProductProxy getValue(ProductProxy productProxy) {
            return productProxy;
        }

        @Override
        public void onBrowserEvent(Context context, Element elem, ProductProxy object, NativeEvent event) {
            getProductTableManager().rowSelected(object);
        }
    };
Zied Hamdi
  • 2,400
  • 1
  • 25
  • 40
  • it seam you're calling super.onBrowserEvent() after stopping the propagation, look at the source code of GWT to see what they do with an event wich propagation was stopped: I don't think they handle that). As you see, in my code, I take the handle ont the event. You should stop the propagation at the moment you don't need anymore GWT to do something. That means at the moment you consume the event like onClick() not at a place where you will dispatch the job to GWT so they handle the event – Zied Hamdi Mar 10 '15 at 09:29
  • In other words: either don't call super.onBrowserEvent(context, elem, patient, event) and handle it your self Or check in onCellPreview() on which column you are to know if you want to call event.stopPropagation() or not – Zied Hamdi Mar 10 '15 at 09:32