Example usage for com.vaadin.ui Button addStyleName

List of usage examples for com.vaadin.ui Button addStyleName

Introduction

In this page you can find the example usage for com.vaadin.ui Button addStyleName.

Prototype

@Override
    public void addStyleName(String style) 

Source Link

Usage

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

License:Open Source License

public CommunitiesView() {
    super(VIEW_NAME);

    criteria = ViewModelProviders.of(CommunitiesView.class).get(CommunityCriteria.class);

    grid = new CommunitiesGrid();
    grid.setCriteria(criteria);/*from w  ww. j  av a2  s  .  co  m*/
    gridLayout = new VerticalLayout();
    gridLayout.addComponent(createFilterBar());
    gridLayout.addComponent(grid);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(false);
    gridLayout.setExpandRatio(grid, 1);
    gridLayout.setSizeFull();
    gridLayout.setStyleName("crud-main-layout");

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) {
        Button exportButton = new Button(I18nProperties.getCaption(Captions.export));
        exportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton));
        exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        exportButton.setIcon(VaadinIcons.TABLE);
        addHeaderComponent(exportButton);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_communities",
                "sormas_communities_" + DateHelper.formatDateForExport(new Date()) + ".csv",
                CommunitiesGrid.EDIT_BTN_ID);
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(exportButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) {
        createButton = new Button(I18nProperties.getCaption(Captions.actionNewEntry));
        createButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        createButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        createButton.addClickListener(e -> ControllerProvider.getInfrastructureController().createCommunity());
        addHeaderComponent(createButton);
    }

    addComponent(gridLayout);
}

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

License:Open Source License

public DistrictsView() {
    super(VIEW_NAME);

    criteria = ViewModelProviders.of(DistrictsView.class).get(DistrictCriteria.class);

    grid = new DistrictsGrid();
    grid.setCriteria(criteria);/*from w ww.java2  s .c om*/
    gridLayout = new VerticalLayout();
    gridLayout.addComponent(createFilterBar());
    gridLayout.addComponent(grid);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(false);
    gridLayout.setExpandRatio(grid, 1);
    gridLayout.setSizeFull();
    gridLayout.setStyleName("crud-main-layout");

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) {
        Button exportButton = new Button(I18nProperties.getCaption(Captions.export));
        exportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton));
        exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        exportButton.setIcon(VaadinIcons.TABLE);
        addHeaderComponent(exportButton);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_districts",
                "sormas_districts_" + DateHelper.formatDateForExport(new Date()) + ".csv",
                DistrictsGrid.EDIT_BTN_ID);
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(exportButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) {
        createButton = new Button(I18nProperties.getCaption(Captions.actionNewEntry));
        createButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        createButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        createButton.addClickListener(e -> ControllerProvider.getInfrastructureController().createDistrict());
        addHeaderComponent(createButton);
    }

    addComponent(gridLayout);
}

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

License:Open Source License

public RegionsView() {
    super(VIEW_NAME);

    criteria = ViewModelProviders.of(RegionsView.class).get(RegionCriteria.class);

    grid = new RegionsGrid();
    grid.setCriteria(criteria);//from  www  . j a  v a 2 s.  co m
    gridLayout = new VerticalLayout();
    gridLayout.addComponent(createFilterBar());
    gridLayout.addComponent(grid);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(false);
    gridLayout.setExpandRatio(grid, 1);
    gridLayout.setSizeFull();
    gridLayout.setStyleName("crud-main-layout");

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) {
        Button exportButton = new Button(I18nProperties.getCaption(Captions.export));
        exportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton));
        exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        exportButton.setIcon(VaadinIcons.TABLE);
        addHeaderComponent(exportButton);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_regions",
                "sormas_regions_" + DateHelper.formatDateForExport(new Date()) + ".csv",
                RegionsGrid.EDIT_BTN_ID);
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(exportButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) {
        createButton = new Button(I18nProperties.getCaption(Captions.actionNewEntry));
        createButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        createButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        createButton.addClickListener(e -> ControllerProvider.getInfrastructureController().createRegion());
        addHeaderComponent(createButton);
    }

    addComponent(gridLayout);
}

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

License:Open Source License

@Override
protected void addFields() {
    addField(ContactDto.CONTACT_CLASSIFICATION, OptionGroup.class);
    addField(ContactDto.CONTACT_STATUS, OptionGroup.class);
    addField(ContactDto.UUID, TextField.class);
    addField(ContactDto.REPORTING_USER, ComboBox.class);
    DateField lastContactDate = addField(ContactDto.LAST_CONTACT_DATE, DateField.class);
    addField(ContactDto.REPORT_DATE_TIME, DateField.class);
    OptionGroup contactProximity = addField(ContactDto.CONTACT_PROXIMITY, OptionGroup.class);
    contactProximity.removeStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
    ComboBox relationToCase = addField(ContactDto.RELATION_TO_CASE, ComboBox.class);
    addField(ContactDto.DESCRIPTION, TextArea.class).setRows(3);

    addField(ContactDto.FOLLOW_UP_STATUS, ComboBox.class);
    addField(ContactDto.FOLLOW_UP_COMMENT, TextArea.class).setRows(1);
    addDateField(ContactDto.FOLLOW_UP_UNTIL, DateField.class, -1);

    ComboBox contactOfficerField = addField(ContactDto.CONTACT_OFFICER, ComboBox.class);
    contactOfficerField.setNullSelectionAllowed(true);

    setReadOnly(true, ContactDto.UUID, ContactDto.REPORTING_USER, ContactDto.REPORT_DATE_TIME,
            ContactDto.CONTACT_STATUS, ContactDto.FOLLOW_UP_STATUS, ContactDto.FOLLOW_UP_UNTIL);

    FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.FOLLOW_UP_STATUS,
            Arrays.asList(ContactDto.FOLLOW_UP_COMMENT),
            Arrays.asList(FollowUpStatus.CANCELED, FollowUpStatus.LOST));

    addValueChangeListener(e -> {/*from  w  w  w.ja va2s  .co m*/
        if (getValue() != null) {
            CaseDataDto caseDto = FacadeProvider.getCaseFacade()
                    .getCaseDataByUuid(getValue().getCaze().getUuid());
            updateLastContactDateValidator();
            updateDiseaseConfiguration(caseDto.getDisease());

            updateFollowUpStatusComponents();

            contactOfficerField.addItems(FacadeProvider.getUserFacade()
                    .getUserRefsByDistrict(caseDto.getDistrict(), false, UserRole.CONTACT_OFFICER));

            getContent().removeComponent(TO_CASE_BTN_LOC);
            if (getValue().getResultingCase() != null) {
                // link to case
                Link linkToData = ControllerProvider.getCaseController().createLinkToData(
                        getValue().getResultingCase().getUuid(),
                        I18nProperties.getCaption(Captions.contactOpenContactCase));
                getContent().addComponent(linkToData, TO_CASE_BTN_LOC);
            } else if (getValue().getContactClassification() == ContactClassification.CONFIRMED) {
                // only when confirmed
                if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CONVERT)) {
                    Button toCaseButton = new Button(
                            I18nProperties.getCaption(Captions.contactCreateContactCase));
                    toCaseButton.addStyleName(ValoTheme.BUTTON_LINK);

                    toCaseButton.addClickListener(new ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            PersonReferenceDto personRef = getValue().getPerson();
                            CaseReferenceDto caseRef = getValue().getCaze();
                            CaseDataDto caze = FacadeProvider.getCaseFacade()
                                    .getCaseDataByUuid(caseRef.getUuid());
                            ControllerProvider.getCaseController().create(personRef, caze.getDisease(),
                                    getValue());
                        }
                    });

                    getContent().addComponent(toCaseButton, TO_CASE_BTN_LOC);
                }
            }
        }
    });

    setRequired(true, ContactDto.CONTACT_CLASSIFICATION, ContactDto.CONTACT_STATUS);
    FieldHelper.addSoftRequiredStyle(lastContactDate, contactProximity, relationToCase);
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private void updateFollowUpStatusComponents() {

    getContent().removeComponent(CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
    getContent().removeComponent(LOST_FOLLOW_UP_BTN_LOC);

    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(ContactDto.FOLLOW_UP_STATUS);
    boolean followUpVisible = getValue() != null && statusField.isVisible();
    if (followUpVisible && UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EDIT)) {
        FollowUpStatus followUpStatus = statusField.getValue();
        if (followUpStatus == FollowUpStatus.FOLLOW_UP) {

            Button cancelButton = new Button(I18nProperties.getCaption(Captions.contactCancelFollowUp));
            cancelButton.setWidth(100, Unit.PERCENTAGE);
            cancelButton.addClickListener(new ClickListener() {
                @Override//from w w w.  j a  v  a  2s . c o m
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.CANCELED);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(cancelButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);

            Button lostButton = new Button(I18nProperties.getCaption(Captions.contactLostToFollowUp));
            lostButton.setWidth(100, Unit.PERCENTAGE);
            lostButton.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.LOST);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(lostButton, LOST_FOLLOW_UP_BTN_LOC);

        } else if (followUpStatus == FollowUpStatus.CANCELED || followUpStatus == FollowUpStatus.LOST) {

            Button resumeButton = new Button(I18nProperties.getCaption(Captions.contactResumeFollowUp));
            resumeButton.addStyleName(CssStyles.FORCE_CAPTION);
            resumeButton.setWidth(100, Unit.PERCENTAGE);
            resumeButton.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.FOLLOW_UP);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(resumeButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
        }
    }
}

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);/*from   w ww.ja v  a  2  s  .  c  om*/
    }

    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.dashboard.diagram.AbstractEpiCurveComponent.java

License:Open Source License

private HorizontalLayout createHeader() {
    HorizontalLayout epiCurveHeaderLayout = new HorizontalLayout();
    epiCurveHeaderLayout.setWidth(100, Unit.PERCENTAGE);
    epiCurveHeaderLayout.setSpacing(true);
    CssStyles.style(epiCurveHeaderLayout, CssStyles.VSPACE_4);

    epiCurveLabel = new Label(I18nProperties.getString(Strings.headingEpiCurve));
    epiCurveLabel.setSizeUndefined();// ww  w.ja  v  a2s . c  o  m
    CssStyles.style(epiCurveLabel, CssStyles.H2, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);

    epiCurveHeaderLayout.addComponent(epiCurveLabel);
    epiCurveHeaderLayout.setComponentAlignment(epiCurveLabel, Alignment.BOTTOM_LEFT);
    epiCurveHeaderLayout.setExpandRatio(epiCurveLabel, 1);

    // "Expand" and "Collapse" buttons
    Button expandEpiCurveButton = new Button("", VaadinIcons.EXPAND);
    CssStyles.style(expandEpiCurveButton, CssStyles.BUTTON_SUBTLE);
    expandEpiCurveButton.addStyleName(CssStyles.VSPACE_NONE);
    Button collapseEpiCurveButton = new Button("", VaadinIcons.COMPRESS);
    CssStyles.style(collapseEpiCurveButton, CssStyles.BUTTON_SUBTLE);
    collapseEpiCurveButton.addStyleName(CssStyles.VSPACE_NONE);

    expandEpiCurveButton.addClickListener(e -> {
        externalExpandListener.accept(true);
        epiCurveHeaderLayout.removeComponent(expandEpiCurveButton);
        epiCurveHeaderLayout.addComponent(collapseEpiCurveButton);
        epiCurveHeaderLayout.setComponentAlignment(collapseEpiCurveButton, Alignment.MIDDLE_RIGHT);
    });
    collapseEpiCurveButton.addClickListener(e -> {
        externalExpandListener.accept(false);
        epiCurveHeaderLayout.removeComponent(collapseEpiCurveButton);
        epiCurveHeaderLayout.addComponent(expandEpiCurveButton);
        epiCurveHeaderLayout.setComponentAlignment(expandEpiCurveButton, Alignment.MIDDLE_RIGHT);
    });
    epiCurveHeaderLayout.addComponent(expandEpiCurveButton);
    epiCurveHeaderLayout.setComponentAlignment(expandEpiCurveButton, Alignment.MIDDLE_RIGHT);

    return epiCurveHeaderLayout;
}

From source file:de.symeda.sormas.ui.dashboard.map.DashboardMapComponent.java

License:Open Source License

private HorizontalLayout createHeader() {
    HorizontalLayout mapHeaderLayout = new HorizontalLayout();
    mapHeaderLayout.setWidth(100, Unit.PERCENTAGE);
    mapHeaderLayout.setSpacing(true);//from   ww w. ja va 2 s. c o m
    CssStyles.style(mapHeaderLayout, CssStyles.VSPACE_4);

    Label mapLabel = new Label();
    if (dashboardDataProvider.getDashboardType() == DashboardType.SURVEILLANCE) {
        mapLabel.setValue(I18nProperties.getString(Strings.headingCaseStatusMap));
    } else {
        mapLabel.setValue(I18nProperties.getString(Strings.headingContactMap));
    }
    mapLabel.setSizeUndefined();
    CssStyles.style(mapLabel, CssStyles.H2, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);

    mapHeaderLayout.addComponent(mapLabel);
    mapHeaderLayout.setComponentAlignment(mapLabel, Alignment.BOTTOM_LEFT);
    mapHeaderLayout.setExpandRatio(mapLabel, 1);

    // "Expand" and "Collapse" buttons
    Button expandMapButton = new Button("", VaadinIcons.EXPAND);
    CssStyles.style(expandMapButton, CssStyles.BUTTON_SUBTLE);
    expandMapButton.addStyleName(CssStyles.VSPACE_NONE);
    Button collapseMapButton = new Button("", VaadinIcons.COMPRESS);
    CssStyles.style(collapseMapButton, CssStyles.BUTTON_SUBTLE);
    collapseMapButton.addStyleName(CssStyles.VSPACE_NONE);

    expandMapButton.addClickListener(e -> {
        externalExpandListener.accept(true);
        mapHeaderLayout.removeComponent(expandMapButton);
        mapHeaderLayout.addComponent(collapseMapButton);
        mapHeaderLayout.setComponentAlignment(collapseMapButton, Alignment.MIDDLE_RIGHT);
    });
    collapseMapButton.addClickListener(e -> {
        externalExpandListener.accept(false);
        mapHeaderLayout.removeComponent(collapseMapButton);
        mapHeaderLayout.addComponent(expandMapButton);
        mapHeaderLayout.setComponentAlignment(expandMapButton, Alignment.MIDDLE_RIGHT);
    });
    mapHeaderLayout.addComponent(expandMapButton);
    mapHeaderLayout.setComponentAlignment(expandMapButton, Alignment.MIDDLE_RIGHT);

    return mapHeaderLayout;
}

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);/*from www  .  jav a  2  s.c om*/

    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.events.EventController.java

License:Open Source License

public CommitDiscardWrapperComponent<EventDataForm> getEventDataEditComponent(final String eventUuid) {
    EventDto event = findEvent(eventUuid);
    EventDataForm eventEditForm = new EventDataForm(false, UserRight.EVENT_EDIT);
    eventEditForm.setValue(event);/*  w w w.  j  a  va  2 s.  co  m*/
    final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<EventDataForm>(
            eventEditForm, eventEditForm.getFieldGroup());

    editView.addCommitListener(new CommitListener() {
        @Override
        public void onCommit() {
            if (!eventEditForm.getFieldGroup().isModified()) {
                EventDto eventDto = eventEditForm.getValue();
                eventDto = FacadeProvider.getEventFacade().saveEvent(eventDto);
                Notification.show(I18nProperties.getString(Strings.messageEventSaved), Type.WARNING_MESSAGE);
                SormasUI.refreshView();
            }
        }
    });

    if (UserProvider.getCurrent().hasUserRole(UserRole.ADMIN)) {
        editView.addDeleteListener(new DeleteListener() {
            @Override
            public void onDelete() {
                FacadeProvider.getEventFacade().deleteEvent(event.toReference(),
                        UserProvider.getCurrent().getUserReference().getUuid());
                UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
            }
        }, I18nProperties.getString(Strings.entityEvent));
    }

    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_ARCHIVE)) {
        boolean archived = FacadeProvider.getEventFacade().isArchived(eventUuid);
        Button archiveEventButton = new Button();
        archiveEventButton.addStyleName(ValoTheme.BUTTON_LINK);
        if (archived) {
            archiveEventButton.setCaption(I18nProperties.getCaption(Captions.actionDearchive));
        } else {
            archiveEventButton.setCaption(I18nProperties.getCaption(Captions.actionArchive));
        }
        archiveEventButton.addClickListener(e -> {
            editView.commit();
            archiveOrDearchiveEvent(eventUuid, !archived);
        });

        editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
        editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
    }

    return editView;
}