Example usage for com.vaadin.ui MenuBar addItem

List of usage examples for com.vaadin.ui MenuBar addItem

Introduction

In this page you can find the example usage for com.vaadin.ui MenuBar addItem.

Prototype

public MenuBar.MenuItem addItem(String caption, MenuBar.Command command) 

Source Link

Document

Add a new item to the menu bar.

Usage

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

License:Open Source License

public HorizontalLayout createTopBar() {
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setSpacing(true);/*w w  w.  j a v a 2  s  . c  om*/
    topLayout.setWidth(100, Unit.PERCENTAGE);

    //      statusButtons = new HashMap<>();
    //
    //      Button contactButton = new Button(I18nProperties.getCaption(Captions.contactRelated), e -> {
    //         grid.reload(getContactRef());
    //         processStatusChangeVisuals(e.getButton());
    //      });
    //      CssStyles.style(contactButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
    //      contactButton.setCaptionAsHtml(true);
    //      topLayout.addComponent(contactButton);
    //      statusButtons.put(contactButton, I18nProperties.getCaption(Captions.contactRelated));
    //
    //      Button personButton = new Button(I18nProperties.getCaption(Captions.contactPersonVisits), e -> {
    //         ContactDto contact = FacadeProvider.getContactFacade().getContactByUuid(getContactRef().getUuid());
    //         grid.reload(contact.getPerson());
    //         processStatusChangeVisuals(e.getButton());
    //      });
    //      CssStyles.style(personButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER, CssStyles.BUTTON_FILTER_LIGHT);
    //      personButton.setCaptionAsHtml(true);
    //      topLayout.addComponent(personButton);
    //      statusButtons.put(personButton, I18nProperties.getCaption(Captions.contactPersonVisits));

    //      topLayout.setExpandRatio(topLayout.getComponent(topLayout.getComponentCount()-1), 1);

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

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

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

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

    if (UserProvider.getCurrent().hasUserRight(UserRight.VISIT_CREATE)) {
        newButton = new Button(I18nProperties.getCaption(Captions.visitNewVisit));
        newButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        newButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        newButton.addClickListener(e -> {
            ControllerProvider.getVisitController().createVisit(this.getContactRef(), r -> grid.reload());
        });
        topLayout.addComponent(newButton);
        topLayout.setComponentAlignment(newButton, Alignment.MIDDLE_RIGHT);
    }

    topLayout.addStyleName(CssStyles.VSPACE_3);
    //      activeStatusButton = contactButton;
    return topLayout;
}

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

License:Open Source License

public HorizontalLayout createTopBar() {
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setSpacing(true);//  www.j  a  v a  2 s. c  o m
    topLayout.setWidth("100%");

    Label header = new Label(I18nProperties.getPrefixCaption(EventDto.I18N_PREFIX, EventDto.EVENT_PERSONS));
    header.setSizeUndefined();
    CssStyles.style(header, CssStyles.H2, CssStyles.VSPACE_NONE);
    topLayout.addComponent(header);

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

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

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

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

    if (UserProvider.getCurrent().hasUserRight(UserRight.EVENTPARTICIPANT_CREATE)) {
        addButton = new Button(I18nProperties.getCaption(Captions.eventParticipantAddPerson));
        addButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        addButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        addButton.addClickListener(e -> {
            ControllerProvider.getEventParticipantController().createEventParticipant(this.getEventRef(),
                    r -> grid.reload());
        });
        topLayout.addComponent(addButton);
        topLayout.setComponentAlignment(addButton, Alignment.MIDDLE_RIGHT);
    }

    topLayout.addStyleName(CssStyles.VSPACE_3);
    return topLayout;
}

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

License:Open Source License

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

    statusButtons = new HashMap<>();

    Button statusAll = new Button(I18nProperties.getCaption(Captions.all), e -> {
        criteria.eventStatus(null);/*w  w w .  j a v a 2  s  . c  o m*/
        navigateTo(criteria);
    });
    CssStyles.style(statusAll, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
    statusAll.setCaptionAsHtml(true);
    statusFilterLayout.addComponent(statusAll);
    statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
    activeStatusButton = statusAll;

    for (EventStatus status : EventStatus.values()) {
        Button statusButton = new Button(status.toString(), e -> {
            criteria.eventStatus(status);
            navigateTo(criteria);
        });
        statusButton.setData(status);
        CssStyles.style(statusButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER,
                CssStyles.BUTTON_FILTER_LIGHT);
        statusButton.setCaptionAsHtml(true);
        statusFilterLayout.addComponent(statusButton);
        statusButtons.put(statusButton, status.toString());
    }

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

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

            Command changeCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .showBulkEventDataEditComponent(grid.asMultiSelect().getSelectedItems());
            };
            bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkEdit), VaadinIcons.ELLIPSIS_H,
                    changeCommand);

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

            Command archiveCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .archiveAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                            public void run() {
                                grid.reload();
                            }
                        });
            };
            archiveItem = bulkOperationsItem.addItem(
                    I18nProperties.getCaption(I18nProperties.getCaption(Captions.actionArchive)),
                    VaadinIcons.ARCHIVE, archiveCommand);

            Command dearchiveCommand = selectedItem -> {
                ControllerProvider.getEventController()
                        .dearchiveAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                            public void run() {
                                grid.reload();
                            }
                        });
            };
            dearchiveItem = bulkOperationsItem.addItem(
                    I18nProperties.getCaption(I18nProperties.getCaption(Captions.actionDearchive)),
                    VaadinIcons.ARCHIVE, dearchiveCommand);
            dearchiveItem.setVisible(false);

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

    return statusFilterLayout;
}

From source file:de.symeda.sormas.ui.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);
    {// w ww  .  ja v  a 2 s  .c om
        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);
                }//www.  jav a  2s  . 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.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 www  . j a 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  a 2s .  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);/*  w  ww .  j  av a  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;
}

From source file:eu.lod2.stat.dsdrepo.DSDRepoComponent.java

public DSDRepoComponent(Repository repository, String dataGraph, String repoGraph) {
    this.repository = repository;
    this.dataGraph = dataGraph;
    this.repoGraph = repoGraph;

    initializeRepoGraph();// w ww. ja va2  s.c  o m

    dcRepo = new SparqlDCRepository(repository);
    graph = new SparqlDCGraph(repository, dataGraph);

    setSizeFull();
    VerticalLayout rootLayout = new VerticalLayout();
    rootLayout.setSizeFull();
    rootLayout.setSpacing(true);
    setDebugId("dsd-repo");

    mainLayout = new VerticalLayout();
    mainLayout.setSizeUndefined();
    mainLayout.setWidth("100%");
    //        mainLayout.setHeight("800px");
    mainLayout.setSpacing(true);

    HorizontalLayout menuLayout = new HorizontalLayout();
    menuLayout.setSpacing(true);
    menuLayout.setWidth("100%");
    rootLayout.addComponent(menuLayout);
    rootLayout.setExpandRatio(menuLayout, 0.0f);

    final MenuBar menu = new MenuBar();
    menu.addStyleName("dsd");
    cmdFindDSD = new MenuBar.Command() {
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            for (MenuBar.MenuItem item : menu.getItems()) {
                if (item == selectedItem) {
                    if (!item.getStyleName().contains("selected")) {
                        if (ds != null)
                            item.setStyleName("selected");
                        findDSDs();
                    }
                } else
                    item.setStyleName("bleja");
            }
        }
    };
    menu.addItem("Find Suitable DSDs", cmdFindDSD).setStyleName("bleja");
    cmdCreateDSD = new MenuBar.Command() {
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            for (MenuBar.MenuItem item : menu.getItems()) {
                if (item == selectedItem) {
                    if (!item.getStyleName().contains("selected")) {
                        if (ds != null)
                            item.setStyleName("selected");
                        createDSD();
                    }
                } else
                    item.setStyleName("bleja");
            }
        }
    };
    menu.addItem("Create DSD", cmdCreateDSD).setStyleName("bleja");
    cmdStoreDSD = new MenuBar.Command() {
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            for (MenuBar.MenuItem item : menu.getItems()) {
                if (item == selectedItem) {
                    if (!item.getStyleName().contains("selected")) {
                        if (ds != null)
                            item.setStyleName("selected");
                        storeDSD();
                    }
                } else
                    item.setStyleName("bleja");
            }
        }
    };
    menu.addItem("Store DSD", cmdStoreDSD).setStyleName("bleja");

    menuLayout.addComponent(menu);
    Label spaceLbl = new Label("");
    menuLayout.addComponent(spaceLbl);
    menuLayout.setExpandRatio(spaceLbl, 2.0f);
    Label lbl = new Label("Choose dataset: ");
    lbl.setSizeUndefined();
    menuLayout.addComponent(lbl);

    Collection<DataSet> colDataSets = graph.getDataSets();
    if (colDataSets == null)
        colDataSets = new LinkedList<DataSet>();
    selectDataSet = new ComboBox(null, colDataSets);
    selectDataSet.setImmediate(true);
    selectDataSet.setNewItemsAllowed(false);
    selectDataSet.setNullSelectionAllowed(false);
    selectDataSet.setWidth("300px");
    selectDataSet.addListener(new Property.ValueChangeListener() {
        public void valueChange(Property.ValueChangeEvent event) {
            ds = (DataSet) event.getProperty().getValue();
        }
    });
    menuLayout.addComponent(selectDataSet);

    Panel mainPanel = new Panel(mainLayout);
    mainPanel.setSizeFull();
    mainPanel.setScrollable(true);
    mainPanel.setStyleName(Reindeer.PANEL_LIGHT);

    Label hrLabel = new Label("<hr/>", Label.CONTENT_XHTML);
    rootLayout.addComponent(hrLabel);
    rootLayout.setExpandRatio(hrLabel, 0.0f);
    rootLayout.addComponent(mainPanel);
    rootLayout.setExpandRatio(mainPanel, 2.0f);
    rootLayout.setMargin(true, false, true, false);

    setCompositionRoot(rootLayout);
}

From source file:fi.jasoft.draganddrop.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    Panel showcase = new Panel();
    showcase.setSizeUndefined();//  w ww  .  ja  v  a  2 s . co m

    navigator = new Navigator(this, showcase);

    for (DemoView view : views) {
        navigator.addView(view.getViewPath(), view);
    }

    // default
    openView(views.get(0));

    MenuBar demos = new MenuBar();
    demos.setStyleName(ValoTheme.MENUBAR_BORDERLESS);

    for (final DemoView view : views) {
        demos.addItem(view.getViewCaption(), new Command() {

            @Override
            public void menuSelected(MenuItem selectedItem) {
                openView(view);
            }
        });
    }

    VerticalLayout root = new VerticalLayout(demos, showcase);
    root.setSizeFull();
    root.setExpandRatio(showcase, 1);
    root.setComponentAlignment(showcase, Alignment.MIDDLE_CENTER);
    setContent(root);

    HorizontalLayout sourceWrapperLayout = new HorizontalLayout();
    Label caption = new Label("Source code for example");
    caption.setStyleName("source-caption");
    sourceWrapperLayout.addComponent(caption);

    Panel sourceWrapper = new Panel(codeLabel);
    sourceWrapper.setStyleName(ValoTheme.PANEL_BORDERLESS);
    sourceWrapper.setHeight(getPage().getBrowserWindowHeight() + "px");
    sourceWrapperLayout.addComponent(sourceWrapper);
    sourceWrapperLayout.setExpandRatio(sourceWrapper, 1);

    Toolbox sourceBox = new Toolbox();
    sourceBox.setOrientation(ORIENTATION.RIGHT_CENTER);
    sourceBox.setContent(sourceWrapperLayout);
    sourceBox.setOverflowSize(30);
    root.addComponent(sourceBox);
}