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:com.tripoin.util.ui.calendar.BeanItemContainerTestUI.java

License:Apache License

/**
 * Opens up a modal dialog window where an event can be modified
 * // w w w . ja v a  2s .  c o  m
 * @param event
 *            The event to modify
 */
private void editEvent(final BasicEvent event) {
    Window modal = new Window("Add event");
    modal.setModal(true);
    modal.setResizable(false);
    modal.setDraggable(false);
    modal.setWidth("300px");
    final FieldGroup fieldGroup = new FieldGroup();

    FormLayout formLayout = new FormLayout();
    TextField captionField = new TextField("Caption");
    captionField.setImmediate(true);
    TextField descriptionField = new TextField("Description");
    descriptionField.setImmediate(true);
    DateField startField = new DateField("Start");
    startField.setResolution(Resolution.MINUTE);
    startField.setImmediate(true);
    DateField endField = new DateField("End");
    endField.setImmediate(true);
    endField.setResolution(Resolution.MINUTE);

    formLayout.addComponent(captionField);
    formLayout.addComponent(descriptionField);
    formLayout.addComponent(startField);
    formLayout.addComponent(endField);

    fieldGroup.bind(captionField, ContainerEventProvider.CAPTION_PROPERTY);
    fieldGroup.bind(descriptionField, ContainerEventProvider.DESCRIPTION_PROPERTY);
    fieldGroup.bind(startField, ContainerEventProvider.STARTDATE_PROPERTY);
    fieldGroup.bind(endField, ContainerEventProvider.ENDDATE_PROPERTY);

    fieldGroup.setItemDataSource(new BeanItem<BasicEvent>(event,
            Arrays.asList(ContainerEventProvider.CAPTION_PROPERTY, ContainerEventProvider.DESCRIPTION_PROPERTY,
                    ContainerEventProvider.STARTDATE_PROPERTY, ContainerEventProvider.ENDDATE_PROPERTY)));
    modal.setContent(formLayout);
    modal.addCloseListener(new Window.CloseListener() {
        /**
        * 
        */
        private static final long serialVersionUID = -3427881784024691882L;

        @Override
        public void windowClose(CloseEvent e) {
            // Commit changes to bean
            try {
                fieldGroup.commit();
            } catch (CommitException e1) {
                e1.printStackTrace();
            }

            if (events.containsId(event)) {
                /*
                 * BeanItemContainer does not notify container listeners
                 * when the bean changes so we need to trigger a
                 * ItemSetChange event
                 */
                BasicEvent dummy = new BasicEvent();
                events.addBean(dummy);
                events.removeItem(dummy);

            } else {
                events.addBean(event);
            }
        }
    });
    getUI().addWindow(modal);
}

From source file:com.wcs.wcslib.vaadin.widget.recaptcha.demo.ConfigComponent.java

License:Apache License

private Layout createLangconfLayout() throws FieldGroup.BindException {
    VerticalLayout langLayout = new VerticalLayout();
    langField = new TextField("lang");
    langLayout.addComponent(new FormLayout(langField));
    final FormLayout translationsLayout = new FormLayout();
    translationsLayout.setSpacing(false);
    useTranslations = new CheckBox("use translations below");
    langLayout.addComponent(useTranslations);
    useTranslations.addValueChangeListener(new Property.ValueChangeListener() {

        @Override/*from w ww  .j  a v a  2  s  .c  o  m*/
        public void valueChange(Property.ValueChangeEvent event) {
            Boolean checked = useTranslations.getValue();
            for (Component c : translationsLayout) {
                c.setEnabled(checked);
            }
        }
    });
    translations = new CustomTranslationsBean();
    BeanFieldGroup<CustomTranslationsBean> translationsFieldGroup = new BeanFieldGroup<CustomTranslationsBean>(
            CustomTranslationsBean.class);
    translationsFieldGroup.setItemDataSource((CustomTranslationsBean) translations);
    Collection<Object> propertyIds = translationsFieldGroup.getUnboundPropertyIds();
    translationsFieldGroup.setBuffered(false);
    for (Object property : propertyIds) {
        Field<?> field = translationsFieldGroup.buildAndBind(property);
        ((TextField) field).setNullRepresentation("");
        field.setCaption(field.getCaption().toLowerCase());
        field.setEnabled(false);
        translationsLayout.addComponent(field);
    }
    langLayout.addComponent(translationsLayout);
    return langLayout;
}

From source file:com.yoncabt.ebr.ui.ReportWindow.java

private void showFields(ReportDefinition definition, final Window w, final FormLayout fl)
        throws AssertionError, JSONException {
    fl.removeAllComponents();//  w  w w  . j av  a2s .  c o  m
    w.setCaption(definition.getCaption());
    for (ReportParam param : definition.getReportParams()) {
        AbstractField comp = null;
        if (param.getInputType() == InputType.COMBO) {
            ComboBox f = new ComboBox(param.getLabel());
            param.getLovData().forEach((k, v) -> {
                f.addItem(k);
                f.setItemCaption(k, (String) v);
            });
            comp = f;
        } else {
            switch (param.getFieldType()) {
            case STRING: {
                TextField f = new TextField(param.getLabel());
                comp = f;
                break;
            }
            case INTEGER: {
                TextField f = new TextField(param.getLabel());
                f.addValidator(new IntegerRangeValidator("Say kontrol", (Integer) param.getMin(),
                        (Integer) param.getMax()));
                comp = f;
                break;
            }
            case LONG: {
                TextField f = new TextField(param.getLabel());
                f.addValidator(new LongRangeValidator("Say kontrol", (Long) param.getMin(),
                        (Long) param.getMax()));
                comp = f;
                break;
            }
            case DOUBLE: {
                TextField f = new TextField(param.getLabel());
                f.addValidator(new DoubleRangeValidator("Say kontrol", (Double) param.getMin(),
                        (Double) param.getMax()));
                comp = f;
                break;
            }
            case DATE: {
                DateField f = new DateField(param.getLabel());
                f.setDateFormat(param.getFormat());
                comp = f;
                break;
            }
            default: {
                throw new AssertionError(param.getName() + " in tipi tannmyor :" + param.getJavaType());
            }
            }
        }
        if (param.getDefaultValue() != null) {
            comp.setValue(param.getDefaultValue());
        }
        comp.setImmediate(true);
        comp.setValidationVisible(false);
        comp.setId(param.getName());
        fl.addComponent(comp);

    }
    if (report instanceof SQLReport) {
        reportType.addItem(ReportOutputFormat.xls);
        reportType.setItemCaption(ReportOutputFormat.xls, ReportOutputFormat.xls.getTypeName());
    } else {
        for (ReportOutputFormat value : ReportOutputFormat.values()) {
            reportType.addItem(value);
            reportType.setItemCaption(value, value.getTypeName());
        }
    }
    reportType.setValue(ReportOutputFormat.xls);
    fl.addComponent(reportType);
    fl.addComponent(reportLocale);
    fl.addComponent(email);
}

From source file:de.akquinet.engineering.vaadin.html5.Html5TestUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    FormLayout layout = new FormLayout();
    colorField.setCaption("Color");
    layout.addComponent(colorField);
    dateField.setCaption("Date");
    layout.addComponent(dateField);//from w w w. j  a  v  a  2s.c  o m
    dateTimeField.setCaption("DateTime");
    layout.addComponent(dateTimeField);
    dateTimeLocalField.setCaption("DateTime-local");
    layout.addComponent(dateTimeLocalField);
    emailField.setCaption("Email");
    layout.addComponent(emailField);
    monthField.setCaption("Month");
    layout.addComponent(monthField);
    numberField.setCaption("Number");
    layout.addComponent(numberField);
    numberFieldMin.setMin(2);
    numberFieldMin.setCaption("Number >=2");
    layout.addComponent(numberFieldMin);
    numberFieldMinMax.setMin(2);
    numberFieldMinMax.setMax(10);
    numberFieldMinMax.setCaption("Number >=2 && <=10");
    layout.addComponent(numberFieldMinMax);
    numberFieldMinMaxStep.setMin(2);
    numberFieldMinMaxStep.setMax(10);
    numberFieldMinMaxStep.setStep(2);
    numberFieldMinMaxStep.setCaption("Number >=2 && <=10 && even");
    layout.addComponent(numberFieldMinMaxStep);
    rangeField.setMin(2);
    rangeField.setMax(10);
    rangeField.setCaption("Range between 2 and 10");
    layout.addComponent(rangeField);
    searchField.setCaption("Search");
    layout.addComponent(searchField);
    telField.setCaption("Tel");
    layout.addComponent(telField);
    timeField.setCaption("Time");
    layout.addComponent(timeField);
    urlField.setCaption("Url");
    layout.addComponent(urlField);
    weekField.setCaption("Week");
    layout.addComponent(weekField);
    summary.setCaption("Summary");
    summary.setRows(20);
    summary.setColumns(80);
    layout.addComponent(summary);
    buildSummary.addClickListener(new ClickListener() {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            StringBuilder str = new StringBuilder();
            str.append(colorField.getCaption() + ": ");
            str.append(colorField.getValue());
            str.append("\n");
            str.append(dateField.getCaption() + ": ");
            str.append(dateField.getValue());
            str.append("\n");
            str.append(dateTimeField.getCaption() + ": ");
            str.append(dateTimeField.getValue());
            str.append("\n");
            str.append(dateTimeLocalField.getCaption() + ": ");
            str.append(dateTimeLocalField.getValue());
            str.append("\n");
            str.append(emailField.getCaption() + ": ");
            str.append(emailField.getValue());
            str.append("\n");
            str.append(monthField.getCaption() + ": ");
            str.append(monthField.getValue());
            str.append("\n");
            str.append(numberField.getCaption() + ": ");
            str.append(numberField.getValue());
            str.append("\n");
            str.append(numberFieldMin.getCaption() + ": ");
            str.append(numberFieldMin.getValue());
            str.append("\n");
            str.append(numberFieldMinMax.getCaption() + ": ");
            str.append(numberFieldMinMax.getValue());
            str.append("\n");
            str.append(numberFieldMinMaxStep.getCaption() + ": ");
            str.append(numberFieldMinMaxStep.getValue());
            str.append("\n");
            str.append(rangeField.getCaption() + ": ");
            str.append(rangeField.getValue());
            str.append("\n");
            str.append(searchField.getCaption() + ": ");
            str.append(searchField.getValue());
            str.append("\n");
            str.append(telField.getCaption() + ": ");
            str.append(telField.getValue());
            str.append("\n");
            str.append(timeField.getCaption() + ": ");
            str.append(timeField.getValue());
            str.append("\n");
            str.append(urlField.getCaption() + ": ");
            str.append(urlField.getValue());
            str.append("\n");
            str.append(weekField.getCaption() + ": ");
            str.append(weekField.getValue());
            str.append("\n");
            summary.setValue(str.toString());
        }
    });
    layout.addComponent(buildSummary);
    setContent(layout);
}

From source file:de.escidoc.admintool.view.util.LayoutHelper.java

License:Open Source License

/**
 * @param form//from   w  w  w .  j av  a  2s .  c  om
 * @param comp
 * @param label
 * @param labelWidth
 * @param width
 * @param height
 * @param required
 */
public static synchronized void addElement(final FormLayout form, final AbstractComponent comp,
        final String label, final int labelWidth, final int width, final int height, final boolean required) {
    comp.setWidth(width + Constants.PX);
    form.addComponent(LayoutHelper.create(label, comp, labelWidth, height, required));
}

From source file:de.escidoc.admintool.view.util.LayoutHelper.java

License:Open Source License

/**
 * @param form// w w  w.  ja v a  2  s.c o m
 * @param comp
 * @param label
 * @param labelWidth
 * @param width
 * @param height
 * @param required
 * @param buttons
 */
public static synchronized void addElement(final FormLayout form, final AbstractComponent comp,
        final String label, final int labelWidth, final int width, final int height, final boolean required,
        final Button[] buttons) {
    comp.setWidth(width + Constants.PX);
    form.addComponent(LayoutHelper.create(label, comp, labelWidth, height, required, buttons));
}

From source file:de.escidoc.admintool.view.util.LayoutHelper.java

License:Open Source License

/**
 * @param form/* ww w . j av  a  2  s.  c o  m*/
 * @param comp
 * @param label
 * @param labelWidth
 * @param width
 * @param required
 */
public static synchronized void addElement(final FormLayout form, final AbstractComponent comp,
        final String label, final int labelWidth, final int width, final boolean required) {
    comp.setWidth(width + Constants.PX);
    form.addComponent(LayoutHelper.create(label, comp, labelWidth, required));
}

From source file:de.fatalix.app.view.login.LoginView.java

private Component buildLoginForm() {
    FormLayout loginForm = new FormLayout();

    loginForm.addStyleName("login-form");
    loginForm.setSizeUndefined();//from   w w  w  .  ja  va 2 s .  c o m
    loginForm.setMargin(false);

    loginForm.addComponent(username = new TextField("Username", "admin"));
    username.setWidth(15, Unit.EM);
    loginForm.addComponent(password = new PasswordField("Password"));
    password.setWidth(15, Unit.EM);
    password.setDescription("Write anything");
    CssLayout buttons = new CssLayout();
    buttons.setStyleName("buttons");
    loginForm.addComponent(buttons);

    buttons.addComponent(login = new Button("Login"));
    login.setDisableOnClick(true);
    login.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                presenter.doLogin(username.getValue(), password.getValue());
            } catch (AuthenticationException ex) {
                LoginView.this.showNotification(
                        new Notification("Wrong login", Notification.Type.ERROR_MESSAGE),
                        ValoTheme.NOTIFICATION_FAILURE);
            } finally {
                login.setEnabled(true);
            }
        }
    });
    login.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    login.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    buttons.addComponent(forgotPassword = new Button("Forgot password?"));
    forgotPassword.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            showNotification(new Notification("Hint: Try anything", Notification.Type.HUMANIZED_MESSAGE),
                    ValoTheme.NOTIFICATION_SUCCESS);
        }
    });
    forgotPassword.addStyleName(ValoTheme.BUTTON_LINK);
    return loginForm;
}

From source file:de.fatalix.bookery.view.login.LoginView.java

License:Open Source License

private Component buildLoginForm() {
    FormLayout loginForm = new FormLayout();

    loginForm.addStyleName("login-form");
    loginForm.setSizeUndefined();/*from w  w  w  .  ja  v  a 2 s.co  m*/
    loginForm.setMargin(false);

    loginForm.addComponent(username = new TextField("Username", "admin"));
    username.setWidth(15, Unit.EM);
    loginForm.addComponent(password = new PasswordField("Password"));
    password.setWidth(15, Unit.EM);
    password.setDescription("");

    CssLayout buttons = new CssLayout();
    buttons.setStyleName("buttons");
    loginForm.addComponent(buttons);
    login = new Button("login");
    buttons.addComponent(login);
    login.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                presenter.doLogin(username.getValue(), password.getValue());
            } catch (AuthenticationException ex) {
                LoginView.this.showNotification(
                        new Notification("Wrong login", Notification.Type.ERROR_MESSAGE),
                        ValoTheme.NOTIFICATION_FAILURE);
            } finally {
                login.setEnabled(true);
            }
        }
    });
    login.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    buttons.addComponent(forgotPassword = new Button("Forgot password?"));
    forgotPassword.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            showNotification(new Notification("Hint: Ask me", Notification.Type.HUMANIZED_MESSAGE),
                    ValoTheme.NOTIFICATION_SUCCESS);
        }
    });
    forgotPassword.addStyleName(ValoTheme.BUTTON_LINK);
    Panel loginPanel = new Panel(loginForm);
    loginPanel.setWidthUndefined();
    loginPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    loginPanel.addAction(new ShortcutListener("commit", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            try {
                presenter.doLogin(username.getValue(), password.getValue());
            } catch (AuthenticationException ex) {
                LoginView.this.showNotification(
                        new Notification("Wrong login", Notification.Type.ERROR_MESSAGE),
                        ValoTheme.NOTIFICATION_FAILURE);
            }
        }
    });
    return loginPanel;
}

From source file:de.fzi.fhemapi.view.vaadin.ui.ServerDetailsForm.java

License:Apache License

public ServerDetailsForm() {
    FormLayout layout = new FormLayout();
    setCompositionRoot(layout);//from  w  ww .j av  a 2s. com

    Label title = new Label("<h1> Server Details</h1>");
    title.setContentMode(Label.CONTENT_XHTML);
    layout.addComponent(title);

    final TextField serverIP = new TextField("Server IP");

    serverIP.setWidth(COMMON_FIELD_WIDTH);
    layout.addComponent(serverIP);

    final TextField port = new TextField("Port");
    port.setWidth(COMMON_FIELD_WIDTH);
    layout.addComponent(port);

    Button applyButton = new Button("Apply");
    layout.addComponent(applyButton);

    applyButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                //               Window mainWindow = new Window();
                FHEMServer server = new FHEMServer((String) serverIP.getValue(),
                        Integer.parseInt((String) port.getValue()));
                getWindow().setContent(new HWindow(server));
                //               VaadinServletResponse response = 
                //                        (VaadinServletResponse) VaadinService.getCurrentResponse();
                //                     Cookie ipCookie = new Cookie("ip", (String)serverIP.getValue());
                //                     Cookie portCookie = new Cookie("port", (String) port.getValue());
                //                     ipCookie.setMaxAge(30 * 24 * 60 * 60);
                //                     ipCookie.setPath("/HWC");
                //                     portCookie.setMaxAge(30 * 24 * 60 * 60);
                //                     portCookie.setPath("/HWC");
                //                     response.addCookie(ipCookie);
                //                     response.addCookie(portCookie);
            } catch (ConnectException e) {
                getWindow().setContent(new Window("Could not connect to FHEM!\n Cause: " + e.getMessage()));
                getWindow().showNotification("Error!", e.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    //
    //       VaadinServletRequest request = 
    //                (VaadinServletRequest) VaadinService.getCurrentRequest();
    //       if(request != null){
    //             Cookie[] cookies = request.getCookies();
    //             for (Cookie cookie : cookies) {
    //                if (cookie.getName().equals("ip")) {
    //                   serverIP.setValue(cookie.getValue());
    //                }else if(cookie.getName().equals("port")){
    //                   port.setValue(cookie.getValue());
    //                }
    //             }
    //       }

}