org.apache.wicket.util.convert.IConverter Java Examples
The following examples show how to use
org.apache.wicket.util.convert.IConverter.
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: SingleTextFieldPanel.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("serial") public static SingleTextFieldPanel createMinMaxNumberField(final String id, final IModel<Integer> model, final Integer minimum, final Integer maximum, final IConverter converter) { final SingleTextFieldPanel panel = new SingleTextFieldPanel(id); final MinMaxNumberField<Integer> textField; if (converter != null) { textField = new MinMaxNumberField<Integer>("text", model, minimum, maximum) { /** * @see org.projectforge.web.wicket.components.MinMaxNumberField#getConverter(java.lang.Class) */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { return converter; } }; } else { textField = new MinMaxNumberField<Integer>("text", model, minimum, maximum); } panel.setTextField(textField); return panel; }
Example #2
Source File: PivotTable.java From nextreports-server with Apache License 2.0 | 6 votes |
protected Label createValueLabel(String id, Object value, final PivotField pivotField) { return new Label(id, Model.of((Serializable) value)) { private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(Class<C> type) { IConverter<C> converter = (IConverter<C>) pivotField.getConverter(); if (converter != null) { return converter; } return super.getConverter(type); } }; }
Example #3
Source File: CommonUtils.java From Orienteer with Apache License 2.0 | 5 votes |
/** * Safe method to get String representation of an object. * Wicket convertions are also has been used * @param data * @return */ @SuppressWarnings("unchecked") public static String toString(Object data) { if(data==null) return "null"; else if (data instanceof CharSequence) return data.toString(); else { IConverter<Object> converter = (IConverter<Object>)OrienteerWebApplication.lookupApplication() .getConverterLocator().getConverter(data.getClass()); if(converter!=null) { return converter.convertToString(data, Session.exists()?Session.get().getLocale():Locale.getDefault()); } else { return data.toString(); } } }
Example #4
Source File: JodaDateField.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(final Class<C> type) { if (converter == null) { converter = new JodaDateConverter(); } return (IConverter<C>)converter; }
Example #5
Source File: GanttChartEditTreeTablePanel.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") private void addProgressColumns(final Item<GanttTreeTableNode> item, final GanttTreeTableNode node, final GanttTask ganttObject, final TaskDO task) { final MinMaxNumberField<Integer> progressField = new MinMaxNumberField<Integer>("progress", new PropertyModel<Integer>(ganttObject, "progress"), 0, 100) { @Override public IConverter getConverter(final Class type) { return new IntegerPercentConverter(0); } }; addColumn(item, progressField, null); new RejectSaveLinksFragment("rejectSaveProgress", item, progressField, task, task != null ? NumberHelper.getAsString(task.getProgress()) : "") { @Override protected void onSave() { task.setProgress(ganttObject.getProgress()); taskDao.update(task); } @Override protected void onReject() { ganttObject.setProgress(task.getProgress()); } }; }
Example #6
Source File: AjaxMaxLengthEditableLabel.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(final Class<C> type) { if (converter != null) { return converter; } else { return super.getConverter(type); } }
Example #7
Source File: PaymentSchedulePanel.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") public void rebuildEntries() { final List<PaymentScheduleDO> entries = model.getObject().getPaymentSchedules(); if (entries != null) { entrysRepeater.removeAll(); for (final PaymentScheduleDO entry : entries) { final WebMarkupContainer item = new WebMarkupContainer(entrysRepeater.newChildId()); entrysRepeater.add(item); final DatePanel datePanel = new DatePanel("scheduleDate", new PropertyModel<Date>(entry, "scheduleDate"), DatePanelSettings.get() .withTargetType(java.sql.Date.class)); item.add(datePanel); final TextField<String> amount = new TextField<String>("amount", new PropertyModel<String>(entry, "amount")) { @SuppressWarnings({ "rawtypes", "unchecked"}) @Override public IConverter getConverter(final Class type) { return new CurrencyConverter(); } }; item.add(amount); item.add(new MaxLengthTextField("comment", new PropertyModel<String>(entry, "comment"))); item.add(new CheckBox("reached", new PropertyModel<Boolean>(entry, "reached"))); if (UserRights.getAccessChecker().hasRight(user, RechnungDao.USER_RIGHT_ID, UserRightValue.READWRITE) == true) { final DivPanel checkBoxDiv = new DivPanel("vollstaendigFakturiert", DivType.BTN_GROUP); item.add(checkBoxDiv); checkBoxDiv.add(new CheckBoxButton(checkBoxDiv.newChildId(), new PropertyModel<Boolean>(entry, "vollstaendigFakturiert"), getString("fibu.auftrag.vollstaendigFakturiert"))); } else { item.add(WicketUtils.getInvisibleComponent("vollstaendigFakturiert")); } } } }
Example #8
Source File: LanguageField.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(final Class<C> type) { return converter; }
Example #9
Source File: MaxLengthTextField.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(final Class<C> type) { if (converter != null) { return converter; } else { return super.getConverter(type); } }
Example #10
Source File: CommonUtils.java From Orienteer with Apache License 2.0 | 5 votes |
/** * Convert given object to localized string * Uses Wicket {@link IConverter} * @param value {@link Object} value which need convert to string * @param defaultValue {@link String} default value if can't convert value to string or value is null * @return {@link String} value converted into string */ public static final String objectToString(Object value, String defaultValue) { String ret = null; if(value!=null) { final Class<?> objectClass = value.getClass(); final IConverter converter = OrienteerWebApplication.get().getConverterLocator().getConverter(objectClass); ret = converter.convertToString(value, OrienteerWebSession.get().getLocale()); } return ret!=null?ret:defaultValue; }
Example #11
Source File: MinMaxNumberField.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { if (converter != null) { return converter; } else { return super.getConverter(type); } }
Example #12
Source File: TemporalTextField.java From pm-wicket-utils with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the default converter if created without pattern; otherwise it returns a * pattern-specific converter. * * @param type * The type for which the convertor should work * * @return A pattern-specific converter * * @see org.apache.wicket.markup.html.form.TextField */ @SuppressWarnings("unchecked") @Override public <C> IConverter<C> getConverter(final Class<C> type) { if (Temporal.class.isAssignableFrom(type)) { return (IConverter<C>)converter; } else { return super.getConverter(type); } }
Example #13
Source File: ConceptFeatureEditor.java From inception with Apache License 2.0 | 5 votes |
@Override public <C> IConverter<C> getConverter(Class<C> aType) { if (aType != null && aType.isAssignableFrom(this.getType())) { return (IConverter<C>) converter; } return super.getConverter(aType); }
Example #14
Source File: OmDateTimePicker.java From openmeetings with Apache License 2.0 | 5 votes |
@Override protected FormComponent<LocalDateTime> newInput(String wicketId, String dateFormat) { return new LocalDateTimeTextField(wicketId, getModel(), dateFormat) { private static final long serialVersionUID = 1L; @Override protected IConverter<?> createConverter(Class<?> clazz) { if (LocalDateTime.class.isAssignableFrom(clazz)) { return converter; } return null; } }; }
Example #15
Source File: FormComponent.java From onedev with MIT License | 5 votes |
private String substitute(String string, final Map<String, Object> vars) throws IllegalStateException { return new VariableInterpolator(string, Application.get() .getResourceSettings() .getThrowExceptionOnMissingResource()) { private static final long serialVersionUID = 1L; @SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected String getValue(String variableName) { Object value = vars.get(variableName); if (value == null ||value instanceof String) { return String.valueOf(value); } IConverter converter = getConverter(value.getClass()); if (converter == null) { return Strings.toString(value); } else { return converter.convertToString(value, getLocale()); } } }.toString(); }
Example #16
Source File: PivotField.java From nextreports-server with Apache License 2.0 | 4 votes |
public void setConverter(IConverter<?> converter) { this.converter = converter; }
Example #17
Source File: MaxLengthTextField.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * Setting a converter is more convenient instead of overriding method getConverter(Class). * @param converter * @return This for chaining. */ public <C> MaxLengthTextField setConverter(final IConverter<C> converter) { this.converter = converter; return this; }
Example #18
Source File: TimeZonePanel.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
public TimeZonePanel(final String id, final IModel<TimeZone> model) { super(id); final String[] availableTimeZones = TimeZone.getAvailableIDs(); Arrays.sort(availableTimeZones); final List<TimeZone> list = getAsTimeZoneObjects(availableTimeZones); final List<String> favoritesIds = new ArrayList<String>(); for (final PFUserDO user : userGroupCache.getAllUsers()) { final String timeZone = user.getTimeZone(); if (timeZone == null) { continue; } if (favoritesIds.contains(timeZone) == false) { favoritesIds.add(timeZone); } } final String[] favoriteIds = favoritesIds.toArray(new String[favoritesIds.size()]); final List<TimeZone> favoriteTimeZones = getAsTimeZoneObjects(favoriteIds); textField = new PFAutoCompleteTextField<TimeZone>("input", model) { @Override protected List<TimeZone> getChoices(final String input) { final List<TimeZone> result = new ArrayList<TimeZone>(); for (final TimeZone timeZone : list) { final String str = converter.convertToString(timeZone, getLocale()).toLowerCase(); if (str.contains(input.toLowerCase()) == true) { result.add(timeZone); } } return result; } /** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { return converter; } @Override protected List<TimeZone> getFavorites() { return favoriteTimeZones; } @Override protected String formatValue(final TimeZone value) { return converter.convertToString(value, getLocale()); } }; textField.withMatchContains(true).withMinChars(2); // Cant't use getString(i18nKey) because we're in the constructor and this would result in a Wicket warning. final String tooltip = PFUserContext.getLocalizedString("tooltip.autocomplete.timeZone"); WicketUtils.addTooltip(textField, tooltip); add(textField); add(new TooltipImage("autocompleteDblClickHelpImage", WebConstants.IMAGE_HELP_KEYBOARD, tooltip)); setRenderBodyOnly(true); }
Example #19
Source File: MinMaxNumberField.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * Setting a converter is more convenient instead of overriding method getConverter(Class). * @param converter * @return This for chaining. */ public MinMaxNumberField<Z> setConverter(final IConverter converter) { this.converter = converter; return this; }
Example #20
Source File: AjaxMaxLengthEditableLabel.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * Setting a converter is more convenient instead of overriding method getConverter(Class). * @param converter * @return This for chaining. */ public <C> AjaxMaxLengthEditableLabel setConverter(final IConverter<C> converter) { this.converter = converter; return this; }
Example #21
Source File: PivotField.java From nextreports-server with Apache License 2.0 | 4 votes |
public IConverter<?> getConverter() { return converter; }
Example #22
Source File: TimeZoneField.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { return converter; }
Example #23
Source File: I18nEnumAutoCompleteTextField.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @Override public <C> IConverter<C> getConverter(final Class<C> type) { return new I18nEnumConverter(this, supportedValues); }
Example #24
Source File: NewGroupSelectPanel.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @param id * @param model * @param caller * @param selectProperty */ @SuppressWarnings("serial") public NewGroupSelectPanel(final String id, final IModel<GroupDO> model, final String label, final ISelectCallerPage caller, final String selectProperty) { super(id, model, caller, selectProperty); groupTextField = new PFAutoCompleteTextField<GroupDO>("groupField", getModel()) { @Override protected List<GroupDO> getChoices(final String input) { final BaseSearchFilter filter = new BaseSearchFilter(); filter.setSearchFields("id", "name"); filter.setSearchString(input); final List<GroupDO> list = groupDao.getList(filter); return list; } @Override protected List<String> getRecentUserInputs() { return getRecentCustomers().getRecents(); } @Override protected String formatLabel(final GroupDO group) { if (group == null) { return ""; } return group.getName(); } @Override protected String formatValue(final GroupDO group) { if (group == null) { return ""; } return group.getName(); } @Override protected void convertInput() { final GroupDO group = getConverter(getType()).convertToObject(getInput(), getLocale()); setConvertedInput(group); if (group != null && (currentGoup == null || group.getId() != currentGoup.getId())) { getRecentCustomers().append(group.getName()); } currentGoup = group; } /** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings({ "unchecked", "rawtypes"}) @Override public <C> IConverter<C> getConverter(final Class<C> type) { return new IConverter() { @Override public Object convertToObject(final String value, final Locale locale) { if (StringUtils.isEmpty(value) == true) { getModel().setObject(null); return null; } // ### FORMAT ### final GroupDO group = groupDao.getByName(value); if (group == null) { error(getString("panel.error.groupNotFound")); } getModel().setObject(group); return group; } @Override public String convertToString(final Object value, final Locale locale) { if (value == null) { return ""; } final GroupDO group = (GroupDO) value; return formatLabel(group); } }; } }; currentGoup = getModelObject(); groupTextField.enableTooltips().withLabelValue(true).withMatchContains(true).withMinChars(2).withAutoSubmit(false); //.withWidth(400); }
Example #25
Source File: Kost2FormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
@Override public IConverter getConverter(final Class type) { return new Kost2Converter(); }
Example #26
Source File: Kost1FormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked"}) @Override public IConverter getConverter(final Class type) { return new Kost1Converter(); }
Example #27
Source File: AuftragsPositionFormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked"}) @Override public IConverter getConverter(final Class type) { return new AuftragsPositionConverter(); }
Example #28
Source File: NewCustomerSelectPanel.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @param id * @param model * @param caller * @param selectProperty */ @SuppressWarnings("serial") public NewCustomerSelectPanel(final String id, final IModel<KundeDO> model, final PropertyModel<String> kundeText, final ISelectCallerPage caller, final String selectProperty) { super(id, model, caller, selectProperty); this.kundeText = kundeText; customerTextField = new PFAutoCompleteTextField<KundeDO>("customerField", getModel()) { @Override protected List<KundeDO> getChoices(final String input) { final BaseSearchFilter filter = new BaseSearchFilter(); filter.setSearchFields("id", "name", "identifier", "division"); filter.setSearchString(input); final List<KundeDO> list = kundeDao.getList(filter); return list; } @Override protected List<String> getRecentUserInputs() { return getRecentCustomers().getRecents(); } @Override protected String formatLabel(final KundeDO customer) { if (customer == null) { return ""; } return kundeFormatter.format(customer, false); } @Override protected String formatValue(final KundeDO customer) { if (customer == null) { return ""; } return kundeFormatter.format(customer, false); } @Override protected void convertInput() { final KundeDO customer = getConverter(getType()).convertToObject(getInput(), getLocale()); setConvertedInput(customer); if (customer != null && (currentCustomer == null || customer.getId() != currentCustomer.getId())) { getRecentCustomers().append(kundeFormatter.format(customer, false)); } currentCustomer = customer; } /** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings({ "unchecked", "rawtypes"}) @Override public <C> IConverter<C> getConverter(final Class<C> type) { return new IConverter() { @Override public Object convertToObject(final String value, final Locale locale) { if (StringUtils.isEmpty(value) == true) { getModel().setObject(null); return null; } final int ind = value.indexOf(" - "); final String idString = ind >= 0 ? value.substring(0, ind) : value; final Integer id = NumberHelper.parseInteger(idString); final KundeDO kunde = id != null ? kundeDao.getById(id) : null; if (kunde == null) { error(getString("panel.error.customernameNotFound")); } getModel().setObject(kunde); return kunde; } @Override public String convertToString(final Object value, final Locale locale) { if (value == null) { return ""; } final KundeDO kunde = (KundeDO) value; return formatLabel(kunde); } }; } }; currentCustomer = getModelObject(); customerTextField.enableTooltips().withLabelValue(true).withMatchContains(true).withMinChars(2).withAutoSubmit(false); // .withWidth(400); }
Example #29
Source File: KontoFormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
@Override public IConverter getConverter(final Class type) { return new KontoConverter(); }
Example #30
Source File: NewProjektSelectPanel.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @param id * @param model * @param caller * @param selectProperty */ @SuppressWarnings("serial") public NewProjektSelectPanel(final String id, final IModel<ProjektDO> model, final String label, final ISelectCallerPage iCaller, final String selectProperty) { super(id, model, iCaller, selectProperty); projectTextField = new PFAutoCompleteTextField<ProjektDO>("projectField", getModel()) { @Override protected List<ProjektDO> getChoices(final String input) { final BaseSearchFilter filter = new BaseSearchFilter(); filter.setSearchFields("id", "name", "identifier", "nummer"); filter.setSearchString(input); final List<ProjektDO> list = projektDao.getList(filter); return list; } @Override protected List<String> getRecentUserInputs() { return getRecentProjects().getRecents(); } @Override protected String formatLabel(final ProjektDO project) { if (project == null) { return ""; } return projektFormatter.format(project, false); } @Override protected String formatValue(final ProjektDO project) { if (project == null) { return ""; } return projektFormatter.format(project, false); } @Override protected void convertInput() { final ProjektDO project = getConverter(getType()).convertToObject(getInput(), getLocale()); setConvertedInput(project); if (project != null && (currentProject == null || project.getId() != currentProject.getId())) { getRecentProjects().append(projektFormatter.format(project, false)); } currentProject = project; } /** * @see org.apache.wicket.Component#getConverter(java.lang.Class) */ @SuppressWarnings({ "unchecked", "rawtypes"}) @Override public <C> IConverter<C> getConverter(final Class<C> type) { return new IConverter() { @Override public Object convertToObject(final String value, final Locale locale) { if (StringUtils.isEmpty(value) == true) { getModel().setObject(null); return null; } final ProjektDO project = getProjekt(value); if (project == null) { error(getString("panel.error.projectNotFound")); } getModel().setObject(project); return project; } @Override public String convertToString(final Object value, final Locale locale) { if (value == null) { return ""; } final ProjektDO project = (ProjektDO) value; return formatLabel(project); } }; } }; currentProject = getModelObject(); projectTextField.enableTooltips().withLabelValue(true).withMatchContains(true).withMinChars(2).withAutoSubmit(false); // .withWidth(400); }