Example usage for com.vaadin.ui HorizontalLayout setSpacing

List of usage examples for com.vaadin.ui HorizontalLayout setSpacing

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setSpacing.

Prototype

@Override
    public void setSpacing(boolean spacing) 

Source Link

Usage

From source file:de.symeda.sormas.ui.dashboard.surveillance.DiseaseStatisticsComponent.java

License:Open Source License

private Layout createOutbreakDistrictComponent() {
    HorizontalLayout component = new HorizontalLayout();
    component.setMargin(false);/*from ww  w . j av a2  s  .c o  m*/
    component.setSpacing(false);

    // count
    outbreakDistrictCountLabel = new Label();
    CssStyles.style(outbreakDistrictCountLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_BOLD,
            CssStyles.LABEL_LARGE, CssStyles.HSPACE_RIGHT_3, CssStyles.VSPACE_TOP_5);
    component.addComponent(outbreakDistrictCountLabel);

    // title
    Label titleLabel = new Label(I18nProperties.getCaption(Captions.dashboardOutbreakDistricts));
    CssStyles.style(titleLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_UPPERCASE, CssStyles.VSPACE_TOP_4);
    component.addComponent(titleLabel);

    return component;
}

From source file:de.symeda.sormas.ui.dashboard.surveillance.DiseaseStatisticsComponent.java

License:Open Source License

private DashboardStatisticsSubComponent createEventComponent() {
    DashboardStatisticsSubComponent eventComponent = new DashboardStatisticsSubComponent();

    // Header//from ww  w .  j ava  2 s . co m
    HorizontalLayout headerLayout = new HorizontalLayout();
    headerLayout.setMargin(false);
    headerLayout.setSpacing(false);

    // count
    eventCountLabel = new Label();
    CssStyles.style(eventCountLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_XXXLARGE, CssStyles.LABEL_BOLD,
            CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);
    headerLayout.addComponent(eventCountLabel);
    // title
    Label titleLabel = new Label(I18nProperties.getCaption(Captions.dashboardNewEvents));
    CssStyles.style(titleLabel, CssStyles.H2, CssStyles.HSPACE_LEFT_4);
    headerLayout.addComponent(titleLabel);

    eventComponent.addComponent(headerLayout);

    // Count layout
    CssLayout countLayout = eventComponent.createCountLayout(true);
    eventStatusConfirmed = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardConfirmed), CountElementStyle.CRITICAL);
    eventComponent.addComponentToCountLayout(countLayout, eventStatusConfirmed);
    eventStatusPossible = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardPossible), CountElementStyle.IMPORTANT);
    eventComponent.addComponentToCountLayout(countLayout, eventStatusPossible);
    eventStatusNotAnEvent = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardNotAnEvent), CountElementStyle.POSITIVE);
    eventComponent.addComponentToCountLayout(countLayout, eventStatusNotAnEvent);
    eventComponent.addComponent(countLayout);

    return eventComponent;
}

From source file:de.symeda.sormas.ui.dashboard.surveillance.DiseaseStatisticsComponent.java

License:Open Source License

private DashboardStatisticsSubComponent createTestResultComponent() {
    DashboardStatisticsSubComponent testResultComponent = new DashboardStatisticsSubComponent();

    // Header/*from  w w  w. j a v a2 s .  c  o m*/
    HorizontalLayout headerLayout = new HorizontalLayout();
    headerLayout.setMargin(false);
    headerLayout.setSpacing(false);
    // count
    testResultCountLabel = new Label();
    CssStyles.style(testResultCountLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_XXXLARGE,
            CssStyles.LABEL_BOLD, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);
    headerLayout.addComponent(testResultCountLabel);
    // title
    Label titleLabel = new Label(I18nProperties.getCaption(Captions.dashboardNewTestResults));
    CssStyles.style(titleLabel, CssStyles.H2, CssStyles.HSPACE_LEFT_4);
    headerLayout.addComponent(titleLabel);

    testResultComponent.addComponent(headerLayout);

    // Count layout
    CssLayout countLayout = testResultComponent.createCountLayout(true);
    testResultPositive = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardPositive), CountElementStyle.CRITICAL);
    testResultComponent.addComponentToCountLayout(countLayout, testResultPositive);
    testResultNegative = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardNegative), CountElementStyle.POSITIVE);
    testResultComponent.addComponentToCountLayout(countLayout, testResultNegative);
    testResultPending = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardPending), CountElementStyle.IMPORTANT);
    testResultComponent.addComponentToCountLayout(countLayout, testResultPending);
    testResultIndeterminate = new DashboardStatisticsCountElement(
            I18nProperties.getCaption(Captions.dashboardIndeterminate), CountElementStyle.MINOR);
    testResultComponent.addComponentToCountLayout(countLayout, testResultIndeterminate);
    testResultComponent.addComponent(countLayout);

    return testResultComponent;
}

From source file:de.symeda.sormas.ui.dashboard.surveillance.DiseaseTileComponent.java

License:Open Source License

void addTopLayout(Disease disease, Long casesCount, boolean isOutbreak) {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setMargin(false);/*from  ww w  .  j  a  v a 2  s. c  o m*/
    layout.setSpacing(false);
    CssStyles.style(layout, CssStyles.getDiseaseColor(disease));
    layout.setHeight(75, Unit.PIXELS);
    layout.setWidth(100, Unit.PERCENTAGE);

    VerticalLayout nameAndOutbreakLayout = new VerticalLayout();
    nameAndOutbreakLayout.setMargin(false);
    nameAndOutbreakLayout.setSpacing(false);
    nameAndOutbreakLayout.setHeight(100, Unit.PERCENTAGE);
    nameAndOutbreakLayout.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout nameLayout = new HorizontalLayout();
    nameLayout.setMargin(false);
    nameLayout.setSpacing(false);
    nameLayout.setWidth(100, Unit.PERCENTAGE);
    nameLayout.setHeight(100, Unit.PERCENTAGE);
    Label nameLabel = new Label(disease.toShortString());
    CssStyles.style(nameLabel, CssStyles.LABEL_WHITE,
            nameLabel.getValue().length() > 12 ? CssStyles.LABEL_LARGE : CssStyles.LABEL_XLARGE,
            CssStyles.LABEL_BOLD, CssStyles.ALIGN_CENTER, CssStyles.LABEL_UPPERCASE);
    nameLayout.addComponent(nameLabel);
    nameLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_CENTER);
    nameAndOutbreakLayout.addComponent(nameLayout);
    nameAndOutbreakLayout.setExpandRatio(nameLayout, 1);

    if (isOutbreak) {
        HorizontalLayout outbreakLayout = new HorizontalLayout();
        outbreakLayout.setMargin(false);
        outbreakLayout.setSpacing(false);
        CssStyles.style(outbreakLayout, CssStyles.BACKGROUND_CRITICAL);
        outbreakLayout.setWidth(100, Unit.PERCENTAGE);
        outbreakLayout.setHeight(30, Unit.PIXELS);
        Label outbreakLabel = new Label(I18nProperties.getCaption(Captions.dashboardOutbreak));
        CssStyles.style(outbreakLabel, CssStyles.LABEL_WHITE, CssStyles.ALIGN_CENTER,
                CssStyles.LABEL_UPPERCASE);
        outbreakLayout.addComponent(outbreakLabel);
        outbreakLayout.setComponentAlignment(outbreakLabel, Alignment.MIDDLE_CENTER);
        nameAndOutbreakLayout.addComponent(outbreakLayout);
    }

    layout.addComponent(nameAndOutbreakLayout);
    layout.setExpandRatio(nameAndOutbreakLayout, 1);

    HorizontalLayout countLayout = new HorizontalLayout();
    countLayout.setMargin(false);
    countLayout.setSpacing(false);
    CssStyles.style(countLayout, CssStyles.getDiseaseColor(disease), CssStyles.BACKGROUND_DARKER);
    countLayout.setHeight(100, Unit.PERCENTAGE);
    countLayout.setWidth(100, Unit.PERCENTAGE);

    Label countLabel = new Label(casesCount.toString());
    CssStyles.style(countLabel, CssStyles.LABEL_WHITE, CssStyles.LABEL_BOLD, CssStyles.LABEL_XXXLARGE,
            CssStyles.ALIGN_CENTER);
    countLayout.addComponent(countLabel);
    countLayout.setComponentAlignment(countLabel, Alignment.MIDDLE_CENTER);

    layout.addComponent(countLayout);
    layout.setExpandRatio(countLayout, 0.65f);

    addComponent(layout);
}

From source file:de.symeda.sormas.ui.dashboard.surveillance.DiseaseTileComponent.java

License:Open Source License

HorizontalLayout createStatsItem(String label, String value, boolean isCritical) {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(false);// ww  w .  j  a va2s .c  o  m
    layout.setSpacing(false);

    Label nameLabel = new Label(label);
    CssStyles.style(nameLabel, CssStyles.LABEL_PRIMARY, isCritical ? CssStyles.LABEL_CRITICAL : "",
            CssStyles.HSPACE_LEFT_3);
    layout.addComponent(nameLabel);
    layout.setExpandRatio(nameLabel, 1);

    Label valueLabel = new Label(value);
    CssStyles.style(valueLabel, CssStyles.LABEL_PRIMARY, isCritical ? CssStyles.LABEL_CRITICAL : "",
            CssStyles.ALIGN_CENTER);
    layout.addComponent(valueLabel);
    layout.setExpandRatio(valueLabel, 0.65f);

    return layout;
}

From source file:de.symeda.sormas.ui.events.EventParticipantsView.java

License:Open Source License

public HorizontalLayout createTopBar() {
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setSpacing(true);
    topLayout.setWidth("100%");

    Label header = new Label(I18nProperties.getPrefixCaption(EventDto.I18N_PREFIX, EventDto.EVENT_PERSONS));
    header.setSizeUndefined();//  w w  w  . j  a v a2 s.  c o m
    CssStyles.style(header, CssStyles.H2, CssStyles.VSPACE_NONE);
    topLayout.addComponent(header);

    // Bulk operation dropdown
    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        topLayout.setWidth(100, Unit.PERCENTAGE);

        MenuBar bulkOperationsDropdown = new MenuBar();
        MenuItem bulkOperationsItem = bulkOperationsDropdown
                .addItem(I18nProperties.getCaption(Captions.bulkActions), null);

        Command deleteCommand = selectedItem -> {
            ControllerProvider.getEventParticipantController()
                    .deleteAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                        public void run() {
                            grid.deselectAll();
                            grid.reload();
                        }
                    });
        };
        bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH,
                deleteCommand);

        topLayout.addComponent(bulkOperationsDropdown);
        topLayout.setComponentAlignment(bulkOperationsDropdown, Alignment.TOP_RIGHT);
        topLayout.setExpandRatio(bulkOperationsDropdown, 1);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENTPARTICIPANT_CREATE)) {
        addButton = new Button(I18nProperties.getCaption(Captions.eventParticipantAddPerson));
        addButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        addButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        addButton.addClickListener(e -> {
            ControllerProvider.getEventParticipantController().createEventParticipant(this.getEventRef(),
                    r -> grid.reload());
        });
        topLayout.addComponent(addButton);
        topLayout.setComponentAlignment(addButton, Alignment.MIDDLE_RIGHT);
    }

    topLayout.addStyleName(CssStyles.VSPACE_3);
    return topLayout;
}

From source file:de.symeda.sormas.ui.events.EventsView.java

License:Open Source License

public HorizontalLayout createFilterBar() {
    HorizontalLayout filterLayout = new HorizontalLayout();
    filterLayout.setSpacing(true);
    filterLayout.setMargin(false);/*  www  .j  av a 2  s  .c  o  m*/
    filterLayout.setSizeUndefined();

    diseaseFilter = new ComboBox();
    diseaseFilter.setWidth(140, Unit.PIXELS);
    diseaseFilter
            .setInputPrompt(I18nProperties.getPrefixCaption(EventIndexDto.I18N_PREFIX, EventIndexDto.DISEASE));
    diseaseFilter
            .addItems(FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases().toArray());
    diseaseFilter.addValueChangeListener(e -> {
        criteria.disease(((Disease) e.getProperty().getValue()));
        navigateTo(criteria);
    });
    filterLayout.addComponent(diseaseFilter);

    reportedByFilter = new ComboBox();
    reportedByFilter.setWidth(140, Unit.PIXELS);
    reportedByFilter.setInputPrompt(I18nProperties.getString(Strings.reportedBy));
    reportedByFilter.addItems((Object[]) UserRole.values());
    reportedByFilter.addValueChangeListener(e -> {
        criteria.reportingUserRole((UserRole) e.getProperty().getValue());
        navigateTo(criteria);
    });
    filterLayout.addComponent(reportedByFilter);

    resetButton = new Button(I18nProperties.getCaption(Captions.actionResetFilters));
    resetButton.setVisible(false);
    resetButton.addClickListener(event -> {
        ViewModelProviders.of(EventsView.class).remove(EventCriteria.class);
        navigateTo(null);
    });
    filterLayout.addComponent(resetButton);

    return filterLayout;
}

From source file:de.symeda.sormas.ui.events.EventsView.java

License:Open Source License

public HorizontalLayout createStatusFilterBar() {
    HorizontalLayout statusFilterLayout = new HorizontalLayout();
    statusFilterLayout.setSpacing(true);
    statusFilterLayout.setMargin(false);
    statusFilterLayout.setWidth(100, Unit.PERCENTAGE);
    statusFilterLayout.addStyleName(CssStyles.VSPACE_3);

    statusButtons = new HashMap<>();

    Button statusAll = new Button(I18nProperties.getCaption(Captions.all), e -> {
        criteria.eventStatus(null);/*from   w ww  .  ja v  a 2s .  c o m*/
        navigateTo(criteria);
    });
    CssStyles.style(statusAll, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
    statusAll.setCaptionAsHtml(true);
    statusFilterLayout.addComponent(statusAll);
    statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
    activeStatusButton = statusAll;

    for (EventStatus status : EventStatus.values()) {
        Button statusButton = new Button(status.toString(), e -> {
            criteria.eventStatus(status);
            navigateTo(criteria);
        });
        statusButton.setData(status);
        CssStyles.style(statusButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER,
                CssStyles.BUTTON_FILTER_LIGHT);
        statusButton.setCaptionAsHtml(true);
        statusFilterLayout.addComponent(statusButton);
        statusButtons.put(statusButton, status.toString());
    }

    HorizontalLayout actionButtonsLayout = new HorizontalLayout();
    actionButtonsLayout.setSpacing(true);
    {
        // Show archived/active cases button
        if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_VIEW_ARCHIVED)) {
            switchArchivedActiveButton = new Button(I18nProperties.getCaption(Captions.eventShowArchived));
            switchArchivedActiveButton.setStyleName(ValoTheme.BUTTON_LINK);
            switchArchivedActiveButton.addClickListener(e -> {
                criteria.archived(Boolean.TRUE.equals(criteria.getArchived()) ? null : Boolean.TRUE);
                navigateTo(criteria);
            });
            actionButtonsLayout.addComponent(switchArchivedActiveButton);
        }

        // Bulk operation dropdown
        if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
            MenuBar bulkOperationsDropdown = new MenuBar();
            MenuItem bulkOperationsItem = bulkOperationsDropdown
                    .addItem(I18nProperties.getCaption(Captions.bulkActions), null);

            Command changeCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .showBulkEventDataEditComponent(grid.asMultiSelect().getSelectedItems());
            };
            bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkEdit), VaadinIcons.ELLIPSIS_H,
                    changeCommand);

            Command deleteCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .deleteAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                            public void run() {
                                grid.reload();
                            }
                        });
            };
            bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH,
                    deleteCommand);

            Command archiveCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .archiveAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                            public void run() {
                                grid.reload();
                            }
                        });
            };
            archiveItem = bulkOperationsItem.addItem(
                    I18nProperties.getCaption(I18nProperties.getCaption(Captions.actionArchive)),
                    VaadinIcons.ARCHIVE, archiveCommand);

            Command dearchiveCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .dearchiveAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                            public void run() {
                                grid.reload();
                            }
                        });
            };
            dearchiveItem = bulkOperationsItem.addItem(
                    I18nProperties.getCaption(I18nProperties.getCaption(Captions.actionDearchive)),
                    VaadinIcons.ARCHIVE, dearchiveCommand);
            dearchiveItem.setVisible(false);

            actionButtonsLayout.addComponent(bulkOperationsDropdown);
        }
    }
    statusFilterLayout.addComponent(actionButtonsLayout);
    statusFilterLayout.setComponentAlignment(actionButtonsLayout, Alignment.TOP_RIGHT);
    statusFilterLayout.setExpandRatio(actionButtonsLayout, 1);

    return statusFilterLayout;
}

From source file:de.symeda.sormas.ui.importer.ImportPersonSelectField.java

License:Open Source License

@Override
protected Component initContent() {
    if (importedCase == null || importedPerson == null) {
        return null;
    }/*from   w  w  w  .ja va2s .com*/

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeUndefined();
    layout.setWidth(100, Unit.PERCENTAGE);

    // Info label

    Label infoLabel = new Label(I18nProperties.getString(Strings.infoImportSimilarity));
    CssStyles.style(infoLabel, CssStyles.VSPACE_3);
    layout.addComponent(infoLabel);

    // Imported case info
    VerticalLayout outerCaseInfoLayout = new VerticalLayout();
    outerCaseInfoLayout.setWidth(100, Unit.PERCENTAGE);
    CssStyles.style(outerCaseInfoLayout, CssStyles.BACKGROUND_ROUNDED_CORNERS,
            CssStyles.BACKGROUND_SUB_CRITERIA, CssStyles.VSPACE_3, "v-scrollable");

    Label importedCaseLabel = new Label(I18nProperties.getString(Strings.headingImportedCaseInfo));
    CssStyles.style(importedCaseLabel, CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
    outerCaseInfoLayout.addComponent(importedCaseLabel);

    HorizontalLayout caseInfoLayout = new HorizontalLayout();
    caseInfoLayout.setSpacing(true);
    caseInfoLayout.setSizeUndefined();
    {
        Label diseaseField = new Label();
        diseaseField.setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISEASE));
        diseaseField
                .setValue(DiseaseHelper.toString(importedCase.getDisease(), importedCase.getDiseaseDetails()));
        diseaseField.setWidthUndefined();
        caseInfoLayout.addComponent(diseaseField);

        Label caseDateField = new Label();
        if (importedCase.getSymptoms().getOnsetDate() != null) {
            caseDateField.setCaption(
                    I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
            caseDateField.setValue(DateHelper.formatLocalShortDate(importedCase.getSymptoms().getOnsetDate()));
        } else {
            caseDateField.setCaption(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REPORT_DATE));
            caseDateField.setValue(DateHelper.formatLocalShortDate(importedCase.getReportDate()));
        }
        caseDateField.setWidthUndefined();
        caseInfoLayout.addComponent(caseDateField);

        Label regionField = new Label();
        regionField.setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REGION));
        regionField.setValue(importedCase.getRegion().toString());
        regionField.setWidthUndefined();
        caseInfoLayout.addComponent(regionField);

        Label districtField = new Label();
        districtField
                .setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISTRICT));
        districtField.setValue(importedCase.getDistrict().toString());
        districtField.setWidthUndefined();
        caseInfoLayout.addComponent(districtField);

        Label communityField = new Label();
        communityField
                .setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.COMMUNITY));
        communityField
                .setValue(importedCase.getCommunity() != null ? importedCase.getCommunity().toString() : "");
        communityField.setWidthUndefined();
        caseInfoLayout.addComponent(communityField);

        Label facilityField = new Label();
        facilityField.setCaption(
                I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_FACILITY));
        facilityField.setValue(FacilityHelper.buildFacilityString(null,
                importedCase.getHealthFacility() != null ? importedCase.getHealthFacility().toString() : "",
                importedCase.getHealthFacilityDetails()));
        facilityField.setWidthUndefined();
        caseInfoLayout.addComponent(facilityField);
    }

    outerCaseInfoLayout.addComponent(caseInfoLayout);
    layout.addComponent(outerCaseInfoLayout);

    // Imported person info
    VerticalLayout outerPersonInfoLayout = new VerticalLayout();
    outerPersonInfoLayout.setWidth(100, Unit.PERCENTAGE);
    CssStyles.style(outerPersonInfoLayout, CssStyles.BACKGROUND_ROUNDED_CORNERS,
            CssStyles.BACKGROUND_SUB_CRITERIA, CssStyles.VSPACE_3, "v-scrollable");

    Label importedPersonLabel = new Label(I18nProperties.getString(Strings.headingImportedPersonInfo));
    CssStyles.style(importedPersonLabel, CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
    outerPersonInfoLayout.addComponent(importedPersonLabel);

    HorizontalLayout personInfoLayout = new HorizontalLayout();
    personInfoLayout.setSpacing(true);
    personInfoLayout.setSizeUndefined();
    {
        Label firstNameField = new Label();
        firstNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.FIRST_NAME));
        firstNameField.setValue(importedPerson.getFirstName());
        firstNameField.setWidthUndefined();
        personInfoLayout.addComponent(firstNameField);

        Label lastNameField = new Label();
        lastNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.LAST_NAME));
        lastNameField.setValue(importedPerson.getLastName());
        lastNameField.setWidthUndefined();
        personInfoLayout.addComponent(lastNameField);

        Label nicknameField = new Label();
        nicknameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.NICKNAME));
        nicknameField.setValue(importedPerson.getNickname());
        nicknameField.setWidthUndefined();
        personInfoLayout.addComponent(nicknameField);

        Label ageField = new Label();
        ageField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.APPROXIMATE_AGE));
        ageField.setValue(ApproximateAgeHelper.formatApproximateAge(importedPerson.getApproximateAge(),
                importedPerson.getApproximateAgeType()));
        ageField.setWidthUndefined();
        personInfoLayout.addComponent(ageField);

        Label sexField = new Label();
        sexField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.SEX));
        sexField.setValue(importedPerson.getSex() != null ? importedPerson.getSex().toString() : "");
        sexField.setWidthUndefined();
        personInfoLayout.addComponent(sexField);

        Label presentConditionField = new Label();
        presentConditionField.setCaption(
                I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.PRESENT_CONDITION));
        presentConditionField.setValue(
                importedPerson.getPresentCondition() != null ? importedPerson.getPresentCondition().toString()
                        : null);
        presentConditionField.setWidthUndefined();
        personInfoLayout.addComponent(presentConditionField);

        Label regionField = new Label();
        regionField.setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.REGION));
        regionField.setValue(importedPerson.getAddress().getRegion() != null
                ? importedPerson.getAddress().getRegion().toString()
                : "");
        regionField.setWidthUndefined();
        personInfoLayout.addComponent(regionField);

        Label districtField = new Label();
        districtField
                .setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.DISTRICT));
        districtField.setValue(importedPerson.getAddress().getDistrict() != null
                ? importedPerson.getAddress().getDistrict().toString()
                : "");
        districtField.setWidthUndefined();
        personInfoLayout.addComponent(districtField);

        Label communityField = new Label();
        communityField
                .setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.COMMUNITY));
        communityField.setValue(importedPerson.getAddress().getCommunity() != null
                ? importedPerson.getAddress().getCommunity().toString()
                : "");
        communityField.setWidthUndefined();
        personInfoLayout.addComponent(communityField);

        Label cityField = new Label();
        cityField.setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.CITY));
        cityField.setValue(importedPerson.getAddress().getCity());
        cityField.setWidthUndefined();
        personInfoLayout.addComponent(cityField);
    }

    outerPersonInfoLayout.addComponent(personInfoLayout);
    layout.addComponent(outerPersonInfoLayout);

    // Person selection/creation
    selectPerson = new OptionGroup(null);
    selectPerson.addItem(SELECT_PERSON);
    selectPerson.setItemCaption(SELECT_PERSON, I18nProperties.getCaption(Captions.personSelect));
    CssStyles.style(selectPerson, CssStyles.VSPACE_NONE);
    selectPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            createNewPerson.setValue(null);
            personGrid.setEnabled(true);
            mergeCheckBox.setEnabled(true);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(personGrid.getSelectedRow() != null);
            }
        }
    });
    layout.addComponent(selectPerson);

    mergeCheckBox = new CheckBox();
    mergeCheckBox.setCaption(I18nProperties.getCaption(Captions.caseImportMergeCase));
    CssStyles.style(mergeCheckBox, CssStyles.VSPACE_3);
    layout.addComponent(mergeCheckBox);

    initPersonGrid();
    // Deselect "create new" when person is selected
    personGrid.addSelectionListener(e -> {
        if (e.getSelected().size() > 0) {
            createNewPerson.setValue(null);
        }
    });
    CssStyles.style(personGrid, CssStyles.VSPACE_3);
    layout.addComponent(personGrid);

    personGrid.addSelectionListener(e -> {
        if (selectionChangeCallback != null) {
            selectionChangeCallback.accept(!e.getSelected().isEmpty());
        }
    });

    createNewPerson = new OptionGroup(null);
    createNewPerson.addItem(CREATE_PERSON);
    createNewPerson.setItemCaption(CREATE_PERSON, I18nProperties.getCaption(Captions.personCreateNew));
    // Deselect grid when "create new" is selected
    createNewPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            selectPerson.setValue(null);
            personGrid.select(null);
            personGrid.setEnabled(false);
            mergeCheckBox.setEnabled(false);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(true);
            }
        }
    });
    layout.addComponent(createNewPerson);

    // Set field values based on internal value
    setInternalValue(super.getInternalValue());

    return layout;
}

From source file:de.symeda.sormas.ui.importer.ImportProgressLayout.java

License:Open Source License

public ImportProgressLayout(int totalCount, UI currentUI, Runnable cancelCallback) {
    this.totalCount = totalCount;
    this.currentUI = currentUI;

    setWidth(100, Unit.PERCENTAGE);/*from  www .  j a va2 s .  c o  m*/
    setMargin(true);

    // Info text and icon/progress circle
    infoLayout = new HorizontalLayout();
    infoLayout.setWidth(100, Unit.PERCENTAGE);
    infoLayout.setSpacing(true);
    initializeInfoComponents();
    currentInfoComponent = progressCircle;
    infoLayout.addComponent(currentInfoComponent);
    infoLabel = new Label(String.format(I18nProperties.getString(Strings.infoImportProcess), totalCount));
    infoLabel.setContentMode(ContentMode.HTML);
    infoLayout.addComponent(infoLabel);
    infoLayout.setExpandRatio(infoLabel, 1);

    addComponent(infoLayout);

    // Progress bar
    progressBar = new ProgressBar(0.0f);
    CssStyles.style(progressBar, CssStyles.VSPACE_TOP_3);
    addComponent(progressBar);
    progressBar.setWidth(100, Unit.PERCENTAGE);

    // Progress info
    HorizontalLayout progressInfoLayout = new HorizontalLayout();
    CssStyles.style(progressInfoLayout, CssStyles.VSPACE_TOP_5);
    progressInfoLayout.setSpacing(true);
    processedImportsLabel = new Label(
            String.format(I18nProperties.getCaption(Captions.importProcessed), 0, totalCount));
    progressInfoLayout.addComponent(processedImportsLabel);
    successfulImportsLabel = new Label(String.format(I18nProperties.getCaption(Captions.importImports), 0));
    CssStyles.style(successfulImportsLabel, CssStyles.LABEL_POSITIVE);
    progressInfoLayout.addComponent(successfulImportsLabel);
    importErrorsLabel = new Label(String.format(I18nProperties.getCaption(Captions.importErrors), 0));
    CssStyles.style(importErrorsLabel, CssStyles.LABEL_CRITICAL);
    progressInfoLayout.addComponent(importErrorsLabel);
    importDuplicatesLabel = new Label(String.format(I18nProperties.getCaption(Captions.importDuplicates), 0));
    CssStyles.style(importDuplicatesLabel, CssStyles.LABEL_WARNING);
    progressInfoLayout.addComponent(importDuplicatesLabel);
    importSkipsLabel = new Label(String.format(I18nProperties.getCaption(Captions.importSkips), 0));
    CssStyles.style(importSkipsLabel, CssStyles.LABEL_MINOR);
    progressInfoLayout.addComponent(importSkipsLabel);
    addComponent(progressInfoLayout);
    setComponentAlignment(progressInfoLayout, Alignment.TOP_RIGHT);

    // Cancel button
    closeCancelButton = new Button(I18nProperties.getCaption(Captions.actionCancel));
    CssStyles.style(closeCancelButton, CssStyles.VSPACE_TOP_2);
    cancelListener = e -> {
        cancelCallback.run();
    };
    closeCancelButton.addClickListener(cancelListener);
    addComponent(closeCancelButton);
    setComponentAlignment(closeCancelButton, Alignment.MIDDLE_RIGHT);
}