001package org.nasdanika.html.model.html.gen; 002 003import org.eclipse.emf.common.notify.AdapterFactory; 004import org.nasdanika.common.Consumer; 005import org.nasdanika.common.ConsumerFactory; 006import org.nasdanika.common.Context; 007import org.nasdanika.common.FunctionFactory; 008import org.nasdanika.common.ProgressMonitor; 009 010public class HtmlElementConsumerFactoryAdapter<M extends org.nasdanika.html.model.html.HtmlElement, T extends org.nasdanika.html.HTMLElement<?>> extends HtmlElementAdapter<M,T> implements ConsumerFactory<T> { 011 012 protected HtmlElementConsumerFactoryAdapter(M htmlElement, AdapterFactory adapterFactory) { 013 super(htmlElement, adapterFactory); 014 } 015 016 @Override 017 public boolean isAdapterForType(Object type) { 018 return type == ConsumerFactory.class; 019 } 020 021 protected Consumer<T> createConsumer(Context context) { 022 return new Consumer<T>() { 023 024 @Override 025 public double size() { 026 return 1; 027 } 028 029 @Override 030 public String name() { 031 return "HTML Element Consumer"; 032 } 033 034 @Override 035 public void execute(T htmlElement, ProgressMonitor progressMonitor) { 036 HtmlElementConsumerFactoryAdapter.this.build(htmlElement, context, progressMonitor); 037 } 038 }; 039 }; 040 041 /** 042 * Builds HTML element. This implementation does nothing. 043 * @param htmlElement 044 * @param progressMonitor 045 */ 046 protected void build(T htmlElement, Context context, ProgressMonitor progressMonitor) {} 047 048 @Override 049 public Consumer<T> create(Context context) { 050 FunctionFactory<T,T> configureFunctionFactory = this::createConfigureFunction; 051 ConsumerFactory<T> consumerFactory = this::createConsumer; 052 return configureFunctionFactory.then(consumerFactory).create(context); 053 } 054 055}