Creating my first extension, help please...

Hello,

I’m trying to create grid extension to recalculate column width when the grid scroll as suggested at this ticket: https://dev.vaadin.com/ticket/17438.

So, I’m following UI extension tutorial on Book of Vaadin chapter 16.7. I’ve create server side extension and the connector. See my code below

The extension

import com.vaadin.server.*;
import com.vaadin.ui.*;

public class gridAutoResize extends AbstractExtension {
    public gridAutoResize(Grid grid) {
        extend(grid);
    }
    
    public void extend(Grid grid) {
        super.extend(grid);
    }
    
    public static void addTo(Grid grid) {
        new gridAutoResize(grid);
    }
}

The connector

import com.vaadin.client.widget.escalator.*;
import com.vaadin.client.widgets.*;
import com.vaadin.client.*;
import com.vaadin.client.extensions.*;
import com.vaadin.shared.ui.*;

@Connect(gridAutoResize.class)
public class gridAutoResizeConnector extends AbstractExtensionConnector {

    @Override
    protected void extend(ServerConnector target) {
        // Get the extended widget
        Grid<?> pw = (Grid<?>) ((ComponentConnector) target).getWidget();
        
        pw.addRowVisibilityChangeHandler(new RowVisibilityChangeHandler() {

            @Override
            public void onRowVisibilityChange(RowVisibilityChangeEvent event) {
                if ((event.getFirstVisibleRow() % event.getVisibleRowCount()) == 0) {
                    pw.recalculateColumnWidths();
                }
            }
            
        });
    }

}

And then I simply attach the extension to my grid

gridAutoResize.addTo(grid);

After I ran the code, the grid didn’t resize automatically when I scrolling.
I know I’ve missed something, but I don’t know what it is. I’m still confuse about server/client side thing. I need any assistance, please.

Thanks.

so after reading other vaadin books and digging some examples, I realized that I should compile widgetset in order to the client side to working.

my updated connector class

[code]
import com.google.gwt.user.client.ui.;
import com.vaadin.client.
;
import com.vaadin.client.extensions.;
import com.vaadin.shared.ui.
;
import com.google.gwt.event.dom.client.;
import com.vaadin.client.widget.escalator.
;

@SuppressWarnings(“serial”)
@Connect(com.mylib.extension.gridautoresize.gridAutoResize.class)
public class gridAutoResizeConnector extends AbstractExtensionConnector {

@Override
protected void extend(ServerConnector target) {
    final Widget pw = ((ComponentConnector) target).getWidget();
    
    final DialogBox dlg = new DialogBox(true);
    dlg.setText("connector enabled = " + isEnabled());
    dlg.showRelativeTo(pw);
    
    pw.addHandler(new ScrollHandler() {

        @Override
        public void onScroll(ScrollEvent event) {
            dlg.setText("enter scroll");
            dlg.showRelativeTo(pw);
            
            ((com.vaadin.client.widgets.Grid<?>)pw).recalculateColumnWidths();
        }
    }, ScrollEvent.getType());
    
    /*pw.addHandler(new RowVisibilityChangeHandler() {        
        @Override
        public void onRowVisibilityChange(RowVisibilityChangeEvent event) {
            dlg.setText("enter scroll");
            dlg.showRelativeTo(pw);
            
            ((com.vaadin.client.widgets.Grid<?>)pw).recalculateColumnWidths();
        }
        
    }, RowVisibilityChangeEvent.TYPE);*/
}

}
[/code]The first dialog box is successfully showing “connector enabled = true”, so I think the connector is already worked.
The problem is the handler I added to the widget, when I scroll the table, it should showing the dialog box saying “enter scroll”, but it didn’t.
I already tried with addDomHandler, addBitlessDomHandler, addHandler, combine with ScrollHandler and RowVisibilityChangeHandler, but no luck here.

Thanks for any help.

silly me…
I can just do this and everything is working ((com.vaadin.client.widgets.Grid<?>)pw).addRowVisibilityChangeHandler(...)