* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormUIFactory formFactory = FormUIFactory.getInstance();
I18nManager i18nMgr = I18nManager.getInstance();
Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
this.flc.contextPut("referenceLanguageKey", referenceLocale.toString());
this.flc.contextPut("referenceLanguage", i18nMgr.getLanguageTranslated(referenceLocale.toString(), false));
// Add bundles and keys selection
List<String> bundlesList = new ArrayList<String>();
List<String> keysList = new ArrayList<String>();
for (I18nItem item : i18nItems) {
if (!bundlesList.contains(item.getBundleName())) {
bundlesList.add(item.getBundleName());
}
if (currentItem.getBundleName().equals(item.getBundleName())) {
keysList.add(item.getKey());
}
}
String[] bundlesListArray = ArrayHelper.toArray(bundlesList);
String[] keysListArray = ArrayHelper.toArray(keysList);
bundlesSelection = formFactory.addDropdownSingleselect("bundlesSelection", this.flc, bundlesListArray, bundlesListArray, null);
bundlesSelection.addActionListener(this, FormEvent.ONCHANGE);
bundlesSelection.select(currentItem.getBundleName(), true);
keysSelection = formFactory.addDropdownSingleselect("keysSelection", this.flc, keysListArray, keysListArray, null);
keysSelection.addActionListener(this, FormEvent.ONCHANGE);
keysSelection.select(currentItem.getKey(), true);
// Add reference box
referenceArea = formFactory.addTextAreaElement("referenceArea", "edit.referenceArea", -1, 1, -1, true, null, this.flc);
referenceArea.setEnabled(false); // read only
// Add compare box
Boolean compareEnabledPrefs = (Boolean) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.FALSE);
compareArea = formFactory.addTextAreaElement("compareArea", "edit.compareArea", -1, 1, -1, true, null, this.flc);
compareArea.setEnabled(false); // read only
compareArea.setVisible(compareEnabledPrefs.booleanValue());
compareSwitch = formFactory.addCheckboxesHorizontal("compareSwitch", null, this.flc, new String[] { KEYS_ENABLED },
new String[] { KEYS_EMPTY }, null);//i18nLabel set to null -> disabled label
compareSwitch.select(KEYS_ENABLED, compareEnabledPrefs.booleanValue());
compareSwitch.addActionListener(listener, FormEvent.ONCLICK);
formLayout.add(compareSwitch);
this.flc.contextPut("compareSwitchEnabled", compareEnabledPrefs);
// Add compare language selection
Set<String> availableLangKeys = I18nModule.getAvailableLanguageKeys();
String[] comparelangKeys = ArrayHelper.toArray(availableLangKeys);
String[] compareLangValues = new String[comparelangKeys.length];
for (int i = 0; i < comparelangKeys.length; i++) {
String key = comparelangKeys[i];
String explLang = i18nMgr.getLanguageInEnglish(key, customizingMode);
String all = explLang;
if (explLang != null && !explLang.equals(key)) all += " (" + key + ")";
compareLangValues[i] = all;
}
ArrayHelper.sort(comparelangKeys, compareLangValues, false, true, false);
// Build css classes for comparison languages
String[] compareLangCssClasses = i18nMgr.createLanguageFlagsCssClasses(comparelangKeys, "b_with_small_icon_left");
String comparePrefs = (String) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_COMPARE_LANG, I18nModule
.getDefaultLocale().toString());
compareLocale = i18nMgr.getLocaleOrNull(comparePrefs);
if (compareLocale == null) compareLocale = I18nModule.getDefaultLocale();
compareLangSelection = formFactory.addDropdownSingleselect("compareLangSelection", this.flc, comparelangKeys, compareLangValues,
compareLangCssClasses);
compareLangSelection.select(i18nMgr.getLocaleKey(compareLocale), true);
this.flc.contextPut("compareLanguageKey", i18nMgr.getLocaleKey(compareLocale));
compareLangSelection.addActionListener(this, FormEvent.ONCHANGE);
compareLangSelection.setEnabled(compareEnabledPrefs.booleanValue());
// Add target box
this.flc.contextPut("targetLanguageKey", i18nMgr.getLocaleKey(currentItem.getLocale()));
this.flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(i18nMgr.getLocaleKey(currentItem.getLocale()), false));
targetArea = formFactory.addTextAreaElement("targetArea", "edit.targetArea", -1, 1, -1, true, null, this.flc);
// Add annotation box
annotationArea = formFactory.addTextAreaElement("annotationArea", "edit.annotationArea", -1, 1, -1, true, null, this.flc);
// Add progress bar
// init with values
progressBarBundle = new ProgressBar("progressBarBundle", 200, 1, bundlesList.size(), translate("generic.bundles"));
progressBarBundle.setPercentagesEnabled(false);
this.flc.put("progressBarBundle", progressBarBundle);
progressBarKey = new ProgressBar("progressBarKey", 200, 1, keysList.size(), translate("generic.keys"));
progressBarKey.setPercentagesEnabled(false);
this.flc.put("progressBarKey", progressBarKey);
// Add navigation buttons
previousLink = new FormLinkImpl("previousLink", "previousLink", "edit.button.previous", Link.BUTTON);
formLayout.add(previousLink);
saveLink = new FormLinkImpl("saveLink", "saveLink", "edit.button.save", Link.BUTTON);
formLayout.add(saveLink);
saveNextLink = new FormLinkImpl("saveNextLink", "saveNextLink", "edit.button.saveNext", Link.BUTTON);
formLayout.add(saveNextLink);
nextLink = new FormLinkImpl("nextLink", "nextLink", "edit.button.next", Link.BUTTON);
formLayout.add(nextLink);
// init values from item
initOrUpdateCurrentItem(ureq);
//
// Override text labels for customizing mode
if (customizingMode) {
// don't edit annotations in customizing mode
annotationArea.setEnabled(false);
// target lang flags and lang name
Locale origLocale = I18nModule.getAllLocales().get(i18nMgr.createOrigianlLocaleKeyForOverlay(currentItem.getLocale()));
this.flc.contextPut("targetLanguageKey", i18nMgr.getLocaleKey(origLocale));
this.flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(i18nMgr.getLocaleKey(origLocale), true));
}
this.flc.contextPut("customizingMode", Boolean.valueOf(customizingMode));
this.flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));
}