package br.com.elotech;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.ClassResource;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.*;
import com.vaadin.ui.themes.ValoTheme;

import javax.servlet.annotation.WebServlet;

/**
 * This UI is the application entry point. A UI may either represent a browser window 
 * (or tab) or some part of a html page where a Vaadin application is embedded.
 * <p>
 * The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be 
 * overridden to add component to the user interface and initialize non-component functionality.
 */
@Title("WebSocialSaude integração de produtos com Siscop")
@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();
        DataGrid dataGrid = new DataGrid();
        ConexaoForm conexaoForm = new ConexaoForm(dataGrid);
        Link link = new Link("", new ExternalResource("http://elotech.com.br/"));
        link.setIcon(new ClassResource("/logo.png"));
        Label l = new Label("Integração de produtos/materiais entre os sistemas <b>Siscop</b> e <b>WebSocialSaude</b>!");
        l.setContentMode(ContentMode.HTML);
        Label creditos = new Label("Desenvolvido pela Equipe WebSocialSaude, v.0.1a, ELOTECH!");
        creditos.setStyleName(ValoTheme.LABEL_SMALL);

        layout.addComponents(link,l,conexaoForm,dataGrid,creditos);
        layout.setComponentAlignment(link, Alignment.TOP_CENTER);
        layout.setComponentAlignment(l, Alignment.TOP_CENTER);
        layout.setComponentAlignment(creditos, Alignment.TOP_CENTER);
        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false, widgetset = "br.com.elotech.AppWidgetSet")
    public static class MyUIServlet extends VaadinServlet {
    }
}
