Tuesday, March 31, 2015

Lazy Load Data in a GWT DataGrid


private static class MyDataGrid<T> extends DataGrid {
    public ScrollPanel getScrollPanel() {
        HeaderPanel header = (HeaderPanel) getWidget();
        return (ScrollPanel) header.getContentWidget();
    }
}

private MyDataGrid<MyDataType> myDataGrid;
private int incrementSize = 20;
private int lastScrollPos = 0;

myDataGrid = new MyDataGrid<MyDataType>();

myDataGrid.getScrollPanel().addScrollHandler(new ScrollHandler(){

    @Override
    public void onScroll(ScrollEvent event) {

        int oldScrollPos = lastScrollPos;
        lastScrollPos = myDataGrid.getScrollPanel().getVerticalScrollPosition();

        // If scrolling up, ignore the event.
        if (oldScrollPos >= lastScrollPos) {
            return;
        }

        //Height of grid contents (including outside the viewable area) - height of the scroll panel
        int maxScrollTop = myDataGrid.getScrollPanel().getWidget().getOffsetHeight() - 
                           myDataGrid.getScrollPanel().getOffsetHeight();

        if(lastScrollPos >= maxScrollTop) {
            myDataGrid.setVisibleRange(0,myDataGrid.getVisibleRange().getLength()+incrementSize);
        }
    }
});

Monday, March 30, 2015

How to createw and fire GWT handler

public class MyEvent extends GwtEvent<MyEvent.MyHandler> {

    private static Type<MyHandler> TYPE;
    public static Type<LegalCreatedHandler> getType() {
        if (TYPE == null) {
            TYPE = new Type<MyHandler>();        }
        return TYPE;    }

    @Override    public Type<MyHandler> getAssociatedType() {
        return (Type) TYPE;    }

    @Override    protected void dispatch(MyEvent.MyHandler handler) {
        handler.onMyEvent(this);    }

    public interface MyHandler extends EventHandler {
        void onMyEvent(MyEvent event);
    }

}

////fire event from your class

fire(new MyEvent());

////ensure that HandlerManager is not null.

///implement handler and register this handler in class that handle this event
this.addHandler(this, MyEvent.getType());


Monday, March 23, 2015

GWT DataGrid refresh on column sorting

GWT DataGrid needs refresh on ListDataProvider when you do sort on column:

sortHandler = new ColumnSortEvent.ListHandler<Client>(dataProvider.getList()) {

    @Override    public void onColumnSort(ColumnSortEvent event) {
        super.onColumnSort(event);        dataProvider.refresh();    }

};

Saturday, March 21, 2015

Linux Ubuntu - Instal and run GWT plugin Firefox 24

https://support.google.com/chrome/answer/95346?hl=en

Linux Ubuntu - where to store all application as Program Files in Windows

In Linux Ubuntu store all your applications under:

/usr/local

Create new directory in it e.g. apps and keep all your downloaded third-party apps there.

Linux Ubuntu - What does the asterisk mean after a filename

The asterisk after a filename means in Linux that that file is executable

Wednesday, March 11, 2015

Wednesday, March 4, 2015

GWT / GXT: difference between WEBAPP and RESOURCES project's directories in storing resources e.g. images, css

Basic things you should remember about RIA structure:

WEB-INF directory holds everything on server e.g. Apache Tomcat servlet container lets say in "private" access i.e. nothing there is assessable by direct URL, only through the call to the server made by your app. 

This means that WEB-INF resources are accessible to the classloader of your Web-Application and not directly visible for the public.
-----------------------------------------------------------------------
So: if you'll store your resources in webapp directory, then after the build all that resources WILL HAVE public access e.g. directly assessable for everyone from their browser e.g. by URL.

If you want to insure your resources privacy e.g. images, css, properties etc you should put them inside of resources directory, NOT in webapp. Thus, after build they will be copied (stored) in WEB-INF directory.

Nevertheless, all your resources you use and store in your packages inside of src/main/java tree will be stored thereafter in WEB_INF/classes along with compiled source, which is not good because they should not be compiled. For this reason it is better to create some public directory for them on the same level of *.gwt.xml or in resources directory.