Search in sources :

Example 6 with ProgressBar

use of org.olat.core.gui.components.progressbar.ProgressBar in project openolat by klemens.

the class CmdUpload method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, Translator trans, boolean cancelResetsButton) {
    this.cancelResetsForm = cancelResetsButton;
    setTranslator(trans);
    currentContainer = folderComponent.getCurrentContainer();
    if (currentContainer.canWrite() != VFSConstants.YES)
        throw new AssertException("Cannot write to selected folder.");
    // mainVC is the main view
    mainVC = createVelocityContainer("upload");
    // Add progress bar
    ubar = new ProgressBar("ubar");
    ubar.setWidth(200);
    ubar.setUnitLabel("MB");
    ubar.setRenderLabelRights(true);
    mainVC.put(ubar.getComponentName(), ubar);
    // Calculate quota and limits
    long actualUsage = 0;
    quotaKB = Quota.UNLIMITED;
    uploadLimitKB = Quota.UNLIMITED;
    inheritingContainer = VFSManager.findInheritingSecurityCallbackContainer(currentContainer);
    if (inheritingContainer != null) {
        secCallback = inheritingContainer.getLocalSecurityCallback();
        actualUsage = VFSManager.getUsageKB(inheritingContainer);
        ubar.setActual(actualUsage / 1024);
        if (inheritingContainer.getLocalSecurityCallback().getQuota() != null) {
            quotaKB = secCallback.getQuota().getQuotaKB().longValue();
            uploadLimitKB = (int) secCallback.getQuota().getUlLimitKB().longValue();
        }
    }
    // set wether we have a quota on this folder
    if (quotaKB == Quota.UNLIMITED) {
        ubar.setIsNoMax(true);
    } else if (quotaKB == 0) {
        ubar.setMax(quotaKB);
    } else {
        ubar.setMax(quotaKB / 1024f);
    }
    // set default ulLimit if none is defined...
    if (uploadLimitKB == Quota.UNLIMITED) {
        uploadLimitKB = QuotaManager.getInstance().getDefaultQuotaDependingOnRole(ureq.getIdentity()).getUlLimitKB().longValue();
    }
    // Add file upload form
    long remainingQuotaKB;
    if (quotaKB == Quota.UNLIMITED)
        remainingQuotaKB = quotaKB;
    else if (quotaKB - actualUsage < 0)
        remainingQuotaKB = 0;
    else
        remainingQuotaKB = quotaKB - actualUsage;
    removeAsListenerAndDispose(fileUploadCtr);
    fileUploadCtr = new FileUploadController(getWindowControl(), currentContainer, ureq, uploadLimitKB, remainingQuotaKB, null, false, true, showMetadata, true, showCancel, false);
    listenTo(fileUploadCtr);
    mainVC.put("fileUploadCtr", fileUploadCtr.getInitialComponent());
    mainVC.contextPut("showFieldset", Boolean.TRUE);
    // if folder full show error msg
    if (remainingQuotaKB == 0) {
        String supportAddr = WebappHelper.getMailConfig("mailQuota");
        String msg = translate("QuotaExceededSupport", new String[] { supportAddr });
        getWindowControl().setError(msg);
        return null;
    }
    putInitialPanel(mainVC);
    return this;
}
Also used : AssertException(org.olat.core.logging.AssertException) ProgressBar(org.olat.core.gui.components.progressbar.ProgressBar) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 7 with ProgressBar

use of org.olat.core.gui.components.progressbar.ProgressBar 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 8 with ProgressBar

use of org.olat.core.gui.components.progressbar.ProgressBar 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)

Aggregations

ProgressBar (org.olat.core.gui.components.progressbar.ProgressBar)8 AssertException (org.olat.core.logging.AssertException)4 I18nModule (org.olat.core.util.i18n.I18nModule)4 Preferences (org.olat.core.util.prefs.Preferences)4 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 FileUploadController (org.olat.core.commons.modules.bc.FileUploadController)2 JSAndCSSComponent (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 WindowControl (org.olat.core.gui.control.WindowControl)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 I18nItem (org.olat.core.util.i18n.I18nItem)2 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)2 SectionContext (org.olat.ims.qti.container.SectionContext)2 Navigator (org.olat.ims.qti.navigator.Navigator)2 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)2 ImsRepositoryResolver (org.olat.ims.qti.process.ImsRepositoryResolver)2 Resolver (org.olat.ims.qti.process.Resolver)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2