// 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
Map formComponents = flc.getFormComponents();
for (int move = rowPos + 1; move <= columnAttribute.size(); move++) {
FormItem oldPos = (FormItem) formComponents.get((String) columnAttribute.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = (FormItem) formComponents.get((String) columnOperator.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = (FormItem) formComponents.get((String) columnValueText.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = (FormItem) formComponents.get((String) columnValueSelection.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = (FormItem) formComponents.get((String) columnAddRow.get(move - 1));
oldPos.setUserObject(Integer.valueOf(move));
oldPos = (FormItem) formComponents.get((String) 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++) {
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(PackageTranslator.NO_TRANSLATION_ERROR_PREFIX) == 0) {
Translator translator = UserManager.getInstance().getPropertyHandlerTranslator(getTranslator());
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(PackageTranslator.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
SingleSelection attribute = uifactory.addDropdownSingleselect(PRE_ATTRIBUTE + rowCreationCounter, null, flc, attrKeys, guiTranslatedAttKeys, null);
attribute.setUserObject(Integer.valueOf(rowPos));
attribute.addActionListener(this, FormEvent.ONCHANGE);
columnAttribute.add(rowPos, attribute.getName());
// 2b) Operator selector
String[] values = OperatorManager.getRegisteredAndAlreadyTranslatedOperatorLabels(getLocale(), operatorKeys);
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
//
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
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
updateValueElementForAttribute(attribute.getKey(0), rowPos, null);
// 4) Add the 'add' and 'remove' buttons
FormLinkImpl addL = new FormLinkImpl("add_" + rowCreationCounter, "add." + rowPos, "+", Link.BUTTON_SMALL + Link.NONTRANSLATED);