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) throws Exception {
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         * @throws Exception
046         */
047        protected void build(T htmlElement, Context context, ProgressMonitor progressMonitor) throws Exception {}       
048        
049        @Override
050        public Consumer<T> create(Context context) throws Exception {
051                FunctionFactory<T,T> configureFunctionFactory = this::createConfigureFunction;
052                ConsumerFactory<T> consumerFactory = this::createConsumer;
053                return configureFunctionFactory.then(consumerFactory).create(context);
054        }               
055
056}