use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.
the class AbstractSimpleBeanReader method read.
@Override
public final List<BEAN_TYPE> read(final List<? extends IBeanKey> parentBeans, final IFilter filter, final List<? extends ISort> sortedProperties, final int firstRow, final int maxRows, final PARAM_TYPE parameter, final IExecutionCallback executionCallback) {
final IFilter decoratedFilter = getDecoratedFilter(filter);
if (decoratedFilter == null && (sortedProperties == null || sortedProperties.size() == 0)) {
return getBeans(parentBeans, parameter, firstRow, maxRows, executionCallback);
} else {
final List<BEAN_TYPE> beans = getBeans(parentBeans, parameter, firstRow, maxRows, executionCallback);
ArrayList<IBeanDto> result = createBeanDtos(beans, executionCallback);
if (decoratedFilter != null) {
result = CapServiceToolkit.beanDtoCollectionFilter().filter(result, decoratedFilter, executionCallback);
}
if (sortedProperties != null && sortedProperties.size() > 0) {
result = collectionSorter.sort(result, sortedProperties, executionCallback);
}
if (result.size() >= firstRow) {
return createBeansSubList(result, firstRow, Math.min(firstRow + maxRows, result.size()), executionCallback);
} else {
return Collections.emptyList();
}
}
}
use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.
the class BeanTableModelImplTest method testClearUpdateClears.
@Test
public void testClearUpdateClears() {
tableModel.load();
triggerPageLoading();
final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
updatableCallback.finished(new ArrayList<IBeanDto>());
updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean1, (IBeanDto) bean2)));
updatableCallback.update(new IBeanDtosClearUpdate() {
});
final int size = tableModel.getSize();
assertTrue("table should be clear but " + size + " bean(s) remained", size == 0);
}
use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.
the class BeanTableModelImplTest method testBeanChangeUpdate.
@Test
public void testBeanChangeUpdate() {
tableModel.getSortModel().setCurrentSorting(Arrays.asList(new ISort() {
@Override
public SortOrder getSortOrder() {
return SortOrder.ASC;
}
@Override
public String getPropertyName() {
return "key";
}
}));
tableModel.load();
triggerPageLoading();
final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
updatableCallback.finished(new ArrayList<IBeanDto>());
updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean1, (IBeanDto) bean2)));
updatableCallback.update(new BeanDtosChangeUpdate(Arrays.asList((IBeanDto) bean1a)));
final int size = tableModel.getSize();
assertTrue("2 beans should be loaded, but was " + size, size == 2);
assertTrue("first bean should be changed by update", tableModel.getBean(0).getValue("value").equals(bean1a.getValue("value")));
assertTrue("second bean should be unchanged by update", tableModel.getBean(1).getValue("value").equals(bean2.getValue("value")));
}
use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.
the class BeanTableModelImplTest method testBeanInsertionUpdate.
@Test
public void testBeanInsertionUpdate() {
tableModel.load();
triggerPageLoading();
final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
updatableCallback.finished(new ArrayList<IBeanDto>());
updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean1, (IBeanDto) bean2)));
final int size = tableModel.getSize();
assertTrue("2 beans should be loaded, but was " + size, size == 2);
}
use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.
the class BeanTableModelImpl method getNewData.
private Map<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> getNewData(final Set<IBeanProxy<BEAN_TYPE>> oldSelection, final List<Integer> newSelection, final Iterable<? extends IBeanDto> beans, final List<IBeanProxy<BEAN_TYPE>> removedBeanProxies) {
// hold the beans that should be deleted but that are currently not deleted
final Set<IBeanDto> beansToDelete = CollectionUtils.createHashSet(beans);
final Map<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>> newData = new HashMap<Integer, ArrayList<IBeanProxy<BEAN_TYPE>>>();
int newPageIndex = 0;
ArrayList<IBeanProxy<BEAN_TYPE>> newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
final int pageCount = getPage(dataModel.getDataRowCount()) + 1;
int addedNullCount = 0;
final List<IBeanProxy<BEAN_TYPE>> beansToUnregister = new LinkedList<IBeanProxy<BEAN_TYPE>>();
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
final ArrayList<IBeanProxy<BEAN_TYPE>> page = data.get(pageIndex);
// add a regular page
if (page != null) {
for (final IBeanProxy<BEAN_TYPE> bean : page) {
final boolean deletedBeanRemoved = beansToDelete.remove(bean);
if (deletedBeanRemoved) {
beansToUnregister.add(bean);
removedBeanProxies.add(bean);
rowCountOfPages--;
if (countedRowCount != null) {
countedRowCount = Integer.valueOf(countedRowCount.intValue() - 1);
}
} else if (newPage.size() < pageSize && addedNullCount < pageSize) {
newPage.add(bean);
} else {
if (addedNullCount < pageSize) {
newData.put(newPageIndex, newPage);
}
newPageIndex++;
newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
newPage.add(bean);
}
if (oldSelection.remove(bean)) {
if (!deletedBeanRemoved) {
newSelection.add(newPageIndex * pageSize + newPage.size() - 1);
}
}
if (bean == null) {
addedNullCount++;
} else {
addedNullCount = 0;
}
}
} else // add a null page (add 'pageSize' times a 'null')
if (addedNullCount < pageSize) {
for (int i = 0; i < pageSize; i++) {
if (newPage.size() < pageSize) {
newPage.add(null);
addedNullCount++;
} else {
if (addedNullCount < pageSize) {
newData.put(newPageIndex, newPage);
}
newPageIndex++;
newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
newPage.add(null);
addedNullCount++;
}
}
} else // skip the page
// (there a more than one page of null's added, so the page can be skipped)
{
newPage = new ArrayList<IBeanProxy<BEAN_TYPE>>(pageSize);
newPageIndex++;
addedNullCount = addedNullCount + pageSize;
}
}
beansStateTracker.unregister(beansToUnregister);
// add the last new page if it has data
if (newPage.size() > 0) {
newData.put(newPageIndex, newPage);
}
return newData;
}
Aggregations