Example usage for com.vaadin.ui HorizontalLayout setWidth

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

Introduction

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

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

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.j ava  2 s  . co  m
    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.StatisticsFilterComponent.java

License:Open Source License

private HorizontalLayout createFilterAttributeElement() {
    HorizontalLayout filterAttributeLayout = new HorizontalLayout();
    filterAttributeLayout.setSpacing(true);
    filterAttributeLayout.setWidth(100, Unit.PERCENTAGE);

    MenuBar filterAttributeDropdown = new MenuBar();
    filterAttributeDropdown.setCaption(I18nProperties.getCaption(Captions.statisticsAttribute));
    MenuItem filterAttributeItem = filterAttributeDropdown
            .addItem(I18nProperties.getCaption(Captions.statisticsAttributeSelect), null);
    MenuBar filterSubAttributeDropdown = new MenuBar();
    filterSubAttributeDropdown.setCaption(I18nProperties.getCaption(Captions.statisticsAttributeSpecification));
    MenuItem filterSubAttributeItem = filterSubAttributeDropdown.addItem(SPECIFY_YOUR_SELECTION, null);

    // Add attribute groups
    for (StatisticsCaseAttributeGroup attributeGroup : StatisticsCaseAttributeGroup.values()) {
        MenuItem attributeGroupItem = filterAttributeItem.addItem(attributeGroup.toString(), null);
        attributeGroupItem.setEnabled(false);

        // Add attributes belonging to the current group
        for (StatisticsCaseAttribute attribute : attributeGroup.getAttributes()) {
            Command attributeCommand = selectedItem -> {
                selectedAttribute = attribute;
                selectedSubAttribute = null;
                filterAttributeItem.setText(attribute.toString());

                // Add style to keep chosen item selected and remove it from all other items
                for (MenuItem menuItem : filterAttributeItem.getChildren()) {
                    menuItem.setStyleName(null);
                }/*from   w  ww  .  j av a  2  s  .c om*/
                selectedItem.setStyleName("selected-filter");

                // Reset the sub attribute dropdown
                filterSubAttributeItem.removeChildren();
                filterSubAttributeItem.setText(SPECIFY_YOUR_SELECTION);

                if (attribute.getSubAttributes().length > 0) {
                    for (StatisticsCaseSubAttribute subAttribute : attribute.getSubAttributes()) {
                        if (subAttribute.isUsedForFilters()) {
                            Command subAttributeCommand = selectedSubItem -> {
                                selectedSubAttribute = subAttribute;
                                filterSubAttributeItem.setText(subAttribute.toString());

                                // Add style to keep chosen item selected and remove it from all other items
                                for (MenuItem menuItem : filterSubAttributeItem.getChildren()) {
                                    menuItem.setStyleName(null);
                                }
                                selectedSubItem.setStyleName("selected-filter");

                                updateFilterElement();
                            };

                            filterSubAttributeItem.addItem(subAttribute.toString(), subAttributeCommand);
                        }
                    }

                    // Only add the sub attribute dropdown if there are any sub attributes that are relevant for the filters section
                    if (filterSubAttributeItem.getChildren() != null
                            && filterSubAttributeItem.getChildren().size() > 0) {
                        filterAttributeLayout.addComponent(filterSubAttributeDropdown);
                        filterAttributeLayout.setExpandRatio(filterSubAttributeDropdown, 1);
                    } else {
                        filterAttributeLayout.removeComponent(filterSubAttributeDropdown);
                    }
                } else {
                    filterAttributeLayout.removeComponent(filterSubAttributeDropdown);
                }
                updateFilterElement();
            };

            filterAttributeItem.addItem(attribute.toString(), attributeCommand);
        }
    }

    filterAttributeLayout.addComponent(filterAttributeDropdown);
    filterAttributeLayout.setExpandRatio(filterAttributeDropdown, 0);
    return filterAttributeLayout;
}

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

License:Open Source License

private HorizontalLayout createFilterComponentLayout() {
    HorizontalLayout filterComponentLayout = new HorizontalLayout();
    filterComponentLayout.setSpacing(true);
    filterComponentLayout.setWidth(100, Unit.PERCENTAGE);

    StatisticsFilterComponent filterComponent = new StatisticsFilterComponent();

    Button removeFilterButton = new Button(VaadinIcons.CLOSE);
    removeFilterButton.setDescription(I18nProperties.getCaption(Captions.statisticsRemoveFilter));
    CssStyles.style(removeFilterButton, CssStyles.FORCE_CAPTION);
    removeFilterButton.addClickListener(e -> {
        filterComponents.remove(filterComponent);
        filtersLayout.removeComponent(filterComponentLayout);
    });/*  ww  w  .  j  a  v  a2  s .com*/

    filterComponentLayout.addComponent(removeFilterButton);
    filterComponents.add(filterComponent);
    filterComponentLayout.addComponent(filterComponent);
    filterComponentLayout.setExpandRatio(filterComponent, 1);

    return filterComponentLayout;
}

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

License:Open Source License

private void addOptionsLayout(VerticalLayout statisticsLayout) {
    Label optionsTitle = new Label(I18nProperties.getCaption(Captions.options));
    optionsTitle.setWidthUndefined();//from w w  w  . ja v  a 2 s  .c  om
    CssStyles.style(optionsTitle, CssStyles.STATISTICS_TITLE);
    statisticsLayout.addComponent(optionsTitle);

    HorizontalLayout optionsLayout = new HorizontalLayout();
    optionsLayout.setWidth(100, Unit.PERCENTAGE);
    optionsLayout.setSpacing(true);
    CssStyles.style(optionsLayout, CssStyles.STATISTICS_TITLE_BOX);
    {
        zeroValues = new CheckBox(I18nProperties.getCaption(Captions.statisticsShowZeroValues));
        zeroValues.setValue(false);
        optionsLayout.addComponent(zeroValues);
    }
    statisticsLayout.addComponent(optionsLayout);
}

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

License:Open Source License

public void generateMap() {
    List<Object[]> resultData = generateStatistics();

    if (resultData.isEmpty()) {
        resultsLayout.addComponent(emptyResultLabel);
        return;/*from  w ww  .  ja va2 s  .c  o m*/
    }

    HorizontalLayout mapLayout = new HorizontalLayout();
    mapLayout.setSpacing(true);
    mapLayout.setMargin(false);
    mapLayout.setWidth(100, Unit.PERCENTAGE);
    mapLayout.setHeightUndefined();

    LeafletMap map = new LeafletMap();
    map.setTileLayerOpacity(0.5f);
    map.setWidth(100, Unit.PERCENTAGE);
    map.setHeight(580, Unit.PIXELS);
    map.setZoom(6);
    GeoLatLon mapCenter = FacadeProvider.getGeoShapeProvider().getCenterOfAllRegions();
    map.setCenter(mapCenter.getLon(), mapCenter.getLat());

    List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllAsReference();

    List<LeafletPolygon> outlinePolygones = new ArrayList<LeafletPolygon>();

    // draw outlines of all regions
    for (RegionReferenceDto region : regions) {

        GeoLatLon[][] regionShape = FacadeProvider.getGeoShapeProvider().getRegionShape(region);
        if (regionShape == null) {
            continue;
        }

        for (int part = 0; part < regionShape.length; part++) {
            GeoLatLon[] regionShapePart = regionShape[part];
            LeafletPolygon polygon = new LeafletPolygon();
            polygon.setCaption(region.getCaption());
            // fillOpacity is used, so we can still hover the region
            polygon.setOptions("{\"weight\": 1, \"color\": '#888', \"fillOpacity\": 0.02}");
            polygon.setLatLons(regionShapePart);
            outlinePolygones.add(polygon);
        }
    }

    map.addPolygonGroup("outlines", outlinePolygones);

    resultData.sort((a, b) -> {
        return Long.compare(((Number) a[0]).longValue(), ((Number) b[0]).longValue());
    });

    BigDecimal valuesLowerQuartile = new BigDecimal(
            resultData.size() > 0 ? ((Number) resultData.get((int) (resultData.size() * 0.25))[0]).longValue()
                    : null);
    BigDecimal valuesMedian = new BigDecimal(
            resultData.size() > 0 ? ((Number) resultData.get((int) (resultData.size() * 0.5))[0]).longValue()
                    : null);
    BigDecimal valuesUpperQuartile = new BigDecimal(
            resultData.size() > 0 ? ((Number) resultData.get((int) (resultData.size() * 0.75))[0]).longValue()
                    : null);

    List<LeafletPolygon> resultPolygons = new ArrayList<LeafletPolygon>();

    // Draw relevant district fills
    for (Object[] resultRow : resultData) {

        ReferenceDto regionOrDistrict = (ReferenceDto) resultRow[1];
        String shapeUuid = regionOrDistrict.getUuid();
        BigDecimal regionOrDistrictValue = new BigDecimal(((Number) resultRow[0]).longValue());
        GeoLatLon[][] shape;
        switch (visualizationComponent.getVisualizationMapType()) {
        case REGIONS:
            shape = FacadeProvider.getGeoShapeProvider().getRegionShape(new RegionReferenceDto(shapeUuid));
            break;
        case DISTRICTS:
            shape = FacadeProvider.getGeoShapeProvider().getDistrictShape(new DistrictReferenceDto(shapeUuid));
            break;
        default:
            throw new IllegalArgumentException(visualizationComponent.getVisualizationMapType().toString());
        }

        if (shape == null) {
            continue;
        }

        for (int part = 0; part < shape.length; part++) {
            GeoLatLon[] shapePart = shape[part];
            String fillColor;
            if (regionOrDistrictValue.compareTo(BigDecimal.ZERO) == 0) {
                fillColor = "#000";
            } else if (regionOrDistrictValue.compareTo(valuesLowerQuartile) < 0) {
                fillColor = "#FEDD6C";
            } else if (regionOrDistrictValue.compareTo(valuesMedian) < 0) {
                fillColor = "#FDBF44";
            } else if (regionOrDistrictValue.compareTo(valuesUpperQuartile) < 0) {
                fillColor = "#F47B20";
            } else {
                fillColor = "#ED1B24";
            }

            LeafletPolygon polygon = new LeafletPolygon();
            polygon.setCaption(regionOrDistrict.getCaption() + "<br>" + regionOrDistrictValue);
            // fillOpacity is used, so we can still hover the region
            polygon.setOptions("{\"stroke\": false, \"color\": '" + fillColor + "', \"fillOpacity\": 0.8}");
            polygon.setLatLons(shapePart);
            resultPolygons.add(polygon);
        }
    }
    map.addPolygonGroup("results", resultPolygons);

    mapLayout.addComponent(map);
    mapLayout.setExpandRatio(map, 1);

    AbstractOrderedLayout regionLegend = DashboardMapComponent.buildRegionLegend(true, CaseMeasure.CASE_COUNT,
            false, valuesLowerQuartile, valuesMedian, valuesUpperQuartile);
    Label legendHeader = new Label(I18nProperties.getCaption(Captions.dashboardMapKey));
    CssStyles.style(legendHeader, CssStyles.H4, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);
    regionLegend.addComponent(legendHeader, 0);

    mapLayout.addComponent(regionLegend);
    mapLayout.setExpandRatio(regionLegend, 0);

    resultsLayout.addComponent(mapLayout);
    resultsLayout.setExpandRatio(mapLayout, 1);
}

From source file:de.symeda.sormas.ui.task.TaskGridComponent.java

License:Open Source License

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

    statusButtons = new HashMap<>();

    HorizontalLayout buttonFilterLayout = new HorizontalLayout();
    buttonFilterLayout.setSpacing(true);
    {//from   ww w  . jav  a2s .com
        Button allTasks = new Button(I18nProperties.getCaption(Captions.all),
                e -> processAssigneeFilterChange(null));
        CssStyles.style(allTasks, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
        allTasks.setCaptionAsHtml(true);
        buttonFilterLayout.addComponent(allTasks);
        statusButtons.put(allTasks, I18nProperties.getCaption(Captions.all));

        Button officerTasks = new Button(I18nProperties.getCaption(Captions.taskOfficerTasks),
                e -> processAssigneeFilterChange(OFFICER_TASKS));
        initializeStatusButton(officerTasks, buttonFilterLayout, OFFICER_TASKS,
                I18nProperties.getCaption(Captions.taskOfficerTasks));
        Button myTasks = new Button(I18nProperties.getCaption(Captions.taskMyTasks),
                e -> processAssigneeFilterChange(MY_TASKS));
        initializeStatusButton(myTasks, buttonFilterLayout, MY_TASKS,
                I18nProperties.getCaption(Captions.taskMyTasks));

        // Default filter for lab users (that don't have any other role) is "My tasks"
        if ((UserProvider.getCurrent().hasUserRole(UserRole.LAB_USER)
                || UserProvider.getCurrent().hasUserRole(UserRole.EXTERNAL_LAB_USER))
                && UserProvider.getCurrent().getUserRoles().size() == 1) {
            activeStatusButton = myTasks;
        } else {
            activeStatusButton = allTasks;
        }
    }
    assigneeFilterLayout.addComponent(buttonFilterLayout);

    HorizontalLayout actionButtonsLayout = new HorizontalLayout();
    actionButtonsLayout.setSpacing(true);
    {
        // Show archived/active cases button
        if (UserProvider.getCurrent().hasUserRight(UserRight.TASK_VIEW_ARCHIVED)) {
            switchArchivedActiveButton = new Button(
                    I18nProperties.getCaption(I18nProperties.getCaption(Captions.taskShowArchived)));
            switchArchivedActiveButton.setStyleName(ValoTheme.BUTTON_LINK);
            switchArchivedActiveButton.addClickListener(e -> {
                criteria.archived(Boolean.TRUE.equals(criteria.getArchived()) ? null : Boolean.TRUE);
                tasksView.navigateTo(criteria);
            });
            actionButtonsLayout.addComponent(switchArchivedActiveButton);
        }
        // Bulk operation dropdown
        if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
            assigneeFilterLayout.setWidth(100, Unit.PERCENTAGE);

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

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

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

    return assigneeFilterLayout;
}

From source file:de.symeda.sormas.ui.task.TaskListComponent.java

License:Open Source License

public TaskListComponent(TaskContext context, ReferenceDto entityRef) {
    setWidth(100, Unit.PERCENTAGE);//  ww  w  .j  ava 2 s.c  o  m
    setMargin(false);
    setSpacing(false);

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

    list = new TaskList(context, entityRef);
    addComponent(list);
    list.reload();

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

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

From source file:de.symeda.sormas.ui.task.TaskListEntry.java

License:Open Source License

public TaskListEntry(TaskIndexDto task) {

    this.task = task;

    setMargin(false);/*from  w ww  .j a v  a2  s. c  om*/
    setSpacing(true);
    setWidth(100, Unit.PERCENTAGE);
    addStyleName(CssStyles.SORMAS_LIST_ENTRY);

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

    // TOP LEFT
    VerticalLayout topLeftLayout = new VerticalLayout();

    topLeftLayout.setMargin(false);
    topLeftLayout.setSpacing(false);

    Label taskTypeLabel = new Label(DataHelper.toStringNullable(task.getTaskType()));
    CssStyles.style(taskTypeLabel, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
    topLeftLayout.addComponent(taskTypeLabel);

    Label suggestedStartLabel = new Label(
            I18nProperties.getPrefixCaption(TaskDto.I18N_PREFIX, TaskDto.SUGGESTED_START) + ": "
                    + DateHelper.formatLocalShortDate(task.getSuggestedStart()));
    topLeftLayout.addComponent(suggestedStartLabel);

    Label dueDateLabel = new Label(I18nProperties.getPrefixCaption(TaskDto.I18N_PREFIX, TaskDto.DUE_DATE) + ": "
            + DateHelper.formatLocalShortDate(task.getDueDate()));
    topLeftLayout.addComponent(dueDateLabel);

    topLayout.addComponent(topLeftLayout);

    // TOP RIGHT
    VerticalLayout topRightLayout = new VerticalLayout();

    topRightLayout.addStyleName(CssStyles.ALIGN_RIGHT);
    topRightLayout.setMargin(false);
    topRightLayout.setSpacing(false);

    Label statusLabel = new Label(DataHelper.toStringNullable(task.getTaskStatus()));
    CssStyles.style(statusLabel, CssStyles.LABEL_BOLD, CssStyles.LABEL_UPPERCASE);
    topRightLayout.addComponent(statusLabel);

    Label priorityLabel = new Label(
            DataHelper.toStringNullable(I18nProperties.getPrefixCaption(TaskDto.I18N_PREFIX, TaskDto.PRIORITY)
                    + ": " + task.getPriority()));
    if (TaskPriority.HIGH == task.getPriority()) {
        priorityLabel.addStyleName(CssStyles.LABEL_IMPORTANT);
    } else if (TaskPriority.NORMAL == task.getPriority()) {
        priorityLabel.addStyleName(CssStyles.LABEL_NEUTRAL);
    }
    topRightLayout.addComponent(priorityLabel);

    Label userLabel = new Label(I18nProperties.getPrefixCaption(TaskDto.I18N_PREFIX, TaskDto.ASSIGNEE_USER)
            + ": " + task.getAssigneeUser().getCaption());
    topRightLayout.addComponent(userLabel);

    topLayout.addComponent(topRightLayout);
    topLayout.setComponentAlignment(topRightLayout, Alignment.TOP_RIGHT);

    String statusStyle;
    switch (task.getTaskStatus()) {
    case DONE:
        statusStyle = CssStyles.LABEL_DONE;
        break;
    case NOT_EXECUTABLE:
        statusStyle = CssStyles.LABEL_NOT;
        break;
    case REMOVED:
        statusStyle = CssStyles.LABEL_DISCARDED;
        break;
    default:
        statusStyle = null;
    }

    if (statusStyle != null) {
        taskTypeLabel.addStyleName(statusStyle);
        suggestedStartLabel.addStyleName(statusStyle);
        dueDateLabel.addStyleName(statusStyle);
        statusLabel.addStyleName(statusStyle);
        priorityLabel.addStyleName(statusStyle);
        userLabel.addStyleName(statusStyle);
    }
}

From source file:de.symeda.sormas.ui.therapy.TherapyView.java

License:Open Source License

private VerticalLayout createPrescriptionsHeader() {
    VerticalLayout prescriptionsHeader = new VerticalLayout();
    prescriptionsHeader.setMargin(false);
    prescriptionsHeader.setSpacing(false);
    prescriptionsHeader.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout headlineRow = new HorizontalLayout();
    headlineRow.setMargin(false);//from   w  w w . j ava 2  s.c om
    headlineRow.setSpacing(true);
    headlineRow.setWidth(100, Unit.PERCENTAGE);
    {
        Label prescriptionsLabel = new Label(I18nProperties.getString(Strings.entityPrescriptions));
        CssStyles.style(prescriptionsLabel, CssStyles.H3);
        headlineRow.addComponent(prescriptionsLabel);
        headlineRow.setExpandRatio(prescriptionsLabel, 1);

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

            Command deleteCommand = selectedItem -> {
                ControllerProvider.getTherapyController()
                        .deleteAllSelectedPrescriptions(prescriptionGrid.getSelectedRows(), new Runnable() {
                            public void run() {
                                reloadPrescriptionGrid();
                            }
                        });
            };
            bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH,
                    deleteCommand);

            headlineRow.addComponent(bulkOperationsDropdown);
            headlineRow.setComponentAlignment(bulkOperationsDropdown, Alignment.MIDDLE_RIGHT);
        }

        Button newPrescriptionButton = new Button(
                I18nProperties.getCaption(Captions.prescriptionNewPrescription));
        CssStyles.style(newPrescriptionButton, ValoTheme.BUTTON_PRIMARY);
        newPrescriptionButton.addClickListener(e -> {
            ControllerProvider.getTherapyController().openPrescriptionCreateForm(
                    prescriptionCriteria.getTherapy(), this::reloadPrescriptionGrid);
        });
        headlineRow.addComponent(newPrescriptionButton);

        headlineRow.setComponentAlignment(newPrescriptionButton, Alignment.MIDDLE_RIGHT);
    }
    prescriptionsHeader.addComponent(headlineRow);

    HorizontalLayout filterRow = new HorizontalLayout();
    filterRow.setMargin(false);
    filterRow.setSpacing(true);
    {
        prescriptionTypeFilter = new ComboBox();
        prescriptionTypeFilter.setWidth(140, Unit.PIXELS);
        prescriptionTypeFilter.setInputPrompt(I18nProperties.getPrefixCaption(PrescriptionDto.I18N_PREFIX,
                PrescriptionDto.PRESCRIPTION_TYPE));
        prescriptionTypeFilter.addItems((Object[]) TreatmentType.values());
        prescriptionTypeFilter.addValueChangeListener(e -> {
            prescriptionCriteria.prescriptionType(((TreatmentType) e.getProperty().getValue()));
            navigateTo(prescriptionCriteria);
        });
        filterRow.addComponent(prescriptionTypeFilter);

        prescriptionTextFilter = new TextField();
        prescriptionTextFilter.setWidth(300, Unit.PIXELS);
        prescriptionTextFilter.setNullRepresentation("");
        prescriptionTextFilter.setInputPrompt(I18nProperties.getString(Strings.promptPrescriptionTextFilter));
        prescriptionTextFilter.addTextChangeListener(e -> {
            prescriptionCriteria.textFilter(e.getText());
            reloadPrescriptionGrid();
        });
        filterRow.addComponent(prescriptionTextFilter);
    }
    prescriptionsHeader.addComponent(filterRow);

    return prescriptionsHeader;
}

From source file:de.symeda.sormas.ui.therapy.TherapyView.java

License:Open Source License

private VerticalLayout createTreatmentsHeader() {
    VerticalLayout treatmentsHeader = new VerticalLayout();
    treatmentsHeader.setMargin(false);// w  w  w  .ja  va 2  s . c  o  m
    treatmentsHeader.setSpacing(false);
    treatmentsHeader.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout headlineRow = new HorizontalLayout();
    headlineRow.setMargin(false);
    headlineRow.setSpacing(true);
    headlineRow.setWidth(100, Unit.PERCENTAGE);
    {
        Label treatmentsLabel = new Label(I18nProperties.getString(Strings.headingTreatments));
        CssStyles.style(treatmentsLabel, CssStyles.H3);
        headlineRow.addComponent(treatmentsLabel);
        headlineRow.setExpandRatio(treatmentsLabel, 1);

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

            Command deleteCommand = selectedItem -> {
                ControllerProvider.getTherapyController()
                        .deleteAllSelectedTreatments(treatmentGrid.getSelectedRows(), new Runnable() {
                            public void run() {
                                reloadTreatmentGrid();
                            }
                        });
            };
            bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH,
                    deleteCommand);

            headlineRow.addComponent(bulkOperationsDropdown);
            headlineRow.setComponentAlignment(bulkOperationsDropdown, Alignment.MIDDLE_RIGHT);
        }

        Button newTreatmentButton = new Button(I18nProperties.getCaption(Captions.treatmentNewTreatment));
        newTreatmentButton.addClickListener(e -> {
            ControllerProvider.getTherapyController().openTreatmentCreateForm(treatmentCriteria.getTherapy(),
                    this::reloadTreatmentGrid);
        });
        headlineRow.addComponent(newTreatmentButton);

        headlineRow.setComponentAlignment(newTreatmentButton, Alignment.MIDDLE_RIGHT);
    }
    treatmentsHeader.addComponent(headlineRow);

    HorizontalLayout filterRow = new HorizontalLayout();
    filterRow.setMargin(false);
    filterRow.setSpacing(true);
    {
        treatmentTypeFilter = new ComboBox();
        treatmentTypeFilter.setWidth(140, Unit.PIXELS);
        treatmentTypeFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(TreatmentDto.I18N_PREFIX, TreatmentDto.TREATMENT_TYPE));
        treatmentTypeFilter.addItems((Object[]) TreatmentType.values());
        treatmentTypeFilter.addValueChangeListener(e -> {
            treatmentCriteria.treatmentType(((TreatmentType) e.getProperty().getValue()));
            navigateTo(treatmentCriteria);
        });
        filterRow.addComponent(treatmentTypeFilter);

        treatmentTextFilter = new TextField();
        treatmentTextFilter.setWidth(300, Unit.PIXELS);
        treatmentTextFilter.setNullRepresentation("");
        treatmentTextFilter.setInputPrompt(I18nProperties.getString(Strings.promptTreatmentTextFilter));
        treatmentTextFilter.addTextChangeListener(e -> {
            treatmentCriteria.textFilter(e.getText());
            reloadTreatmentGrid();
        });
        filterRow.addComponent(treatmentTextFilter);
    }
    treatmentsHeader.addComponent(filterRow);

    return treatmentsHeader;
}