Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Clickhandler to a cellTable cell (or row )

I would like to have a handler on a column of my cellTable.The column is an ImageResourceCell and I would that when I click on it, it delete the row Here is my code

Column<MyObject, ImageResource> imageColumn = 
    new Column<MyObject, ImageResource>(newImageResourceCell()) {
        @Override
        public ImageResource  getValue(MyObject object) {
             return Bundle.Util.getInstance().deleteRegexButton();
        }
    }; 
cellTable.addColumn(imageColumn,SafeHtmlUtils.fromSafeConstant("<br/>");

But I didn't know how to insert a handler as described Is it possible ??

any suggestions are welcome

Thanks.

like image 302
javaxiss Avatar asked May 31 '11 07:05

javaxiss


2 Answers

Cells have to declare the events they handle, then the browser event can be passed to the cell.

    ImageResourceCell myImgCell = new ImageResourceCell() {
        public Set<String> getConsumedEvents() {
            HashSet<String> events = new HashSet<String>();
            events.add("click");
            return events;
        }
    };

    Column<MyObject, ImageResource> imageColumn = new Column<MyObject, ImageResource>(myImgCell) {
        @Override
        public ImageResource getValue(MyObject dataObj) {
                    return Bundle.Util.getInstance().deleteRegexButton();
        }

        @Override
        public void onBrowserEvent(Context context, Element elem,
                MyObject object, NativeEvent event) {
            super.onBrowserEvent(context, elem, object, event); 
            if ("click".equals(event.getType())) {
                //call your click event handler here
            }
        }
    };

More info here: http://code.google.com/webtoolkit/doc/latest/DevGuideUiCustomCells.html

Note: this works with GWT 2.4, did not try with GWT 2.2.

like image 88
jscott Avatar answered Nov 20 '22 17:11

jscott


Have you seen Adding clickHandler to row in CellTable in GWT??

like image 42
z00bs Avatar answered Nov 20 '22 17:11

z00bs