use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class ColorSpecialHandler method getValue.
@Override
public String getValue() {
FormLayoutContainer innerFLC = (FormLayoutContainer) getFormItem();
Map<String, FormItem> items = innerFLC.getFormComponents();
String ddValue = "";
String inputValue = "";
FormItem inputItem = null;
for (Entry<String, FormItem> fiEntry : items.entrySet()) {
String compName = fiEntry.getKey();
FormItem fi = fiEntry.getValue();
if (compName.endsWith("sel") && fi instanceof SingleSelection) {
ddValue = ((SingleSelection) fi).isOneSelected() ? ((SingleSelection) fi).getSelectedKey() : "";
}
if (compName.endsWith("value") && fi instanceof TextElement) {
inputItem = fi;
inputValue = ((TextElement) fi).getValue();
}
}
if (ddValue.equals("") && StringHelper.containsNonWhitespace(inputValue)) {
// use input-value if valid
Pattern pattern = Pattern.compile(HEX_PATTERN);
Matcher matcher = pattern.matcher(inputValue);
if (matcher.matches()) {
hasError = false;
return inputValue;
} else {
hasError = true;
inputItem.setErrorKey("color.hex.error", null);
return "";
}
}
if (!ddValue.equals("") && StringHelper.containsNonWhitespace(inputValue)) {
inputItem.setErrorKey("color.double.error", null);
}
return ddValue;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class LicenseAdminConfigController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (enabledEl == source) {
doEnableHandlers();
} else if (addLicenseTypeButton == source) {
doAddLicenseType(ureq);
} else if (tableEl == source) {
if (event instanceof SelectionEvent) {
SelectionEvent se = (SelectionEvent) event;
String cmd = se.getCommand();
LicenseTypeRow licenseTypeRow = dataModel.getObject(se.getIndex());
if (CMD_UP.equals(cmd)) {
doUp(se.getIndex());
} else if (CMD_DOWN.equals(cmd)) {
doDown(se.getIndex());
} else if (CMD_TRANSLATE.equals(cmd)) {
doOpenTranslator(ureq, licenseTypeRow.getLicenseType());
} else if (CMD_EDIT.equals(cmd)) {
doEditLicenseType(ureq, licenseTypeRow.getLicenseType());
}
}
} else if (source instanceof MultipleSelectionElement) {
MultipleSelectionElement multipleSelectionElement = (MultipleSelectionElement) source;
doActivateLicenseType(multipleSelectionElement);
} else if (source instanceof SingleSelection) {
SingleSelection singleSelection = (SingleSelection) source;
String name = singleSelection.getName();
if (name.startsWith(DEFAULT_LICENSE_TYPE_PREFIX)) {
doSetDefaultLicenceType(source, singleSelection);
} else if (name.startsWith(LICENSOR_CREATOR_TYPE_PREFIX)) {
doSetLicensorCreator(source, singleSelection);
}
} else if (source instanceof FormLink) {
Object userObject = source.getUserObject();
if (userObject instanceof LicenseHandler) {
LicenseHandler handler = (LicenseHandler) userObject;
doEditLicensorConstant(ureq, handler);
}
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class LicenseAdminConfigController method reloadDefaultLicenseTypeEl.
private void reloadDefaultLicenseTypeEl(LicenseHandler handler) {
SingleSelection defaultLicenseTypeEl = defaultLicenseTypeEls.get(handler.getType());
if (defaultLicenseTypeEl != null) {
List<LicenseType> activatedLicenseTypes = licenseService.loadActiveLicenseTypes(handler);
Collections.sort(activatedLicenseTypes);
String[] licenseTypeKeys = getLicenseTypeKeys(activatedLicenseTypes);
String[] licenseTypeValues = getLicenseTypeValues(activatedLicenseTypes);
defaultLicenseTypeEl.setKeysAndValues(licenseTypeKeys, licenseTypeValues, null);
String defaultLicenseTypeKey = licenseModule.getDefaultLicenseTypeKey(handler);
if (Arrays.asList(licenseTypeKeys).contains(defaultLicenseTypeKey)) {
defaultLicenseTypeEl.select(defaultLicenseTypeKey, true);
}
}
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class FormUIFactory method addRadiosHorizontal.
/**
* Add horizontal aligned radio buttons. <br>
*
* @param name
* @param i18nLabel
* @param formLayout
* @param theKeys
* @param theValues
* @return
*/
public SingleSelection addRadiosHorizontal(final String name, final String i18nLabel, FormItemContainer formLayout, final String[] theKeys, final String[] theValues) {
SingleSelection ss = new SingleSelectionImpl(name, name, SingleSelection.Layout.horizontal);
ss.setKeysAndValues(theKeys, theValues, null);
setLabelIfNotNull(i18nLabel, ss);
formLayout.add(ss);
return ss;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class AttributeEasyRowAdderController method setAttributeConditions.
/**
* Method to initialize this form with the given extended conditions
*
* @param cond
*/
public void setAttributeConditions(final List<ExtendedCondition> cond) {
if (getRowCount() > 1) {
throw new AssertException("more than one row found, don't know what do do");
}
if (!isinit) {
throw new AssertException("must call init() before calling setAttributeConditions() !");
}
// use default initialized rows when no conditions have to be set
if (cond.size() == 0) {
return;
}
// remove default row from init process to make process of generating the
// existing configuration easier
removeRowAt(0);
for (final Iterator<ExtendedCondition> iterator = cond.iterator(); iterator.hasNext(); ) {
final ExtendedCondition extendedCondition = iterator.next();
final int row = getRowCount();
// now count is always one more than the row position, thus the next position to add a row
// is the same as the current row count
addRowAt(row);
// set value in attribute selection
SingleSelection ssi = (SingleSelection) flc.getFormComponent(columnAttribute.get(row));
ssi.select(extendedCondition.getAttribute(), true);
// set value in operator selection
ssi = (SingleSelection) flc.getFormComponent(columnOperator.get(row));
ssi.select(extendedCondition.getOperator().getOperatorKey(), true);
// set the selectable values for this attribute if available and set the
// preselected / predefined value.
final String attribute = extendedCondition.getAttribute();
updateValueElementForAttribute(attribute, row, extendedCondition.getValue());
}
}
Aggregations