Example usage for com.vaadin.server Sizeable UNITS_PERCENTAGE

List of usage examples for com.vaadin.server Sizeable UNITS_PERCENTAGE

Introduction

In this page you can find the example usage for com.vaadin.server Sizeable UNITS_PERCENTAGE.

Prototype

Unit UNITS_PERCENTAGE

To view the source code for com.vaadin.server Sizeable UNITS_PERCENTAGE.

Click Source Link

Usage

From source file:tad.grupo7.ccamistadeslargas.EventosLayout.java

/**
 * Se muestra el evento en el vertical layout derecho del splitpanel.
 *
 * @param e Recoge el evento que se quiere mostrar.
 *///  w  w w  .  ja  v a2  s  .  c  o m
private void mostrarEvento(Evento e) {
    removeAllComponents();
    //T?TULO
    CssLayout labels = new CssLayout();
    labels.addStyleName("labels");
    Label l = new Label("Evento " + e.getNombre());
    l.setSizeUndefined();
    l.addStyleName(ValoTheme.LABEL_H2);
    l.addStyleName(ValoTheme.LABEL_COLORED);
    //FORMULARIO POR SI SE QUIERE EDITAR EL EVENTO
    TextField nombre = new TextField("Nombre");
    nombre.setValue(e.getNombre());
    nombre.setRequired(true);
    ComboBox divisa = new ComboBox("Divisa");
    divisa.setNullSelectionAllowed(false);
    divisa.setRequired(true);
    divisa.addItem("");
    divisa.addItem("$");

    HorizontalLayout layouth = new HorizontalLayout();
    HorizontalLayout layouth2 = new HorizontalLayout();
    layouth.setSpacing(true);
    layouth2.setSpacing(true);

    final Button actualizar = new Button("Actualizar Evento");
    final Button eliminar = new Button("Eliminar Evento");
    final Button addPago = new Button("Aadir Pago");
    final Button addParticipante = new Button("Aadir Participante");
    layouth.addComponents(actualizar, eliminar);
    layouth2.addComponents(addPago, addParticipante);
    final Button hacerCuentas = new Button("Hacer las cuentas");
    //BOTN PARA ACTUALIZAR EL EVENTO
    actualizar.addClickListener(clickEvent -> {
        try {
            nombre.validate();
            divisa.validate();
            if (EventoDAO.readDBObject(nombre.getValue(), usuario.getId()) == null) {
                EventoDAO.update(e.getId(), nombre.getValue(), divisa.getValue().toString());
                Notification n = new Notification("Evento actualizado",
                        Notification.Type.ASSISTIVE_NOTIFICATION);
                n.setPosition(Position.TOP_CENTER);
                n.show(Page.getCurrent());
                mostrarEventos();
            } else {
                Notification n = new Notification("Ya existe un evento con ese nombre",
                        Notification.Type.WARNING_MESSAGE);
                n.setPosition(Position.TOP_CENTER);
                n.show(Page.getCurrent());
            }
        } catch (Validator.InvalidValueException ex) {
            Notification n = new Notification("Error con los campos", Notification.Type.WARNING_MESSAGE);
            n.setPosition(Position.TOP_CENTER);
            n.show(Page.getCurrent());
        }

    });
    //BOTN PARA QUE SALGA UNA VENTANA EMERGENTE PARA AADIR UN GASTO AL EVENTO
    addPago.addClickListener(clickEvent -> {
        mostrarFormularioAddGasto(e);
    });
    //BOTN PARA ELIMINAR EL EVENTO
    eliminar.addClickListener(clickEvent -> {
        EventoDAO.delete(e.getId());
        removeAllComponents();
        mostrarEventos();
    });
    //BOTN PARA AADIR PARTICIPANTES
    addParticipante.addClickListener(clickEvent -> {
        mostrarFormularioAddParticipante(e);
    });
    //BOTN PARA HACER LAS CUENTAS
    hacerCuentas.addClickListener(clickEvent -> {
        removeAllComponents();
        VerticalLayout vl = new VerticalLayout();
        Table tablaResumenPlusvalia = getTablaResumenPlusvalia(e);
        HorizontalLayout hl1 = new HorizontalLayout(tablaResumenPlusvalia);
        hl1.setMargin(true);
        hl1.setSpacing(true);
        vl.addComponent(hl1);
        for (Participante p : ParticipanteDAO.readAllFromEvento(e.getId())) {
            HorizontalLayout hl = new HorizontalLayout(getTablaResumenGastosPorPersona(e, p));
            hl.setMargin(true);
            hl.setSpacing(true);
            vl.addComponent(hl);
        }
        setSplitPosition(100, Sizeable.UNITS_PERCENTAGE);
        setFirstComponent(vl);
    });
    //TABLA CON TODOS LOS GASTOS DEL EVENTO
    Table tablaGastos = getTablaGastos(e);
    //TABLA CON TODOS LOS PARTICIPANTES DEL EVENTO
    Table tablaParticipantes = getTablaParticipantes(e);
    //AADIMOS LOS COMPONENTES
    FormLayout form = new FormLayout(nombre, divisa, layouth, layouth2, hacerCuentas);
    VerticalLayout vl = new VerticalLayout(l, form, tablaGastos, tablaParticipantes);
    vl.setMargin(true);
    setFirstComponent(vl);
}