Search in sources :

Example 1 with PresentationModelBuilder

use of com.canoo.dp.impl.remoting.PresentationModelBuilder in project dolphin-platform by canoo.

the class ListMapperImpl method processEvent.

@Override
public void processEvent(final PropertyInfo observableListInfo, final String sourceId, final ListChangeEvent<?> event) {
    final String attributeName = observableListInfo.getAttributeName();
    for (final ListChangeEvent.Change<?> change : event.getChanges()) {
        final int from = change.getFrom();
        final int to = from + change.getRemovedElements().size();
        final List<?> newElements = event.getSource().subList(from, change.getTo());
        final int count = newElements.size();
        final PresentationModelBuilder builder = builderFactory.createBuilder();
        builder.withType(PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceId).withAttribute("attribute", attributeName).withAttribute("from", from).withAttribute("to", to).withAttribute("count", count);
        int i = 0;
        for (final Object current : newElements) {
            try {
                builder.withAttribute(Integer.toString(i++), observableListInfo.convertToDolphin(current));
            } catch (Exception e) {
                throw new MappingException("Error in event processing!", e);
            }
        }
        builder.create();
    }
}
Also used : ListChangeEvent(com.canoo.platform.remoting.ListChangeEvent) PresentationModelBuilder(com.canoo.dp.impl.remoting.PresentationModelBuilder) MappingException(com.canoo.dp.impl.remoting.MappingException) MappingException(com.canoo.dp.impl.remoting.MappingException)

Aggregations

MappingException (com.canoo.dp.impl.remoting.MappingException)1 PresentationModelBuilder (com.canoo.dp.impl.remoting.PresentationModelBuilder)1 ListChangeEvent (com.canoo.platform.remoting.ListChangeEvent)1