Example usage for org.apache.wicket.extensions.markup.html.form.palette.component Recorder Recorder

List of usage examples for org.apache.wicket.extensions.markup.html.form.palette.component Recorder Recorder

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.form.palette.component Recorder Recorder.

Prototype

public Recorder(final String id, final Palette<T> palette) 

Source Link

Usage

From source file:gr.abiss.calipso.wicket.components.formfields.pallete.Palette.java

License:Open Source License

/**
 * @param id//  w  w w . j  av  a  2 s .  c o m
 *            Component id
 * @param choicesModel
 *            Model representing collection of all available choices
 * @param choiceRenderer
 *            Render used to render choices. This must use unique IDs for
 *            the objects, not the index.
 * @param rows
 *            Number of choices to be visible on the screen with out
 *            scrolling
 * @param allowOrder
 *            Allow user to move selections up and down
 */
public Palette(String id, IModel choicesModel, IChoiceRenderer choiceRenderer, int rows, boolean allowOrder) {
    super(id, choicesModel, choiceRenderer, rows, allowOrder);
    this.recorder = new Recorder(id + "_recorder", this);
}

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);// ww  w .  ja v a 2 s.co 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);
        }
    });
}