com.vaadin.ui.DateField Java Examples

The following examples show how to use com.vaadin.ui.DateField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DurationField.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void valueChange(final Property.ValueChangeEvent event) {
    // do not delete this method, even when removing the code inside this
    // method. This method overwrites the super method, which is
    // necessary, that parsing works correctly on pressing enter key

    if (!(event.getProperty() instanceof DurationField)) {
        return;
    }
    final Date value = (Date) event.getProperty().getValue();

    // setValue() calls valueChanged again, when the minimum is greater
    // than the maximum this can lead to an endless loop
    if (value != null && minimumDuration != null && maximumDuration != null
            && minimumDuration.before(maximumDuration)) {

        if (compareTimeOfDates(value, maximumDuration) > 0) {
            ((DateField) event.getProperty()).setValue(maximumDuration);
        }

        if (compareTimeOfDates(minimumDuration, value) > 0) {
            ((DateField) event.getProperty()).setValue(minimumDuration);
        }
    }
}
 
Example #2
Source File: FieldFactory.java    From vaadin-grid-util with MIT License 6 votes vote down vote up
public static <T> DateField genDateField(Binder<T> binder, String propertyId, final java.text.SimpleDateFormat dateFormat) {
    DateField dateField = new DateField();

    binder.bind(dateField, propertyId);
    if (dateFormat != null) {
        dateField.setDateFormat(dateFormat.toPattern());
    }
    dateField.setWidth("100%");

    dateField.setResolution(DateResolution.DAY);
    dateField.addStyleName(STYLENAME_GRIDCELLFILTER);
    dateField.addStyleName(ValoTheme.DATEFIELD_TINY);
    dateField.addValueChangeListener(e -> {
        if (binder.isValid()) {
            dateField.setComponentError(null);
        }
    });
    return dateField;
}
 
Example #3
Source File: MilestoneEditFormFieldFactory.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected HasValue<?> onCreateField(Object propertyId) {
    if (Milestone.Field.assignuser.equalTo(propertyId)) {
        return new ProjectMemberSelectionField();
    } else if (propertyId.equals("status")) {
        return new ProgressStatusComboBox();
    } else if (propertyId.equals("name")) {
        return new MTextField().withRequiredIndicatorVisible(true);
    } else if (propertyId.equals("description")) {
        return new RichTextArea();
    } else if ("section-attachments".equals(propertyId)) {
        Milestone beanItem = attachForm.getBean();
        if (beanItem.getId() != null) {
            String attachmentPath = AttachmentUtils.getProjectEntityAttachmentPath(AppUI.getAccountId(),
                    beanItem.getProjectid(), ProjectTypeConstants.MILESTONE, "" + beanItem.getId());
            attachmentUploadField = new AttachmentUploadField(attachmentPath);
        } else {
            attachmentUploadField = new AttachmentUploadField();
        }
        return attachmentUploadField;
    } else if (Milestone.Field.startdate.equalTo(propertyId) || Milestone.Field.enddate.equalTo(propertyId)) {
        return new DateField();
    }

    return null;
}
 
Example #4
Source File: ProjectGeneralInfoStep.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected HasValue<?> onCreateField(final Object propertyId) {
    if (Project.Field.description.equalTo(propertyId)) {
        return new RichTextArea();
    } else if (Project.Field.status.equalTo(propertyId)) {
        ProjectStatusComboBox statusField = new ProjectStatusComboBox();
        statusField.setRequiredIndicatorVisible(true);
        if (project.getStatus() == null) {
            project.setStatus(StatusI18nEnum.Open.name());
        }
        return statusField;
    } else if (Project.Field.shortname.equalTo(propertyId)) {
        return new MTextField().withRequiredIndicatorVisible(true).withWidth(WebThemes.FORM_CONTROL_WIDTH);
    } else if (Project.Field.name.equalTo(propertyId)) {
        return new MTextField().withRequiredIndicatorVisible(true).withWidth(WebThemes.FORM_CONTROL_WIDTH);
    } else if (Project.Field.memlead.equalTo(propertyId)) {
        return new ActiveUserComboBox();
    } else if (Project.Field.planstartdate.equalTo(propertyId) || Project.Field.planenddate.equalTo(propertyId)) {
        return new DateField();
    }

    return null;
}
 
Example #5
Source File: GridCellWrapper.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
public void addField(Component field) {
    if (field instanceof HasValue && ((HasValue)field).isRequiredIndicatorVisible() && captionComp!= null) {
        captionComp.addStyleName(WebThemes.REQUIRED_FIELD_INDICATOR);
    }
    fieldWrapper.removeAllComponents();
    field.setCaption(null);

    if (field.getWidth() != -1) {
        // continue
    } else if (field instanceof MultiSelectComp || field instanceof DateField) {
        field.setWidth(WebThemes.FORM_CONTROL_WIDTH);
    } else {
        field.setWidth("100%");
    }
    fieldWrapper.withComponent(field);
}
 
Example #6
Source File: ActionTypeOptionGroupAssignmentLayout.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private void addAutoForceItemWithLabelAndDateField() {
    final FlexibleOptionGroupItemComponent autoForceItem = actionTypeOptionGroup
            .getItemComponent(ActionTypeOption.AUTO_FORCED);
    autoForceItem.setStyleName(STYLE_DIST_WINDOW_ACTIONTYPE);
    autoForceItem.setId(UIComponentIdProvider.ACTION_TYPE_OPTION_GROUP_SAVE_TIMEFORCED);
    addComponent(autoForceItem);
    final Label autoForceLabel = new Label();
    autoForceLabel.setStyleName("statusIconPending");
    autoForceLabel.setIcon(FontAwesome.HISTORY);
    autoForceLabel.setCaption(i18n.getMessage(UIMessageIdProvider.CAPTION_ACTION_TIME_FORCED));
    autoForceLabel.setDescription(i18n.getMessage(UIMessageIdProvider.TOOLTIP_TIMEFORCED_ITEM));
    autoForceLabel.setStyleName(STYLE_DIST_WINDOW_ACTIONTYPE);
    addComponent(autoForceLabel);

    forcedTimeDateField = new DateField();
    forcedTimeDateField.setInvalidAllowed(false);
    forcedTimeDateField.setInvalidCommitted(false);
    forcedTimeDateField.setEnabled(false);
    forcedTimeDateField.setStyleName("dist-window-forcedtime");

    final TimeZone tz = SPDateTimeUtil.getBrowserTimeZone();
    forcedTimeDateField.setValue(
            Date.from(LocalDateTime.now().plusWeeks(2).atZone(SPDateTimeUtil.getTimeZoneId(tz)).toInstant()));
    forcedTimeDateField.setImmediate(true);
    forcedTimeDateField.setTimeZone(tz);
    forcedTimeDateField.setLocale(HawkbitCommonUtil.getCurrentLocale());
    forcedTimeDateField.setResolution(Resolution.MINUTE);
    forcedTimeDateField.addStyleName(ValoTheme.DATEFIELD_SMALL);
    addComponent(forcedTimeDateField);
}
 
Example #7
Source File: VersionEditFormFieldFactory.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected HasValue<?> onCreateField(final Object propertyId) {
    if (Version.Field.name.equalTo(propertyId)) {
        return new MTextField().withRequiredIndicatorVisible(true);
    } else if (Version.Field.description.equalTo(propertyId)) {
        return new RichTextArea();
    } else if (Version.Field.duedate.equalTo(propertyId)) {
        return new DateField();
    }

    return null;
}
 
Example #8
Source File: FormUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new DateField with format for current locale and given style.
 * @param style DateFormat style
 * @return a new DateField
 */
public static DateField newDateField(int style) {
	DateField df = new DateField();
	Locale locale = LocaleContextHolder.getLocale();
	df.setLocale(locale);
	DateFormat dateFormat = DateFormat.getDateInstance(style);
	
	if (dateFormat instanceof SimpleDateFormat) {
		SimpleDateFormat sdf = (SimpleDateFormat) dateFormat;
		df.setDateFormat(sdf.toPattern());
	}
	
	return df;
}
 
Example #9
Source File: AutoStartOptionGroupLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private void createOptionGroup() {
    autoStartOptionGroup = new FlexibleOptionGroup();
    autoStartOptionGroup.addItem(AutoStartOption.MANUAL);
    autoStartOptionGroup.addItem(AutoStartOption.AUTO_START);
    autoStartOptionGroup.addItem(AutoStartOption.SCHEDULED);
    selectDefaultOption();

    final FlexibleOptionGroupItemComponent manualItem = autoStartOptionGroup
            .getItemComponent(AutoStartOption.MANUAL);
    manualItem.setStyleName(STYLE_DIST_WINDOW_AUTO_START);
    // set Id for Forced radio button.
    manualItem.setId(UIComponentIdProvider.ROLLOUT_START_MANUAL_ID);
    addComponent(manualItem);
    final Label manualLabel = new Label();
    manualLabel.setStyleName("statusIconPending");
    manualLabel.setIcon(FontAwesome.HAND_PAPER_O);
    manualLabel.setCaption(i18n.getMessage("caption.rollout.start.manual"));
    manualLabel.setDescription(i18n.getMessage("caption.rollout.start.manual.desc"));
    manualLabel.setStyleName("padding-right-style");
    addComponent(manualLabel);

    final FlexibleOptionGroupItemComponent autoStartItem = autoStartOptionGroup
            .getItemComponent(AutoStartOption.AUTO_START);
    autoStartItem.setId(UIComponentIdProvider.ROLLOUT_START_AUTO_ID);
    autoStartItem.setStyleName(STYLE_DIST_WINDOW_AUTO_START);
    addComponent(autoStartItem);
    final Label autoStartLabel = new Label();
    autoStartLabel.setSizeFull();
    autoStartLabel.setIcon(FontAwesome.PLAY);
    autoStartLabel.setCaption(i18n.getMessage("caption.rollout.start.auto"));
    autoStartLabel.setDescription(i18n.getMessage("caption.rollout.start.auto.desc"));
    autoStartLabel.setStyleName("padding-right-style");
    addComponent(autoStartLabel);

    final FlexibleOptionGroupItemComponent scheduledItem = autoStartOptionGroup
            .getItemComponent(AutoStartOption.SCHEDULED);
    scheduledItem.setStyleName(STYLE_DIST_WINDOW_AUTO_START);
    // setted Id for Time Forced radio button.
    scheduledItem.setId(UIComponentIdProvider.ROLLOUT_START_SCHEDULED_ID);
    addComponent(scheduledItem);
    final Label scheduledLabel = new Label();
    scheduledLabel.setStyleName("statusIconPending");
    scheduledLabel.setIcon(FontAwesome.CLOCK_O);
    scheduledLabel.setCaption(i18n.getMessage("caption.rollout.start.scheduled"));
    scheduledLabel.setDescription(i18n.getMessage("caption.rollout.start.scheduled.desc"));
    scheduledLabel.setStyleName(STYLE_DIST_WINDOW_AUTO_START);
    addComponent(scheduledLabel);

    startAtDateField = new DateField();
    startAtDateField.setInvalidAllowed(false);
    startAtDateField.setInvalidCommitted(false);
    startAtDateField.setEnabled(false);
    startAtDateField.setStyleName("dist-window-forcedtime");

    final TimeZone tz = SPDateTimeUtil.getBrowserTimeZone();
    startAtDateField.setValue(
            Date.from(LocalDateTime.now().plusMinutes(30).atZone(SPDateTimeUtil.getTimeZoneId(tz)).toInstant()));
    startAtDateField.setImmediate(true);
    startAtDateField.setTimeZone(tz);
    startAtDateField.setLocale(HawkbitCommonUtil.getCurrentLocale());
    startAtDateField.setResolution(Resolution.MINUTE);
    startAtDateField.addStyleName(ValoTheme.DATEFIELD_SMALL);
    addComponent(startAtDateField);
}
 
Example #10
Source File: AutoStartOptionGroupLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
public DateField getStartAtDateField() {
    return startAtDateField;
}
 
Example #11
Source File: ActionTypeOptionGroupAssignmentLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
public DateField getForcedTimeDateField() {
    return forcedTimeDateField;
}
 
Example #12
Source File: BugEditFormFieldFactory.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected HasValue<?> onCreateField(final Object propertyId) {
    final SimpleBug beanItem = attachForm.getBean();
    if (BugWithBLOBs.Field.environment.equalTo(propertyId) || BugWithBLOBs.Field.description.equalTo(propertyId)) {
        return new RichTextArea();
    } else if (propertyId.equals("priority")) {
        return new PriorityComboBox();
    } else if (propertyId.equals("assignuser")) {
        ProjectMemberSelectionField field = new ProjectMemberSelectionField();
        field.addValueChangeListener(valueChangeEvent -> {
            String username = valueChangeEvent.getValue();
            if (username != null) {
                subscribersComp.addFollower(username);
            }
        });
        return field;
    } else if ("section-attachments".equals(propertyId)) {
        if (beanItem.getId() != null) {
            String attachmentPath = AttachmentUtils.getProjectEntityAttachmentPath(AppUI.getAccountId(),
                    beanItem.getProjectid(), ProjectTypeConstants.BUG, "" + beanItem.getId());
            attachmentUploadField = new AttachmentUploadField(attachmentPath);
        } else {
            attachmentUploadField = new AttachmentUploadField();
        }
        return attachmentUploadField;
    } else if (propertyId.equals("severity")) {
        return new BugSeverityComboBox();
    } else if (propertyId.equals("components")) {
        componentSelect = new ComponentMultiSelectField();
        return componentSelect;
    } else if (propertyId.equals("affectedVersions")) {
        affectedVersionSelect = new VersionMultiSelectField();
        return affectedVersionSelect;
    } else if (propertyId.equals("fixedVersions")) {
        fixedVersionSelect = new VersionMultiSelectField();
        return fixedVersionSelect;
    } else if (propertyId.equals("name")) {
        return new MTextField().withRequiredIndicatorVisible(true);
    } else if (propertyId.equals("milestoneid")) {
        return new MilestoneComboBox();
    } else if (BugWithBLOBs.Field.originalestimate.equalTo(propertyId) ||
            (BugWithBLOBs.Field.remainestimate.equalTo(propertyId))) {
        return new DoubleField().withWidth(WebThemes.FORM_CONTROL_WIDTH);
    } else if ("section-followers".equals(propertyId)) {
        return subscribersComp;
    } else if (BugWithBLOBs.Field.startdate.equalTo(propertyId) || BugWithBLOBs.Field.enddate.equalTo(propertyId)
            || BugWithBLOBs.Field.duedate.equalTo(propertyId)) {
        return new DateField();
    }

    return null;
}
 
Example #13
Source File: RangeDateField.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
public RangeDateField() {
    startDateField = new DateField();
    endDateField = new DateField();
    with(ELabel.html(UserUIContext.getMessage(DayI18nEnum.OPT_FROM)), startDateField,
            ELabel.html(UserUIContext.getMessage(DayI18nEnum.OPT_TO)), endDateField).alignAll(Alignment.MIDDLE_LEFT);
}
 
Example #14
Source File: FormUtils.java    From jdal with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new DateField with format for current locale and {@link DateFormat#SHORT} style
 * @return a new DateField
 */
public static DateField newDateField() {
	return newDateField(DateFormat.SHORT);
}