use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class RubricController method forgeDiscreteRadioButtons.
private SliderWrapper forgeDiscreteRadioButtons(Slider slider, Rubric element) {
int start = element.getStart();
int end = element.getEnd();
int steps = element.getSteps();
double[] theSteps = new double[steps];
String[] theKeys = new String[steps];
String[] theValues = new String[steps];
double step = (end - start + 1) / (double) steps;
for (int i = 0; i < steps; i++) {
theSteps[i] = start + (i * step);
theKeys[i] = Double.toString(theSteps[i]);
theValues[i] = "";
}
SingleSelection radioEl = uifactory.addRadiosVertical("slider_" + (count++), null, flc, theKeys, theValues);
radioEl.setDomReplacementWrapperRequired(false);
radioEl.addActionListener(FormEvent.ONCHANGE);
int widthInPercent = EvaluationFormElementWrapper.getWidthInPercent(element);
radioEl.setWidthInPercent(widthInPercent, true);
SliderWrapper sliderWrapper = new SliderWrapper(slider, radioEl);
radioEl.setUserObject(sliderWrapper);
return sliderWrapper;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class LLEditForm method addNewFormLink.
/**
* Add a new form link line to the list of link elements.
*
* @param link the link model object
*/
private void addNewFormLink(int index, final LLModel link) {
// add link target
TextElement lTarget = uifactory.addTextElement("target" + counter, null, -1, link.getTarget(), flc);
lTarget.setPlaceholderKey("target.example", null);
lTarget.clearError();
lTarget.setEnabled(!link.isIntern());
lTarget.setDisplaySize(40);
lTarget.setMandatory(true);
lTarget.setNotEmptyCheck("ll.table.target.error");
lTarget.setItemValidatorProvider(new ItemValidatorProvider() {
public boolean isValidValue(String value, ValidationError validationError, Locale locale) {
try {
if (!value.contains("://")) {
value = "http://".concat(value);
}
new URL(value);
} catch (MalformedURLException e) {
validationError.setErrorKey("ll.table.target.error.format");
return false;
}
return true;
}
});
lTarget.addActionListener(FormEvent.ONCHANGE);
lTarget.setUserObject(link);
lTargetInputList.add(index, lTarget);
// add html target
SingleSelection htmlTargetSelection = uifactory.addDropdownSingleselect("html_target" + counter, flc, new String[] { BLANK_KEY, SELF_KEY }, new String[] { translate("ll.table.html_target"), translate("ll.table.html_target.self") }, null);
htmlTargetSelection.setUserObject(link);
htmlTargetSelection.select((SELF_KEY.equals(link.getHtmlTarget()) ? SELF_KEY : BLANK_KEY), true);
lHtmlTargetInputList.add(index, htmlTargetSelection);
// add link description
TextElement lDescription = uifactory.addTextElement("description" + counter, null, -1, link.getDescription(), flc);
lDescription.clearError();
lDescription.setDisplaySize(20);
lDescription.setNotEmptyCheck("ll.table.description.error");
lDescription.setMandatory(true);
lDescription.setPlaceholderKey("ll.table.description", null);
lDescription.setUserObject(link);
lDescriptionInputList.add(index, lDescription);
// add link comment
TextElement lComment = uifactory.addTextAreaElement("comment" + counter, null, -1, 2, 50, true, link.getComment(), flc);
lComment.setPlaceholderKey("ll.table.comment", null);
lComment.setDisplaySize(20);
lComment.setUserObject(link);
lCommentInputList.add(index, lComment);
// add link add action button
FormLink addButton = new FormLinkImpl("add" + counter, "add" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
addButton.setUserObject(link);
addButton.setDomReplacementWrapperRequired(false);
addButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_add");
flc.add(addButton);
lAddButtonList.add(index, addButton);
// add link deletion action button
FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
delButton.setUserObject(link);
delButton.setDomReplacementWrapperRequired(false);
delButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_delete_item");
flc.add(delButton);
lDelButtonList.add(index, delButton);
// custom media action button
FormLink mediaButton = new FormLinkImpl("media" + counter, "media" + counter, " ", Link.NONTRANSLATED);
mediaButton.setIconLeftCSS("o_icon o_icon_browse o_icon-lg");
mediaButton.setDomReplacementWrapperRequired(false);
mediaButton.setUserObject(link);
flc.add(mediaButton);
lCustomMediaButtonList.add(index, mediaButton);
// increase the counter to enable unique component names
counter++;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class ChecklistEditCheckpointsController method addNewFormCheckpoint.
private void addNewFormCheckpoint(int index, Checkpoint checkpoint) {
// add checkpoint title
String pointTitle = checkpoint.getTitle() == null ? "" : checkpoint.getTitle();
TextElement title = uifactory.addTextElement("title" + counter, null, -1, pointTitle, titleContainer);
// TODO:SK:2009-11-20:PB:should be default -> check layout in velocity.
title.showError(false);
title.setDisplaySize(20);
title.setMandatory(true);
// TODO:Stefan Köber: please verify that the default not empty check does the same as you ItemValidatorProvider
title.setNotEmptyCheck("cl.table.title.error");
title.setUserObject(checkpoint);
titleInputList.add(index, title);
// add checkpoint description
TextElement description = uifactory.addTextElement("description" + counter, null, -1, checkpoint.getDescription(), titleContainer);
description.setDisplaySize(35);
description.setMandatory(false);
description.setUserObject(checkpoint);
descriptionInputList.add(index, description);
// add link comment
String[] keys = CheckpointMode.getModes();
String[] values = new String[keys.length];
for (int i = 0; i < keys.length; i++) {
values[i] = translate(keys[i]);
}
SingleSelection mode = uifactory.addDropdownSingleselect("modus" + counter, "form.enableCancelEnroll", titleContainer, keys, values, null);
mode.select(checkpoint.getMode(), checkpoint.getMode() != null);
mode.setUserObject(checkpoint);
modeInputList.add(index, mode);
// add link deletion action button
FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "cl.table.delete", Link.BUTTON_SMALL);
delButton.setUserObject(checkpoint);
titleContainer.add(delButton);
delButtonList.add(index, delButton);
// increase the counter to enable unique component names
counter++;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class CountryCodePropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale,
* org.olat.core.id.User, java.lang.String, boolean,
* org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
String[] allKeys = new String[countryKeys.length + 1];
System.arraycopy(countryKeys, 0, allKeys, 1, countryKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
// make pre-selection of the formItem
String internalValue = getInternalValue(user);
if (internalValue == null || internalValue.isEmpty() || NO_SEL_KEY.equals(internalValue)) {
sse.select(NO_SEL_KEY, true);
} else if (isValidValue(user, internalValue, null, null) && internalValue != null) {
sse.select("country.code." + internalValue, true);
}
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
sse.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
sse.setMandatory(true);
}
return sse;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project OpenOLAT by OpenOLAT.
the class GenericSelectionPropertyHandler method getStringValue.
@Override
public String getStringValue(FormItem formItem) {
if (isMultiselect) {
Collection<String> selectedKeys = ((MultipleSelectionElement) formItem).getSelectedKeys();
StringBuilder sb = new StringBuilder();
for (String sKey : selectedKeys) {
sb.append(sKey).append(KEY_DELIMITER);
}
return sb.toString();
}
if (formItem instanceof SingleSelection) {
SingleSelection sel = (SingleSelection) formItem;
if (sel.isOneSelected()) {
return sel.getSelectedKey();
} else {
return null;
}
}
return null;
}
Aggregations