📄 processrowscallback.java
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package org.extremecomponents.table.callback;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.List;import org.apache.commons.beanutils.BeanComparator;import org.apache.commons.collections.CollectionUtils;import org.apache.commons.collections.comparators.NullComparator;import org.apache.commons.collections.comparators.ReverseComparator;import org.extremecomponents.base.BaseModel;import org.extremecomponents.table.bean.Table;import org.extremecomponents.table.core.ParameterRegistry;import org.extremecomponents.table.handler.FilterPredicate;import org.extremecomponents.table.handler.SortHandler;import org.extremecomponents.util.ExtremeUtils;/** * The default implementation of the callbacks that handle the * retrieving, filtering, and sorting of the collection that * gets passed to the eXtremeTable. * * @author Jeff Johnston */public final class ProcessRowsCallback implements RetrieveRowsCallback, FilterRowsCallback, SortRowsCallback { public Collection retrieveRows(BaseModel model) throws Exception { Table table = model.getTableHandler().getTable(); List list = (List) ExtremeUtils.retrieveFromScope(model.getPageContext(), table.getCollection(), table .getScope()); if (list == null) { throw new Exception( "The eXtremeComponent could not find the List of Beans (or Map) identified by the collection and scope attributes."); } return list; } public Collection filterRows(BaseModel model, Collection rows) throws Exception { List results = new ArrayList(); FilterPredicate filterPredicate = new FilterPredicate(model); CollectionUtils.select(rows, filterPredicate, results); return results; } public Collection sortRows(BaseModel model, Collection rows) throws Exception { String property = model.getSortHandler().getSortableProperty(); String sortOrder = model.getRegistry().getParameter(ParameterRegistry.SORT + property); if (sortOrder.equals(SortHandler.SORT_ASC_)) { BeanComparator comparator = new BeanComparator(property, new NullComparator()); Collections.sort((List) rows, comparator); } else if (sortOrder.equals(SortHandler.SORT_DESC_)) { BeanComparator reversedNaturalOrderBeanComparator = new BeanComparator(property, new ReverseComparator( new NullComparator())); Collections.sort((List) rows, reversedNaturalOrderBeanComparator); } return rows; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -