Example usage for com.vaadin.ui HorizontalLayout setExpandRatio

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

Introduction

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

Prototype

public void setExpandRatio(Component component, float ratio) 

Source Link

Document

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

Usage

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

License:Open Source License

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

    statusButtons = new HashMap<>();

    HorizontalLayout buttonFilterLayout = new HorizontalLayout();
    buttonFilterLayout.setSpacing(true);
    {/*from   www  . j a v  a 2  s .c  o m*/
        Button statusAll = new Button(I18nProperties.getCaption(Captions.all), e -> processStatusChange(null));
        CssStyles.style(statusAll, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
        statusAll.setCaptionAsHtml(true);
        buttonFilterLayout.addComponent(statusAll);
        statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
        activeStatusButton = statusAll;

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

    shipmentFilterLayout.addComponent(buttonFilterLayout);

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

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

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

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

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

    return shipmentFilterLayout;
}

From source file:de.symeda.sormas.ui.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);
                }/* w w  w . j  a  v  a 2 s  .  c  o m*/
                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 ava2s  .c  o  m*/

    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

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

    if (resultData.isEmpty()) {
        resultsLayout.addComponent(emptyResultLabel);
        return;// ww  w.  j  a v a2s  .  co 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);
    {//  w w  w  . ja v a  2 s  . c om
        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.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  a v a2  s  . c o  m*/
    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);//from www.j  a  va 2 s  .  c om
    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;
}

From source file:de.symeda.sormas.ui.utils.DateTimeField.java

License:Open Source License

@Override
protected Component initContent() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);//from  ww w. jav  a 2 s.  c o m
    layout.setWidth(100, Unit.PERCENTAGE);

    dateField = new DateField();
    dateField.setWidth(100, Unit.PERCENTAGE);
    dateField.setDateFormat(DateHelper.getLocalDatePattern());
    dateField.setLenient(true);
    layout.addComponent(dateField);
    layout.setExpandRatio(dateField, 0.5f);

    if (!converterSet) {
        dateField.setConverter(converter);
        converterSet = true;
    }

    timeField = new ComboBox();
    timeField.addContainerProperty(CAPTION_PROPERTY_ID, String.class, null);
    timeField.setItemCaptionPropertyId(CAPTION_PROPERTY_ID);

    // fill
    for (int hours = 0; hours <= 23; hours++) {
        for (int minutes = 0; minutes <= 59; minutes += 15) {
            ensureTimeEntry(hours, minutes);
        }
    }

    timeField.setNewItemsAllowed(true);
    timeField.setNewItemHandler(new NewItemHandler() {
        @Override
        public void addNewItem(String newItemCaption) {
            Date date = DateHelper.parseTime(newItemCaption);
            timeField.setValue(ensureTimeEntry(date));
        }
    });

    timeField.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(timeField);
    layout.setExpandRatio(timeField, 0.5f);

    // value cn't be set on readOnly fields
    dateField.setReadOnly(false);
    timeField.setReadOnly(false);

    // set field values based on internal value
    setInternalValue(super.getInternalValue());

    dateField.setReadOnly(isReadOnly());
    timeField.setReadOnly(isReadOnly());

    Property.ValueChangeListener validationValueChangeListener = new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            markAsDirty();
        }
    };
    dateField.addValueChangeListener(validationValueChangeListener);
    timeField.addValueChangeListener(validationValueChangeListener);

    return layout;
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.MultiscaleComponent.java

License:Open Source License

void buildEmptyComments() {

    // add comments
    VerticalLayout addComment = new VerticalLayout();
    addComment.setMargin(true);/*ww w  .  ja  v a2s  .  co  m*/
    addComment.setWidth(100, Unit.PERCENTAGE);
    final TextArea comments = new TextArea();
    comments.setInputPrompt("Write your comment here...");
    comments.setWidth(100, Unit.PERCENTAGE);
    comments.setRows(2);
    Button commentsOk = new Button("Add Comment");
    commentsOk.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    commentsOk.addClickListener(new ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = -5369241494545155677L;

        public void buttonClick(ClickEvent event) {
            if ("".equals(comments.getValue()))
                return;

            String newComment = comments.getValue();
            // reset comments
            comments.setValue("");
            // use some date format
            Date dNow = new Date();
            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

            Note note = new Note();
            note.setComment(newComment);
            note.setUsername(controller.getUser());
            note.setTime(ft.format(dNow));

            // show it now
            // pastcomments.getContainerDataSource().addItem(note);
            notes.add(note);

            // TODO write back
            Label commentsLabel = new Label(translateComments(notes), ContentMode.HTML);
            commentsPanel.setContent(commentsLabel);

            // write back to openbis
            if (!controller.addNote(note)) {
                Notification.show("Could not add comment to sample. How did you do that?");
            }

        }

    });

    HorizontalLayout inputPrompt = new HorizontalLayout();
    inputPrompt.addComponent(comments);
    inputPrompt.addComponent(commentsOk);

    inputPrompt.setWidth(50, Unit.PERCENTAGE);
    inputPrompt.setComponentAlignment(commentsOk, Alignment.TOP_RIGHT);
    inputPrompt.setExpandRatio(comments, 1.0f);

    // addComment.addComponent(comments);
    // addComment.addComponent(commentsOk);

    addComment.addComponent(commentsPanel);
    addComment.addComponent(inputPrompt);

    // addComment.setComponentAlignment(comments, Alignment.TOP_CENTER);
    // addComment.setComponentAlignment(commentsOk, Alignment.MIDDLE_CENTER);

    addComment.setComponentAlignment(commentsPanel, Alignment.TOP_CENTER);
    addComment.setComponentAlignment(inputPrompt, Alignment.MIDDLE_CENTER);

    mainlayout.addComponent(addComment);

    // mainlayout.addComponent(pastcomments);
    Label commentsLabel = new Label("No comments added so far.", ContentMode.HTML);
    commentsPanel.setContent(commentsLabel);

    // mainlayout.addComponent(commentsPanel);
    // mainlayout.setComponentAlignment(commentsPanel,
    // Alignment.TOP_CENTER);
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.QbicmainportletUI.java

License:Open Source License

/**
 * builds page if user is not logged in/*from  w w  w.j ava  2s  .  c  om*/
 */
private void buildNotLoggedinLayout() {
    // Mail to qbic
    ExternalResource resource = new ExternalResource("mailto:info@qbic.uni-tuebingen.de");
    Link mailToQbicLink = new Link("", resource);
    mailToQbicLink.setIcon(new ThemeResource("mail9.png"));

    ThemeDisplay themedisplay = (ThemeDisplay) VaadinService.getCurrentRequest()
            .getAttribute(WebKeys.THEME_DISPLAY);

    // redirect to liferay login page
    Link loginPortalLink = new Link("", new ExternalResource(themedisplay.getURLSignIn()));
    loginPortalLink.setIcon(new ThemeResource("lock12.png"));

    // left part of the page
    VerticalLayout signIn = new VerticalLayout();
    signIn.addComponent(
            new Label("<h3>Sign in to manage your projects and access your data:</h3>", ContentMode.HTML));
    signIn.addComponent(loginPortalLink);
    signIn.setStyleName("no-user-login");
    // right part of the page
    VerticalLayout contact = new VerticalLayout();
    contact.addComponent(
            new Label("<h3>If you are interested in doing projects get in contact:</h3>", ContentMode.HTML));
    contact.addComponent(mailToQbicLink);
    contact.setStyleName("no-user-login");

    // build final layout, with some gaps between
    HorizontalLayout notSignedInLayout = new HorizontalLayout();
    Label expandingGap1 = new Label();
    expandingGap1.setWidth("100%");
    notSignedInLayout.addComponent(expandingGap1);
    notSignedInLayout.addComponent(signIn);

    notSignedInLayout.addComponent(contact);
    notSignedInLayout.setExpandRatio(expandingGap1, 0.16f);
    notSignedInLayout.setExpandRatio(signIn, 0.36f);

    notSignedInLayout.setExpandRatio(contact, 0.36f);

    notSignedInLayout.setWidth("100%");
    notSignedInLayout.setSpacing(true);
    setContent(notSignedInLayout);
}