* @param sortDir the sort dir
*/
@SuppressWarnings("rawtypes")
public void sort(String field, SortDir sortDir) {
final StoreEvent<M> event = createStoreEvent();
event.setSortInfo(new SortInfo(field, sortDir));
if (!fireEvent(BeforeSort, event)) {
return;
}
SortInfo prev = new SortInfo(sortInfo.getSortField(), sortInfo.getSortDir());
if (sortDir == null) {
if (sortInfo.getSortField() != null && !sortInfo.getSortField().equals(field)) {
sortInfo.setSortDir(SortDir.NONE);
}
switch (sortInfo.getSortDir()) {
case ASC:
sortDir = SortDir.DESC;
break;
case DESC:
case NONE:
sortDir = SortDir.ASC;
break;
}
}
sortInfo.setSortField(field);
sortInfo.setSortDir(sortDir);
if (loader != null && loader instanceof RemoteSortTreeLoader) {
final RemoteSortTreeLoader treeLoader = (RemoteSortTreeLoader) loader;
if (treeLoader.isRemoteSort()) {
Listener<LoadEvent> l = new Listener<LoadEvent>() {
public void handleEvent(LoadEvent le) {
treeLoader.removeListener(Loader.Load, this);
sortInfo = le.<ListLoadConfig> getConfig().getSortInfo();
event.setSortInfo(sortInfo);
fireEvent(Sort, createStoreEvent());
}
};
treeLoader.addListener(Loader.Load, l);
treeLoader.setSortDir(sortDir);
treeLoader.setSortField(field);
if (!treeLoader.load()) {
treeLoader.removeListener(Loader.Load, l);
sortInfo.setSortField(prev.getSortField());
sortInfo.setSortDir(prev.getSortDir());
}
return;
}
}