Search in sources :

Example 6 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class BeanKeyFactoryImpl method createKeysFromDtos.

@Override
public List<IBeanKey> createKeysFromDtos(final Collection<? extends IBeanDto> beanDtos) {
    Assert.paramNotNull(beanDtos, "beanDtos");
    final List<IBeanKey> result = new LinkedList<IBeanKey>();
    for (final IBeanDto dto : beanDtos) {
        result.add(createKeyFromDto(dto));
    }
    return result;
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList)

Example 7 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class BeanListExecutionHelper method updateTransientBeans.

private void updateTransientBeans(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final List<IBeanDto> result) {
    if (executedBeans.size() != result.size()) {
        listModel.removeBeans(executedBeans);
        for (final IBeanDto beanDto : result) {
            listModel.addBeanDto(beanDto);
        }
    } else {
        final Iterator<IBeanProxy<BEAN_TYPE>> sourceIterator = executedBeans.iterator();
        final Iterator<IBeanDto> resultIterator = result.iterator();
        while (sourceIterator.hasNext()) {
            sourceIterator.next().update(resultIterator.next());
        }
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 8 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class BeanListExecutionHelper method updateBeans.

private void updateBeans(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final List<IBeanDto> result) {
    // put the resulting beans into a map for faster access later
    final Map<Object, IBeanDto> resultMap = new LinkedHashMap<Object, IBeanDto>();
    for (final IBeanDto beanDto : result) {
        resultMap.put(beanDto.getId(), beanDto);
    }
    // update the executed beans with the beans get as result from the service
    final List<IBeanProxy<BEAN_TYPE>> beansToDelete = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (final IBeanProxy<BEAN_TYPE> bean : executedBeans) {
        final IBeanDto updatedBean = resultMap.remove(bean.getId());
        if (updatedBean != null) {
            bean.update(updatedBean);
        } else {
            beansToDelete.add(bean);
        }
    }
    // remove the beans from the model that was not returned by the service
    if (!beansToDelete.isEmpty()) {
        listModel.removeBeans(beansToDelete);
    }
    // add the beans to the model that was created by the service
    for (final IBeanDto beanDto : resultMap.values()) {
        listModel.addBeanDto(beanDto);
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 9 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class BeanProxyFactoryImpl method createProxies.

@Override
public List<IBeanProxy<BEAN_TYPE>> createProxies(final Collection<? extends IBeanDto> beanDtos, final IAttributeSet attributes) {
    Assert.paramNotNull(beanDtos, "beanDtos");
    Assert.paramNotNull(attributes, "attributes");
    final List<IBeanProxy<BEAN_TYPE>> result = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (final IBeanDto beanDto : beanDtos) {
        result.add(createProxy(beanDto, attributes));
    }
    return result;
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 10 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class CsvExporter method writeBeans.

private int writeBeans(final List<IBeanDto> beans, final PrintStream ps, int exportedCount, final Integer totalCount, final IExecutionCallback executionCallback) throws Exception {
    for (final IBeanDto bean : beans) {
        if (!executionCallback.isCanceled()) {
            exportedCount++;
            if (totalCount != null) {
                executionCallback.setDescription(MessageReplacer.replace(Messages.getString("CsvExporter.Export") + " ' %1 ' " + Messages.getString("CsvExporter.of") + " ' %2 ' %3 ", String.valueOf(exportedCount), Integer.toString(totalCount), model.getEntityLabelPlural()));
                executionCallback.workedOne();
            } else {
                executionCallback.setDescription(MessageReplacer.replace(Messages.getString("CsvExporter.Export") + "' %1 ' %2 ", String.valueOf(exportedCount), model.getEntityLabelPlural()));
            }
            ps.println(beanToCsv(bean));
        } else {
            return -1;
        }
    }
    return exportedCount;
}
Also used : 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