Example usage for com.vaadin.ui FormLayout addComponent

List of usage examples for com.vaadin.ui FormLayout addComponent

Introduction

In this page you can find the example usage for com.vaadin.ui FormLayout addComponent.

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:ru.codeinside.gses.webui.components.EmployeeInfo.java

License:Mozilla Public License

public EmployeeInfo(String userLogin, Button button) {

    setCaption("? ? ".concat(userLogin));

    FormLayout layout = new FormLayout();
    for (Component c : AdminServiceProvider.get().withEmployee(userLogin, new CreateInfo())) {
        layout.addComponent(c);
    }//w  w  w  .jav  a2  s  . co m
    addComponent(layout);
    addComponent(button);
}

From source file:ru.codeinside.gses.webui.declarant.DeclarantFactory.java

License:Mozilla Public License

public static Component create() {

    // TODO: ??   ??!
    final ServiceQueryDefinition amSQ = new ServiceQueryDefinition(ProcedureType.Administrative);
    final LazyQueryContainer amSC = new LazyQueryContainer(amSQ, new ServiceQueryFactory(false));
    final ProcedureQueryDefinition amPQ = new ProcedureQueryDefinition(ProcedureType.Administrative);
    final LazyQueryContainer amPC = new LazyQueryContainer(amPQ,
            new ProcedureQueryFactory(Flash.login(), false));

    final ProcedureQueryDefinition mmQ = new ProcedureQueryDefinition(ProcedureType.Interdepartmental);
    final LazyQueryContainer mmC = new LazyQueryContainer(mmQ, new ProcedureQueryFactory(Flash.login(), false));

    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();/*ww  w. j  a v  a2  s  .co  m*/
    layout.setMargin(true);
    final Label header = new Label(
            " ?  ?? ?? ?");
    header.addStyleName("h1");
    layout.addComponent(header);

    final Select amS = new Select("", amPC);
    String selectWidth = "400px";
    amS.setWidth(selectWidth);
    amS.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
    amS.setItemCaptionPropertyId("name");
    amS.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
    amS.setNullSelectionAllowed(true);
    amS.setNewItemsAllowed(false);
    amS.setImmediate(true);

    final Select amSS = new Select("?", amSC);
    amSS.setWidth(selectWidth);
    amSS.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
    amSS.setItemCaptionPropertyId("name");
    amSS.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
    amSS.setNullSelectionAllowed(true);
    amSS.setNewItemsAllowed(false);
    amSS.setImmediate(true);

    final FormLayout amLayout = new FormLayout();

    final Panel amPanel = new Panel();
    amLayout.addComponent(amSS);
    amLayout.addComponent(amS);
    amPanel.addComponent(amLayout);

    final Select mmS = new Select("", mmC);
    mmS.setFilteringMode(Select.FILTERINGMODE_OFF);
    mmS.setWidth(selectWidth);
    mmS.setItemCaptionPropertyId("name");
    mmS.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
    mmS.setNullSelectionAllowed(true);
    mmS.setNewItemsAllowed(false);
    mmS.setImmediate(true);

    final FormLayout mmLayout = new FormLayout();
    final Panel mmPanel = new Panel();
    //    mmLayout.addComponent(mmSS);
    mmLayout.addComponent(mmS);
    mmPanel.addComponent(mmLayout);

    final VerticalLayout amWrapper = new VerticalLayout();
    amWrapper.setSizeFull();
    amWrapper.addComponent(amPanel);

    final VerticalLayout imWrapper = new VerticalLayout();
    imWrapper.setSizeFull();
    imWrapper.addComponent(mmPanel);

    final TabSheet typeSheet = new TabSheet();
    typeSheet.setSizeFull();
    typeSheet.addTab(amWrapper, "?? ");
    typeSheet.addTab(imWrapper, "? ");
    layout.addComponent(typeSheet);
    layout.setExpandRatio(typeSheet, 1);

    // 

    amSS.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Property prop = event.getProperty();
            if (prop.getValue() == null) {
                amPQ.serviceId = -1;
            } else {
                amPQ.serviceId = (Long) amSC.getItem(prop.getValue()).getItemProperty("id").getValue();
            }
            amS.select(null);
            amPC.refresh();
        }
    });

    final ProcedureSelectListener administrativeProcedureSelectListener = new ProcedureSelectListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void selectProcedure(long id) {
            if (amWrapper.getComponentCount() > 1) {
                amWrapper.removeComponent(amWrapper.getComponent(1));
            }
            if (id > 0) {
                final Component cmp = createStartEventForm(id, this, layout);
                if (cmp != null) {
                    amWrapper.addComponent(cmp);
                    amWrapper.setExpandRatio(cmp, 1f);
                } else {
                    amS.select(null);
                    amPC.refresh();
                    amSC.refresh();
                }
            }
        }
    };
    final ProcedureSelectListener interdepartamentalProcedureSelectListener = new ProcedureSelectListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void selectProcedure(long id) {
            if (imWrapper.getComponentCount() > 1) {
                imWrapper.removeComponent(imWrapper.getComponent(1));
            }
            if (id > 0) {
                final Component cmp = createStartEventForm(id, this, layout);
                if (cmp != null) {
                    imWrapper.addComponent(cmp);
                    imWrapper.setExpandRatio(cmp, 1f);
                }
            }
        }
    };
    amS.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Object itemId = event.getProperty().getValue();
            final long procedureId = itemId == null ? -1
                    : (Long) amPC.getItem(itemId).getItemProperty("id").getValue();
            administrativeProcedureSelectListener.selectProcedure(procedureId);
        }
    });
    mmS.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Object itemId = event.getProperty().getValue();
            final long procedureId = itemId == null ? -1
                    : (Long) mmC.getItem(itemId).getItemProperty("id").getValue();
            interdepartamentalProcedureSelectListener.selectProcedure(procedureId);
        }
    });

    return layout;
}

From source file:sample.ui.view.PersonEditor.java

License:Apache License

public FormLayout getLayout() {
    //      this.departmentSelector = departmentSelector;
    //      this.person = person;
    this.setClosable(true);

    FormLayout layout = new FormLayout();
    // Form for editing the bean
    final BeanFieldGroup<Person> binder = new BeanFieldGroup<Person>(Person.class);
    binder.setItemDataSource(person);/* w ww .j  a v  a  2 s . c  om*/
    binder.setFieldFactory(this);
    layout.addComponent(binder.buildAndBind("Name", "firstName"));
    layout.addComponent(binder.buildAndBind("Last name", "lastName"));
    layout.addComponent(binder.buildAndBind("Street", "street"));
    layout.addComponent(binder.buildAndBind("City", "city"));
    layout.addComponent(binder.buildAndBind("Zip Code", "zipCode"));
    layout.addComponent(binder.buildAndBind("Phone", "phoneNumber"));
    layout.addComponent(binder.buildAndBind("Departman", "department"));

    // Buffer the form content
    binder.setBuffered(true);
    // A button to commit the buffer
    layout.addComponent(new Button("OK", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                binder.commit();
                fireEvent(new Event(PersonEditor.this));
                Notification.show("Thanks!");
            } catch (CommitException e) {
                Notification.show("You fail!");
            }
            close();
        }
    }));

    // A button to discard the buffer
    layout.addComponent(new Button("Discard", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            binder.discard();
            Notification.show("Discarded!");
            close();
        }
    }));

    return layout;
}

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

/**
 * Muestra el formulario para aadir un gasto al evento.
 *
 * @param e Evento al que aadir el gasto.
 *//*from  w w w  . jav  a2s  .c  o  m*/
private void mostrarFormularioAddGasto(Evento e) {
    //T?TULO
    CssLayout labels = new CssLayout();
    labels.addStyleName("labels");
    Label l = new Label("Aadir Gasto");
    l.setSizeUndefined();
    l.addStyleName(ValoTheme.LABEL_H2);
    l.addStyleName(ValoTheme.LABEL_COLORED);
    //FORMULARIO
    TextField titulo = new TextField("Ttulo");
    titulo.setRequired(true);
    TextField precio = new TextField("Precio");
    precio.setRequired(true);
    List<Participante> participantes = ParticipanteDAO.readAllFromEvento(e.getId());
    ComboBox pagador = new ComboBox("Pagador");
    List<Participante> deudores = new ArrayList<>();
    Label d = new Label("Deudores");
    FormLayout form = new FormLayout(l, titulo, precio, pagador, d);
    for (Participante p : participantes) {
        pagador.addItem(p.getNombre());
        CheckBox c = new CheckBox(p.getNombre());
        c.addValueChangeListener(evento -> {
            deudores.add(p);
        });
        form.addComponent(c);
    }
    final Button add = new Button("Aadir Gasto");
    add.addStyleName(ValoTheme.BUTTON_PRIMARY);
    add.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    //SI SE CLICA EN AADIR PAGO SE CREA EL PAGO A LA VEZ QUE SE CIERRA LA VENTANA
    add.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                titulo.validate();
                precio.validate();
                pagador.validate();
                GastoDAO.create(titulo.getValue(), Double.valueOf(precio.getValue()), e.getId(),
                        ParticipanteDAO.read(pagador.getValue().toString(), usuario.getId()).getId(), deudores);
                mostrarEvento(e);
            } catch (Validator.InvalidValueException ex) {
                Notification n = new Notification("Rellena todos los campos",
                        Notification.Type.WARNING_MESSAGE);
                n.setPosition(Position.TOP_CENTER);
                n.show(Page.getCurrent());
            }
        }
    });
    //AADIMOS LOS COMPONENTES
    form.addComponent(add);
    setSecondComponent(form);
}

From source file:trader.LoginUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    setLocale(Locale.ENGLISH);//from  www .j  a v  a  2s  . co  m

    FormLayout loginForm = new FormLayout();
    loginForm.setSizeUndefined();

    loginForm.addComponent(userName = new TextField("Username"));
    loginForm.addComponent(passwordField = new PasswordField("Password"));
    loginForm.addComponent(rememberMe = new CheckBox("Remember me"));
    loginForm.addComponent(login = new Button("Login"));
    login.addStyleName(ValoTheme.BUTTON_PRIMARY);
    login.setDisableOnClick(true);
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addClickListener(new Button.ClickListener() {
        /**
        * 
        */
        private static final long serialVersionUID = 7813011112417170727L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            login();
        }
    });

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setSpacing(true);
    loginLayout.setSizeUndefined();

    if (request.getParameter("logout") != null) {
        loggedOutLabel = new Label("You have been logged out!");
        loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS);
        loggedOutLabel.setSizeUndefined();
        loginLayout.addComponent(loggedOutLabel);
        loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER);
    }

    loginLayout.addComponent(loginFailedLabel = new Label());
    loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER);
    loginFailedLabel.setSizeUndefined();
    loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE);
    loginFailedLabel.setVisible(false);

    loginLayout.addComponent(loginForm);
    loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER);

    VerticalLayout rootLayout = new VerticalLayout(loginLayout);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER);
    setContent(rootLayout);
    setSizeFull();
}

From source file:uk.co.intec.keyDatesApp.components.MainViewFilter.java

License:Apache License

/**
 * Main method to load the filtering fields and valueChangeListeners for
 * those fields.//from  ww  w  .  j  a v a  2s .  c o m
 */
public void loadContent() {
    final FormLayout cust = new FormLayout();
    cust.setMargin(false);
    setCustField(new ComboBox("Customer:", KeyDateDatabaseUtils.getCustContainer()));
    getCustField().setInputPrompt("No Customer Selected");
    getCustField().setFilteringMode(FilteringMode.STARTSWITH);
    getCustField().setImmediate(true);
    getCustField().setInvalidAllowed(false);
    getCustField().setNullSelectionAllowed(true);
    getCustField().setPageLength(5);
    getCustField().setWidth("95%");
    getCustField().setResponsive(true);
    getCustField().addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        /*
         * (non-Javadoc)
         *
         * @see
         * com.vaadin.data.Property.ValueChangeListener#valueChange(com.
         * vaadin.data.Property.ValueChangeEvent)
         */
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            final KeyDateViewWrapper viewWrapper = getParentView().getViewWrapper();
            getParentView().loadRowData(viewWrapper.getEntriesAsMap((String) event.getProperty().getValue(),
                    viewWrapper.getStartDate(), viewWrapper.isSingleCat(), viewWrapper.getCount()));
            getParentView().getPager().loadPagerPagesButtons();
        }
    });
    cust.addComponent(getCustField());

    final FormLayout date = new FormLayout();
    date.setMargin(false);
    setDateField(new PopupDateField("Start Date:"));
    getDateField().setValue(new Date());
    getDateField().setResolution(Resolution.DAY);
    getDateField().setLocale(Locale.getDefault());
    getDateField().setResponsive(true);
    getDateField().setTextFieldEnabled(false);
    getDateField().setWidth("95%");
    getDateField().setRequired(true);
    getDateField().setRequiredError("A date is required!");

    getDateField().addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        /*
         * (non-Javadoc)
         *
         * @see
         * com.vaadin.data.Property.ValueChangeListener#valueChange(com.
         * vaadin.data.Property.ValueChangeEvent)
         */
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            final KeyDateViewWrapper viewWrapper = getParentView().getViewWrapper();
            getParentView().loadRowData(viewWrapper.getEntriesAsMap(viewWrapper.getCustomerName(),
                    (Date) event.getProperty().getValue(), viewWrapper.isSingleCat(), viewWrapper.getCount()));
            getParentView().getPager().loadPagerPagesButtons();
        }
    });

    date.addComponent(getDateField());

    final FormLayout singleCatLayout = new FormLayout();
    singleCatLayout.setMargin(false);
    singleCatLayout.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
    setSingleCatButton(new CheckBox());
    getSingleCatButton().setStyleName(ValoTheme.CHECKBOX_SMALL);
    getSingleCatButton().setResponsive(true);
    getSingleCatButton().setCaption("Restrict to Date");
    getSingleCatButton().setWidth("95%");
    getSingleCatButton().addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        /*
         * (non-Javadoc)
         *
         * @see
         * com.vaadin.data.Property.ValueChangeListener#valueChange(com.
         * vaadin.data.Property.ValueChangeEvent)
         */
        @Override
        public void valueChange(ValueChangeEvent event) {
            final KeyDateViewWrapper viewWrapper = getParentView().getViewWrapper();
            final Boolean val = (Boolean) event.getProperty().getValue();
            getParentView().loadRowData(viewWrapper.getEntriesAsMap(viewWrapper.getCustomerName(),
                    viewWrapper.getStartDate(), val.booleanValue(), viewWrapper.getCount()));
            getParentView().getPager().loadPagerPagesButtons();
        }
    });
    singleCatLayout.addComponent(getSingleCatButton());

    addComponents(cust, date, singleCatLayout);
    setExpandRatio(cust, 2);
    setExpandRatio(date, 1);
    setExpandRatio(singleCatLayout, 1);
    setComponentAlignment(singleCatLayout, Alignment.MIDDLE_RIGHT);

}

From source file:xyz.iipster.ui.DefaultIbmiLoginComponent.java

License:Apache License

@Override
public void attach() {
    super.attach();
    final FormLayout fl = new FormLayout();
    fl.setSizeUndefined();//from  w  w w. ja va2s  .  c om

    userNameTF.setCaption(i18N.get("iipster.login.username.label"));
    //        userNameTF.setRequired(true);
    userNameTF.addStyleName("upper-case");
    userNameTF.setMaxLength(10);
    passwordPF.setCaption(i18N.get("iipster.login.password.label"));
    //        passwordPF.setRequired(true);

    fl.addComponent(userNameTF);
    fl.addComponent(passwordPF);

    final VerticalLayout vl = new VerticalLayout();
    vl.setSizeUndefined();
    vl.addComponent(fl);
    vl.setExpandRatio(fl, 1F);
    vl.setComponentAlignment(fl, Alignment.MIDDLE_CENTER);

    final HorizontalLayout hl = new HorizontalLayout();
    hl.setSizeUndefined();

    loginButton.setCaption(i18N.get("iipster.login.loginButton.label"));
    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    loginButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    loginButton.addClickListener(event -> {
        if (userNameTF.isEmpty()) {
            Notification.show(i18N.get("iipster.login.username.missing"), Notification.Type.WARNING_MESSAGE);
            userNameTF.focus();
            return;
        }
        if (passwordPF.isEmpty()) {
            Notification.show(i18N.get("iipster.login.password.missing"), Notification.Type.WARNING_MESSAGE);
            passwordPF.focus();
            return;
        }

        try {
            Authentication auth = securityUtils.login(userNameTF.getValue(), passwordPF.getValue());
            eventBus.post(new LoginEvent(auth.getPrincipal().toString()));
        } catch (BadCredentialsException e) {
            Notification.show(i18N.get("iipster.login.bad.credential"), Notification.Type.WARNING_MESSAGE);
        } catch (DisabledException e) {
            Notification.show(i18N.get("iipster.login.disabled"), Notification.Type.WARNING_MESSAGE);
        } catch (CredentialsExpiredException e) {
            changePasswordComponent.setUserName(userNameTF.getValue());
            changePasswordComponent.setCurrentPassword(passwordPF.getValue());
            UI.getCurrent().addWindow(changePasswordComponent);
        } catch (Exception e) {
            Notification.show(i18N.get("iipster.login.error"), Notification.Type.WARNING_MESSAGE);
        }
    });
    hl.addComponent(loginButton);
    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.MIDDLE_CENTER);
    vl.setSizeUndefined();

    vl.setMargin(true);
    final Panel panel = new Panel(i18N.get("iipster.login.panel.title"), vl);
    panel.setSizeUndefined();

    rootLayout.addComponent(panel);
    rootLayout.setSizeFull();
    rootLayout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    setCompositionRoot(rootLayout);
    setSizeFull();
}