PDA

View Full Version : PagingLoader with pageSize=0



Firelight
20 Mar 2014, 1:03 AM
I've extended PagingLoader and have overriden load(PagingLoadConfig config) method. And used as loader in ComboBox.

As investigated the ComboBoxCell changes load config to incompatible instance depends on pageSize value itself:


protected ListLoadConfig getParams(String query) { if (pageSize > 0) {
PagingLoadConfig config = null;
if (loader.isReuseLoadConfig()) {
config = (PagingLoadConfig) loader.getLastLoadConfig();
} else {
config = new PagingLoadConfigBean();
}
config.setLimit(pageSize);
config.setOffset(0);
return config;
} else {
ListLoadConfig config = null;
if (loader.isReuseLoadConfig()) {
config = (ListLoadConfig) loader.getLastLoadConfig();
} else {
config = new ListLoadConfigBean();
}
return config;
}
}




calling snippet in doQuery(..) :


@SuppressWarnings("unchecked") ListLoader<ListLoadConfig, ListLoadResult<?>> l = (ListLoader<ListLoadConfig, ListLoadResult<?>>) loader;


// delay expanding - hide the empty list with shadow until something is loaded.
if (listView.getLoadingHtml() == null) {
final GroupingHandlerRegistration tmpHandler = new GroupingHandlerRegistration();
LoadHandler<ListLoadConfig, ListLoadResult<?>> loadHandler = new LoadHandler<ListLoadConfig, ListLoadResult<?>>() {
@Override
public void onLoad(LoadEvent<ListLoadConfig, ListLoadResult<?>> event) {
tmpHandler.removeHandler();
expand(context, parent, updater, value);
}
};
tmpHandler.add(l.addLoadHandler(loadHandler));
}


l.load(getParams(query));






I've messed up with this code approach. Some questions to developers:

How to get around of threw ClassCastException (ListLoadConfigBean tries to cast as PagingLoadConfig) on l.load(getParams(query))?
Why not use "instanceof" when detecting config version in above code?
What if i try to extend ListLoadConfig and use in my own loader? I guess ComboBoxCell cannot handle it ever. Right?

Firelight
21 Mar 2014, 5:50 AM
The current workaround is using following class and creating comboboxes using this one.


public class BaseComboBoxCell<T> extends ComboBoxCell<T> {

public BaseComboBoxCell(ListStore<T> store, LabelProvider<? super T> labelProvider, final SafeHtmlRenderer<T> renderer) {
super(store, labelProvider, renderer);
}


@Override
protected ListLoadConfig getParams(String query) {
// todo CustomLoader?
if (loader instanceof PageLoader) {
PagingLoadConfig config = null;
if (loader.isReuseLoadConfig()) {
config = (PagingLoadConfig) loader.getLastLoadConfig();
} else {
config = new PagingLoadConfigBean(0, pageSize);
}
return config;
} else {
//ListLoader assumed
ListLoadConfig config = null;
if (loader.isReuseLoadConfig()) {
config = (ListLoadConfig) loader.getLastLoadConfig();
} else {
config = new ListLoadConfigBean();
}
return config;
}
}
}