001package org.nasdanika.html.model.bootstrap.gen;
002
003import java.util.List;
004
005import org.eclipse.emf.common.notify.AdapterFactory;
006import org.eclipse.emf.common.util.EList;
007import org.nasdanika.common.CollectionCompoundConsumerFactory;
008import org.nasdanika.common.ConsumerFactory;
009import org.nasdanika.common.Context;
010import org.nasdanika.common.Function;
011import org.nasdanika.emf.EObjectAdaptable;
012import org.nasdanika.html.HTMLElement;
013import org.nasdanika.html.model.bootstrap.TableRow;
014
015public class TableRowContainerConsumerFactoryAdapter<M extends org.nasdanika.html.model.bootstrap.TableRowContainer, T extends org.nasdanika.html.bootstrap.RowContainer<?,?>> extends BootstrapElementConsumerFactoryAdapter<M,T> {
016
017        public TableRowContainerConsumerFactoryAdapter(M tableRowContainer, AdapterFactory adapterFactory) {
018                super(tableRowContainer, adapterFactory);
019        }
020        
021        @Override
022        protected Function<HTMLElement<?>, HTMLElement<?>> createConfigureFunction(Context context) throws Exception {
023                EList<TableRow> rows = getTarget().getRows();
024                if (rows.isEmpty()) {
025                        return super.createConfigureFunction(context);
026                }
027        
028                @SuppressWarnings("rawtypes")
029                List<ConsumerFactory<HTMLElement>> rowConsumers = EObjectAdaptable.adaptToConsumerFactoryNonNull(rows, org.nasdanika.html.HTMLElement.class);
030                CollectionCompoundConsumerFactory<HTMLElement<?>> rowsConsumerFactory = new CollectionCompoundConsumerFactory<>("Creating rows", rowConsumers);                 
031                return super.createConfigureFunction(context).then(rowsConsumerFactory.asFunctionFactory().create(context));
032        }
033
034}