Example usage for com.vaadin.ui Label setVisible

List of usage examples for com.vaadin.ui Label setVisible

Introduction

In this page you can find the example usage for com.vaadin.ui Label setVisible.

Prototype

@Override
    public void setVisible(boolean visible) 

Source Link

Usage

From source file:com.constellio.app.ui.pages.base.MainLayoutImpl.java

protected Component buildLicense() {
    boolean showFooter = !"true".equals(System.getProperty("no_footer_message"));
    Label licenseLabel = new Label($("MainLayout.footerLicense"));
    licenseLabel.addStyleName(ValoTheme.LABEL_TINY);
    licenseLabel.setContentMode(ContentMode.HTML);
    licenseLabel.setVisible(showFooter);
    return licenseLabel;
}

From source file:com.hybridbpm.ui.MainMenu.java

License:Apache License

protected void addMenuItemComponent(final ViewDefinition viewDefinition, String parameters) {
    CssLayout dashboardWrapper = new CssLayout();
    dashboardWrapper.addStyleName("badgewrapper");
    dashboardWrapper.addStyleName(ValoTheme.MENU_ITEM);
    dashboardWrapper.setWidth(100.0f, Sizeable.Unit.PERCENTAGE);

    Label notificationsBadge = new Label();
    notificationsBadge.addStyleName(ValoTheme.MENU_BADGE);
    notificationsBadge.setWidthUndefined();
    notificationsBadge.setVisible(false);

    if (viewDefinition != null) {
        dashboardWrapper.addComponents(new ValoMenuItemButton(viewDefinition, parameters), notificationsBadge);
        menuItemsLayout.addComponent(dashboardWrapper);
    } else if (HybridbpmUI.getDeveloperMode()) {
        dashboardWrapper.addComponents(new ValoMenuAddViewButton(), notificationsBadge);
        menuItemsLayout.addComponent(dashboardWrapper);
    }//from  w  w  w  . j av  a  2s  .c  o  m
}

From source file:com.hybridbpm.ui.MainMenu.java

License:Apache License

public void changeNotification(String viewUrl, Boolean visible, String message) {
    for (Component component : menuItemsLayout) {
        if (component instanceof CssLayout) {
            Component button = ((CssLayout) component).getComponent(0);
            if (button instanceof ValoMenuItemButton) {
                ValoMenuItemButton valoMenuItemButton = (ValoMenuItemButton) button;
                if (valoMenuItemButton.getView().getUrl().equals(viewUrl)) {
                    Label label = (Label) ((CssLayout) component).getComponent(1);
                    label.setValue(message);
                    label.setVisible(visible);
                }//w  w w  .j av  a 2  s. c o  m
            }
        }
    }
}

From source file:com.peergreen.webconsole.core.vaadin7.BaseUI.java

License:Open Source License

/**
 * Build login view//ww  w.  j  a  v  a 2  s.co  m
 *
 * @param exit
 */
private void buildLoginView(final boolean exit) {
    if (exit) {
        root.removeAllComponents();
    }
    notifierService.closeAll();

    addStyleName("login");

    VerticalLayout loginLayout = new VerticalLayout();
    loginLayout.setId("webconsole_loginlayout_id");
    loginLayout.setSizeFull();
    loginLayout.addStyleName("login-layout");
    root.addComponent(loginLayout);

    final CssLayout loginPanel = new CssLayout();
    loginPanel.addStyleName("login-panel");

    HorizontalLayout labels = new HorizontalLayout();
    labels.setWidth(MAX_WIDTH);
    labels.setMargin(true);
    loginPanel.addComponent(labels);

    Label welcome = new Label("Welcome");
    welcome.addStyleName("h4");
    labels.addComponent(welcome);
    labels.setComponentAlignment(welcome, Alignment.MIDDLE_LEFT);

    Label title = new Label(consoleName);
    //title.setSizeUndefined();
    title.addStyleName("h2");
    title.addStyleName("light");
    labels.addComponent(title);
    labels.setComponentAlignment(title, Alignment.MIDDLE_RIGHT);

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.setMargin(true);
    fields.addStyleName("fields");

    final TextField username = new TextField("Username");
    username.focus();
    username.setId("webconsole_login_username");
    fields.addComponent(username);

    final PasswordField password = new PasswordField("Password");
    password.setId("webconsole_login_password");
    fields.addComponent(password);

    final Button signin = new Button("Sign In");
    signin.setId("webconsole_login_signin");
    signin.addStyleName("default");
    fields.addComponent(signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    final ShortcutListener enter = new ShortcutListener("Sign In", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            signin.click();
        }
    };

    signin.addShortcutListener(enter);
    loginPanel.addComponent(fields);

    HorizontalLayout bottomRow = new HorizontalLayout();
    bottomRow.setWidth(MAX_WIDTH);
    bottomRow.setMargin(new MarginInfo(false, true, false, true));
    final CheckBox keepLoggedIn = new CheckBox("Keep me logged in");
    bottomRow.addComponent(keepLoggedIn);
    bottomRow.setComponentAlignment(keepLoggedIn, Alignment.MIDDLE_LEFT);
    // Add new error message
    final Label error = new Label("Wrong username or password.", ContentMode.HTML);
    error.setId("webconsole_login_error");
    error.addStyleName("error");
    error.setSizeUndefined();
    error.addStyleName("light");
    // Add animation
    error.addStyleName("v-animate-reveal");
    error.setVisible(false);
    bottomRow.addComponent(error);
    bottomRow.setComponentAlignment(error, Alignment.MIDDLE_RIGHT);
    loginPanel.addComponent(bottomRow);

    signin.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (authenticate(username.getValue(), password.getValue())) {
                //                    if (keepLoggedIn.getValue()) {
                //                        //Cookie userCookie = getCookieByName(PEERGREEN_USER_COOKIE_NAME);
                //                       if (getCookieByName(PEERGREEN_USER_COOKIE_NAME) == null) {
                //                            // Get a token for this user and create a cooki
                //                            Page.getCurrent().getJavaScript().execute( String.format("document.cookie = '%s=%s; path=%s'",
                //                                    PEERGREEN_USER_COOKIE_NAME, token, VaadinService.getCurrentRequest().getContextPath()));
                //                        } else {
                //                            // update token
                //                            userCookie.setValue(token);
                //                            userCookie.setPath(VaadinService.getCurrentRequest().getContextPath());
                //                        }
                //                    }

                buildMainView();
            } else {
                error.setVisible(true);
            }
        }
    });

    loginLayout.addComponent(loginPanel);
    loginLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
}

From source file:de.metas.ui.web.vaadin.window.editor.FieldEditor.java

License:Open Source License

@Override
protected Label createLabelComponent() {
    final Label label = super.createLabelComponent();
    if (label != null) {
        label.setVisible(displayed);
    }/*from ww  w. ja  va  2 s  .c om*/
    return label;
}

From source file:de.metas.ui.web.vaadin.window.editor.FieldEditor.java

License:Open Source License

private void setDisplayed(boolean displayed) {
    if (this.displayed == displayed) {
        return;/*from  ww w  .ja  v  a  2 s .c o m*/
    }

    this.displayed = displayed;

    // Update UI
    setVisible(displayed);
    final Label label = getLabelIfCreated();
    if (label != null) {
        label.setVisible(displayed);
    }
}

From source file:de.symeda.sormas.ui.caze.CasesView.java

License:Open Source License

public CasesView() {
    super(VIEW_NAME);
    originalViewTitle = getViewTitleLabel().getValue();

    criteria = ViewModelProviders.of(CasesView.class).get(CaseCriteria.class);
    if (criteria.getArchived() == null) {
        criteria.archived(false);//w ww .  java 2s . c  o m
    }

    grid = new CaseGrid();
    grid.setCriteria(criteria);
    gridLayout = new VerticalLayout();
    gridLayout.addComponent(createFilterBar());
    gridLayout.addComponent(createStatusFilterBar());
    gridLayout.addComponent(grid);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(false);
    gridLayout.setSizeFull();
    gridLayout.setExpandRatio(grid, 1);
    gridLayout.setStyleName("crud-main-layout");

    grid.getDataProvider().addDataProviderListener(e -> updateStatusButtons());

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_IMPORT)) {
        Button importButton = new Button(I18nProperties.getCaption(Captions.actionImport));
        importButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        importButton.setIcon(VaadinIcons.UPLOAD);
        importButton.addClickListener(e -> {
            Window popupWindow = VaadinUiUtil.showPopupWindow(new CaseImportLayout());
            popupWindow.setCaption(I18nProperties.getString(Strings.headingImportCases));
            popupWindow.addCloseListener(c -> {
                grid.reload();
            });
        });
        addHeaderComponent(importButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EXPORT)) {
        PopupButton exportButton = new PopupButton(I18nProperties.getCaption(Captions.export));
        exportButton.setId("export");
        exportButton.setIcon(VaadinIcons.DOWNLOAD);
        VerticalLayout exportLayout = new VerticalLayout();
        exportLayout.setSpacing(true);
        exportLayout.setMargin(true);
        exportLayout.addStyleName(CssStyles.LAYOUT_MINIMAL);
        exportLayout.setWidth(200, Unit.PIXELS);
        exportButton.setContent(exportLayout);
        addHeaderComponent(exportButton);

        Button basicExportButton = new Button(I18nProperties.getCaption(Captions.exportBasic));
        basicExportButton.setId("basicExport");
        basicExportButton.setDescription(I18nProperties.getString(Strings.infoBasicExport));
        basicExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        basicExportButton.setIcon(VaadinIcons.TABLE);
        basicExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(basicExportButton);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_cases",
                "sormas_cases_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(basicExportButton);

        Button extendedExportButton = new Button(I18nProperties.getCaption(Captions.exportDetailed));
        extendedExportButton.setId("extendedExport");
        extendedExportButton.setDescription(I18nProperties.getString(Strings.infoDetailedExport));
        extendedExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        extendedExportButton.setIcon(VaadinIcons.FILE_TEXT);
        extendedExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(extendedExportButton);

        StreamResource extendedExportStreamResource = DownloadUtil.createCsvExportStreamResource(
                CaseExportDto.class,
                (Integer start, Integer max) -> FacadeProvider.getCaseFacade()
                        .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max),
                (propertyId, type) -> {
                    String caption = I18nProperties.getPrefixCaption(CaseExportDto.I18N_PREFIX, propertyId,
                            I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId,
                                    I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId,
                                            I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, propertyId,
                                                    I18nProperties.getPrefixCaption(EpiDataDto.I18N_PREFIX,
                                                            propertyId,
                                                            I18nProperties.getPrefixCaption(
                                                                    HospitalizationDto.I18N_PREFIX,
                                                                    propertyId))))));
                    if (Date.class.isAssignableFrom(type)) {
                        caption += " (" + DateHelper.getLocalShortDatePattern() + ")";
                    }
                    return caption;
                }, "sormas_cases_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        new FileDownloader(extendedExportStreamResource).extend(extendedExportButton);

        Button sampleExportButton = new Button(I18nProperties.getCaption(Captions.exportSamples));
        sampleExportButton.setId("sampleExport");
        sampleExportButton.setDescription(I18nProperties.getString(Strings.infoSampleExport));
        sampleExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        sampleExportButton.setIcon(VaadinIcons.FILE_TEXT);
        sampleExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(sampleExportButton);

        StreamResource sampleExportStreamResource = DownloadUtil.createCsvExportStreamResource(
                SampleExportDto.class,
                (Integer start, Integer max) -> FacadeProvider.getSampleFacade()
                        .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max),
                (propertyId, type) -> {
                    String caption = I18nProperties.getPrefixCaption(SampleExportDto.I18N_PREFIX, propertyId,
                            I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, propertyId,
                                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId,
                                            I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId,
                                                    I18nProperties.getPrefixCaption(
                                                            AdditionalTestDto.I18N_PREFIX, propertyId)))));
                    if (Date.class.isAssignableFrom(type)) {
                        caption += " (" + DateHelper.getLocalShortDatePattern() + ")";
                    }
                    return caption;
                }, "sormas_samples_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        new FileDownloader(sampleExportStreamResource).extend(sampleExportButton);

        // Warning if no filters have been selected
        Label warningLabel = new Label(I18nProperties.getString(Strings.infoExportNoFilters), ContentMode.HTML);
        warningLabel.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(warningLabel);
        warningLabel.setVisible(false);

        exportButton.addClickListener(e -> {
            warningLabel.setVisible(!criteria.hasAnyFilterActive());
        });
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_MERGE)) {
        Button mergeDuplicatesButton = new Button(I18nProperties.getCaption(Captions.caseMergeDuplicates));
        mergeDuplicatesButton.setId("mergeDuplicates");
        mergeDuplicatesButton.setIcon(VaadinIcons.COMPRESS_SQUARE);
        mergeDuplicatesButton
                .addClickListener(e -> ControllerProvider.getCaseController().navigateToMergeCasesView());
        addHeaderComponent(mergeDuplicatesButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_CREATE)) {
        createButton = new Button(I18nProperties.getCaption(Captions.caseNewCase));
        createButton.setId("create");
        createButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        createButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        createButton.addClickListener(e -> ControllerProvider.getCaseController().create());
        addHeaderComponent(createButton);
    }

    addComponent(gridLayout);
}

From source file:de.symeda.sormas.ui.contact.ContactsView.java

License:Open Source License

public ContactsView() {
    super(VIEW_NAME);

    originalViewTitle = getViewTitleLabel().getValue();

    criteria = ViewModelProviders.of(ContactsView.class).get(ContactCriteria.class);
    if (criteria.getArchived() == null) {
        criteria.archived(false);/* w  ww .  j a  va 2s.c o m*/
    }

    grid = new ContactGrid();
    grid.setCriteria(criteria);
    gridLayout = new VerticalLayout();
    gridLayout.addComponent(createFilterBar());
    gridLayout.addComponent(createStatusFilterBar());
    gridLayout.addComponent(grid);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(false);
    gridLayout.setSizeFull();
    gridLayout.setExpandRatio(grid, 1);
    gridLayout.setStyleName("crud-main-layout");
    grid.getDataProvider().addDataProviderListener(e -> updateStatusButtons());

    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EXPORT)) {

        PopupButton exportButton = new PopupButton(I18nProperties.getCaption(Captions.export));
        exportButton.setIcon(VaadinIcons.DOWNLOAD);
        VerticalLayout exportLayout = new VerticalLayout();
        exportLayout.setSpacing(true);
        exportLayout.setMargin(true);
        exportLayout.addStyleName(CssStyles.LAYOUT_MINIMAL);
        exportLayout.setWidth(200, Unit.PIXELS);
        exportButton.setContent(exportLayout);
        addHeaderComponent(exportButton);

        Button basicExportButton = new Button(I18nProperties.getCaption(Captions.exportBasic));
        basicExportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton));
        basicExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        basicExportButton.setIcon(VaadinIcons.TABLE);
        basicExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(basicExportButton);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_contacts",
                "sormas_contacts_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(basicExportButton);

        Button extendedExportButton = new Button(I18nProperties.getCaption(Captions.exportDetailed));
        extendedExportButton
                .setDescription(I18nProperties.getDescription(Descriptions.descDetailedExportButton));
        extendedExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        extendedExportButton.setIcon(VaadinIcons.FILE_TEXT);
        extendedExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(extendedExportButton);

        StreamResource extendedExportStreamResource = DownloadUtil.createCsvExportStreamResource(
                ContactExportDto.class,
                (Integer start, Integer max) -> FacadeProvider.getContactFacade()
                        .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max),
                (propertyId, type) -> {
                    String caption = I18nProperties.getPrefixCaption(ContactExportDto.I18N_PREFIX, propertyId,
                            I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, propertyId,
                                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId,
                                            I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId,
                                                    I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX,
                                                            propertyId,
                                                            I18nProperties.getPrefixCaption(
                                                                    HospitalizationDto.I18N_PREFIX,
                                                                    propertyId))))));
                    if (Date.class.isAssignableFrom(type)) {
                        caption += " (" + DateHelper.getLocalShortDatePattern() + ")";
                    }
                    return caption;
                }, "sormas_contacts_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        new FileDownloader(extendedExportStreamResource).extend(extendedExportButton);

        // Warning if no filters have been selected
        Label warningLabel = new Label(I18nProperties.getString(Strings.infoExportNoFilters));
        warningLabel.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(warningLabel);
        warningLabel.setVisible(false);

        exportButton.addClickListener(e -> {
            warningLabel.setVisible(!criteria.hasAnyFilterActive());
        });
    }

    addComponent(gridLayout);
}

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

License:Open Source License

private void initializeRequestedTests() {
    // Yes/No fields for requesting pathogen/additional tests
    OptionGroup pathogenTestingRequestedField = addField(SampleDto.PATHOGEN_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(pathogenTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    pathogenTestingRequestedField.setWidthUndefined();
    OptionGroup additionalTestingRequestedField = addField(SampleDto.ADDITIONAL_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(additionalTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    additionalTestingRequestedField.setWidthUndefined();

    // CheckBox groups to select the requested pathogen/additional tests
    OptionGroup requestedPathogenTestsField = addField(SampleDto.REQUESTED_PATHOGEN_TESTS, OptionGroup.class);
    CssStyles.style(requestedPathogenTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedPathogenTestsField.setMultiSelect(true);
    requestedPathogenTestsField.addItems((Object[]) PathogenTestType.values());
    requestedPathogenTestsField.removeItem(PathogenTestType.OTHER);
    requestedPathogenTestsField.setCaption(null);
    OptionGroup requestedAdditionalTestsField = addField(SampleDto.REQUESTED_ADDITIONAL_TESTS,
            OptionGroup.class);
    CssStyles.style(requestedAdditionalTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedAdditionalTestsField.setMultiSelect(true);
    requestedAdditionalTestsField.addItems((Object[]) AdditionalTestType.values());
    requestedAdditionalTestsField.setCaption(null);

    // Text fields to type in other tests
    TextField requestedOtherPathogenTests = addField(SampleDto.REQUESTED_OTHER_PATHOGEN_TESTS, TextField.class);
    TextField requestedOtherAdditionalTests = addField(SampleDto.REQUESTED_OTHER_ADDITIONAL_TESTS,
            TextField.class);

    // Information texts
    Label requestedPathogenInfoLabel = new Label(I18nProperties.getString(Strings.infoSamplePathogenTesting));
    getContent().addComponent(requestedPathogenInfoLabel, PATHOGEN_TESTING_INFO_LOC);
    Label requestedAdditionalInfoLabel = new Label(
            I18nProperties.getString(Strings.infoSampleAdditionalTesting));
    getContent().addComponent(requestedAdditionalInfoLabel, ADDITIONAL_TESTING_INFO_LOC);

    // Set initial visibility
    requestedPathogenTestsField.setVisible(false);
    requestedPathogenInfoLabel.setVisible(false);
    requestedAdditionalTestsField.setVisible(false);
    requestedAdditionalInfoLabel.setVisible(false);
    requestedOtherPathogenTests.setVisible(false);
    requestedOtherAdditionalTests.setVisible(false);

    // CheckBoxes should be hidden when no tests are requested
    pathogenTestingRequestedField.addValueChangeListener(f -> {
        requestedPathogenInfoLabel.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
        requestedPathogenTestsField.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
        requestedOtherPathogenTests.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
    });/*from www  .j a v  a2  s  .  c o m*/

    if (!UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)) {
        // Hide additional testing fields when user is not allowed to see them
        additionalTestingRequestedField.setVisible(false);
    } else {
        additionalTestingRequestedField.addValueChangeListener(f -> {
            requestedAdditionalInfoLabel.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
            requestedAdditionalTestsField.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
            requestedOtherAdditionalTests.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
        });
    }
}

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

License:Open Source License

private void initializeRequestedTests() {
    // Yes/No fields for requesting pathogen/additional tests
    OptionGroup pathogenTestingRequestedField = addField(SampleDto.PATHOGEN_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(pathogenTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    pathogenTestingRequestedField.setWidthUndefined();
    OptionGroup additionalTestingRequestedField = addField(SampleDto.ADDITIONAL_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(additionalTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    additionalTestingRequestedField.setWidthUndefined();

    // CheckBox groups to select the requested pathogen/additional tests
    OptionGroup requestedPathogenTestsField = addField(SampleDto.REQUESTED_PATHOGEN_TESTS, OptionGroup.class);
    CssStyles.style(requestedPathogenTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedPathogenTestsField.setMultiSelect(true);
    requestedPathogenTestsField.addItems((Object[]) PathogenTestType.values());
    requestedPathogenTestsField.removeItem(PathogenTestType.OTHER);
    requestedPathogenTestsField.setCaption(null);
    OptionGroup requestedAdditionalTestsField = addField(SampleDto.REQUESTED_ADDITIONAL_TESTS,
            OptionGroup.class);
    CssStyles.style(requestedAdditionalTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedAdditionalTestsField.setMultiSelect(true);
    requestedAdditionalTestsField.addItems((Object[]) AdditionalTestType.values());
    requestedAdditionalTestsField.setCaption(null);

    // Text fields to type in other tests
    TextField requestedOtherPathogenTests = addField(SampleDto.REQUESTED_OTHER_PATHOGEN_TESTS, TextField.class);
    TextField requestedOtherAdditionalTests = addField(SampleDto.REQUESTED_OTHER_ADDITIONAL_TESTS,
            TextField.class);

    // The code below relies on getValue() to return the sample of the form and therefore has to be delayed until the sample is set
    addValueChangeListener(e -> {/* ww  w . j a  v  a2 s  .  co m*/
        if (!requestedTestsInitialized) {
            if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_EDIT_NOT_OWNED)
                    || UserProvider.getCurrent().getUuid().equals(getValue().getReportingUser().getUuid())) {
                // Information texts for users that can edit the requested tests
                Label requestedPathogenInfoLabel = new Label(
                        I18nProperties.getString(Strings.infoSamplePathogenTesting));
                getContent().addComponent(requestedPathogenInfoLabel, PATHOGEN_TESTING_INFO_LOC);
                Label requestedAdditionalInfoLabel = new Label(
                        I18nProperties.getString(Strings.infoSampleAdditionalTesting));
                getContent().addComponent(requestedAdditionalInfoLabel, ADDITIONAL_TESTING_INFO_LOC);

                // Set initial visibility
                requestedPathogenTestsField
                        .setVisible(Boolean.TRUE.equals(getValue().getPathogenTestingRequested()));
                requestedPathogenInfoLabel
                        .setVisible(Boolean.TRUE.equals(getValue().getPathogenTestingRequested()));
                requestedOtherPathogenTests
                        .setVisible(Boolean.TRUE.equals(getValue().getPathogenTestingRequested()));

                // CheckBoxes should be hidden when no tests are requested
                pathogenTestingRequestedField.addValueChangeListener(f -> {
                    requestedPathogenInfoLabel.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                    requestedPathogenTestsField.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                    requestedOtherPathogenTests.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                });

                if (!UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)) {
                    // Hide additional testing fields when user is not allowed to see them
                    additionalTestingRequestedField.setVisible(false);
                    requestedAdditionalTestsField.setVisible(false);
                    requestedAdditionalInfoLabel.setVisible(false);
                    requestedOtherAdditionalTests.setVisible(false);
                } else {
                    requestedAdditionalTestsField
                            .setVisible(Boolean.TRUE.equals(getValue().getAdditionalTestingRequested()));
                    requestedAdditionalInfoLabel
                            .setVisible(Boolean.TRUE.equals(getValue().getAdditionalTestingRequested()));
                    requestedOtherAdditionalTests
                            .setVisible(Boolean.TRUE.equals(getValue().getAdditionalTestingRequested()));

                    additionalTestingRequestedField.addValueChangeListener(f -> {
                        requestedAdditionalInfoLabel
                                .setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                        requestedAdditionalTestsField
                                .setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                        requestedOtherAdditionalTests
                                .setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                    });
                }
            } else {
                // If the user can't edit the sample, they see a read-only list of requested tests
                setVisible(false, SampleDto.PATHOGEN_TESTING_REQUESTED, SampleDto.ADDITIONAL_TESTING_REQUESTED,
                        SampleDto.REQUESTED_PATHOGEN_TESTS, SampleDto.REQUESTED_ADDITIONAL_TESTS);

                // Display a label for every requested pathogen test or hide the whole section if no tests have been requested
                if (Boolean.TRUE.equals(getValue().getPathogenTestingRequested())
                        && !getValue().getRequestedPathogenTests().isEmpty()) {
                    Label pathogenTestsHeading = new Label(
                            I18nProperties.getString(Strings.headingRequestedPathogenTests));
                    CssStyles.style(pathogenTestsHeading, CssStyles.LABEL_BOLD, CssStyles.LABEL_SECONDARY,
                            CssStyles.VSPACE_4);
                    getContent().addComponent(pathogenTestsHeading, PATHOGEN_TESTING_READ_HEADLINE_LOC);

                    CssLayout requestedPathogenTestsLayout = new CssLayout();
                    CssStyles.style(requestedPathogenTestsLayout, CssStyles.VSPACE_3);
                    for (PathogenTestType testType : getValue().getRequestedPathogenTests()) {
                        Label testLabel = new Label(testType.toString());
                        testLabel.setWidthUndefined();
                        CssStyles.style(testLabel, CssStyles.LABEL_ROUNDED_CORNERS,
                                CssStyles.LABEL_BACKGROUND_FOCUS_LIGHT, CssStyles.VSPACE_4,
                                CssStyles.HSPACE_RIGHT_4);
                        requestedPathogenTestsLayout.addComponent(testLabel);
                    }
                    getContent().addComponent(requestedPathogenTestsLayout, REQUESTED_PATHOGEN_TESTS_READ_LOC);
                }

                // If the user can view additional tests, display a label for every requested additional test
                // or hide the whole section if no tests have been requested
                if (UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)
                        && Boolean.TRUE.equals(getValue().getAdditionalTestingRequested())
                        && !getValue().getRequestedAdditionalTests().isEmpty()) {
                    Label additionalTestsHeading = new Label(
                            I18nProperties.getString(Strings.headingRequestedAdditionalTests));
                    CssStyles.style(additionalTestsHeading, CssStyles.LABEL_BOLD, CssStyles.LABEL_SECONDARY,
                            CssStyles.VSPACE_4);
                    getContent().addComponent(additionalTestsHeading, ADDITIONAL_TESTING_READ_HEADLINE_LOC);

                    CssLayout requestedAdditionalTestsLayout = new CssLayout();
                    CssStyles.style(requestedAdditionalTestsLayout, CssStyles.VSPACE_3);
                    for (AdditionalTestType testType : getValue().getRequestedAdditionalTests()) {
                        Label testLabel = new Label(testType.toString());
                        testLabel.setWidthUndefined();
                        CssStyles.style(testLabel, CssStyles.LABEL_ROUNDED_CORNERS,
                                CssStyles.LABEL_BACKGROUND_FOCUS_LIGHT, CssStyles.VSPACE_4,
                                CssStyles.HSPACE_RIGHT_4);
                        requestedAdditionalTestsLayout.addComponent(testLabel);
                    }
                    getContent().addComponent(requestedAdditionalTestsLayout,
                            REQUESTED_ADDITIONAL_TESTS_READ_LOC);
                }

            }
        }

        requestedTestsInitialized = true;
    });
}