List of usage examples for org.apache.wicket Localizer getString
public String getString(final String key, final Component component, final String defaultValue) throws MissingResourceException
From source file:com.googlecode.wicketwebbeans.fields.DateTimeField.java
License:Apache License
/** * Construct a new DateTimeField./*from w w w . j a v a 2 s. co m*/ * * @param id the Wicket id for the editor. * @param model the model. * @param metaData the meta data for the property. * @param viewOnly true if the component should be view-only. */ public DateTimeField(String id, IModel<Date> model, ElementMetaData metaData, boolean viewOnly) { super(id, model, metaData, viewOnly); type = metaData.getPropertyType(); boolean displayTz = false; Component metaDataComponent = metaData.getBeanMetaData().getComponent(); Localizer localizer = metaDataComponent.getLocalizer(); if (Time.class.isAssignableFrom(type)) { fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "time" + FORMAT_SUFFIX, metaDataComponent, TIME_FMT_STR); } else if (java.sql.Date.class.isAssignableFrom(type)) { fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR); } else if (Calendar.class.isAssignableFrom(type)) { fmt = viewOnly ? localizer.getString(DATE_TIME_FIELD_PREFIX + "datetimetz" + FORMAT_SUFFIX, metaDataComponent, DATE_TIME_ZONE_FMT_STR) : localizer.getString(DATE_TIME_FIELD_PREFIX + "datetime" + FORMAT_SUFFIX, metaDataComponent, DATE_TIME_FMT_STR); displayTz = true; } else { // if (Date.class.isAssignableFrom(type) || Timestamp.class.isAssignableFrom(type)) fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "datetime" + FORMAT_SUFFIX, metaDataComponent, DATE_TIME_FMT_STR); } String customFmt = getFormat(); if (customFmt != null) { fmt = customFmt; } final InternalDateConverter converter = new InternalDateConverter(); Fragment fragment; if (viewOnly) { fragment = new Fragment("frag", "viewer"); Label label = new LabelWithMinSize("date", model) { private static final long serialVersionUID = 1L; @Override public IConverter getConverter(Class type) { return converter; } }; fragment.add(label); } else { fragment = new Fragment("frag", "editor"); final FormComponent dateField = new DateTextField("dateTextField", model) { private static final long serialVersionUID = 1L; @Override public IConverter getConverter(Class type) { return converter; } }; setFieldParameters(dateField); fragment.add(dateField); DatePickerSettings settings = new DatePickerSettings(); settings.setStyle(settings.newStyleWinter()); settings.setIcon(new ResourceReference(this.getClass(), "calendar.gif")); DatePicker picker = new PopupDatePicker("datePicker", dateField, settings); // This sucks! It expects a DateConverter. I've got my own. DateConverter dateConverter = new DateConverter() { private static final long serialVersionUID = 1L; @Override public DateFormat getDateFormat(Locale locale) { SimpleDateFormat dateFmt = new SimpleDateFormat(fmt); dateFmt.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFmt; } @Override protected Class getTargetType() { return type; } }; picker.setDateConverter(dateConverter); fragment.add(picker); if (displayTz) { Label label = new Label("timezone", model) { private static final long serialVersionUID = 1L; @Override public IConverter getConverter(Class type) { return new TimeZoneConverter(); } }; fragment.add(label); } else { fragment.add(new Label("timezone", "")); } } add(fragment); }
From source file:com.googlecode.wicketwebbeans.fields.YUIDateField.java
License:Apache License
/** * Construct a new YUIDateField./*from ww w. j av a2 s . c o m*/ * * @param id the Wicket id for the editor. * @param model the model. * @param metaData the meta data for the property. * @param viewOnly true if the component should be view-only. */ public YUIDateField(String id, IModel<Date> model, ElementMetaData metaData, boolean viewOnly) { super(id, model, metaData, viewOnly); type = metaData.getPropertyType(); boolean displayTz = false; Component metaDataComponent = metaData.getBeanMetaData().getComponent(); Localizer localizer = metaDataComponent.getLocalizer(); if (Time.class.isAssignableFrom(type) || java.sql.Date.class.isAssignableFrom(type) || Date.class.isAssignableFrom(type) || Timestamp.class.isAssignableFrom(type)) { fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR); } else if (Calendar.class.isAssignableFrom(type)) { fmt = viewOnly ? localizer.getString(DATE_TIME_FIELD_PREFIX + "datetz" + FORMAT_SUFFIX, metaDataComponent, DATE_ZONE_FMT_STR) : localizer.getString(DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR); displayTz = true; } else { throw new RuntimeException("YUIDateField does not handle " + type); } String customFmt = getFormat(); if (customFmt != null) { fmt = customFmt; } Fragment fragment; if (viewOnly) { fragment = new Fragment("frag", "viewer"); fragment.add(DateLabel.withConverter("date", model, new InternalDateConverter())); } else { fragment = new Fragment("frag", "editor"); FormComponent dateField = DateTextField.withConverter("dateTextField", model, new InternalDateConverter()); setFieldParameters(dateField); fragment.add(dateField); dateField.add(new DatePicker() { private static final long serialVersionUID = 1L; @Override protected boolean enableMonthYearSelection() { return false; } @Override protected CharSequence getIconUrl() { return RequestCycle.get().urlFor(new ResourceReference(YUIDateField.class, "calendar.gif")); } }); if (displayTz) { DateLabel tzLabel = DateLabel.withConverter("timezone", model, new TimeZoneConverter()); fragment.add(tzLabel); } else { fragment.add(new Label("timezone", "").setVisible(false)); } } add(fragment); }
From source file:com.googlecode.wicketwebbeans.util.WicketUtil.java
License:Apache License
/** * Substitutes macros of the form "${key}" in string to the corresponding value of * "key" in localizer. // w w w .ja v a2s . co m * * @param string the input string containing the macros. * @param component the component whose Localizer is used to localize the string. * * @return a String with the macros expanded. If a macro key cannot be found in * localizer, the macro is substituted with "?string?". */ public static String substituteMacros(String string, Component component) { Localizer localizer = component.getLocalizer(); StringBuilder buf = new StringBuilder(string); int idx = 0; while ((idx = buf.indexOf("${", idx)) >= 0) { int endIdx = buf.indexOf("}", idx + 2); if (endIdx > 0) { String key = buf.substring(idx + 2, endIdx); String value = localizer.getString(key, component, '?' + key + '?'); if (value != null) { buf.replace(idx, endIdx + 1, value); } else { // Nothing found, skip macro. idx += 2; } } } return buf.toString(); }
From source file:jp.xet.uncommons.wicket.converter.BooleanConverter.java
License:Apache License
@Override public String convertToString(Boolean value, Locale locale) { if (value == null) { return null; }// ww w .j a v a2s . c om Localizer localizer = Application.get().getResourceSettings().getLocalizer(); return localizer.getString(prefix + "." + value, (Component) null, (String) null); }
From source file:jp.xet.uncommons.wicket.converter.RelativeDateConverter.java
License:Apache License
@Override public String convertToString(Date value, Locale locale) { long duration = (System.currentTimeMillis() - value.getTime()) / 1000; Localizer localizer = Application.get().getResourceSettings().getLocalizer(); if (duration < 60) { return localizer.getString("RelativeDateConverter.second", component, Model.of(duration)); }//from w w w . j a v a2 s .co m duration /= 60; if (duration < 60) { return localizer.getString("RelativeDateConverter.minute", component, Model.of(duration)); } duration /= 24; if (duration < 24) { return localizer.getString("RelativeDateConverter.hour", component, Model.of(duration)); } duration /= 7; if (duration == 1) { return localizer.getString("RelativeDateConverter.yesterday", component, Model.of(duration)); } if (duration < 7) { return localizer.getString("RelativeDateConverter.day", component, Model.of(duration)); } IConverterLocator locator = Application.get().getConverterLocator(); return locator.getConverter(Date.class).convertToString(value, locale); }
From source file:net.rrm.ehour.ui.timesheet.dto.TimesheetRow.java
License:Open Source License
/** * Get status/* w ww. j av a2 s . co m*/ * @return */ public String getStatus() { if (assignmentStatus != null && assignmentStatus.getAggregate() != null && assignmentStatus.getAggregate().getAvailableHours() != null && assignmentStatus.getAggregate().getAvailableHours().or(0f) < 0) { AvailableHours hours = new AvailableHours( (int) (getAssignmentStatus().getAggregate().getAvailableHours().or(0f) * -1)); Localizer localizer = Application.get().getResourceSettings().getLocalizer(); return localizer.getString("timesheet.errorNoHours", null, new Model<>(hours)); } return "<br />"; }
From source file:org.wicketopia.model.label.DisplayNameModel.java
License:Apache License
public static String getDisplayName(Displayable displayable, Localizer localizer, Component component) { return localizer.getString(displayable.getDisplayNameMessageKey(), component, displayable.getDisplayName()); }
From source file:org.wicketstuff.security.log.AuthorizationMessageSource.java
License:Apache License
/** * @see org.apache.wicket.validation.IErrorMessageSource#getMessage(java.lang.String, java.util.Map) *//*from w w w . j a v a 2 s.c o m*/ @Override public final String getMessage(String key, Map<String, Object> vars) { Localizer localizer = Application.get().getResourceSettings().getLocalizer(); // Note: It is important that the default value of "" is provided // to getString() not to throw a MissingResourceException or to // return a default string like "[Warning: String ..." String message = localizer.getString(key, getComponent(), ""); if (Strings.isEmpty(message)) { return null; } else { return new MapVariableInterpolator(message, mergeVariables(vars), Application.get().getResourceSettings().getThrowExceptionOnMissingResource()).toString(); } }