@Override public Field getPropertyField(FormProperty formProperty) { // Writable string PopupDateField dateField = new PopupDateField(getPropertyLabel(formProperty)); String datePattern = (String) formProperty.getType().getInformation("datePattern"); dateField.setDateFormat(datePattern); dateField.setRequired(formProperty.isRequired()); dateField.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty))); dateField.setEnabled(formProperty.isWritable()); if (formProperty.getValue() != null) { // Try parsing the current value SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); try { Date date = dateFormat.parse(formProperty.getValue()); dateField.setValue(date); } catch (ParseException e) { // TODO: what happens if current value is illegal date? } } return dateField; }
@Override public String getFieldValue(FormProperty formProperty, Field field) { PopupDateField dateField = (PopupDateField) field; Date selectedDate = (Date) dateField.getValue(); if(selectedDate != null) { // Use the datePattern specified in the form property type String datePattern = (String) formProperty.getType().getInformation("datePattern"); SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); return dateFormat.format(selectedDate); } return null; }
/** * Method to find I18NHandler for the component * @param component * @return {@link I18NComponentHandler} */ public static I18NComponentHandler getHandler (Component component) { if (componentHandler != null && component != null) { I18NComponentHandler handler = componentHandler.get(component.getClass()); if (handler != null) return handler; } if (component instanceof Label) return new I18NLableHandler((Label)component); if (component instanceof AbstractTextField) return new I18NFieldHandler((AbstractTextField)component); if (component instanceof PopupDateField) return new I18NFieldHandler((PopupDateField)component); if (component instanceof Table) return new I18NTableHandler((Table)component); if (component instanceof AbstractSelect) return new I18NAbstractSelectHandler((AbstractSelect)component); if (component instanceof TabSheet || component.getParent() instanceof TabSheet) return new I18NTabSheetHandler(component); if (component instanceof JUploader) return new I18NJUploadHandler((JUploader) component); if (component instanceof MenuBar) return new I18NMenuBarHandler((MenuBar) component); if (component instanceof AbstractComponent) return new I18NAbstractComponentHandler ((AbstractComponent)component); return new I18NComponentHandler(component); }
public void applyI18N(Component component, Locale locale) { super.applyI18N(component, locale); if (component instanceof AbstractTextField) { ((AbstractTextField) component).setInputPrompt(getInputPrompt(locale)); ((AbstractTextField) component).setRequiredError(getRequiredError(locale)); } else if (component instanceof ComboBox) { ((ComboBox) component).setInputPrompt(getInputPrompt(locale)); ((ComboBox) component).setRequiredError(getRequiredError(locale)); } else if (component instanceof PopupDateField) { ((PopupDateField) component).setInputPrompt(getInputPrompt(locale)); ((PopupDateField) component).setRequiredError(getRequiredError(locale)); } }
@SuppressWarnings("unused") private static PopupDateField createOrderTimeField() { PopupDateField orderTimeField = new PopupDateField(); orderTimeField.setResolution(Resolution.SECOND); return orderTimeField; }
public I18NFieldHandler(PopupDateField component) { super(component); this.i18NInputPrompt = component.getInputPrompt(); this.i18NRequiredError = component.getRequiredError(); }
@AutoGenerated private AbsoluteLayout buildMainLayout() { // common part: create layout mainLayout = new AbsoluteLayout(); mainLayout.setImmediate(false); mainLayout.setWidth("560px"); mainLayout.setHeight("300px"); mainLayout.setMargin(true); // top-level component properties setWidth("560px"); setHeight("300px"); // protocolTypeField protocolTypeField = new TextField(); protocolTypeField.setCaption("Tipo Procolo"); protocolTypeField.setImmediate(false); protocolTypeField.setWidth("340px"); protocolTypeField.setHeight("24px"); protocolTypeField.setTabIndex(1); mainLayout.addComponent(protocolTypeField, "top:56.0px;left:20.0px;"); // fileNameField fileNameField = new TextField(); fileNameField.setCaption("Nombre Fichero"); fileNameField.setImmediate(false); fileNameField.setWidth("340px"); fileNameField.setHeight("-1px"); mainLayout.addComponent(fileNameField, "top:17.0px;left:20.0px;"); // protocolDateField protocolDateField = new PopupDateField(); protocolDateField.setCaption("Fecha Protocolo"); protocolDateField.setImmediate(false); protocolDateField.setWidth("160px"); protocolDateField.setHeight("-1px"); mainLayout.addComponent(protocolDateField, "top:20.0px;left:380.0px;"); // payloadField payloadField = new TextArea(); payloadField.setCaption("Carga Protocolo"); payloadField.setImmediate(false); payloadField.setWidth("520px"); payloadField.setHeight("180px"); mainLayout.addComponent(payloadField, "top:100.0px;left:20.0px;"); return mainLayout; }
private Component buildForm() { HorizontalLayout form = new HorizontalLayout(); form.setWidth("100%"); // initPacksSources(); /* * packsSelect = new ComboBox(); * packsSelect.setInputPrompt(Messages.getString( * "Caption.Button.ChoosePack")); for (String packTitle : sortedPacks) { * packsSelect.addItem(packTitle); } * packsSelect.setTextInputAllowed(false); * packsSelect.setNullSelectionAllowed(false); * packsSelect.setRequired(true); * packsSelect.setRequiredError(Messages.getString( * "Message.Error.NoPackSelected")); * packsSelect.setValidationVisible(false); * form.addComponent(packsSelect); */ dateFieldFrom = new PopupDateField(); dateFieldFrom.setResolution(Resolution.SECOND); dateFieldFrom.setDateFormat(Messages.getString("Format.DateTime")); dateFieldFrom.setInputPrompt(Messages.getString("Caption.Field.DateFrom")); dateFieldFrom.setImmediate(true); dateFieldFrom.setValidationVisible(false); form.addComponent(dateFieldFrom); dateFieldTo = new PopupDateField(); dateFieldTo.setResolution(Resolution.SECOND); dateFieldTo.setDateFormat(Messages.getString("Format.DateTime")); dateFieldTo.setInputPrompt(Messages.getString("Caption.Field.DateTo")); dateFieldTo.setImmediate(true); dateFieldTo.setValidationVisible(false); form.addComponent(dateFieldTo); Validator dateValidator = new Validator() { @Override public void validate(Object value) throws InvalidValueException { if (dateFieldFrom.getValue() == null && dateFieldTo.getValue() == null) { throw new InvalidValueException(Messages.getString("Message.Error.NoDateSelected")); } } }; dateFieldFrom.addValidator(dateValidator); dateFieldTo.addValidator(dateValidator); Button selectionButton = new Button(Messages.getString("Caption.Button.ShowTests")); selectionButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { // packsSelect.validate(); dateFieldFrom.validate(); dateFieldTo.validate(); // Pack pack = packMap.get(packsSelect.getValue()); Date dateFrom = (Date) dateFieldFrom.getValue(); Date dateTo = (Date) dateFieldTo.getValue(); showTests(dateFrom, dateTo); } catch (InvalidValueException e) { // packsSelect.setValidationVisible(!packsSelect.isValid()); dateFieldFrom.setValidationVisible(!dateFieldFrom.isValid()); dateFieldTo.setValidationVisible(!dateFieldTo.isValid()); Notification.show(e.getMessage(), Type.WARNING_MESSAGE); } } }); form.addComponent(selectionButton); return form; }