Search in sources :

Example 76 with Preferences

use of org.olat.core.util.prefs.Preferences in project openolat by klemens.

the class PortalImpl method saveUserPortalColumnsConfiguration.

private void saveUserPortalColumnsConfiguration(UserRequest ureq, List userColumns) {
    Preferences gp = ureq.getUserSession().getGuiPreferences();
    gp.putAndSave(PortalImpl.class, "userPortalColumns" + name, userColumns);
}
Also used : Preferences(org.olat.core.util.prefs.Preferences)

Example 77 with Preferences

use of org.olat.core.util.prefs.Preferences in project openolat by klemens.

the class TranslationToolI18nItemEditCrumbController method initForm.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm
	 * (org.olat.core.gui.components.form.flexible.FormItemContainer,
	 * org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
	 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
    flc.contextPut("referenceLanguageKey", referenceLocale.toString());
    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 = uifactory.addDropdownSingleselect("bundlesSelection", this.flc, bundlesListArray, bundlesListArray, null);
    bundlesSelection.setDomReplacementWrapperRequired(false);
    bundlesSelection.addActionListener(FormEvent.ONCHANGE);
    bundlesSelection.select(currentItem.getBundleName(), true);
    keysSelection = uifactory.addDropdownSingleselect("keysSelection", this.flc, keysListArray, keysListArray, null);
    keysSelection.setDomReplacementWrapperRequired(false);
    keysSelection.addActionListener(FormEvent.ONCHANGE);
    keysSelection.select(currentItem.getKey(), true);
    // Add reference box
    referenceArea = uifactory.addTextAreaElement("referenceArea", "edit.referenceArea", -1, 1, -1, true, null, this.flc);
    // read only
    referenceArea.setEnabled(false);
    // Add compare box
    Boolean compareEnabledPrefs = (Boolean) guiPrefs.get(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.FALSE);
    compareArea = uifactory.addTextAreaElement("compareArea", "edit.compareArea", -1, 1, -1, true, null, this.flc);
    // read only
    compareArea.setEnabled(false);
    compareArea.setVisible(compareEnabledPrefs.booleanValue());
    String[] compareSwitchValues = new String[] { translate("generic.enable") };
    compareSwitch = uifactory.addCheckboxesVertical("compareSwitch", null, flc, KEYS_ENABLED, compareSwitchValues, 1);
    compareSwitch.setDomReplacementWrapperRequired(false);
    compareSwitch.select(KEYS_ENABLED[0], compareEnabledPrefs.booleanValue());
    compareSwitch.addActionListener(FormEvent.ONCLICK);
    formLayout.add(compareSwitch);
    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 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 = uifactory.addDropdownSingleselect("compareLangSelection", flc, comparelangKeys, compareLangValues, null);
    compareLangSelection.setDomReplacementWrapperRequired(false);
    compareLangSelection.select(i18nModule.getLocaleKey(compareLocale), true);
    flc.contextPut("compareLanguageKey", i18nModule.getLocaleKey(compareLocale));
    compareLangSelection.addActionListener(FormEvent.ONCHANGE);
    compareLangSelection.setEnabled(compareEnabledPrefs.booleanValue());
    // Add target box
    flc.contextPut("targetLanguageKey", i18nModule.getLocaleKey(currentItem.getLocale()));
    flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(i18nModule.getLocaleKey(currentItem.getLocale()), false));
    targetArea = uifactory.addTextAreaElement("targetArea", "edit.targetArea", -1, 5, -1, true, null, flc);
    // Add annotation box
    annotationArea = uifactory.addTextAreaElement("annotationArea", "edit.annotationArea", -1, 1, -1, true, null, flc);
    // Add progress bar
    // init with values
    progressBarBundle = new ProgressBar("progressBarBundle", 300, 1, bundlesList.size(), translate("generic.bundles"));
    progressBarBundle.setPercentagesEnabled(false);
    flc.put("progressBarBundle", progressBarBundle);
    progressBarKey = new ProgressBar("progressBarKey", 300, 1, keysList.size(), translate("generic.keys"));
    progressBarKey.setPercentagesEnabled(false);
    flc.put("progressBarKey", progressBarKey);
    // Add navigation buttons
    previousLink = uifactory.addFormLink("previousLink", "edit.button.previous", null, formLayout, Link.BUTTON);
    previousLink.setIconLeftCSS("o_icon o_icon_previous_page");
    saveLink = uifactory.addFormLink("saveLink", "edit.button.save", null, formLayout, Link.BUTTON);
    saveNextLink = uifactory.addFormLink("saveNextLink", "edit.button.saveNext", null, formLayout, Link.BUTTON);
    formLayout.add(saveNextLink);
    nextLink = uifactory.addFormLink("nextLink", "edit.button.next", null, formLayout, Link.BUTTON);
    nextLink.setIconRightCSS("o_icon o_icon_next_page");
    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()));
        if (origLocale == null) {
            origLocale = currentItem.getLocale();
        }
        String localeKey = i18nModule.getLocaleKey(origLocale);
        flc.contextPut("targetLanguageKey", localeKey);
        flc.contextPut("targetLanguage", i18nMgr.getLanguageTranslated(localeKey, true));
    }
    flc.contextPut("customizingMode", Boolean.valueOf(customizingMode));
    flc.contextPut("customizingPrefix", (customizingMode ? "customize." : ""));
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) Locale(java.util.Locale) I18nItem(org.olat.core.util.i18n.I18nItem) ArrayList(java.util.ArrayList) Preferences(org.olat.core.util.prefs.Preferences) ProgressBar(org.olat.core.gui.components.progressbar.ProgressBar)

Example 78 with Preferences

use of org.olat.core.util.prefs.Preferences in project openolat by klemens.

the class TranslationToolI18nItemEditCrumbController method updateCompareArea.

private void updateCompareArea(UserRequest ureq) {
    Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
    if (compareSwitch.isSelected(0)) {
        // Add target value
        String compareValue = i18nMgr.getLocalizedString(currentItem.getBundleName(), currentItem.getKey(), null, compareLocale, customizingMode, false, false, false, 0);
        compareArea.setValue(compareValue);
        // save settings as gui prefs
        guiPrefs.put(I18nModule.class, I18nModule.GUI_PREFS_PREFERRED_COMPARE_LANG, compareLocale.toString());
        guiPrefs.putAndSave(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.TRUE);
    } else {
        guiPrefs.putAndSave(I18nModule.class, I18nModule.GUI_PREFS_COMPARE_LANG_ENABLED, Boolean.FALSE);
    }
    // update GUI
    this.flc.contextPut("compareSwitchEnabled", Boolean.valueOf(compareSwitch.isSelected(0)));
    this.flc.contextPut("compareLanguageKey", compareLocale.toString());
}
Also used : Preferences(org.olat.core.util.prefs.Preferences)

Example 79 with Preferences

use of org.olat.core.util.prefs.Preferences in project openolat by klemens.

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);
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) Preferences(org.olat.core.util.prefs.Preferences) ProgressBar(org.olat.core.gui.components.progressbar.ProgressBar)

Example 80 with Preferences

use of org.olat.core.util.prefs.Preferences in project openolat by klemens.

the class CheckListRunController method isPanelOpen.

private boolean isPanelOpen(UserRequest ureq, String panelId, boolean def) {
    Preferences guiPrefs = ureq.getUserSession().getGuiPreferences();
    Boolean showConfig = (Boolean) guiPrefs.get(CheckListRunController.class, getOpenPanelId(panelId));
    return showConfig == null ? def : showConfig.booleanValue();
}
Also used : Preferences(org.olat.core.util.prefs.Preferences)

Aggregations

Preferences (org.olat.core.util.prefs.Preferences)92 ArrayList (java.util.ArrayList)12 I18nModule (org.olat.core.util.i18n.I18nModule)8 WindowManager (org.olat.core.gui.WindowManager)6 ContextEntry (org.olat.core.id.context.ContextEntry)6 UserSession (org.olat.core.util.UserSession)6 HashSet (java.util.HashSet)4 Locale (java.util.Locale)4 Map (java.util.Map)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 UserTool (org.olat.admin.user.tools.UserTool)4 UserToolExtension (org.olat.admin.user.tools.UserToolExtension)4 Component (org.olat.core.gui.components.Component)4 FlexiTableSort (org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)4 ProgressBar (org.olat.core.gui.components.progressbar.ProgressBar)4 HistoryPoint (org.olat.core.id.context.HistoryPoint)4 I18nItem (org.olat.core.util.i18n.I18nItem)4 LocationHistory (org.olat.modules.lecture.model.LocationHistory)4 Date (java.util.Date)2 List (java.util.List)2