Java源码示例:com.vaadin.ui.DateField
示例1
@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);
}
}
}
示例2
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;
}
示例3
@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;
}
示例4
@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;
}
示例5
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);
}
示例6
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);
}
示例7
@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;
}
示例8
/**
* 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;
}
示例9
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);
}
示例10
public DateField getStartAtDateField() {
return startAtDateField;
}
示例11
public DateField getForcedTimeDateField() {
return forcedTimeDateField;
}
示例12
@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;
}
示例13
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);
}
示例14
/**
* 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);
}