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.BiSupplier; 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) throws Exception { 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<BiSupplier<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>>, HTMLElement<?>> partsFunctionFactory = partsFactory.asBiSupplierFunctionFactory(); 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, BiSupplier<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>>> createTableFunction(Context context) { 060 return new Function<org.nasdanika.html.bootstrap.Table, BiSupplier<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 BiSupplier<Map<EStructuralFeature, HTMLElement<?>>, HTMLElement<?>> execute(org.nasdanika.html.bootstrap.Table table, ProgressMonitor progressMonitor) throws Exception { 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 BiSupplier<Map<EStructuralFeature,HTMLElement<?>>, HTMLElement<?>>() { 096 097 @Override 098 public Map<EStructuralFeature, HTMLElement<?>> getFirst() { 099 return sectionsMap; 100 } 101 102 @Override 103 public HTMLElement<?> getSecond() { 104 return table.toHTMLElement(); 105 } 106 107 }; 108 } 109 110 }; 111 } 112 113}