Example usage for com.vaadin.ui InlineDateTimeField InlineDateTimeField

List of usage examples for com.vaadin.ui InlineDateTimeField InlineDateTimeField

Introduction

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

Prototype

public InlineDateTimeField() 

Source Link

Document

Constructs an empty InlineDateTimeField with no caption.

Usage

From source file:dhbw.clippinggorilla.userinterface.views.ArchiveView.java

public ArchiveView() {
    HorizontalLayout optionsLayout = new HorizontalLayout();
    optionsLayout.setWidth("100%");

    Grid<Clipping> gridClippings = new Grid<>();
    Set<Clipping> clippings = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
            LocalDate.now(ZoneId.of("Europe/Berlin")));
    gridClippings.setItems(clippings);//from  w w w  .  j  a v a2  s .  co  m

    InlineDateTimeField datePicker = new InlineDateTimeField();
    datePicker.setValue(LocalDateTime.now(ZoneId.of("Europe/Berlin")));
    datePicker.setLocale(Locale.GERMANY);
    datePicker.setResolution(DateTimeResolution.DAY);
    datePicker.addValueChangeListener(date -> {
        Set<Clipping> clippingsOfDate = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
                date.getValue().toLocalDate());
        gridClippings.setItems(clippingsOfDate);
        gridClippings.getDataProvider().refreshAll();
    });

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Column columnTime = gridClippings.addColumn(c -> {
        return c.getDate().format(formatter);
    });
    Language.setCustom(Word.TIME, s -> columnTime.setCaption(s));
    Column columnAmountArticles = gridClippings.addColumn(c -> {
        long amountArticles = c.getArticles().values().stream().flatMap(l -> l.stream()).count();
        amountArticles += c.getArticlesFromGroup().values().stream().flatMap(l -> l.stream()).count();
        if (amountArticles != 1) {
            return amountArticles + " " + Language.get(Word.ARTICLES);
        } else {
            return amountArticles + " " + Language.get(Word.ARTICLE);
        }
    });
    Language.setCustom(Word.ARTICLES, s -> {
        columnAmountArticles.setCaption(s);
        gridClippings.getDataProvider().refreshAll();
    });

    gridClippings.setHeight("100%");
    gridClippings.setSelectionMode(Grid.SelectionMode.SINGLE);
    gridClippings.addSelectionListener(c -> {
        if (c.getFirstSelectedItem().isPresent()) {
            currentClipping = c.getFirstSelectedItem().get();
            showClippingBy(currentClipping, currentSort);
        }
    });

    optionsLayout.addComponents(datePicker, gridClippings);
    optionsLayout.setComponentAlignment(datePicker, Alignment.BOTTOM_CENTER);
    optionsLayout.setComponentAlignment(gridClippings, Alignment.BOTTOM_RIGHT);
    optionsLayout.setExpandRatio(gridClippings, 5);

    VerticalLayout sortLayout = new VerticalLayout();

    comboBoxSortOptions = new ComboBox<>(Language.get(Word.SORT_BY));
    Language.setCustom(Word.SORT_BY, s -> {
        comboBoxSortOptions.setCaption(s);
        comboBoxSortOptions.getDataProvider().refreshAll();
    });
    comboBoxSortOptions.setItems(EnumSet.allOf(ClippingView.SortOptions.class));
    comboBoxSortOptions.setItemCaptionGenerator(s -> s.getName());
    comboBoxSortOptions.setItemIconGenerator(s -> s.getIcon());
    comboBoxSortOptions.setValue(currentSort);
    comboBoxSortOptions.setTextInputAllowed(false);
    comboBoxSortOptions.setEmptySelectionAllowed(false);
    comboBoxSortOptions.addStyleName("comboboxsort");
    comboBoxSortOptions.addValueChangeListener(e -> {
        currentSort = e.getValue();
        showClippingBy(currentClipping, currentSort);
    });
    comboBoxSortOptions.setVisible(false);

    sortLayout.setMargin(false);
    sortLayout.setSpacing(false);
    sortLayout.addComponent(comboBoxSortOptions);

    clippingArticlesLayout = new VerticalLayout();
    clippingArticlesLayout.setSpacing(true);
    clippingArticlesLayout.setMargin(false);
    clippingArticlesLayout.setSizeFull();

    addComponents(optionsLayout, sortLayout, clippingArticlesLayout);
}

From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java

private Component buildClippingsTab(User user) {
    HorizontalLayout root = new HorizontalLayout();
    root.setCaption(Language.get(Word.CLIPPINGS));
    root.setIcon(VaadinIcons.NEWSPAPER);
    root.setWidth("100%");
    root.setSpacing(true);//from w w w  .j a  v  a 2s  . c  o m
    root.setMargin(true);

    FormLayout formLayoutClippingDetails = new FormLayout();
    formLayoutClippingDetails.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    root.addComponent(formLayoutClippingDetails);

    CheckBox checkBoxReceiveEmails = new CheckBox();
    checkBoxReceiveEmails.setValue(UserUtils.getEmailNewsletter(user));
    checkBoxReceiveEmails.addValueChangeListener(v -> UserUtils.setEmailNewsletter(user, v.getValue()));
    HorizontalLayout layoutCheckBoxReceiveEmails = new HorizontalLayout(checkBoxReceiveEmails);
    layoutCheckBoxReceiveEmails.setCaption(Language.get(Word.EMAIL_SUBSCRIPTION));
    layoutCheckBoxReceiveEmails.setMargin(false);
    layoutCheckBoxReceiveEmails.setSpacing(false);

    HorizontalLayout layoutAddNewClippingTime = new HorizontalLayout();
    layoutAddNewClippingTime.setMargin(false);
    layoutAddNewClippingTime.setCaption(Language.get(Word.ADD_CLIPPING_TIME));
    layoutAddNewClippingTime.setWidth("100%");

    InlineDateTimeField dateFieldNewClippingTime = new InlineDateTimeField();
    LocalDateTime value = LocalDateTime.now(ZoneId.of("Europe/Berlin"));
    dateFieldNewClippingTime.setValue(value);
    dateFieldNewClippingTime.setLocale(VaadinSession.getCurrent().getLocale());
    dateFieldNewClippingTime.setResolution(DateTimeResolution.MINUTE);
    dateFieldNewClippingTime.addStyleName("time-only");

    Button buttonAddClippingTime = new Button();
    buttonAddClippingTime.setIcon(VaadinIcons.PLUS);
    buttonAddClippingTime.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonAddClippingTime.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonAddClippingTime.addClickListener(e -> {
        LocalTime generalTime = dateFieldNewClippingTime.getValue().toLocalTime();
        layoutClippingTimes.addComponent(getTimeRow(user, generalTime));
        UserUtils.addClippingSendTime(user, generalTime);
    });
    layoutAddNewClippingTime.addComponents(dateFieldNewClippingTime, buttonAddClippingTime);
    layoutAddNewClippingTime.setComponentAlignment(dateFieldNewClippingTime, Alignment.MIDDLE_LEFT);
    layoutAddNewClippingTime.setComponentAlignment(buttonAddClippingTime, Alignment.MIDDLE_CENTER);
    layoutAddNewClippingTime.setExpandRatio(dateFieldNewClippingTime, 5);

    layoutClippingTimes = new VerticalLayout();
    layoutClippingTimes.setMargin(new MarginInfo(true, false, false, true));
    layoutClippingTimes.setCaption(Language.get(Word.CLIPPING_TIMES));
    layoutClippingTimes.setWidth("100%");
    layoutClippingTimes.addStyleName("times");

    Set<LocalTime> userTimes = user.getClippingTime();
    userTimes.forEach(t -> layoutClippingTimes.addComponent(getTimeRow(user, t)));

    formLayoutClippingDetails.addComponents(layoutCheckBoxReceiveEmails, layoutAddNewClippingTime,
            layoutClippingTimes);

    return root;
}