001package org.nasdanika.html.model.bootstrap.gen;
002
003import java.util.HashMap;
004import java.util.Map;
005
006import org.eclipse.emf.common.notify.AdapterFactory;
007import org.eclipse.emf.ecore.EStructuralFeature;
008import org.nasdanika.common.Supplier;
009import org.nasdanika.common.ConsumerFactory;
010import org.nasdanika.common.Context;
011import org.nasdanika.common.Function;
012import org.nasdanika.common.FunctionFactory;
013import org.nasdanika.common.MapCompoundConsumerFactory;
014import org.nasdanika.common.ProgressMonitor;
015import org.nasdanika.emf.EObjectAdaptable;
016import org.nasdanika.html.HTMLElement;
017import org.nasdanika.html.model.bootstrap.BootstrapPackage;
018import org.nasdanika.html.model.bootstrap.Table;
019import org.nasdanika.html.model.bootstrap.TableHeader;
020import org.nasdanika.html.model.bootstrap.TableSection;
021
022public class TableConsumerFactoryAdapter extends TableRowContainerConsumerFactoryAdapter<org.nasdanika.html.model.bootstrap.Table, org.nasdanika.html.bootstrap.Table> {
023
024        public TableConsumerFactoryAdapter(org.nasdanika.html.model.bootstrap.Table table, AdapterFactory adapterFactory) {
025                super(table, adapterFactory);
026        }
027        
028        @SuppressWarnings({ "unchecked", "rawtypes" })
029        @Override
030        protected Function<HTMLElement<?>, HTMLElement<?>> createConfigureFunction(Context context) {
031                MapCompoundConsumerFactory<EStructuralFeature,HTMLElement<?>> partsFactory = new MapCompoundConsumerFactory<>("Sections");
032                org.nasdanika.html.model.bootstrap.Table semanticElement = getTarget();
033                
034                TableHeader header = semanticElement.getHeader();
035                if (header != null) {
036                        partsFactory.put(BootstrapPackage.Literals.TABLE__HEADER, (ConsumerFactory<HTMLElement<?>>) (ConsumerFactory) EObjectAdaptable.adaptToConsumerFactoryNonNull(header, org.nasdanika.html.HTMLElement.class));
037                }
038                
039                TableSection body = semanticElement.getBody();
040                if (body != null) {
041                        partsFactory.put(BootstrapPackage.Literals.TABLE__BODY, (ConsumerFactory<HTMLElement<?>>) (ConsumerFactory) EObjectAdaptable.adaptToConsumerFactoryNonNull(body, org.nasdanika.html.HTMLElement.class));
042                }
043                
044                TableSection footer = semanticElement.getFooter();
045                if (footer != null) {
046                        partsFactory.put(BootstrapPackage.Literals.TABLE__FOOTER, (ConsumerFactory<HTMLElement<?>>) (ConsumerFactory) EObjectAdaptable.adaptToConsumerFactoryNonNull(footer, org.nasdanika.html.HTMLElement.class));
047                }
048                
049                FunctionFactory<Supplier.FunctionResult<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>>, HTMLElement<?>> partsFunctionFactory = partsFactory.asResultFunctionFactory();
050                
051                return super.createConfigureFunction(context).then(getWrapper(context)).then(createTableFunction(context)).then(partsFunctionFactory.create(context));
052        }
053                
054        /**
055         * Takes table, creates sections as needed and performs other configuration. 
056         * @param context
057         * @return {@link BiSupplier} with a map of sections as first and the argument table as second.
058         */
059        protected Function<org.nasdanika.html.bootstrap.Table, Supplier.FunctionResult<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>>> createTableFunction(Context context) {
060                return new Function<org.nasdanika.html.bootstrap.Table, Supplier.FunctionResult<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>>>() {
061        
062                        @Override
063                        public double size() {
064                                return 1;
065                        }
066        
067                        @Override
068                        public String name() {
069                                return "Table";
070                        }
071
072                        @Override
073                        public Supplier.FunctionResult<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>> execute(org.nasdanika.html.bootstrap.Table table, ProgressMonitor progressMonitor) {
074                                Map<EStructuralFeature, HTMLElement<?>> sectionsMap = new HashMap<>();
075                                Table semanticElement = getTarget();
076                                if (semanticElement.getHeader() != null) {
077                                        sectionsMap.put(BootstrapPackage.Literals.TABLE__HEADER, table.header().toHTMLElement());
078                                }
079                                
080                                if (semanticElement.getBody() != null) {
081                                        sectionsMap.put(BootstrapPackage.Literals.TABLE__BODY, table.body().toHTMLElement());
082                                }
083                                
084                                if (semanticElement.getFooter() != null) {
085                                        sectionsMap.put(BootstrapPackage.Literals.TABLE__FOOTER, table.footer().toHTMLElement());
086                                }
087                                                                
088                                table.dark(semanticElement.isDark());
089                                table.striped(semanticElement.isStriped());
090                                table.bordered(semanticElement.isBordered());
091                                table.borderless(semanticElement.isBorderless());
092                                table.hover(semanticElement.isHover());
093                                table.small(semanticElement.isSmall());
094                                
095                                return new Supplier.FunctionResult<Map<EStructuralFeature,HTMLElement<?>>, HTMLElement<?>>(sectionsMap, table.toHTMLElement());
096                        }
097                        
098                };
099        }
100                
101}