Java Code Examples for org.apache.wicket.markup.html.form.IChoiceRenderer

The following examples show how to use org.apache.wicket.markup.html.form.IChoiceRenderer. These examples are extracted from open source projects. 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 Project: webanno   Author: webanno   File: UserSelectionPanel.java    License: Apache License 2.0 6 votes vote down vote up
private IChoiceRenderer<User> makeUserChoiceRenderer()
{
    return new org.apache.wicket.markup.html.form.ChoiceRenderer<User>()
    {
        private static final long serialVersionUID = 4607720784161484145L;

        @Override
        public Object getDisplayValue(User aUser)
        {
            String permissionLevels = projectRepository
                    .getProjectPermissionLevels(aUser, projectModel.getObject()).stream()
                    .map(PermissionLevel::getName).collect(joining(", ", "[", "]"));
            
            return aUser.getUsername() + " " + permissionLevels
                    + (aUser.isEnabled() ? "" : " (login disabled)");
        }
    };
}
 
Example #2
Source Project: syncope   Author: apache   File: AjaxPalettePanel.java    License: Apache License 2.0 6 votes vote down vote up
protected List<T> getFilteredList(final Collection<T> choices, final String filter) {
    IChoiceRenderer<? super T> renderer = palette.getChoiceRenderer();

    Map<T, String> idForChoice = choices.stream().collect(Collectors.toMap(
            Function.identity(), choice -> renderer.getIdValue(choice, 0), (c1, c2) -> c1));

    Pattern pattern = Pattern.compile(filter, Pattern.CASE_INSENSITIVE);

    List<T> filtered = new ArrayList<>(choices.size());
    choices.forEach(choice -> {
        if (pattern.matcher(idForChoice.get(choice)).matches()) {
            filtered.add(choice);
        }
    });

    return filtered;
}
 
Example #3
Source Project: syncope   Author: apache   File: SelectableRecorder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Synchronize ids collection from the palette's model
 */
private void initIds() {
    // construct the model string based on selection collection
    IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer();
    StringBuilder modelStringBuffer = new StringBuilder();
    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");
    }
    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<>(modelString));
    updateIds(modelString);
}
 
Example #4
Source Project: syncope   Author: apache   File: SelectableRecorder.java    License: Apache License 2.0 6 votes vote down vote up
public T getSelectedItem() {
    if (selectedId == null) {
        return null;
    }

    IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer();

    T selected = null;
    for (T choice : getPalette().getChoices()) {
        if (renderer.getIdValue(choice, 0).equals(selectedId)) {
            selected = choice;
            break;
        }
    }

    return selected;
}
 
Example #5
Source Project: syncope   Author: apache   File: SelectableRecorder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<T> getSelectedList() {
    IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer();
    if (ids.length == 0) {
        return List.of();
    }

    List<T> selected = new ArrayList<>(ids.length);
    for (String id : ids) {
        for (T choice : getPalette().getChoices()) {
            if (renderer.getIdValue(choice, 0).equals(id)) {
                selected.add(choice);
                break;
            }
        }
    }
    return selected;
}
 
Example #6
Source Project: syncope   Author: apache   File: SelectableRecorder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<T> getUnselectedList() {
    IChoiceRenderer<? super T> renderer = getPalette().getChoiceRenderer();
    Collection<? extends T> choices = getPalette().getChoices();

    if (choices.size() - ids.length == 0) {
        return List.of();
    }

    List<T> unselected = new ArrayList<>(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;
}
 
Example #7
Source Project: sakai   Author: sakaiproject   File: SakaiSpinnerDropDownChoice.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param id the wicket id
 * @param choiceModel the model to hold the selected choice
 * @param choices the available choices
 * @param renderer how to render each choice
 * @param labelModel the model for the <label> tag
 * @param behavior behaviour invoked when the selection changes
 */
public SakaiSpinnerDropDownChoice(String id, IModel<T> choiceModel, List<T> choices, IChoiceRenderer<T> renderer,
		IModel<String> labelModel, SakaiSpinningSelectOnChangeBehavior behavior)
{
	super(id, choiceModel);
	select = new DropDownChoice<>("spinnerSelect", choiceModel, choices, renderer);
	select.setLabel(labelModel);
	select.add(behavior);
	add(select);
	setRenderBodyOnly(true);
}
 
Example #8
Source Project: ontopia   Author: ontopia   File: AjaxOntopolyDropDownChoice.java    License: Apache License 2.0 5 votes vote down vote up
public AjaxOntopolyDropDownChoice(String id, IModel<T> model, IModel<List<T>> choices, IChoiceRenderer<? super T> renderer) {
  super(id, model, choices, renderer);

  setOutputMarkupId(true);

  add(new AjaxFormComponentUpdatingBehavior("onchange") {
    @Override
    protected void onUpdate(AjaxRequestTarget target) {
      AjaxOntopolyDropDownChoice.this.onUpdate(target);
    }
  });
}
 
Example #9
Source Project: syncope   Author: apache   File: NonI18nPalette.java    License: Apache License 2.0 5 votes vote down vote up
public NonI18nPalette(final String id,
        final IModel<? extends Collection<T>> model,
        final IModel<? extends Collection<? extends T>> choicesModel,
        final IChoiceRenderer<? super T> choiceRenderer, final int rows,
        final boolean allowOrder, final boolean allowMoveAll) {

    super(id, model, choicesModel, choiceRenderer, rows, allowOrder, allowMoveAll);
}
 
Example #10
Source Project: sakai   Author: sakaiproject   File: SakaiSpinnerDropDownChoice.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param id the wicket id
 * @param choiceModel the model to hold the selected choice
 * @param choices the available choices
 * @param renderer how to render each choice
 * @param labelModel the model for the <label> tag
 * @param behavior behaviour invoked when the selection changes
 */
public SakaiSpinnerDropDownChoice(String id, IModel<T> choiceModel, List<T> choices, IChoiceRenderer<T> renderer,
		IModel<String> labelModel, SakaiSpinningSelectOnChangeBehavior behavior)
{
	super(id, choiceModel);
	select = new DropDownChoice<>("spinnerSelect", choiceModel, choices, renderer);
	select.setLabel(labelModel);
	select.add(behavior);
	add(select);
	setRenderBodyOnly(true);
}
 
Example #11
Source Project: nextreports-server   Author: nextreports   File: ExtendedPalette.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * @param id             Component id
    * @param model          Model representing collection of user's selections
    * @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
    * @param allowMoveAll   Allow user to add or remove all items at once
    */
public ExtendedPalette(String id, IModel<List<T>> model,
                          IModel<? extends Collection<? extends T>> choicesModel,
                          IChoiceRenderer<T> choiceRenderer,
                          int rows, boolean allowOrder, boolean allowMoveAll) {
       super(id, model, choicesModel, choiceRenderer, rows, allowOrder, allowMoveAll);

       this.choicesModel = choicesModel;
       this.choiceRenderer = choiceRenderer;
       this.rows = rows;
       this.allowOrder = allowOrder;
       this.allowMoveAll = allowMoveAll;
   }
 
Example #12
Source Project: artifact-listener   Author: openwide-java   File: GenericSelect2DropDownMultipleChoice.java    License: Apache License 2.0 5 votes vote down vote up
protected GenericSelect2DropDownMultipleChoice(String id, IModel<? extends Collection<T>> collectionModel,
		IModel<? extends List<? extends T>> choicesModel, IChoiceRenderer<? super T> renderer) {
	super(id, collectionModel, choicesModel, renderer);
	
	Select2Behavior<T, T> select2Behavior = Select2Behavior.forChoice(this);
	fillSelect2Settings(select2Behavior.getSettings());
	add(select2Behavior);
}
 
Example #13
Source Project: webanno   Author: webanno   File: OverviewListChoice.java    License: Apache License 2.0 4 votes vote down vote up
public OverviewListChoice(String aId, IModel<? extends List<? extends T>> aChoices,
        IChoiceRenderer<? super T> aRenderer)
{
    super(aId, aChoices, aRenderer);
}
 
Example #14
Source Project: webanno   Author: webanno   File: OverviewListChoice.java    License: Apache License 2.0 4 votes vote down vote up
public OverviewListChoice(String aId, IModel<T> aModel,
        IModel<? extends List<? extends T>> aChoices, IChoiceRenderer<? super T> aRenderer,
        int aMaxRows)
{
    super(aId, aModel, aChoices, aRenderer, aMaxRows);
}
 
Example #15
Source Project: webanno   Author: webanno   File: OverviewListChoice.java    License: Apache License 2.0 4 votes vote down vote up
public OverviewListChoice(String aId, IModel<T> aModel,
        IModel<? extends List<? extends T>> aChoices, IChoiceRenderer<? super T> aRenderer)
{
    super(aId, aModel, aChoices, aRenderer);
}
 
Example #16
Source Project: webanno   Author: webanno   File: OverviewListChoice.java    License: Apache License 2.0 4 votes vote down vote up
public OverviewListChoice(String aId, IModel<T> aModel, List<? extends T> aChoices,
        IChoiceRenderer<? super T> aRenderer, int aMaxRows)
{
    super(aId, aModel, aChoices, aRenderer, aMaxRows);
}
 
Example #17
Source Project: webanno   Author: webanno   File: OverviewListChoice.java    License: Apache License 2.0 4 votes vote down vote up
public OverviewListChoice(String aId, IModel<T> aModel, List<? extends T> aChoices,
        IChoiceRenderer<? super T> aRenderer)
{
    super(aId, aModel, aChoices, aRenderer);
}
 
Example #18
Source Project: webanno   Author: webanno   File: OverviewListChoice.java    License: Apache License 2.0 4 votes vote down vote up
public OverviewListChoice(String aId, List<? extends T> aChoices,
        IChoiceRenderer<? super T> aRenderer)
{
    super(aId, aChoices, aRenderer);
}
 
Example #19
Source Project: sakai   Author: sakaiproject   File: IndicatingAjaxDropDownChoice.java    License: Educational Community License v2.0 4 votes vote down vote up
public IndicatingAjaxDropDownChoice(String id, List<T> data, IChoiceRenderer<? super T> renderer) {
	super(id, data, renderer);
	add(indicatorAppender);
}
 
Example #20
Source Project: sakai   Author: sakaiproject   File: IndicatingAjaxDropDownChoice.java    License: Educational Community License v2.0 4 votes vote down vote up
public IndicatingAjaxDropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) {
	super(id, model, choices, renderer);
	add(indicatorAppender);
}
 
Example #21
Source Project: ontopia   Author: ontopia   File: TopicDropDownChoice.java    License: Apache License 2.0 4 votes vote down vote up
public TopicDropDownChoice(String id, IModel<T> model, IModel<List<T>> choices, IChoiceRenderer<T> renderer) {
  super(id, model, choices, renderer);
}
 
Example #22
Source Project: syncope   Author: apache   File: AjaxDropDownChoicePanel.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public AjaxDropDownChoicePanel<T> setChoiceRenderer(final IChoiceRenderer<T> renderer) {
    DropDownChoice.class.cast(field).setChoiceRenderer(renderer);
    return this;
}
 
Example #23
Source Project: syncope   Author: apache   File: AjaxPalettePanel.java    License: Apache License 2.0 4 votes vote down vote up
public Builder<T> setRenderer(final IChoiceRenderer<T> renderer) {
    this.renderer = renderer;
    return this;
}
 
Example #24
Source Project: syncope   Author: apache   File: SearchClausePanel.java    License: Apache License 2.0 4 votes vote down vote up
default IChoiceRenderer<SearchClause.Type> typeRenderer() {
    return new ChoiceRenderer<>();
}
 
Example #25
Source Project: sakai   Author: sakaiproject   File: IndicatingAjaxDropDownChoice.java    License: Educational Community License v2.0 4 votes vote down vote up
public IndicatingAjaxDropDownChoice(String id, List<T> data, IChoiceRenderer<? super T> renderer) {
	super(id, data, renderer);
	add(indicatorAppender);
}
 
Example #26
Source Project: sakai   Author: sakaiproject   File: IndicatingAjaxDropDownChoice.java    License: Educational Community License v2.0 4 votes vote down vote up
public IndicatingAjaxDropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, IChoiceRenderer<? super T> renderer) {
	super(id, model, choices, renderer);
	add(indicatorAppender);
}
 
Example #27
Source Project: projectforge-webapp   Author: micromata   File: TeamEventReminderComponent.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.apache.wicket.Component#onInitialize()
 */
@SuppressWarnings({ "unchecked", "serial"})
@Override
protected void onInitialize()
{
  super.onInitialize();

  final boolean reminderOptionVisibility = data.getReminderActionType() != null;

  // ### unchecked
  reminderDurationTypeList = (List<ReminderDurationUnit>) getTypeList(ReminderDurationUnit.class);
  reminderActionTypeList = (List<ReminderActionType>) getTypeList(ReminderActionType.class);
  final IChoiceRenderer<ReminderDurationUnit> reminderDurationTypeRenderer = (IChoiceRenderer<ReminderDurationUnit>) getChoiceRenderer(ReminderDurationUnit.class); //
  final IChoiceRenderer<ReminderActionType> reminderActionTypeRenderer = (IChoiceRenderer<ReminderActionType>) getChoiceRenderer(ReminderActionType.class); //
  // ###

  final MinMaxNumberField<Integer> reminderDuration = new MinMaxNumberField<Integer>(reminderPanel.getTextFieldId(),
      new PropertyModel<Integer>(data, "reminderDuration"), 0, DURATION_MAX);
  WicketUtils.setSize(reminderDuration, 3);
  setComponentProperties(reminderDuration, reminderOptionVisibility, true);

  // reminder duration dropDown
  final IModel<List<ReminderDurationUnit>> reminderDurationChoicesModel = new PropertyModel<List<ReminderDurationUnit>>(this,
      "reminderDurationTypeList");
  final IModel<ReminderDurationUnit> reminderDurationActiveModel = new PropertyModel<ReminderDurationUnit>(data, "reminderDurationType");
  final DropDownChoicePanel<ReminderDurationUnit> reminderDurationTypeChoice = new DropDownChoicePanel<ReminderDurationUnit>(
      reminderPanel.newChildId(), reminderDurationActiveModel, reminderDurationChoicesModel, reminderDurationTypeRenderer, false);
  setComponentProperties(reminderDurationTypeChoice.getDropDownChoice(), reminderOptionVisibility, true);

  // reminder action dropDown
  final IModel<List<ReminderActionType>> reminderActionTypeChoiceModel = new PropertyModel<List<ReminderActionType>>(this,
      "reminderActionTypeList");
  final IModel<ReminderActionType> reminderActionActiveModel = new PropertyModel<ReminderActionType>(data, "reminderActionType");
  final DropDownChoicePanel<ReminderActionType> reminderActionTypeChoice = new DropDownChoicePanel<ReminderActionType>(
      reminderPanel.newChildId(), new DropDownChoice<ReminderActionType>(DropDownChoicePanel.WICKET_ID, reminderActionActiveModel,
          reminderActionTypeChoiceModel, reminderActionTypeRenderer) {
        /**
         * @see org.apache.wicket.markup.html.form.AbstractSingleSelectChoice#getNullKey()
         */
        @Override
        protected String getNullValidKey()
        {
          return "plugins.teamcal.event.reminder.NONE";
        }
      });
  reminderActionTypeChoice.setNullValid(true);
  reminderActionTypeChoice.getDropDownChoice().add(new AjaxFormComponentUpdatingBehavior("onChange") {

    @Override
    protected void onUpdate(final AjaxRequestTarget target)
    {
      final boolean isVisible = data.getReminderActionType() != null;
      if (isVisible == true) {
        // Pre-set default values if the user selects a reminder action:
        if (NumberHelper.greaterZero(data.getReminderDuration()) == false) {
          data.setReminderDuration(15);
        }
        if (data.getReminderDurationUnit() == null) {
          data.setReminderDurationUnit(ReminderDurationUnit.MINUTES);
        }
      }
      reminderDuration.setVisible(isVisible);
      reminderDurationTypeChoice.getDropDownChoice().setVisible(isVisible);
      reminderDurationTypeChoice.setRequired(isVisible);
      target.add(reminderDurationTypeChoice.getDropDownChoice(), reminderDuration);
    }

  });
  reminderPanel.add(reminderActionTypeChoice);
  reminderPanel.add(reminderDuration);
  reminderPanel.add(reminderDurationTypeChoice);
}
 
Example #28
Source Project: nextreports-server   Author: nextreports   File: DestinationsPanel.java    License: Apache License 2.0 4 votes vote down vote up
private void addDestinationType() {
     Label type = new Label("type", getString("ActionContributor.Run.destination.type"));
     add(type);

     List<String> types = new ArrayList<String>();
     boolean supportsAlert = schedulerJob.getReport().isAlarmType() || schedulerJob.getReport().isIndicatorType() || schedulerJob.getReport().isDisplayType();
     if (supportsAlert) {
     	types.add(DestinationType.ALERT.toString());
     } else {
     	for (DestinationType dt : DestinationType.values()) {
     		if (!DestinationType.ALERT.toString().equals(dt.toString())) {
     			types.add(dt.toString());
     		}
     	}
     }
     
     IChoiceRenderer<String> typeRenderer = new ChoiceRenderer<String>() {
@Override
public Object getDisplayValue(String object) {
	return getString("DestinationsPanel.type." + object);
}        	
     };
     
     typeChoice = new DropDownChoice<String>("typeChoice", new Model<String>(), types, typeRenderer) {
     	
private static final long serialVersionUID = 1L;

@Override
protected CharSequence getDefaultChoice(String selectedValue) {
             return "<option value=\"\">" + getString("nullValid") + "</option>";
}
         
     };
     add(typeChoice);
     typeChoice.setNullValid(true);
     typeChoice.setOutputMarkupId(true);
     typeChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
     	
private static final long serialVersionUID = 1L;

protected void onUpdate(AjaxRequestTarget target) {
             showNewDestination(target);
         }
         
     });
 }
 
Example #29
Source Project: nextreports-server   Author: nextreports   File: ExtendedPalette.java    License: Apache License 2.0 4 votes vote down vote up
public ExtendedPalette(String id, IModel<List<T>> model, IModel<? extends Collection<? extends T>> choicesModel, IChoiceRenderer<T> choiceRenderer,
                       int rows, boolean allowOrder) {
    this(id, model, choicesModel, choiceRenderer, rows, allowOrder, false);
}
 
Example #30
Source Project: nextreports-server   Author: nextreports   File: ExtendedPalette.java    License: Apache License 2.0 4 votes vote down vote up
public IChoiceRenderer<T> getChoiceRenderer() {
    return choiceRenderer;
}