/*
 * Copyright (c) 2015 - Tyl Consulting s.a.s.
 *
 *   Authors: Edoardo Vacchi
 *   Contributors: Marco Pancotti, Daniele Zonca
 *
 * 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.tylproject.vaadin.addon.fieldbinder.behavior.containers.listcontainer;

import org.tylproject.vaadin.addon.datanav.events.ItemCreate;
import org.tylproject.vaadin.addon.fieldbinder.FieldBinder;
import org.tylproject.vaadin.addon.fieldbinder.behavior.commons.FieldBinders;
import org.vaadin.viritin.ListContainer;

/**
 * Created by evacchi on 15/12/14.
 */
public class ListContainerCrud<T> extends FieldBinders.BaseCrud<T> {
    public ListContainerCrud(FieldBinder<T> fieldBinder) {
        super(fieldBinder);
    }

    @Override
    protected boolean verifyMatch(Class<?> clazz) {
        return ListContainer.class.isAssignableFrom(clazz);
    }

    @Override
    public void itemCreate(ItemCreate.Event event) {
        super.itemCreate(event);
        T bean = createBean();
        ListContainer<T> container = ((ListContainer<T>) event.getSource().getContainer());
        container.addItem(bean);
        event.getSource().setCurrentItemId(bean);
    }
}

@@ -777,61 +777,292 @@
 ort 
-org.tylproject.vaadin.addon.datanav.events.ItemCreate
+com.vaadin.addon.jpacontainer.JPAContainer;%0Aimport org.tylproject.vaadin.addon.datanav.DataNavigation;%0Aimport org.tylproject.vaadin.addon.datanav.events.ItemCreate;%0Aimport org.tylproject.vaadin.addon.datanav.events.OnCommit;%0Aimport org.tylproject.vaadin.addon.datanav.events.OnDiscard
 ;%0Aim
@@ -1612,29 +1612,25 @@
 oid 
-itemCreate(ItemCreate
+onCommit(OnCommit
 .Eve
@@ -1659,18 +1659,16 @@
 per.
-itemCreate
+onCommit
 (eve
@@ -1684,120 +1684,95 @@
     
-T bean = createBean();%0A        ListContainer%3CT%3E container = ((ListConta
+DataNavigation nav = event.getSource();%0A        T bean = fieldB
 in
+d
 er
-%3CT%3E) event.getSource().getContainer()
+.getBeanDataSource(
 );%0A 
@@ -1778,25 +1778,32 @@
         
-c
+nav.getC
 ontainer
 .addItem
@@ -1794,16 +1794,18 @@
 ontainer
+()
 .addItem
@@ -1820,33 +1820,19 @@
         
-event.getSource()
+nav
 .setCurr
@@ -1854,10 +1854,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Simplify ListContainer CRUD