List of usage examples for org.apache.wicket.markup.html.form IChoiceRenderer getIdValue
String getIdValue(T object, int index);
From source file:ca.travelagency.components.fields.GenericDropDownChoiceTest.java
License:Apache License
@Test public void testRender() throws Exception { // setup//from w w w .j ava2s.com SystemUser systemUser = SystemUserHelper.makeSystemUser(); // Execute IChoiceRenderer<SystemUser> renderer = fixture.makeRenderer(); // validate Assert.assertEquals(systemUser.getName(), renderer.getDisplayValue(systemUser)); Assert.assertEquals("" + systemUser.getId(), renderer.getIdValue(systemUser, 0)); }
From source file:de.invesdwin.nowicket.component.palette.component.AOptions.java
License:Apache License
/** * {@inheritDoc}//from ww w .ja v a 2s .com */ @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { final StringBuilder buffer = new StringBuilder(128); final Iterator<T> options = getOptionsIterator(); final IChoiceRenderer<T> renderer = getPalette().getChoiceRenderer(); final boolean localizeDisplayValues = localizeDisplayValues(); while (options.hasNext()) { final T choice = options.next(); final CharSequence id; //CHECKSTYLE:OFF { //CHECKSTYLE:ON final String value = renderer.getIdValue(choice, 0); if (getEscapeModelStrings()) { id = Strings.escapeMarkup(value); } else { id = value; } } final CharSequence value; //CHECKSTYLE:OFF { //CHECKSTYLE:ON final Object displayValue = renderer.getDisplayValue(choice); final Class<?> displayClass = displayValue == null ? null : displayValue.getClass(); @SuppressWarnings("unchecked") final IConverter<Object> converter = (IConverter<Object>) getConverter(displayClass); String displayString = converter.convertToString(displayValue, getLocale()); if (localizeDisplayValues) { displayString = getLocalizer().getString(displayString, this, displayString); } if (getEscapeModelStrings()) { value = Strings.escapeMarkup(displayString); } else { value = displayString; } } buffer.append("\n<option value=\"").append(id).append("\""); final Map<String, String> additionalAttributesMap = getAdditionalAttributes(choice); if (additionalAttributesMap != null) { for (final Map.Entry<String, String> entry : additionalAttributesMap.entrySet()) { buffer.append(' ').append(entry.getKey()).append("=\"").append(entry.getValue()).append("\""); } } buffer.append(">").append(value).append("</option>"); } buffer.append("\n"); replaceComponentTagBody(markupStream, openTag, buffer); }
From source file:de.invesdwin.nowicket.component.palette.component.Recorder.java
License:Apache License
/** * Synchronize ids collection from the palette's model *///w w w . j a va 2s . co m private void initIds() { // construct the model string based on selection collection final IChoiceRenderer<T> renderer = getPalette().getChoiceRenderer(); final StringBuilder modelStringBuffer = new StringBuilder(); final Collection<T> modelCollection = getPalette().getModelCollection(); if (modelCollection == null) { throw new WicketRuntimeException( "Expected getPalette().getModelCollection() to return a non-null value." + " Please make sure you have model object assigned to the palette"); } final Iterator<T> selection = modelCollection.iterator(); int i = 0; while (selection.hasNext()) { modelStringBuffer.append(renderer.getIdValue(selection.next(), i++)); if (selection.hasNext()) { modelStringBuffer.append(','); } } // set model and update ids array final String modelString = modelStringBuffer.toString(); setDefaultModel(new Model<String>(modelString)); updateIds(modelString); }
From source file:de.invesdwin.nowicket.component.palette.component.Recorder.java
License:Apache License
/** * @return list over selected choices//from ww w . j ava 2 s. co m */ protected List<T> getSelectedList() { if (getSelectedIds().isEmpty()) { return Collections.emptyList(); } final IChoiceRenderer<T> renderer = getPalette().getChoiceRenderer(); final List<T> selected = new ArrayList<T>(getSelectedIds().size()); final Collection<? extends T> choices = getPalette().getChoices(); final Map<T, String> idForChoice = new HashMap<T, String>(choices.size()); // reduce number of method calls by building a lookup table for (final T choice : choices) { idForChoice.put(choice, renderer.getIdValue(choice, 0)); } for (final String id : getSelectedIds()) { for (final T choice : choices) { final String idValue = idForChoice.get(choice); if (id.equals(idValue)) { selected.add(choice); break; } } } return selected; }
From source file:de.invesdwin.nowicket.component.palette.component.Recorder.java
License:Apache License
/** * @return list over unselected choices//from ww w. j a va 2s. c o m */ protected List<T> getUnselectedList() { final Collection<? extends T> choices = getPalette().getChoices(); if (choices.size() - getSelectedIds().size() == 0) { return Collections.<T>emptyList(); } final IChoiceRenderer<T> renderer = getPalette().getChoiceRenderer(); final List<T> unselected = new ArrayList<T>(Math.max(1, choices.size() - getSelectedIds().size())); for (final T choice : choices) { final String choiceId = renderer.getIdValue(choice, 0); if (!getSelectedIds().contains(choiceId)) { unselected.add(choice); } } return unselected; }
From source file:net.unbewaff.wicketcrudr.providers.editor.Palette.java
License:Apache License
/** * Synchronize ids collection from the palette's model *///from ww w . j a v a 2s.c om private void initIds() { // construct the model string based on selection collection IChoiceRenderer<T> renderer = getPalettePanel().getChoiceRenderer(); StringBuilder modelStringBuffer = new StringBuilder(); Collection<T> modelCollection = getPalettePanel().getModelCollection(); if (modelCollection == null) { throw new WicketRuntimeException( "Expected getPalette().getModelCollection() to return a non-null value." + " Please make sure you have model object assigned to the palette"); } Iterator<T> selection = modelCollection.iterator(); int i = 0; while (selection.hasNext()) { modelStringBuffer.append(renderer.getIdValue(selection.next(), i++)); if (selection.hasNext()) { modelStringBuffer.append(","); } } // set model and update ids array String modelString = modelStringBuffer.toString(); setDefaultModel(new Model<String>(modelString)); updateIds(modelString); }
From source file:net.unbewaff.wicketcrudr.providers.editor.Palette.java
License:Apache License
/** * @return iterator over selected choices *//*from ww w. j a v a 2s.c om*/ @SuppressWarnings("unchecked") public Iterator<T> getSelectedChoices() { IChoiceRenderer<T> renderer = getPalettePanel().getChoiceRenderer(); if (ids.length == 0) { return Collections.EMPTY_LIST.iterator(); } List<T> selected = new ArrayList<T>(ids.length); for (String id : ids) { for (T choice : getPalettePanel().getChoices()) { if (renderer.getIdValue(choice, 0).equals(id)) { selected.add(choice); break; } } } return selected.iterator(); }
From source file:net.unbewaff.wicketcrudr.providers.editor.Palette.java
License:Apache License
/** * @return iterator over unselected choices *///w w w .ja v a2 s. c o m public Iterator<T> getUnselectedChoices() { IChoiceRenderer<T> renderer = getPalettePanel().getChoiceRenderer(); Collection<? extends T> choices = getPalettePanel().getChoices(); if (choices.size() - ids.length == 0) { return Collections.<T>emptyList().iterator(); } List<T> unselected = new ArrayList<T>(Math.max(1, choices.size() - ids.length)); for (T choice : choices) { final String choiceId = renderer.getIdValue(choice, 0); boolean selected = false; for (String id : ids) { if (id.equals(choiceId)) { selected = true; break; } } if (!selected) { unselected.add(choice); } } return unselected.iterator(); }
From source file:net.unbewaff.wicketcrudr.providers.editorpanel.components.AbstractOptions.java
License:Apache License
/** * {@inheritDoc}//from w w w . ja v a 2 s . c o m */ @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { StringBuilder buffer = new StringBuilder(128); Iterator<T> options = getOptionsIterator(); IChoiceRenderer<T> renderer = getPalette().getChoiceRenderer(); while (options.hasNext()) { final T choice = options.next(); final CharSequence id; { String value = renderer.getIdValue(choice, 0); if (getEscapeModelStrings()) { id = Strings.escapeMarkup(value); } else { id = value; } } final CharSequence value; { Object displayValue = renderer.getDisplayValue(choice); Class<?> displayClass = displayValue == null ? null : displayValue.getClass(); @SuppressWarnings("unchecked") IConverter<Object> converter = (IConverter<Object>) getConverter(displayClass); String displayString = converter.convertToString(displayValue, getLocale()); displayString = getLocalizer().getString(displayString, this, displayString); if (getEscapeModelStrings()) { value = Strings.escapeMarkup(displayString); } else { value = displayString; } } buffer.append("\n<option value=\"").append(id).append("\""); Map<String, String> additionalAttributesMap = getAdditionalAttributes(choice); if (additionalAttributesMap != null) { for (Map.Entry<String, String> entry : additionalAttributesMap.entrySet()) { buffer.append(' ').append(entry.getKey()).append("=\"").append(entry.getValue()).append("\""); } } buffer.append(">").append(value).append("</option>"); } buffer.append("\n"); replaceComponentTagBody(markupStream, openTag, buffer); }
From source file:org.apache.syncope.client.console.wicket.markup.html.form.AjaxPalettePanel.java
License:Apache License
private void initialize(final IModel<List<T>> model, final Builder<T> builder) { setOutputMarkupId(true);/*from ww w. j a va 2s. c o m*/ this.palette = new NonI18nPalette<T>("paletteField", model, choicesModel, builder.renderer, 8, builder.allowOrder, builder.allowMoveAll) { private static final long serialVersionUID = -3074655279011678437L; @Override protected Component newAvailableHeader(final String componentId) { return new Label(componentId, new ResourceModel("palette.available", builder.availableLabel)); } @Override protected Component newSelectedHeader(final String componentId) { return new Label(componentId, new ResourceModel("palette.selected", builder.selectedLabel)); } @Override protected Recorder<T> newRecorderComponent() { return new Recorder<T>("recorder", this) { private static final long serialVersionUID = -9169109967480083523L; @Override public List<T> getUnselectedList() { final IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer(); final Collection<? extends T> choices = getPalette().getChoices(); final List<T> unselected = new ArrayList<>(choices.size()); final List<String> ids = Arrays.asList(getValue().split(",")); for (final T choice : choices) { final String choiceId = renderer.getIdValue(choice, 0); if (!ids.contains(choiceId)) { unselected.add(choice); } } return unselected; } @Override public List<T> getSelectedList() { final IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer(); final Collection<? extends T> choices = getPalette().getChoices(); final List<T> selected = new ArrayList<>(choices.size()); // reduce number of method calls by building a lookup table final Map<T, String> idForChoice = new HashMap<>(choices.size()); for (final T choice : choices) { idForChoice.put(choice, renderer.getIdValue(choice, 0)); } final String value = getValue(); int start = value.indexOf(';') + 1; for (final String id : Strings.split(value.substring(start), ',')) { for (final T choice : choices) { final String idValue = idForChoice.get(choice); if (id.equals(idValue)) { selected.add(choice); break; } } } return selected; } }; } }; add(palette.setOutputMarkupId(true)); final Form<?> form = new Form<>("form"); add(form.setEnabled(builder.filtered).setVisible(builder.filtered)); final AjaxTextFieldPanel filter = new AjaxTextFieldPanel("filter", "filter", queryFilter, false); filter.hideLabel().setOutputMarkupId(true); form.add(filter); form.add(new AjaxSubmitLink("search") { private static final long serialVersionUID = -1765773642975892072L; @Override protected void onAfterSubmit(final AjaxRequestTarget target, final Form<?> form) { super.onAfterSubmit(target, form); target.add(palette); } }); }