1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| add(new Palette<Service>("services", new PropertyModel<List<Service>>(offre, "services"), allServices, serviceRenderer, 15, false){
@Override
protected ResourceReference getCSS() {
return null;
}
@Override
protected Component newAvailableHeader(String componentId) {
return new Label(componentId, "Services disponibles");
}
@Override
protected Component newSelectedHeader(String componentId) {
return new Label(componentId, "Services sélectionnés");
}
@Override
protected Component newChoicesComponent(){
return new ChoiceSelection("choices", this, false);
}
@Override
protected Component newSelectionComponent(){
return new ChoiceSelection("selection", this, true);
}
class ChoiceSelection extends AbstractOptions<Service>{
private boolean isSelected = false;
public ChoiceSelection(String id, Palette<Service> palette, boolean isSelected){
super(id, palette);
this.isSelected = isSelected;
}
@Override
protected Iterator<Service> getOptionsIterator(){
return (isSelected)? getPalette().getSelectedChoices() : getPalette().getUnselectedChoices();
}
@Override
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag){
final AppendingStringBuffer buffer = new AppendingStringBuffer(128);
Iterator<Service> options = getOptionsIterator();
IChoiceRenderer<Service> renderer = getPalette().getChoiceRenderer();
while (options.hasNext()){
Service choice = options.next();
String id = renderer.getIdValue(choice, 0);
String value = (String)renderer.getDisplayValue(choice);
buffer.append("\n<option title='"+value+"' value=\"").append(id).append("\"");
Map<String, String> additionalAttributesMap = getAdditionalAttributes(choice);
if (additionalAttributesMap != null){
for (String s : additionalAttributesMap.keySet()){
buffer.append(" " + s + "=\"" + additionalAttributesMap.get(s) + "\"");
}
}
buffer.append(">").append(value).append("</option>");
}
buffer.append("\n");
replaceComponentTagBody(markupStream, openTag, buffer);
}
}}); |
Partager