use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class CourseLayoutGeneratorController method prepareStyleEditor.
private void prepareStyleEditor(Map<String, Map<String, Object>> customConfig) {
// keep config order
guiWrapper = new LinkedHashMap<String, Map<String, FormItem>>();
List<AbstractLayoutElement> allElements = customCMgr.getAllAvailableElements();
List<AbstractLayoutAttribute> allAttribs = customCMgr.getAllAvailableAttributes();
styleFlc.contextPut("allAttribs", allAttribs);
// needed reference to get listener back.
styleFlc.setUserObject(this);
for (AbstractLayoutElement abstractLayoutElement : allElements) {
String elementType = abstractLayoutElement.getLayoutElementTypeName();
Map<String, Object> elConf = customConfig.get(elementType);
AbstractLayoutElement concreteElmt = abstractLayoutElement.createInstance(elConf);
HashMap<String, FormItem> elAttribGui = new HashMap<String, FormItem>();
List<AbstractLayoutAttribute> attributes = concreteElmt.getAvailableAttributes();
for (AbstractLayoutAttribute attrib : attributes) {
String compName = elementType + ELEMENT_ATTRIBUTE_DELIM + attrib.getLayoutAttributeTypeName();
FormItem fi = attrib.getFormItem(compName, styleFlc);
fi.addActionListener(FormEvent.ONCHANGE);
elAttribGui.put(attrib.getLayoutAttributeTypeName(), fi);
}
guiWrapper.put(elementType, elAttribGui);
}
styleFlc.contextPut("guiWrapper", guiWrapper);
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
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.FormItem in project OpenOLAT by OpenOLAT.
the class MemberSearchForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormLayoutContainer leftContainer = FormLayoutContainer.createDefaultFormLayout("left_1", getTranslator());
leftContainer.setRootForm(mainForm);
formLayout.add(leftContainer);
// user property
login = uifactory.addTextElement("login", "search.login", 128, "", leftContainer);
login.setDisplaySize(28);
userPropertyHandlers = userManager.getUserPropertyHandlersFor(getClass().getCanonicalName(), false);
propFormItems = new HashMap<String, FormItem>();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, leftContainer);
fi.setTranslator(this.getTranslator());
// DO NOT validate email field => see OLAT-3324, OO-155, OO-222
if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
TextElement textElement = (TextElement) fi;
textElement.setItemValidatorProvider(null);
}
if (fi instanceof TextElement) {
((TextElement) fi).setDisplaySize(28);
}
propFormItems.put(userPropertyHandler.getName(), fi);
}
// others
FormLayoutContainer rightContainer = FormLayoutContainer.createDefaultFormLayout("right_1", getTranslator());
rightContainer.setRootForm(mainForm);
formLayout.add(rightContainer);
// roles
String[] roleValues = new String[roleKeys.length];
for (int i = roleKeys.length; i-- > 0; ) {
roleValues[i] = translate("search." + roleKeys[i]);
}
rolesEl = uifactory.addCheckboxesHorizontal("roles", "search.roles", rightContainer, roleKeys, roleValues);
for (String roleKey : roleKeys) {
rolesEl.select(roleKey, true);
}
String[] openValues = new String[originKeys.length];
for (int i = originKeys.length; i-- > 0; ) {
openValues[i] = translate("search." + originKeys[i]);
}
originEl = uifactory.addRadiosHorizontal("openBg", "search.origin", rightContainer, originKeys, openValues);
originEl.select("all", true);
FormLayoutContainer buttonLayout = FormLayoutContainer.createDefaultFormLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
searchButton = uifactory.addFormLink("search", buttonLayout, Link.BUTTON);
searchButton.setCustomEnabledLinkCSS("btn btn-primary");
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class UserSearchForm method validate.
private boolean validate() {
boolean atLeastOne = false;
if (login.isVisible()) {
atLeastOne = StringHelper.containsNonWhitespace(login.getValue());
}
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
FormItem ui = propFormItems.get(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (StringHelper.containsNonWhitespace(uiValue) && !uiValue.equals("-")) {
atLeastOne = true;
}
}
}
if (!atLeastOne) {
showWarning("error.search.form.notempty");
}
return atLeastOne;
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class MetadataBulkChangeController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (checkboxSwitch.contains(source)) {
MultipleSelectionElement checkbox = (MultipleSelectionElement) source;
FormItem item = (FormItem) checkbox.getUserObject();
item.setVisible(checkbox.isAtLeastSelected(1));
checkboxContainer.get(checkbox).setDirty(true);
} else if (licenseEl == source) {
updateLicenseVisibility();
licenseWrapperCont.setDirty(true);
} else {
super.formInnerEvent(ureq, source, event);
}
}
Aggregations