use of org.olat.core.util.prefs.Preferences in project OpenOLAT by OpenOLAT.
the class TranslationToolLauncherController method setNewInlineStatus.
/**
* Helper to persist the new inline edit configuration and update the GUI
* accordingly
*
* @param ureq
* @param enable
*/
private void setNewInlineStatus(UserRequest ureq, boolean enable) {
Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
guiPrefs.putAndSave(I18nModule.class, I18nModule.GUI_PREFS_INLINE_TRANSLATION_ENABLED, Boolean.valueOf(enable));
updateInlineTranslationStatusAndLink(guiPrefs);
}
use of org.olat.core.util.prefs.Preferences in project OpenOLAT by OpenOLAT.
the class TranslationToolStartCrumbController method initLanguageSelectorElements.
private void initLanguageSelectorElements(UserSession usess, FormUIFactory formFactory, FormItemContainer formLayout) {
// Add language selection as a subform
List<String> referenceLangs;
if (customizingMode) {
// Add all enabled languages that can be customized
referenceLangs = new ArrayList<>(i18nModule.getEnabledLanguageKeys());
} else {
// Add configured reference languages in translation mode
referenceLangs = i18nModule.getTransToolReferenceLanguages();
}
String[] referencelangKeys = ArrayHelper.toArray(referenceLangs);
String[] referenceLangValues = new String[referencelangKeys.length];
for (int i = 0; i < referencelangKeys.length; i++) {
String key = referencelangKeys[i];
String explLang = i18nManager.getLanguageInEnglish(key, false);
String all = explLang;
if (explLang != null && !explLang.equals(key))
all += " (" + key + ")";
referenceLangValues[i] = all;
}
ArrayHelper.sort(referencelangKeys, referenceLangValues, false, true, false);
// Build css classes for reference languages
// Use first reference locale as default
referenceLocale = i18nManager.getLocaleOrNull(referenceLangs.get(0));
// Override with user preset
Preferences guiPrefs = usess.getGuiPreferences();
String referencePrefs = (String) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_REFERENCE_LANG, referenceLangs.get(0));
for (String refLang : referencelangKeys) {
if (referencePrefs.equals(refLang)) {
referenceLocale = i18nManager.getLocaleOrNull(referencePrefs);
break;
}
}
referenceLangSelection = formFactory.addDropdownSingleselect("start.referenceLangSelection", formLayout, referencelangKeys, referenceLangValues, null);
referenceLangSelection.select(referenceLocale.toString(), true);
this.flc.contextPut("referenceLangKey", referenceLocale.toString());
referenceLangSelection.addActionListener(FormEvent.ONCHANGE);
// Add target languages without overlays
Set<String> translatableKeys;
if (customizingMode) {
// Use all enabled languages in customizing mode
translatableKeys = i18nModule.getOverlayLanguageKeys();
} else {
// Allow translators to also translate other languages if they really desire. Show all languages.
translatableKeys = i18nModule.getTranslatableLanguageKeys();
}
String[] targetlangKeys = ArrayHelper.toArray(translatableKeys);
String[] targetLangValues = new String[targetlangKeys.length];
for (int i = 0; i < targetlangKeys.length; i++) {
String key = targetlangKeys[i];
// Since in case of customizing mode the target lang key does already
// contain the customizing key, there is no need to get the language with
// overlay enabled, this would double the customizing extension to the key
String explLang;
if (customizingMode) {
String origKey = i18nManager.createOrigianlLocaleKeyForOverlay(i18nModule.getAllLocales().get(key));
explLang = i18nManager.getLanguageInEnglish(origKey, true);
} else {
explLang = i18nManager.getLanguageInEnglish(key, false);
}
String all = explLang;
if (explLang != null && !explLang.equals(key))
all += " (" + key + ")";
targetLangValues[i] = all;
}
ArrayHelper.sort(targetlangKeys, targetLangValues, false, true, false);
// Build css classes for reference languages
targetLangSelection = formFactory.addDropdownSingleselect("start.targetLangSelection", formLayout, targetlangKeys, targetLangValues, null);
// Select current language if in list or the first one in the menu
if (customizingMode) {
// Use same as reference language in customizing mode
targetLocale = i18nModule.getOverlayLocales().get(referenceLocale);
// Disable target lang selection - user should only choose reference language, target is updated automatically
targetLangSelection.setEnabled(false);
} else {
// Use users current language in translation mode
targetLocale = getTranslator().getLocale();
if (!Arrays.asList(targetlangKeys).contains(i18nModule.getLocaleKey(targetLocale))) {
targetLocale = i18nManager.getLocaleOrNull(targetlangKeys[0]);
}
}
targetLangSelection.select(i18nModule.getLocaleKey(targetLocale), true);
// Add lang key for image - don't use customizing lang key
if (customizingMode) {
this.flc.contextPut("targetLangKey", i18nManager.createOrigianlLocaleKeyForOverlay(targetLocale));
} else {
this.flc.contextPut("targetLangKey", targetLocale.toString());
}
targetLangSelection.addActionListener(FormEvent.ONCHANGE);
// Add progress bar as normal component (not a form element)
int bundlesCount = i18nManager.countBundles(null, true);
progressBar = new ProgressBar("progressBar", 300, 0, 0, translate("start.progressBar.unitLabel", bundlesCount + ""));
this.flc.put("progressBar", progressBar);
}
use of org.olat.core.util.prefs.Preferences in project OpenOLAT by OpenOLAT.
the class RamPreferencesStorage method getPreferencesFor.
/**
* @see org.olat.core.util.prefs.PreferencesStorage#getPreferencesFor(org.olat.core.id.Identity,
* boolean)
*/
public Preferences getPreferencesFor(Identity identity, boolean useTransientPreferences) {
Preferences p;
synchronized (this) {
// o_clusterOK by:fj is not persistent, for session only
p = identToPrefs.get(identity.getName());
if (p == null) {
p = new RamPreferences();
identToPrefs.put(identity.getName(), p);
}
}
return p;
}
use of org.olat.core.util.prefs.Preferences in project OpenOLAT by OpenOLAT.
the class FormatConfigHelper method loadExportFormat.
public static ExportFormat loadExportFormat(UserRequest ureq) {
ExportFormat formatConfig = null;
if (ureq != null) {
try {
Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
String formatConfigString = (String) guiPrefs.get(ExportOptionsController.class, QTI_EXPORT_ITEM_FORMAT_CONFIG);
if (StringHelper.containsNonWhitespace(formatConfigString)) {
formatConfig = (ExportFormat) configXstream.fromXML(formatConfigString);
} else {
formatConfig = new ExportFormat(true, true, true, true, true);
}
} catch (Exception e) {
log.error("could not establish object from xml", e);
formatConfig = new ExportFormat(true, true, true, true, true);
}
}
return formatConfig;
}
use of org.olat.core.util.prefs.Preferences in project OpenOLAT by OpenOLAT.
the class FormatConfigHelper method updateExportFormat.
public static void updateExportFormat(UserRequest ureq, boolean responsecols, boolean poscol, boolean pointcol, boolean timecols, boolean commentcol) {
// save new config in GUI prefs
Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
if (guiPrefs != null) {
ExportFormat formatConfig = new ExportFormat(responsecols, poscol, pointcol, timecols, commentcol);
try {
String formatConfigString = configXstream.toXML(formatConfig);
guiPrefs.putAndSave(ExportOptionsController.class, QTI_EXPORT_ITEM_FORMAT_CONFIG, formatConfigString);
} catch (Exception e) {
log.error("", e);
}
}
}
Aggregations