use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class UsrPropCfgTableController method buildPropertyHandlerTable.
/**
* builds the userPropertyHandler-Table
*/
private void buildPropertyHandlerTable() {
List<UserPropertyHandler> myHandlerList = usrPropCfgMng.getUserPropertiesConfigObject().getPropertyHandlers();
// first search for all group-values in the propertyHandlers
List<String> allGroupValues = new ArrayList<>();
for (UserPropertyHandler handler : myHandlerList) {
String group = handler.getGroup();
if (!allGroupValues.contains(group))
allGroupValues.add(group);
}
// take the defaults
for (int k = 0; k < GROUP_KEYS.length; k++) {
String group = GROUP_KEYS[k];
if (!allGroupValues.contains(group))
allGroupValues.add(group);
}
final String[] selectableGroups = allGroupValues.toArray(new String[0]);
// the table-rows
String handlerName;
SingleSelection groupDropdown;
FormToggle fi;
FormLink translateLink;
FormLink handlerLink;
String translatedName;
for (UserPropertyHandler handler : myHandlerList) {
handlerName = handler.getName();
// the group field
groupDropdown = uifactory.addDropdownSingleselect(FT_NAME_PREFIX_GRPN + handlerName, propTableFlc, selectableGroups, selectableGroups, null);
if (Arrays.asList(selectableGroups).contains(handler.getGroup())) {
groupDropdown.select(handler.getGroup(), true);
} else {
logWarn("could not set group-select to " + handler.getGroup() + " (" + handler.getName() + ")", null);
}
groupDropdown.setUserObject(handler);
groupDropdown.showLabel(false);
groupDropdown.addActionListener(FormEvent.ONCHANGE);
// the "active"-toggle button
fi = uifactory.addToggleButton(FT_NAME_PREFIX_TGL + handlerName, " ", propTableFlc, null, null);
if (usrPropCfgMng.getUserPropertiesConfigObject().isActiveHandler(handler))
fi.toggleOn();
else
fi.toggleOff();
if (!UsrPropCfgManager.canBeDeactivated(handler))
fi.setEnabled(false);
fi.setUserObject(handler);
rowToggleButtonsMap.put(handlerName, fi);
// the "translate" link
if (isPropertyHandlerTranslated(handler)) {
translateLink = uifactory.addFormLink(FT_NAME_PREFIX_TRANSL + handlerName, "upc.edittranslate", "label", propTableFlc, Link.LINK);
} else {
translateLink = uifactory.addFormLink(FT_NAME_PREFIX_TRANSL + handlerName, "upc.translate", "label", propTableFlc, Link.LINK);
translateLink.setCustomEnabledLinkCSS("o_ochre");
}
translateLink.setUserObject(handler);
// the "handler-config" link
if (handlerConfigCtrlFactory.hasConfig(handler)) {
handlerLink = uifactory.addFormLink(FT_NAME_PREFIX_HDNL + handlerName, "upc.hndlconfig", "label", propTableFlc, Link.LINK);
handlerLink.setUserObject(handler);
}
// put the translation (in the current language) for the property
translatedName = I18nManager.getInstance().getLocalizedString(UserPropertyHandler.class.getPackage().getName(), handler.i18nFormElementLabelKey(), null, getLocale(), true, true);
uifactory.addStaticTextElement(FT_NAME_PREFIX_TRANSNAME + handlerName, (translatedName == null ? "-" : translatedName), propTableFlc);
}
propTableFlc.contextPut("rows", myHandlerList);
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class GenericSelectionPropertyHandler method isValid.
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
if (formItem.isMandatory()) {
if (isMultiselect) {
MultipleSelectionElement msel = (MultipleSelectionElement) formItem;
msel.setErrorKey("form.legende.mandatory", null);
return msel.isAtLeastSelected(1);
} else {
SingleSelection ssel = (SingleSelection) formItem;
if (ssel.getSelectedKey().equals(NO_SEL_KEY)) {
ssel.setErrorKey("form.legende.mandatory", null);
return false;
}
}
}
return true;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class GenericSelectionPropertyHandler 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) {
FormItem newItem = null;
if (isMultiselect) {
MultipleSelectionElement mse = FormUIFactory.getInstance().addCheckboxesHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, selectionKeys, getTranslatedValues(selectionKeys, locale));
for (String sKey : getSelectedKeys(user)) {
mse.select(sKey, true);
}
newItem = mse;
} else {
String[] allKeys = new String[selectionKeys.length + 1];
System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.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 (isValidValue(user, internalValue, null, null) && internalValue != null)
sse.select(internalValue, true);
newItem = sse;
}
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
newItem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
newItem.setMandatory(true);
}
return newItem;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class YearPropertyHandler method addFormItem.
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
/* let's load the years */
loadSelectionKeysFromConfig();
// add the no-selection entry to the dropdown
String[] allKeys = new String[selectionKeys.length + 1];
System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, allKeys, null);
String internalValue = getInternalValue(user);
if (isValidValue(user, internalValue, null, null) && internalValue != null)
sse.select(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 klemens.
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;
}
Aggregations