Search in sources :

Example 1 with IBeanDto

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();
        }
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IFilter(org.jowidgets.cap.common.api.filter.IFilter)

Example 2 with IBeanDto

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);
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) IBeanDtosClearUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosClearUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 3 with IBeanDto

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")));
}
Also used : BeanDtosChangeUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ISort(org.jowidgets.cap.common.api.sort.ISort) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 4 with IBeanDto

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);
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 5 with IBeanDto

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto)

Aggregations

IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)40 LinkedList (java.util.LinkedList)20 ArrayList (java.util.ArrayList)16 List (java.util.List)12 Test (org.junit.Test)12 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)8 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)7 IBeanDtosUpdate (org.jowidgets.cap.common.api.bean.IBeanDtosUpdate)5 IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)5 BeanDtosInsertionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate)5 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)5 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)4 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 HashMap (java.util.HashMap)3 ISort (org.jowidgets.cap.common.api.sort.ISort)3 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)3 TableCellBluePrint (org.jowidgets.tools.model.table.TableCellBluePrint)3 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)2 BeanDtosChangeUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate)2 IBeanSelectionClipboard (org.jowidgets.cap.ui.api.clipboard.IBeanSelectionClipboard)2