Example usage for com.vaadin.ui HorizontalLayout setExpandRatio

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

Introduction

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

Prototype

public void setExpandRatio(Component component, float ratio) 

Source Link

Document

This method is used to control how excess space in layout is distributed among components.

Usage

From source file:de.symeda.sormas.ui.dashboard.statistics.DashboardStatisticsGraphicalGrowthElement.java

License:Open Source License

public DashboardStatisticsGraphicalGrowthElement(String caption, String svgFillClass) {
    this.setMargin(false);
    this.setSpacing(false);

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

    Label captionLabel = new Label(caption);
    CssStyles.style(captionLabel, CssStyles.LABEL_SECONDARY, CssStyles.LABEL_BOLD);
    captionAndValueLayout.addComponent(captionLabel);

    countLabel = new Label();
    CssStyles.style(countLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_BOLD, CssStyles.HSPACE_RIGHT_4);
    countLabel.setWidthUndefined();// ww  w .  ja  va 2 s.c o m
    captionAndValueLayout.addComponent(countLabel);
    growthLabel = new Label();
    growthLabel.setHeightUndefined();
    growthLabel.setWidthUndefined();
    growthLabel.setContentMode(ContentMode.HTML);
    CssStyles.style(growthLabel, CssStyles.LABEL_SMALL, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_BOLD,
            CssStyles.HSPACE_RIGHT_4);
    captionAndValueLayout.addComponent(growthLabel);
    percentageLabel = new Label();
    CssStyles.style(percentageLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_BOLD);
    percentageLabel.setWidthUndefined();
    captionAndValueLayout.addComponent(percentageLabel);

    captionAndValueLayout.setComponentAlignment(captionLabel, Alignment.MIDDLE_LEFT);
    captionAndValueLayout.setComponentAlignment(countLabel, Alignment.MIDDLE_RIGHT);
    captionAndValueLayout.setComponentAlignment(growthLabel, Alignment.MIDDLE_RIGHT);
    captionAndValueLayout.setComponentAlignment(percentageLabel, Alignment.MIDDLE_RIGHT);
    captionAndValueLayout.setExpandRatio(captionLabel, 1);

    addComponent(captionAndValueLayout);

    svgBarElement = new SvgBarElement(svgFillClass);
    svgBarElement.setWidth(100, Unit.PERCENTAGE);
    addComponent(svgBarElement);
}

From source file:de.symeda.sormas.ui.dashboard.statistics.DashboardStatisticsSubComponent.java

License:Open Source License

public void addHeader(String headline, Image icon, boolean showTotalCount) {
    HorizontalLayout headerLayout = new HorizontalLayout();
    headerLayout.setWidth(100, Unit.PERCENTAGE);
    headerLayout.setSpacing(true);/*from www  .ja va  2  s .  c  o m*/
    headerLayout.setMargin(false);
    CssStyles.style(headerLayout, CssStyles.VSPACE_4);

    VerticalLayout labelAndTotalLayout = new VerticalLayout();
    {
        labelAndTotalLayout.setMargin(false);
        labelAndTotalLayout.setSpacing(false);
        Label headlineLabel = new Label(headline);
        CssStyles.style(headlineLabel, CssStyles.H2, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);
        labelAndTotalLayout.addComponent(headlineLabel);

        if (showTotalCount) {
            totalCountLabel = new Label();
            CssStyles.style(totalCountLabel, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_XXXLARGE,
                    CssStyles.LABEL_BOLD, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);
            labelAndTotalLayout.addComponent(totalCountLabel);
        } else {
            CssStyles.style(labelAndTotalLayout, CssStyles.VSPACE_4);
        }

    }
    headerLayout.addComponent(labelAndTotalLayout);
    headerLayout.setComponentAlignment(labelAndTotalLayout, Alignment.BOTTOM_LEFT);
    headerLayout.setHeightUndefined();
    headerLayout.setExpandRatio(labelAndTotalLayout, 1);

    if (icon != null) {
        headerLayout.addComponent(icon);
        headerLayout.setComponentAlignment(icon, Alignment.TOP_RIGHT);
    }

    addComponent(headerLayout);
    setExpandRatio(headerLayout, 0);
}

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

License:Open Source License

private Layout createCaseFatalityComponent() {
    HorizontalLayout component = new HorizontalLayout();
    component.setMargin(false);//from   w ww.j  av a2  s .  c om
    component.setSpacing(false);
    component.setWidth(100, Unit.PERCENTAGE);

    // rate
    {
        HorizontalLayout rateLayout = new HorizontalLayout();
        rateLayout.setMargin(false);
        rateLayout.setSpacing(false);

        // value
        caseFatalityRateValue = new Label("00.0%");
        CssStyles.style(caseFatalityRateValue, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_BOLD,
                CssStyles.LABEL_LARGE, CssStyles.HSPACE_RIGHT_3, CssStyles.VSPACE_TOP_5);
        rateLayout.addComponent(caseFatalityRateValue);

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

        component.addComponent(rateLayout);
        component.setExpandRatio(rateLayout, 1);
    }

    // count      
    {
        HorizontalLayout countLayout = new HorizontalLayout();
        countLayout.setMargin(false);
        countLayout.setSpacing(false);

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

        // value
        caseFatalityCountValue = new Label("0");
        CssStyles.style(caseFatalityCountValue, CssStyles.LABEL_PRIMARY, CssStyles.LABEL_BOLD,
                CssStyles.LABEL_LARGE, CssStyles.HSPACE_RIGHT_5, CssStyles.VSPACE_TOP_5);
        countLayout.addComponent(caseFatalityCountValue);

        // growth
        caseFatalityCountGrowth = new Label("", ContentMode.HTML);
        CssStyles.style(caseFatalityCountGrowth, CssStyles.VSPACE_TOP_5);
        countLayout.addComponent(caseFatalityCountGrowth);

        component.addComponent(countLayout);
        component.setExpandRatio(countLayout, 0);
        component.setComponentAlignment(countLayout, Alignment.MIDDLE_RIGHT);
    }

    return component;
}

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  w  w w. ja v  a 2  s .c om
    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  v  a 2s  .co  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.dashboard.surveillance.SurveillanceOverviewLayout.java

License:Open Source License

private void addDiseaseBurdenView() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(false);/*  w  ww  . j  a v  a2  s .  c  o  m*/

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

    // "Expand" and "Collapse" buttons
    Button showTableViewButton = new Button("", VaadinIcons.TABLE);
    CssStyles.style(showTableViewButton, CssStyles.BUTTON_SUBTLE);
    showTableViewButton.addStyleName(CssStyles.VSPACE_NONE);

    Button showTileViewButton = new Button("", VaadinIcons.SQUARE_SHADOW);
    CssStyles.style(showTileViewButton, CssStyles.BUTTON_SUBTLE);
    showTileViewButton.addStyleName(CssStyles.VSPACE_NONE);

    showTableViewButton.addClickListener(e -> {
        layout.removeComponent(diseaseTileViewLayout);
        layout.addComponent(diseaseBurdenComponent);
        layout.setExpandRatio(diseaseBurdenComponent, 1);

        layout.removeComponent(showTableViewButton);
        layout.addComponent(showTileViewButton);
        layout.setComponentAlignment(showTileViewButton, Alignment.TOP_RIGHT);
    });
    showTileViewButton.addClickListener(e -> {
        layout.removeComponent(diseaseBurdenComponent);
        layout.addComponent(diseaseTileViewLayout);
        layout.setExpandRatio(diseaseTileViewLayout, 1);

        layout.removeComponent(showTileViewButton);
        layout.addComponent(showTableViewButton);
        layout.setComponentAlignment(showTableViewButton, Alignment.TOP_RIGHT);
    });

    layout.addComponent(showTableViewButton);
    layout.setComponentAlignment(showTableViewButton, Alignment.TOP_RIGHT);

    diseaseBurdenView = layout;
    addComponent(diseaseBurdenView, BURDEN_LOC);

    if (UserRole.isSupervisor(UserProvider.getCurrent().getUser().getUserRoles()))
        showTableViewButton.click();
}

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

License:Open Source License

private void addShowMoreAndLessButtons() {

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setHeightUndefined();// w  w  w.  ja  va  2  s  . c o m
    buttonsLayout.setWidth(100, Unit.PERCENTAGE);
    buttonsLayout.setMargin(new MarginInfo(false, true));

    showMoreButton = new Button(I18nProperties.getCaption(Captions.dashboardShowAllDiseases),
            VaadinIcons.CHEVRON_DOWN);
    CssStyles.style(showMoreButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.VSPACE_TOP_NONE, CssStyles.VSPACE_4);
    showLessButton = new Button(I18nProperties.getCaption(Captions.dashboardShowFirstDiseases),
            VaadinIcons.CHEVRON_UP);
    CssStyles.style(showLessButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.VSPACE_TOP_NONE, CssStyles.VSPACE_4);
    hideOverview = new CheckBox(I18nProperties.getCaption(Captions.dashboardHideOverview));
    CssStyles.style(hideOverview, CssStyles.VSPACE_3);

    showMoreButton.addClickListener(e -> {
        isShowingAllDiseases = true;
        refresh();

        showMoreButton.setVisible(false);
        showLessButton.setVisible(true);
    });

    showLessButton.addClickListener(e -> {
        isShowingAllDiseases = false;
        refresh();

        showLessButton.setVisible(false);
        showMoreButton.setVisible(true);
    });

    hideOverview.addValueChangeListener(e -> {
        if (hideOverview.getValue()) {
            diseaseBurdenView.setVisible(false);
            diseaseDifferenceComponent.setVisible(false);
            showLessButton.setVisible(false);
            showMoreButton.setVisible(false);
        } else {
            diseaseBurdenView.setVisible(true);
            diseaseDifferenceComponent.setVisible(true);
            showLessButton.setVisible(isShowingAllDiseases);
            showMoreButton.setVisible(!isShowingAllDiseases);
        }
    });

    buttonsLayout.addComponent(showMoreButton);
    buttonsLayout.addComponent(showLessButton);
    buttonsLayout.setComponentAlignment(showMoreButton, Alignment.BOTTOM_CENTER);
    buttonsLayout.setExpandRatio(showMoreButton, 1);
    buttonsLayout.setComponentAlignment(showLessButton, Alignment.BOTTOM_CENTER);
    buttonsLayout.setExpandRatio(showLessButton, 1);
    buttonsLayout.addComponent(hideOverview);
    buttonsLayout.setComponentAlignment(hideOverview, Alignment.BOTTOM_RIGHT);
    buttonsLayout.setExpandRatio(hideOverview, 0);

    addComponent(buttonsLayout, EXTEND_BUTTONS_LOC);

    isShowingAllDiseases = false;
    showLessButton.setVisible(false);
    buttonsLayout.setExpandRatio(showLessButton, 1);
}

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

License:Open Source License

public HorizontalLayout createTopBar() {
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setSpacing(true);/*w  w w . j  ava2 s  .c  om*/
    topLayout.setWidth("100%");

    Label header = new Label(I18nProperties.getPrefixCaption(EventDto.I18N_PREFIX, EventDto.EVENT_PERSONS));
    header.setSizeUndefined();
    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 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 w w  .j a  va2 s.  c om*/
        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.reports.ReportsView.java

License:Open Source License

public HorizontalLayout createFilterBar() {
    HorizontalLayout filterLayout = new HorizontalLayout();
    filterLayout.setMargin(false);//w  w  w.  j  a  va  2 s  .  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;
}