use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class AttributeEasyRowAdderController method addRowAt.
/**
* Internal method to add a new row at the given position
*
* @param i
*/
private void addRowAt(final int rowPos) {
// 1) Make room for the new row if the row is inserted between existing
// rows. Increment the row id in the user object of the form elements and
// move them in the form element arrays
final Map<String, FormItem> formComponents = flc.getFormComponents();
for (int move = rowPos + 1; move <= columnAttribute.size(); move++) {
FormItem oldPos = formComponents.get(columnAttribute.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = formComponents.get(columnOperator.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = formComponents.get(columnValueText.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = formComponents.get(columnValueSelection.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = formComponents.get(columnAddRow.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = formComponents.get(columnRemoveRow.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
}
// 2) create the new row
// get gui translated shib attributes - fallback is to use the key also as value
final String[] guiTranslatedAttKeys = new String[attrKeys.length];
for (int j = 0; j < attrKeys.length; j++) {
final String key = attrKeys[j];
// OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
// of Translator because that's the only one not
String translated = getTranslator().translate(key, null, Level.OFF);
if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
final Translator translator = UserManager.getInstance().getPropertyHandlerTranslator(getTranslator());
final String prefix = "form.name.";
// OLAT-5089: use translate(String key, String[] args, boolean fallBackToDefaultLocale) version
// of Translator because that's the only one not
translated = translator.translate(prefix + key, null, Level.OFF);
if (translated.indexOf(Translator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
// could not translate this key, use key for non-translated values
guiTranslatedAttKeys[j] = key;
} else {
guiTranslatedAttKeys[j] = translated;
}
} else {
guiTranslatedAttKeys[j] = translated;
}
}
// sort after the values
ArrayHelper.sort(attrKeys, guiTranslatedAttKeys, false, true, true);
// use this sorted keys-values
final SingleSelection attribute = uifactory.addDropdownSingleselect(PRE_ATTRIBUTE + rowCreationCounter, null, flc, attrKeys, guiTranslatedAttKeys, null);
attribute.setUserObject(Integer.valueOf(rowPos));
attribute.addActionListener(FormEvent.ONCHANGE);
columnAttribute.add(rowPos, attribute.getName());
// 2b) Operator selector
final String[] values = OperatorManager.getRegisteredAndAlreadyTranslatedOperatorLabels(getLocale(), operatorKeys);
final FormItem operator = uifactory.addDropdownSingleselect(PRE_OPERATOR + rowCreationCounter, null, flc, operatorKeys, values, null);
operator.setUserObject(Integer.valueOf(rowPos));
columnOperator.add(rowPos, operator.getName());
// 2c) Attribute value - can be either a text input field or a selection
// drop down box - create both and hide the selection box
//
final TextElement valuetxt = uifactory.addTextElement(PRE_VALUE_TEXT + rowCreationCounter, null, -1, null, flc);
valuetxt.setDisplaySize(25);
valuetxt.setNotEmptyCheck("form.easy.error.attribute");
valuetxt.setUserObject(Integer.valueOf(rowPos));
columnValueText.add(rowPos, valuetxt.getName());
// now the selection box
final FormItem iselect = uifactory.addDropdownSingleselect(PRE_VALUE_SELECTION + rowCreationCounter, null, flc, new String[0], new String[0], null);
iselect.setUserObject(Integer.valueOf(rowPos));
iselect.setVisible(false);
columnValueSelection.add(rowPos, iselect.getName());
// 3) Init values for this row, assume selection of attribute at position 0
if (ArrayUtils.contains(attrKeys, preselectedAttribute)) {
attribute.select(preselectedAttribute, true);
updateValueElementForAttribute(attribute.getKey(ArrayUtils.indexOf(attrKeys, preselectedAttribute)), rowPos, preselectedAttributeValue);
} else {
updateValueElementForAttribute(attribute.getKey(0), rowPos, null);
}
// 4) Add the 'add' and 'remove' buttons
final FormLinkImpl addL = new FormLinkImpl("add_" + rowCreationCounter, "add." + rowPos, "+", Link.BUTTON_SMALL + Link.NONTRANSLATED);
addL.setUserObject(Integer.valueOf(rowPos));
flc.add(addL);
columnAddRow.add(rowPos, addL.getName());
//
final FormLinkImpl removeL = new FormLinkImpl("remove_" + rowCreationCounter, "remove." + rowPos, "-", Link.BUTTON_SMALL + Link.NONTRANSLATED);
removeL.setUserObject(Integer.valueOf(rowPos));
flc.add(removeL);
columnRemoveRow.add(rowPos, removeL.getName());
// new row created, increment counter for unique form element id's
rowCreationCounter++;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class GuiDemoFlexiFormAdvancedController method addTextFields.
/**
* Adds a mandatory and a read-only text field to the provided form.
*
* @param formItemsFactory
* @param form
*/
private void addTextFields(FormItemContainer form) {
// Mandatory text field
final TextElement textField = uifactory.addTextElement("textField", "guidemo.form.text", 256, "", form);
textField.setMandatory(true);
textField.setNotEmptyCheck("guidemo.form.error.notempty");
textField.setExampleKey("advanced_form.text_field.example", null);
// Read-only text field
final TextElement readOnly = uifactory.addTextElement("readOnly", "guidemo.form.readonly", 256, "forever", form);
readOnly.setEnabled(false);
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class OAuthAdminController method mandatory.
private boolean mandatory(TextElement... textEls) {
boolean allOk = true;
if (textEls != null) {
for (int i = textEls.length; i-- > 0; ) {
TextElement textEl = textEls[i];
if (textEl != null) {
textEl.clearError();
if (!StringHelper.containsNonWhitespace(textEl.getValue())) {
textEl.setErrorKey("form.legende.mandatory", null);
allOk &= false;
}
}
}
}
return allOk;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class OAuthRegistrationController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
OAuthUser oauthUser = registration.getOauthUser();
usernameEl = uifactory.addTextElement("username", "user.login", 128, "", formLayout);
usernameEl.setMandatory(true);
if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
usernameEl.setValue(oauthUser.getId());
}
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
propFormItems.put(userPropertyHandler.getName(), fi);
if (fi instanceof TextElement) {
String value = oauthUser.getProperty(userPropertyHandler.getName());
if (StringHelper.containsNonWhitespace(value)) {
((TextElement) fi).setValue(value);
}
}
}
}
uifactory.addSpacerElement("lang", formLayout, true);
// second the user language
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
langEl = uifactory.addDropdownSingleselect("user.language", formLayout, langKeys, langValues, null);
FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("save", buttonLayout);
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class FIBScoreController method createTextEntryWrapper.
private FIBEntryWrapper createTextEntryWrapper(AbstractEntry entry) {
String points = "";
Double score = entry.getScore();
if (score != null) {
points = score.toString();
}
String pointElId = "points_" + counter++;
TextElement pointEl = uifactory.addTextElement(pointElId, null, 5, points, scoreCont);
pointEl.setDisplaySize(5);
pointEl.setEnabled(!restrictedEdit && !readOnly);
scoreCont.add(pointElId, pointEl);
return new FIBEntryWrapper(entry, pointEl);
}
Aggregations