Example usage for com.vaadin.v7.ui ComboBox setWidth

List of usage examples for com.vaadin.v7.ui ComboBox setWidth

Introduction

In this page you can find the example usage for com.vaadin.v7.ui ComboBox setWidth.

Prototype

public void setWidth(float width, Unit unit);

Source Link

Document

Sets the width of the object.

Usage

From source file:de.symeda.sormas.ui.configuration.infrastructure.CommunityEditForm.java

License:Open Source License

@Override
protected void addFields() {
    addField(CommunityDto.NAME, TextField.class);
    ComboBox region = new ComboBox();
    region.setCaption(I18nProperties.getPrefixCaption(CommunityDto.I18N_PREFIX, REGION_LOC));
    region.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(region, REGION_LOC);
    ComboBox district = addField(CommunityDto.DISTRICT, ComboBox.class);

    setRequired(true, CommunityDto.NAME, CommunityDto.DISTRICT);
    region.setRequired(true);//from  w w w .j  a  v  a  2 s . c  o  m

    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district,
                regionDto != null ? FacadeProvider.getDistrictFacade().getAllByRegion(regionDto.getUuid())
                        : null);
    });

    district.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null && region.getValue() == null) {
            DistrictDto communityDistrict = FacadeProvider.getDistrictFacade()
                    .getDistrictByUuid(((DistrictReferenceDto) e.getProperty().getValue()).getUuid());
            region.setValue(communityDistrict.getRegion());
        }
    });

    region.addItems(FacadeProvider.getRegionFacade().getAllAsReference());

    // TODO: Workaround until cases and other data is properly transfered when infrastructure data changes
    if (!create) {
        region.setEnabled(false);
        district.setEnabled(false);
    }
}