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.Menu.java

License:Open Source License

public Menu(Navigator navigator) {
    this.navigator = navigator;
    setPrimaryStyleName(ValoTheme.MENU_ROOT);
    menuPart = new CssLayout();
    menuPart.addStyleName(ValoTheme.MENU_PART);

    // header of the menu
    final HorizontalLayout top = new HorizontalLayout();
    top.setDefaultComponentAlignment(Alignment.TOP_CENTER);
    top.addStyleName(ValoTheme.MENU_TITLE);
    top.setSpacing(true);
    Label title = new Label("SORMAS");
    title.setSizeUndefined();/*from www  .j a va  2  s  .com*/
    Image image = new Image(null, new ThemeResource("img/sormas-logo.png"));
    CssStyles.style(image, ValoTheme.MENU_LOGO, ValoTheme.BUTTON_LINK);
    image.addClickListener(new MouseEvents.ClickListener() {
        @Override
        public void click(MouseEvents.ClickEvent event) {
            SormasUI.get().getNavigator().navigateTo(SurveillanceDashboardView.VIEW_NAME);
        }
    });
    top.addComponent(image);
    top.addComponent(title);
    menuPart.addComponent(top);

    // logout menu item
    MenuBar logoutMenu = new MenuBar();
    logoutMenu.addItem(I18nProperties.getCaption(Captions.actionLogout) + " ("
            + UserProvider.getCurrent().getUserName() + ")", VaadinIcons.SIGN_OUT, new Command() {
                @Override
                public void menuSelected(MenuItem selectedItem) {
                    LoginHelper.logout();
                }
            });

    logoutMenu.addStyleName("user-menu");
    menuPart.addComponent(logoutMenu);

    // button for toggling the visibility of the menu when on a small screen
    final Button showMenu = new Button(I18nProperties.getCaption(Captions.menu), new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent event) {
            if (menuPart.getStyleName().contains(VALO_MENU_VISIBLE)) {
                menuPart.removeStyleName(VALO_MENU_VISIBLE);
            } else {
                menuPart.addStyleName(VALO_MENU_VISIBLE);
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(VALO_MENU_TOGGLE);
    showMenu.setIcon(VaadinIcons.MENU);
    menuPart.addComponent(showMenu);

    // container for the navigation buttons, which are added by addView()
    menuItemsLayout = new CssLayout();
    menuItemsLayout.setPrimaryStyleName(VALO_MENUITEMS);
    menuPart.addComponent(menuItemsLayout);

    addComponent(menuPart);
}

From source file:de.symeda.sormas.ui.person.PersonSelectField.java

License:Open Source License

@Override
protected Component initContent() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);//from w w  w .  j  av  a2 s .  c om
    layout.setSizeUndefined();
    layout.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout nameLayout = new HorizontalLayout();
    nameLayout.setSpacing(true);
    nameLayout.setWidth(100, Unit.PERCENTAGE);

    firstNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.FIRST_NAME));
    firstNameField.setWidth(100, Unit.PERCENTAGE);
    firstNameField.setRequired(true);
    nameLayout.addComponent(firstNameField);

    lastNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.LAST_NAME));
    lastNameField.setWidth(100, Unit.PERCENTAGE);
    lastNameField.setRequired(true);
    nameLayout.addComponent(lastNameField);

    CssStyles.style(searchMatchesButton, CssStyles.FORCE_CAPTION, ValoTheme.BUTTON_PRIMARY);
    searchMatchesButton.addClickListener(e -> {
        personGrid.reload(firstNameField.getValue(), lastNameField.getValue());
        selectBestMatch();
    });
    nameLayout.addComponent(searchMatchesButton);

    layout.addComponent(nameLayout);

    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);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(personGrid.getSelectedRow() != null);
            }
        }
    });
    layout.addComponent(selectPerson);

    initPersonGrid();
    // unselect "create new" when person is selected
    personGrid.addSelectionListener(e -> {
        if (e.getSelected().size() > 0) {
            createNewPerson.setValue(null);
        }
    });
    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));
    // unselect grid when "create new" is selected
    createNewPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            selectPerson.setValue(null);
            personGrid.select(null);
            personGrid.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.reports.ReportsView.java

License:Open Source License

public HorizontalLayout createFilterBar() {
    HorizontalLayout filterLayout = new HorizontalLayout();
    filterLayout.setMargin(false);// w w  w  .  j a  v  a 2s  .co  m
    filterLayout.setSpacing(true);
    filterLayout.addStyleName(CssStyles.VSPACE_3);
    filterLayout.setWidth(100, Unit.PERCENTAGE);

    EpiWeek prevEpiWeek = DateHelper.getPreviousEpiWeek(new Date());
    int year = prevEpiWeek.getYear();
    int week = prevEpiWeek.getWeek();

    yearFilter = new ComboBox();
    yearFilter.setWidth(200, Unit.PIXELS);
    yearFilter.addItems(DateHelper.getYearsToNow());
    yearFilter.select(year);
    yearFilter.setCaption(I18nProperties.getString(Strings.year));
    yearFilter.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    yearFilter.addValueChangeListener(e -> {
        updateEpiWeeks((int) e.getProperty().getValue(), (int) epiWeekFilter.getValue());
        reloadGrid();
    });
    filterLayout.addComponent(yearFilter);

    epiWeekFilter = new ComboBox();
    epiWeekFilter.setWidth(200, Unit.PIXELS);
    updateEpiWeeks(year, week);
    epiWeekFilter.setCaption(I18nProperties.getString(Strings.epiWeek));
    epiWeekFilter.addValueChangeListener(e -> {
        reloadGrid();
    });
    filterLayout.addComponent(epiWeekFilter);

    Button lastWeekButton = new Button(I18nProperties.getCaption(Captions.dashboardLastWeek));
    lastWeekButton.addStyleName(CssStyles.FORCE_CAPTION);
    lastWeekButton.addClickListener(e -> {
        EpiWeek epiWeek = DateHelper.getPreviousEpiWeek(new Date());
        yearFilter.select(epiWeek.getYear());
        epiWeekFilter.select(epiWeek.getWeek());
    });
    filterLayout.addComponent(lastWeekButton);

    Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
    infoLabel.setDescription(I18nProperties.getString(Strings.infoWeeklyReportsView));
    infoLabel.setSizeUndefined();
    CssStyles.style(infoLabel, CssStyles.LABEL_XLARGE, CssStyles.LABEL_SECONDARY);
    filterLayout.addComponent(infoLabel);
    filterLayout.setComponentAlignment(infoLabel, Alignment.MIDDLE_RIGHT);
    filterLayout.setExpandRatio(infoLabel, 1);

    return filterLayout;
}

From source file:de.symeda.sormas.ui.samples.PathogenTestListEntry.java

License:Open Source License

public PathogenTestListEntry(PathogenTestDto pathogenTest) {
    setSpacing(true);/*from   w  w  w  .ja  va  2 s.  c o m*/
    setMargin(false);
    setWidth(100, Unit.PERCENTAGE);
    addStyleName(CssStyles.SORMAS_LIST_ENTRY);
    this.pathogenTest = pathogenTest;

    VerticalLayout labelLayout = new VerticalLayout();
    labelLayout.setSpacing(false);
    labelLayout.setMargin(false);
    labelLayout.setWidth(100, Unit.PERCENTAGE);
    addComponent(labelLayout);
    setExpandRatio(labelLayout, 1);

    HorizontalLayout topLabelLayout = new HorizontalLayout();
    topLabelLayout.setSpacing(false);
    topLabelLayout.setMargin(false);
    topLabelLayout.setWidth(100, Unit.PERCENTAGE);
    labelLayout.addComponent(topLabelLayout);
    Label labelTopLeft = new Label(
            PathogenTestType.toString(pathogenTest.getTestType(), pathogenTest.getTestTypeText()));
    CssStyles.style(labelTopLeft, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
    topLabelLayout.addComponent(labelTopLeft);

    if (pathogenTest.getTestResultVerified()) {
        Label labelTopRight = new Label(VaadinIcons.CHECK_CIRCLE.getHtml(), ContentMode.HTML);
        labelTopRight.setSizeUndefined();
        labelTopRight.addStyleName(CssStyles.LABEL_LARGE);
        labelTopRight.setDescription(I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX,
                PathogenTestDto.TEST_RESULT_VERIFIED));
        topLabelLayout.addComponent(labelTopRight);
        topLabelLayout.setComponentAlignment(labelTopRight, Alignment.TOP_RIGHT);
    }

    if (!DataHelper.isNullOrEmpty(pathogenTest.getTestResultText())) {
        Label resultTextLabel = new Label(pathogenTest.getTestResultText());
        labelLayout.addComponent(resultTextLabel);
    }

    HorizontalLayout middleLabelLayout = new HorizontalLayout();
    middleLabelLayout.setSpacing(false);
    middleLabelLayout.setMargin(false);
    middleLabelLayout.setWidth(100, Unit.PERCENTAGE);
    labelLayout.addComponent(middleLabelLayout);
    Label labelLeft = new Label(DataHelper.toStringNullable(
            DiseaseHelper.toString(pathogenTest.getTestedDisease(), pathogenTest.getTestedDiseaseDetails())));
    middleLabelLayout.addComponent(labelLeft);

    Label labelRight = new Label(DateHelper.formatLocalShortDateTime(pathogenTest.getTestDateTime()));
    labelRight.addStyleName(CssStyles.ALIGN_RIGHT);
    middleLabelLayout.addComponent(labelRight);
    middleLabelLayout.setComponentAlignment(labelRight, Alignment.TOP_RIGHT);

    Label labelBottom = new Label(DataHelper.toStringNullable(pathogenTest.getTestResult()));
    CssStyles.style(labelBottom, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
    if (pathogenTest.getTestResult() == PathogenTestResultType.POSITIVE)
        CssStyles.style(labelBottom, CssStyles.LABEL_CRITICAL);
    else
        CssStyles.style(labelBottom, CssStyles.LABEL_WARNING);
    labelLayout.addComponent(labelBottom);
}

From source file:de.symeda.sormas.ui.samples.SampleGridComponent.java

License:Open Source License

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

    UserDto user = UserProvider.getCurrent().getUser();

    testResultFilter = new ComboBox();
    testResultFilter.setWidth(140, Unit.PIXELS);
    testResultFilter.setInputPrompt(
            I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TEST_RESULT));
    testResultFilter.addItems((Object[]) PathogenTestResultType.values());
    testResultFilter.addValueChangeListener(e -> {
        criteria.pathogenTestResult(((PathogenTestResultType) e.getProperty().getValue()));
        samplesView.navigateTo(criteria);
    });
    filterLayout.addComponent(testResultFilter);

    specimenConditionFilter = new ComboBox();
    specimenConditionFilter.setWidth(140, Unit.PIXELS);
    specimenConditionFilter.setInputPrompt(
            I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, SampleDto.SPECIMEN_CONDITION));
    specimenConditionFilter.addItems((Object[]) SpecimenCondition.values());
    specimenConditionFilter.addValueChangeListener(e -> {
        criteria.specimenCondition(((SpecimenCondition) e.getProperty().getValue()));
        samplesView.navigateTo(criteria);
    });
    filterLayout.addComponent(specimenConditionFilter);

    classificationFilter = new ComboBox();
    classificationFilter.setWidth(140, Unit.PIXELS);
    classificationFilter.setInputPrompt(
            I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.CASE_CLASSIFICATION));
    classificationFilter.addItems((Object[]) CaseClassification.values());
    classificationFilter.addValueChangeListener(e -> {
        criteria.caseClassification(((CaseClassification) e.getProperty().getValue()));
        samplesView.navigateTo(criteria);
    });
    filterLayout.addComponent(classificationFilter);

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

    regionFilter = new ComboBox();
    if (user.getRegion() == null) {
        regionFilter.setWidth(140, Unit.PIXELS);
        regionFilter
                .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REGION));
        regionFilter.addItems(FacadeProvider.getRegionFacade().getAllAsReference());
        regionFilter.addValueChangeListener(e -> {
            RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
            criteria.region(region);
            samplesView.navigateTo(criteria);
        });
        filterLayout.addComponent(regionFilter);
    }

    districtFilter = new ComboBox();
    districtFilter.setWidth(140, Unit.PIXELS);
    districtFilter
            .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISTRICT));
    districtFilter.setDescription(I18nProperties.getDescription(Descriptions.descDistrictFilter));
    districtFilter.addValueChangeListener(e -> {
        criteria.district(((DistrictReferenceDto) e.getProperty().getValue()));
        samplesView.navigateTo(criteria);
    });

    if (user.getRegion() != null) {
        districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllByRegion(user.getRegion().getUuid()));
        districtFilter.setEnabled(true);
    } else {
        regionFilter.addValueChangeListener(e -> {
            RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
            districtFilter.removeAllItems();
            if (region != null) {
                districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllByRegion(region.getUuid()));
                districtFilter.setEnabled(true);
            } else {
                districtFilter.setEnabled(false);
            }
        });
        districtFilter.setEnabled(false);
    }
    filterLayout.addComponent(districtFilter);

    labFilter = new ComboBox();
    labFilter.setWidth(140, Unit.PIXELS);
    labFilter.setInputPrompt(I18nProperties.getPrefixCaption(SampleIndexDto.I18N_PREFIX, SampleIndexDto.LAB));
    labFilter.addItems(FacadeProvider.getFacilityFacade().getAllLaboratories(true));
    labFilter.addValueChangeListener(e -> {
        criteria.laboratory(((FacilityReferenceDto) e.getProperty().getValue()));
        samplesView.navigateTo(criteria);
    });
    filterLayout.addComponent(labFilter);

    searchField = new TextField();
    searchField.setWidth(200, Unit.PIXELS);
    searchField.setNullRepresentation("");
    searchField.setInputPrompt(I18nProperties.getString(Strings.promptSamplesSearchField));
    searchField.addTextChangeListener(e -> {
        criteria.caseCodeIdLike(e.getText());
        grid.reload();
    });
    filterLayout.addComponent(searchField);

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

    return filterLayout;
}

From source file:de.symeda.sormas.ui.samples.SampleGridComponent.java

License:Open Source License

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

    statusButtons = new HashMap<>();

    HorizontalLayout buttonFilterLayout = new HorizontalLayout();
    buttonFilterLayout.setSpacing(true);
    {/*from w ww .ja  v  a2  s.  co m*/
        Button statusAll = new Button(I18nProperties.getCaption(Captions.all), e -> processStatusChange(null));
        CssStyles.style(statusAll, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
        statusAll.setCaptionAsHtml(true);
        buttonFilterLayout.addComponent(statusAll);
        statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
        activeStatusButton = statusAll;

        Button notShippedButton = new Button(I18nProperties.getCaption(Captions.sampleNotShipped),
                e -> processStatusChange(NOT_SHIPPED));
        initializeStatusButton(notShippedButton, buttonFilterLayout, NOT_SHIPPED,
                I18nProperties.getCaption(Captions.sampleNotShipped));
        Button shippedButton = new Button(I18nProperties.getCaption(Captions.sampleShipped),
                e -> processStatusChange(SHIPPED));
        initializeStatusButton(shippedButton, buttonFilterLayout, SHIPPED,
                I18nProperties.getCaption(Captions.sampleShipped));
        Button receivedButton = new Button(I18nProperties.getCaption(Captions.sampleReceived),
                e -> processStatusChange(RECEIVED));
        initializeStatusButton(receivedButton, buttonFilterLayout, RECEIVED,
                I18nProperties.getCaption(Captions.sampleReceived));
        Button referredButton = new Button(I18nProperties.getCaption(Captions.sampleReferred),
                e -> processStatusChange(REFERRED));
        initializeStatusButton(referredButton, buttonFilterLayout, REFERRED,
                I18nProperties.getCaption(Captions.sampleReferred));
    }

    shipmentFilterLayout.addComponent(buttonFilterLayout);

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

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

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

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

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

    return shipmentFilterLayout;
}

From source file:de.symeda.sormas.ui.samples.SampleListComponent.java

License:Open Source License

public SampleListComponent(CaseReferenceDto caseRef) {
    setWidth(100, Unit.PERCENTAGE);//from   ww  w. j a  v  a2 s . com
    setMargin(false);
    setSpacing(false);

    HorizontalLayout componentHeader = new HorizontalLayout();
    componentHeader.setMargin(false);
    componentHeader.setSpacing(false);
    componentHeader.setWidth(100, Unit.PERCENTAGE);
    addComponent(componentHeader);

    list = new SampleList(caseRef);
    addComponent(list);
    list.reload();

    Label tasksHeader = new Label(I18nProperties.getString(Strings.entitySamples));
    tasksHeader.addStyleName(CssStyles.H3);
    componentHeader.addComponent(tasksHeader);

    if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_CREATE)) {
        createButton = new Button(I18nProperties.getCaption(Captions.sampleNewSample));
        createButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        createButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        createButton
                .addClickListener(e -> ControllerProvider.getSampleController().create(caseRef, this::reload));
        componentHeader.addComponent(createButton);
        componentHeader.setComponentAlignment(createButton, Alignment.MIDDLE_RIGHT);
    }
}

From source file:de.symeda.sormas.ui.samples.SampleListEntry.java

License:Open Source License

public SampleListEntry(SampleIndexDto sample) {

    this.sample = sample;

    setMargin(false);/*from ww w.java  2s.  com*/
    setSpacing(true);
    setWidth(100, Unit.PERCENTAGE);
    addStyleName(CssStyles.SORMAS_LIST_ENTRY);

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setWidth(100, Unit.PERCENTAGE);
    mainLayout.setMargin(false);
    mainLayout.setSpacing(false);
    addComponent(mainLayout);
    setExpandRatio(mainLayout, 1);

    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setWidth(100, Unit.PERCENTAGE);
    topLayout.setMargin(false);
    topLayout.setSpacing(false);
    mainLayout.addComponent(topLayout);

    VerticalLayout topLeftLayout = new VerticalLayout();
    {
        topLeftLayout.setMargin(false);
        topLeftLayout.setSpacing(false);

        Label materialLabel = new Label(DataHelper.toStringNullable(sample.getSampleMaterial()));
        CssStyles.style(materialLabel, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
        topLeftLayout.addComponent(materialLabel);

        Label dateTimeLabel = new Label(
                I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, SampleDto.SAMPLE_DATE_TIME) + ": "
                        + DateHelper.formatLocalShortDate(sample.getSampleDateTime()));
        topLeftLayout.addComponent(dateTimeLabel);

        Label labLabel = new Label(DataHelper.toStringNullable(sample.getLab()));
        topLeftLayout.addComponent(labLabel);
    }
    topLayout.addComponent(topLeftLayout);

    VerticalLayout topRightLayout = new VerticalLayout();
    {
        topRightLayout.addStyleName(CssStyles.ALIGN_RIGHT);
        topRightLayout.setMargin(false);
        topRightLayout.setSpacing(false);

        Label resultLabel = new Label();
        CssStyles.style(resultLabel, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
        if (sample.getPathogenTestResult() != null) {
            resultLabel.setValue(DataHelper.toStringNullable(sample.getPathogenTestResult()));
            if (sample.getPathogenTestResult() == PathogenTestResultType.POSITIVE) {
                resultLabel.addStyleName(CssStyles.LABEL_CRITICAL);
            } else if (sample.getPathogenTestResult() == PathogenTestResultType.INDETERMINATE) {
                resultLabel.addStyleName(CssStyles.LABEL_WARNING);
            }
        } else if (sample.getSpecimenCondition() == SpecimenCondition.NOT_ADEQUATE) {
            resultLabel.setValue(DataHelper.toStringNullable(sample.getSpecimenCondition()));
            resultLabel.addStyleName(CssStyles.LABEL_WARNING);
        }
        topRightLayout.addComponent(resultLabel);

        Label referredLabel = new Label();
        CssStyles.style(referredLabel, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
        if (sample.isReferred()) {
            referredLabel.setValue(I18nProperties.getCaption(Captions.sampleReferredShort));
            referredLabel.addStyleName(CssStyles.LABEL_NOT);
        } else if (sample.isReceived()) {
            referredLabel.setValue(I18nProperties.getCaption(Captions.sampleReceived) + " "
                    + DateHelper.formatLocalShortDate(sample.getReceivedDate()));
        } else if (sample.isShipped()) {
            referredLabel.setValue(I18nProperties.getCaption(Captions.sampleShipped) + " "
                    + DateHelper.formatLocalShortDate(sample.getShipmentDate()));
        } else {
            referredLabel.setValue(I18nProperties.getCaption(Captions.sampleNotShippedLong));
        }
        topRightLayout.addComponent(referredLabel);
    }
    topLayout.addComponent(topRightLayout);
    topLayout.setComponentAlignment(topRightLayout, Alignment.TOP_RIGHT);

    if (UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)) {
        Label labelAdditionalTests = new Label(I18nProperties.getString(Strings.entityAdditionalTests) + " "
                + sample.getAdditionalTestingStatus().toString().toLowerCase());
        mainLayout.addComponent(labelAdditionalTests);
    }
}

From source file:de.symeda.sormas.ui.statistics.DatabaseExportView.java

License:Open Source License

public DatabaseExportView() {
    super(VIEW_NAME);

    databaseTableToggles = new HashMap<>();
    databaseExportLayout = new VerticalLayout();
    databaseExportLayout.setSpacing(false);
    databaseExportLayout.setMargin(false);
    HorizontalLayout headerLayout = new HorizontalLayout();
    headerLayout.setSpacing(true);
    headerLayout.setMargin(false);/*from   w ww .j ava  2s  .  com*/
    Label infoLabel = new Label(I18nProperties.getString(Strings.infoDatabaseExportTables));
    headerLayout.addComponent(infoLabel);
    headerLayout.setComponentAlignment(infoLabel, Alignment.MIDDLE_LEFT);
    headerLayout.addComponent(createSelectionButtonsLayout());
    databaseExportLayout.addComponent(headerLayout);
    databaseExportLayout.addComponent(createDatabaseTablesLayout());
    Button exportButton = new Button(I18nProperties.getCaption(Captions.export), VaadinIcons.DOWNLOAD);
    CssStyles.style(exportButton, ValoTheme.BUTTON_PRIMARY);
    StreamResource streamResource = DownloadUtil.createDatabaseExportStreamResource(this,
            "sormas_export_" + DateHelper.formatDateForExport(new Date()) + ".zip", "application/zip");
    FileDownloader fileDownloader = new FileDownloader(streamResource);
    fileDownloader.extend(exportButton);
    databaseExportLayout.addComponent(exportButton);
    databaseExportLayout.setMargin(true);
    databaseExportLayout.setSpacing(true);

    addComponent(databaseExportLayout);
}