use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class AttributeEasyRowAdderController method updateValueElementForAttribute.
/**
* Internal method to update a row's value element. This can be a text input box or a selection drop down depending on the shibboleth module configuration and the selected attribute. The method
* will set the given value as the users selected / inputed value
*
* @param attribute The attribute key. Must not be NULL
* @param row the row ID
* @param value The value that should be selected / used in the text input field. Can be NULL.
*/
private void updateValueElementForAttribute(final String attribute, final int row, final String value) {
String[] selectableKeys = getSelectableKeys(attribute);
// Get the value text input and selection drop down form elements for this
// row. Don't use the element name since there we have the global row
// counter in the name and _not_ the current row id!
final SingleSelection iselect = (SingleSelection) flc.getFormComponent(columnValueSelection.get(row));
final TextElement tei = (TextElement) flc.getFormComponent(columnValueText.get(row));
if (selectableKeys.length > 0) {
attributeAsSelectBox(attribute, value, selectableKeys, iselect, tei);
} else {
attributeAsTextField(value, iselect, tei);
}
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection 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.SingleSelection in project openolat by klemens.
the class CourseReminderEditController method initRuleForm.
protected RuleElement initRuleForm(UserRequest ureq, RuleSPI ruleSpi, ReminderRule rule) {
String id = Integer.toString(counter++);
String type = ruleSpi.getClass().getSimpleName();
SingleSelection typeEl = uifactory.addDropdownSingleselect("rule.type.".concat(id), null, rulesCont, typeKeys, typeValues, null);
typeEl.addActionListener(FormEvent.ONCHANGE);
for (String typeKey : typeKeys) {
if (type.equals(typeKey)) {
typeEl.select(typeKey, true);
}
}
FormLink addRuleButton = uifactory.addFormLink("add.rule.".concat(id), "add", "add.rule", null, rulesCont, Link.BUTTON);
addRuleButton.setIconLeftCSS("o_icon o_icon-fw o_icon_add");
addRuleButton.setElementCssClass("o_sel_course_add_rule");
FormLink deleteRuleButton = uifactory.addFormLink("delete.rule.".concat(id), "delete", "delete.rule", null, rulesCont, Link.BUTTON);
deleteRuleButton.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
deleteRuleButton.setElementCssClass("o_sel_course_delete_rule");
RuleEditorFragment editor = ruleSpi.getEditorFragment(rule, entry);
FormItem customItem = editor.initForm(rulesCont, this, ureq);
RuleElement ruleEl = new RuleElement(typeEl, addRuleButton, deleteRuleButton, editor, customItem);
typeEl.setUserObject(ruleEl);
addRuleButton.setUserObject(ruleEl);
deleteRuleButton.setUserObject(ruleEl);
return ruleEl;
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class CourseReminderEditController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source instanceof SingleSelection) {
RuleElement panelToUpdate = null;
for (RuleElement ruleEl : ruleEls) {
if (source == ruleEl.getTypeEl()) {
panelToUpdate = ruleEl;
}
}
if (panelToUpdate != null) {
SingleSelection typeEl = (SingleSelection) source;
RuleSPI type = reminderModule.getRuleSPIByType(typeEl.getSelectedKey());
doUpdateRuleForm(ureq, panelToUpdate, type);
}
} else if (source instanceof FormLink) {
FormLink button = (FormLink) source;
String cmd = button.getCmd();
if ("add".equals(cmd)) {
doAddRule(ureq, (RuleElement) button.getUserObject());
} else if ("delete".equals(cmd)) {
doDeleteRule(ureq, (RuleElement) button.getUserObject());
}
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.core.gui.components.form.flexible.elements.SingleSelection in project openolat by klemens.
the class EvaluationFormController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (saveAsDoneButton == source) {
doConfirmDone(ureq);
} else if (source instanceof SingleSelection) {
SingleSelection radioEl = (SingleSelection) source;
Object uobject = radioEl.getUserObject();
if (uobject instanceof SliderWrapper) {
String selectedKey = radioEl.getSelectedKey();
SliderWrapper sliderWrapper = (SliderWrapper) uobject;
saveNumericalResponse(new BigDecimal(selectedKey), selectedKey, sliderWrapper.getId());
}
} else if (source instanceof SliderElement) {
SliderElement slider = (SliderElement) source;
Object uobject = slider.getUserObject();
if (uobject instanceof SliderWrapper) {
double value = slider.getValue();
SliderWrapper sliderWrapper = (SliderWrapper) uobject;
saveNumericalResponse(BigDecimal.valueOf(value), Double.toString(value), sliderWrapper.getId());
}
} else if (source instanceof FormLink) {
FormLink link = (FormLink) source;
Object uobject = link.getUserObject();
if (uobject instanceof TextInputWrapper) {
TextInputWrapper wrapper = (TextInputWrapper) uobject;
String value = wrapper.getTextEl().getValue();
saveNumericalResponse(null, value, wrapper.getId());
}
} else if (source instanceof FileElement) {
FileElement fileElement = (FileElement) source;
Object uobject = fileElement.getUserObject();
if (uobject instanceof FileUploadWrapper) {
FileUploadWrapper wrapper = (FileUploadWrapper) uobject;
if (event instanceof FileElementEvent) {
if (FileElementEvent.DELETE.equals(event.getCommand())) {
saveFileResponse(null, null, wrapper.getId());
fileElement.setInitialFile(null);
if (fileElement.getUploadFile() != null) {
fileElement.reset();
}
flc.setDirty(true);
}
} else if (fileElement.isUploadSuccess()) {
File file = fileElement.getUploadFile();
String filename = fileElement.getUploadFileName();
saveFileResponse(file, filename, wrapper.getId());
}
}
}
super.formInnerEvent(ureq, source, event);
}
Aggregations