Example usage for com.vaadin.ui FormLayout setMargin

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

Introduction

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

Prototype

@Override
    public void setMargin(boolean enabled) 

Source Link

Usage

From source file:com.jain.common.authenticate.LoginAction.java

License:Apache License

private void createFieldGroup(VerticalLayout layout) {
    I18NProvider provider = DefaultI18NResourceProvider.instance();

    userName = new TextField("user.name");
    userName.setCursorPosition(0);//from  w  w  w.j av a  2  s. c  o m
    userName.setRequired(true);
    userName.setRequiredError(provider.getMessage(getLocale(), "common.something.required", "user.name.title",
            JAction.LOGIN.getDisplayName()));
    userName.setDescription("user.name");
    userName.setSizeFull();
    userName.setStyleName(JNStyleConstants.J_FIELD);

    password = new PasswordField("password");
    password.setRequired(true);
    password.setRequiredError(provider.getMessage(getLocale(), "common.something.required", "password.title",
            JAction.LOGIN.getDisplayName()));
    password.setDescription("password");
    password.setSizeFull();
    password.setStyleName(JNStyleConstants.J_FIELD);

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setStyleName(ApplicationTheme.VIEW);
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);
    verticalLayout.setWidth("100%");

    FormLayout formLayout = new FormLayout();
    formLayout.setStyleName(ApplicationTheme.ALTERNATE_VIEW);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);
    formLayout.setWidth("100%");
    formLayout.addComponent(userName);
    formLayout.addComponent(password);

    verticalLayout.addComponent(formLayout);

    layout.addComponent(verticalLayout);
}

From source file:com.logicbomb.newschool.MyAppWidgetSet.LoginWidget.java

public LoginWidget() {
    setMargin(true);/* w w w  .ja  v  a 2s  .  c  o  m*/
    setSpacing(true);

    Panel iPanel = new Panel();
    iPanel.addStyleName("backColorWhite");
    iPanel.setSizeUndefined();

    addComponent(iPanel);

    TextField iTextField = new TextField("Username");
    iTextField.setWidth("300px");
    iTextField.setRequired(true);
    iTextField.setInputPrompt("Your username (eg. joe@email.com)");
    iTextField.setIcon(FontAwesome.USER);
    iTextField.addValidator(new EmailValidator("Username must be an email address"));
    iTextField.setInvalidAllowed(true);
    iTextField.focus();

    PasswordField iPasswordField = new PasswordField("Password");
    iPasswordField.setIcon(FontAwesome.KEY);
    iPasswordField.setWidth("300px");
    iPasswordField.setRequired(true);
    iPasswordField.setValue("");
    iPasswordField.setNullRepresentation("");

    Button iButton = new Button("Login");
    iButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            addComponent(new Label("Login Successfully"));
        }
    });

    FormLayout iFormLayout = new FormLayout();
    iFormLayout.setSpacing(true);
    iFormLayout.setMargin(true);
    iFormLayout.addComponent(iTextField);
    iFormLayout.addComponent(iPasswordField);
    iFormLayout.addComponent(iButton);
    iPanel.setContent(iFormLayout);

}

From source file:com.mcparland.john.vaadin_cookbook.CRUD.java

License:Apache License

/**
 * Create the form for the given item.//from w w w  .ja  v a  2 s.  c  o  m
 * 
 * @param item
 *            the item.
 * @return a layout for the form.
 */
@SuppressWarnings("serial")
private Layout createForm(Item item) {
    FormLayout layout = new FormLayout();
    layout.setSpacing(true);
    layout.setMargin(true);
    final FieldGroup group = new FieldGroup(item);
    for (Object propertyId : group.getUnboundPropertyIds()) {
        layout.addComponent(group.buildAndBind(propertyId));
    }
    Button button = new Button("Commmit");
    button.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                group.commit();
            } catch (CommitException e) {
                Notification.show(e.getCause().getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    layout.addComponent(button);
    return layout;
}

From source file:com.mcparland.john.vaadin_mvn_arch.samples.authentication.LoginScreen.java

License:Apache License

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

    loginForm.addStyleName("login-form");
    loginForm.setSizeUndefined();//  ww w  . ja  v a 2s . 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() {
        /**
         * The serialVersionUID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                login();
            } 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() {
        /**
         * The serialVersionUID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            showNotification(new Notification("Hint: Try anything"));
        }
    });
    forgotPassword.addStyleName(ValoTheme.BUTTON_LINK);
    return loginForm;
}

From source file:com.mechanicshop.components.DataEntryLayout.java

private void buildLayout() {
    FormLayout formLayout1 = new FormLayout();

    formLayout1.setMargin(new MarginInfo(false, false, false, true));
    formLayout1.setSpacing(true);// w  w w. ja va  2 s.c om

    FormLayout formLayout2 = new FormLayout();
    formLayout2.setMargin(new MarginInfo(false, false, false, true));
    formLayout2.setSpacing(true);

    FormLayout formLayout3 = new FormLayout();
    formLayout3.setMargin(new MarginInfo(false, true, false, true));
    formLayout3.setSpacing(true);

    tfTag.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfTag.setWidth("180px");
    tfTag.setMaxLength(3);
    tfTag.setNullRepresentation("");
    tfPhone.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfPhone.setWidth("180px");
    tfPhone.setNullRepresentation("");
    tfPhone.setMaxLength(11);
    tfName.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfName.setWidth("180px");
    tfName.setMaxLength(50);
    tfName.setNullRepresentation("");
    tfVehicle.setWidth("180px");
    tfVehicle.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfVehicle.setMaxLength(75);
    tfVehicle.setNullRepresentation("");
    tfLicensePlate.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfLicensePlate.setWidth("180px");
    tfLicensePlate.setMaxLength(10);
    tfLicensePlate.setNullRepresentation("");
    tfVin.setWidth("180px");
    tfVin.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfVin.setMaxLength(17);
    tfVin.setNullRepresentation("");
    dfInShop.setImmediate(true);
    dfInShop.addStyleName(ValoTheme.DATEFIELD_TINY);
    dfInShop.setInputPrompt("Select");
    dfInShop.setWidth("120px");

    dfOutShop.setImmediate(true);
    dfOutShop.addStyleName(ValoTheme.DATEFIELD_TINY);
    dfOutShop.setInputPrompt("Select");
    dfOutShop.setWidth("120px");

    nsStatus.addItems("In", "Out", "Pending", "Ready", "Comeback");
    nsStatus.setImmediate(true);
    nsStatus.setWidth("120px");
    nsStatus.setStyleName(ValoTheme.COMBOBOX_TINY);
    nsStatus.setValue("In");
    tfMileage.setWidth("120px");
    tfMileage.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfMileage.setMaxLength(6);
    tfMileage.setNullRepresentation("");
    tfPicked.setWidth("120px");
    tfPicked.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfPicked.setMaxLength(3);
    tfPicked.setNullRepresentation("");
    tfPayment.setWidth("180px");
    tfPayment.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfPayment.setMaxLength(50);
    tfPayment.setNullRepresentation("");
    taRemarks.setWidth("500px");
    taRemarks.setStyleName(ValoTheme.TEXTFIELD_TINY);
    taRemarks.setMaxLength(500);
    taRemarks.setNullRepresentation("");
    tfRebuilder.setWidth("180px");
    tfRebuilder.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfRebuilder.setMaxLength(20);
    tfRebuilder.setNullRepresentation("");
    tfInstaller.setWidth("180px");
    tfInstaller.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfInstaller.setMaxLength(20);
    tfInstaller.setNullRepresentation("");
    tfFirstCheckBy.setWidth("500px");
    tfFirstCheckBy.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfFirstCheckBy.setMaxLength(100);
    tfFirstCheckBy.setNullRepresentation("");
    tfSecondCheckBy.setWidth("500px");
    tfSecondCheckBy.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfSecondCheckBy.setMaxLength(100);
    tfSecondCheckBy.setNullRepresentation("");
    dfFirstCheckDate.setImmediate(true);
    dfFirstCheckDate.addStyleName(ValoTheme.DATEFIELD_TINY);
    dfFirstCheckDate.setInputPrompt("Select");
    dfFirstCheckDate.setWidth("120px");

    dfSecondCheckDate.setImmediate(true);
    dfSecondCheckDate.addStyleName(ValoTheme.DATEFIELD_TINY);
    dfSecondCheckDate.setInputPrompt("Select");
    dfSecondCheckDate.setWidth("120px");

    taMedia.setWidth("500px");
    taMedia.setStyleName(ValoTheme.TEXTFIELD_TINY);
    taMedia.setNullRepresentation("");
    taMedia2.setWidth("500px");
    taMedia2.setStyleName(ValoTheme.TEXTFIELD_TINY);
    taMedia2.setNullRepresentation("");
    tfReferedBy.setWidth("180px");
    tfReferedBy.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfReferedBy.setMaxLength(20);
    tfReferedBy.setNullRepresentation("");
    tfWarrantyLimit.setWidth("180px");
    tfWarrantyLimit.setStyleName(ValoTheme.TEXTFIELD_TINY);
    tfWarrantyLimit.setMaxLength(5);
    tfWarrantyLimit.setNullRepresentation("");
    nsWarranty.setWidth("120px");
    nsWarranty.setStyleName(ValoTheme.TEXTFIELD_TINY);
    nsWarranty.addItems("YES", "NO");
    nsWarranty.setValue("NO");
    nsWarranty.setStyleName(ValoTheme.COMBOBOX_TINY);

    nsSMS.setWidth("120px");
    nsSMS.setStyleName(ValoTheme.TEXTFIELD_TINY);
    nsSMS.addItems("YES", "NO");
    nsSMS.setValue("NO");
    nsComeback.setWidth("120px");
    nsComeback.setStyleName(ValoTheme.TEXTFIELD_TINY);
    nsComeback.addItems("YES", "NO");
    nsComeback.setValue("NO");
    nsComeback.setStyleName(ValoTheme.COMBOBOX_TINY);

    formLayout1.addComponents(tfTag, tfPhone, tfName, tfVehicle, tfPayment, tfRebuilder, tfInstaller,
            tfLicensePlate, tfVin, tfReferedBy, tfWarrantyLimit);

    formLayout2.addComponents(nsWarranty, dfInShop, dfOutShop, nsStatus, nsSMS, nsComeback, tfMileage, tfPicked,
            dfFirstCheckDate, dfSecondCheckDate);

    formLayout3.addComponents(tfFirstCheckBy, tfSecondCheckBy, taRemarks, taMedia, taMedia2);

    HorizontalLayout layoutButtons = new HorizontalLayout();
    layoutButtons.setMargin(new MarginInfo(false, true, false, true));

    sendBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {

            Integer tag = null;
            Integer mileage = null;
            if (tfTag.getValue() != null)
                if (!tfTag.getValue().isEmpty()) {
                    tag = (Integer.parseInt(tfTag.getValue()));
                } else
                    tag = null;

            if (tfMileage.getValue() != null)
                if (!tfMileage.getValue().isEmpty()) {
                    mileage = (Integer.parseInt(tfMileage.getValue()));
                } else
                    mileage = null;

            Object[] args = new Object[] { tag, tfPhone.getValue(), tfName.getValue(), tfVehicle.getValue(),
                    tfLicensePlate.getValue(), tfVin.getValue(), dfInShop.getValue(), dfOutShop.getValue(),
                    nsStatus.getValue(), mileage, tfPicked.getValue(), tfPayment.getValue(),
                    taRemarks.getValue(), tfRebuilder.getValue(), tfInstaller.getValue(),
                    tfFirstCheckBy.getValue(), tfSecondCheckBy.getValue(), dfFirstCheckDate.getValue(),
                    dfSecondCheckDate.getValue(), taMedia.getValue(), taMedia2.getValue(),
                    tfReferedBy.getValue(), tfWarrantyLimit.getValue(), nsWarranty.getValue(), nsSMS.getValue(),
                    nsComeback.getValue() };

            if (sendBtn.getCaption().equals("Add")) {
                try {
                    String status = nsStatus.getValue().toString();
                    searchService.insertCar(args, status);
                    Notification.show("Entry inserted succesfully");
                    close();
                } catch (Exception e) {
                    e.printStackTrace();
                    Notification.show("An error has occurred", Notification.Type.ERROR_MESSAGE);
                }
            } else {
                try {
                    searchService.editCar(args, tableName, no);
                    Notification.show("Entry edited succesfully");
                    close();
                } catch (Exception e) {
                    e.printStackTrace();
                    Notification.show("An error has occurred", Notification.Type.ERROR_MESSAGE);
                }

            }
        }

    });
    sendBtn.setImmediate(true);
    sendBtn.setStyleName(ValoTheme.BUTTON_TINY);
    sendBtn.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    layoutButtons.setSizeUndefined();
    layoutButtons.setSpacing(true);
    layoutButtons.addComponents(sendBtn);

    hLayoutForms.addComponents(formLayout1, formLayout2, formLayout3);

    mainLayout.addComponent(hLayoutForms);
    mainLayout.addComponent(layoutButtons);
    mainLayout.setComponentAlignment(hLayoutForms, Alignment.MIDDLE_CENTER);
    mainLayout.setComponentAlignment(layoutButtons, Alignment.MIDDLE_LEFT);
    mainLayout.setExpandRatio(hLayoutForms, 3);

}

From source file:com.morevaadin.vaadin7.converter.ConverterView.java

License:Apache License

public ConverterView() {

    FormLayout layout = new FormLayout();

    layout.setMargin(true);

    setCompositionRoot(layout);/*  www .  j a v a  2s.c o m*/

    FieldGroup group = new FieldGroup();

    Account account = new Account();

    Money money = Money.of(CurrencyUnit.USD, new BigDecimal(1000));

    account.setBalance(money);

    group.setItemDataSource(new BeanItem<Account>(account));

    TextField field = (TextField) group.buildAndBind("Balance", "balance");

    field.setImmediate(true);
    field.setConverter(Money.class);

    layout.addComponent(field);
}

From source file:com.ocs.dynamo.functional.ui.MultiDomainEditLayout.java

License:Apache License

public void build() {

    mainLayout = new DefaultVerticalLayout(true, true);

    // form that contains the combo box
    FormLayout form = new FormLayout();
    form.setMargin(true);
    form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
    mainLayout.addComponent(form);/*from   ww  w . j  a  v  a  2  s  . c  o  m*/

    // combo box for selecting domain
    domainCombo = new ComboBox(message("ocs.select.domain"));
    for (Class<? extends Domain> clazz : getDomainClasses()) {
        domainCombo.addItem(clazz);
        domainCombo.setItemCaption(clazz, getEntityModelFactory().getModel(clazz).getDisplayName());
    }
    domainCombo.setNullSelectionAllowed(false);
    domainCombo.setSizeFull();

    // respond to a change by displaying the correct domain
    domainCombo.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 8441066091930807231L;

        @Override
        @SuppressWarnings("unchecked")
        public void valueChange(ValueChangeEvent event) {
            selectDomain((Class<? extends Domain>) event.getProperty().getValue());
        }
    });

    form.addComponent(domainCombo);

    selectedDomainLayout = new DefaultVerticalLayout();
    mainLayout.addComponent(selectedDomainLayout);

    // select the first domain (if there is any)
    if (!getDomainClasses().isEmpty()) {
        domainCombo.setValue(getDomainClasses().get(0));
    }
    setCompositionRoot(mainLayout);
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedSearchForm.java

License:Apache License

/**
 * Builds the layout that contains the various search filters
 * /*from w  w  w.ja va 2s.  c  o  m*/
 * @param entityModel
 *            the entity model
 * @return
 */
protected Layout constructFilterLayout() {
    if (nrOfColumns == 1) {
        form = new FormLayout();
        // don't use all the space unless it's a popup window
        if (!getFormOptions().isPopup()) {
            form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
        }
    } else {
        // create a number of form layouts next to each others
        form = new GridLayout(nrOfColumns, 1);
        form.setSizeFull();

        for (int i = 0; i < nrOfColumns; i++) {
            FormLayout column = new FormLayout();
            column.setMargin(true);
            subForms.add(column);
            form.addComponent(column);
        }
    }

    // add any extra fields
    List<Component> extra = constructExtraSearchFields();
    for (Component c : extra) {
        if (nrOfColumns == 1) {
            form.addComponent(c);
        } else {
            int index = fieldsAdded % nrOfColumns;
            subForms.get(index).addComponent(c);
        }
        fieldsAdded++;
    }

    // iterate over the searchable attributes and add a field for each
    iterate(getEntityModel().getAttributeModels());
    return form;
}

From source file:com.ocs.dynamo.ui.composite.form.UploadForm.java

License:Apache License

@Override
protected void doBuildLayout(Layout main) {
    FormLayout form = new FormLayout();
    form.setMargin(true);
    if (ScreenMode.VERTICAL.equals(screenMode)) {
        form.setStyleName(DynamoConstants.CSS_CLASS_HALFSCREEN);
    }//from ww w .ja v a2 s.  com

    main.addComponent(form);

    // add custom components
    doBuildForm(form);

    // add file upload field
    UploadReceiver receiver = new UploadReceiver();

    Upload upload = new Upload(message("ocs.uploadform.title"), receiver);

    upload.addSucceededListener(receiver);
    form.addComponent(upload);

    if (showCancelButton) {
        Button cancelButton = new Button(message("ocs.cancel"));
        cancelButton.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                cancel();
            }
        });
        main.addComponent(cancelButton);
    }
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create the component to take a snapshot.
 * /*w ww.  j a v  a  2s .com*/
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createTakeSnap() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);

    final FormLayout takeSnapLayout = new FormLayout();
    takeSnapLayout.setMargin(true);
    takeSnapLayout.setImmediate(true);
    takeSnapLayout.setWidth(null);
    layout.addComponent(takeSnapLayout);
    layout.setComponentAlignment(takeSnapLayout, Alignment.MIDDLE_CENTER);

    // Enter name
    final TextField vvrName = new TextField("Name", "");
    takeSnapLayout.addComponent(vvrName);

    // take button
    final Button take = new Button("Take snapshot");
    layout.addComponent(take);
    layout.setComponentAlignment(take, Alignment.MIDDLE_CENTER);

    take.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                model.takeDeviceSnapshot(vvrName.getValue());
                Notification.show("New snapshot created", Notification.Type.TRAY_NOTIFICATION);
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("Snapshot not taken: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return layout;
}