package no.priv.bang.ukelonn.impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;

import com.vaadin.addon.touchkit.server.TouchKitServlet;
import com.vaadin.server.DefaultUIProvider;
import com.vaadin.server.ServiceException;
import com.vaadin.server.SessionInitEvent;
import com.vaadin.server.SessionInitListener;
import com.vaadin.server.UIProvider;
import com.vaadin.server.VaadinServletService;
import com.vaadin.server.VaadinSession;

public class UkelonnServlet extends TouchKitServlet {
    private static final long serialVersionUID = 2305317590355701822L;
    private UkelonnServletProvider ukelonnServletProvider;

    public UkelonnServlet(UkelonnServletProvider ukelonnServletProvider) {
        this.ukelonnServletProvider = ukelonnServletProvider;
    }

    @Override
    protected void servletInitialized() throws ServletException {
        super.servletInitialized();
        addSessionInitListenerThatWillSetUIProviderOnSession();
    }

    private void addSessionInitListenerThatWillSetUIProviderOnSession() {
        VaadinServletService service = getService();
        service.addSessionInitListener(new SessionInitListener() {
			private static final long serialVersionUID = -5085594781477821868L;

				@Override
                public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
                    VaadinSession session = sessionInitEvent.getSession();
                    removeDefaultUIProvider(session);
                    session.addUIProvider(ukelonnServletProvider);
                }

                private void removeDefaultUIProvider(VaadinSession session) {
                	List<UIProvider> uiProviders = new ArrayList<UIProvider>(session.getUIProviders());
                	for (UIProvider uiProvider : uiProviders) {
						if (DefaultUIProvider.class.getCanonicalName().equals(uiProvider.getClass().getCanonicalName())) {
							session.removeUIProvider(uiProvider);
						}
					}
                }
            });
    }

}

@@ -1189,19 +1189,32 @@
 ner() %7B%0A
-%09%09%09
+                
 private 
@@ -1274,20 +1274,32 @@
 1868L;%0A%0A
-%09%09%09%09
+                
 @Overrid
@@ -1710,17 +1710,20 @@
         
-%09
+    
 List%3CUIP
@@ -1814,17 +1814,20 @@
         
-%09
+    
 for (UIP
@@ -1862,22 +1862,40 @@
 ders) %7B%0A
-%09%09%09%09%09%09
+                        
 if (Defa
@@ -1989,15 +1989,36 @@
 ) %7B%0A
-%09%09%09%09%09%09%09
+                            
 sess
@@ -2055,21 +2055,54 @@
 r);%0A
-%09%09%09%09%09%09%7D%0A%09%09%09%09%09
+                        %7D%0A                    
 %7D%0A  

Fix formatting, change tabs to spaces.