use of org.apache.wicket.extensions.markup.html.form.palette.component.Recorder in project syncope by apache.
the class AjaxPalettePanel method initialize.
private void initialize(final IModel<List<T>> model, final Builder<T> builder) {
setOutputMarkupId(true);
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(","));
choices.forEach(choice -> {
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());
choices.forEach(choice -> {
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);
}
});
}
Aggregations