Search in sources :

Example 1 with Recorder

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);
        }
    });
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) Label(org.apache.wicket.markup.html.basic.Label) Form(org.apache.wicket.markup.html.form.Form) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Palette(org.apache.wicket.extensions.markup.html.form.palette.Palette) Recorder(org.apache.wicket.extensions.markup.html.form.palette.component.Recorder) Collection(java.util.Collection) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) HashMap(java.util.HashMap) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) StringUtils(org.apache.commons.lang3.StringUtils) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Strings(org.apache.wicket.util.string.Strings) Pattern(java.util.regex.Pattern) IModel(org.apache.wicket.model.IModel) ResourceModel(org.apache.wicket.model.ResourceModel) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) Recorder(org.apache.wicket.extensions.markup.html.form.palette.component.Recorder) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceModel(org.apache.wicket.model.ResourceModel) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.apache.wicket.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 ListUtils (org.apache.commons.collections4.ListUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Component (org.apache.wicket.Component)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)1 Palette (org.apache.wicket.extensions.markup.html.form.palette.Palette)1 Recorder (org.apache.wicket.extensions.markup.html.form.palette.component.Recorder)1 Label (org.apache.wicket.markup.html.basic.Label)1 Form (org.apache.wicket.markup.html.form.Form)1 IChoiceRenderer (org.apache.wicket.markup.html.form.IChoiceRenderer)1 IModel (org.apache.wicket.model.IModel)1