com.vphakala.VaadinUI.java Source code

Java tutorial

Introduction

Here is the source code for com.vphakala.VaadinUI.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vphakala;

import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.*;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import org.springframework.beans.factory.annotation.Autowired;

@SpringUI
@Theme("valo")
public class VaadinUI extends UI {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private SubscriberService subscriberService;

    TabSheet mainLayout;
    CustomerUI customerTab;
    SubscriberUI subscriberTab;

    @Override
    protected void init(VaadinRequest request) {

        customerTab = new CustomerUI(customerService);
        subscriberTab = new SubscriberUI(subscriberService);

        mainLayout = new TabSheet();

        mainLayout.addSelectedTabChangeListener(new TabSheet.SelectedTabChangeListener() {
            public void selectedTabChange(SelectedTabChangeEvent event) {
                TabSheet tabsheet = event.getTabSheet();
                Layout tab = (Layout) tabsheet.getSelectedTab();
                if (tab == subscriberTab) {
                    subscriberTab.setUIFields(customerTab.getEmail().getValue());
                } else if (tab == customerTab) {
                    // no action needed
                } else {
                    Notification.show("*** shit happens ***");
                }
            }
        });

        mainLayout.addTab(customerTab);
        mainLayout.addTab(subscriberTab);

        setContent(mainLayout);
    }
}