Search in sources :

Example 1 with FormToggle

use of org.olat.core.gui.components.form.flexible.elements.FormToggle in project OpenOLAT by OpenOLAT.

the class UsrPropCfgTableController method buildPropertyHandlerTable.

/**
 * builds the userPropertyHandler-Table
 */
private void buildPropertyHandlerTable() {
    List<UserPropertyHandler> myHandlerList = usrPropCfgMng.getUserPropertiesConfigObject().getPropertyHandlers();
    // first search for all group-values in the propertyHandlers
    List<String> allGroupValues = new ArrayList<>();
    for (UserPropertyHandler handler : myHandlerList) {
        String group = handler.getGroup();
        if (!allGroupValues.contains(group))
            allGroupValues.add(group);
    }
    // take the defaults
    for (int k = 0; k < GROUP_KEYS.length; k++) {
        String group = GROUP_KEYS[k];
        if (!allGroupValues.contains(group))
            allGroupValues.add(group);
    }
    final String[] selectableGroups = allGroupValues.toArray(new String[0]);
    // the table-rows
    String handlerName;
    SingleSelection groupDropdown;
    FormToggle fi;
    FormLink translateLink;
    FormLink handlerLink;
    String translatedName;
    for (UserPropertyHandler handler : myHandlerList) {
        handlerName = handler.getName();
        // the group field
        groupDropdown = uifactory.addDropdownSingleselect(FT_NAME_PREFIX_GRPN + handlerName, propTableFlc, selectableGroups, selectableGroups, null);
        if (Arrays.asList(selectableGroups).contains(handler.getGroup())) {
            groupDropdown.select(handler.getGroup(), true);
        } else {
            logWarn("could not set group-select to " + handler.getGroup() + " (" + handler.getName() + ")", null);
        }
        groupDropdown.setUserObject(handler);
        groupDropdown.showLabel(false);
        groupDropdown.addActionListener(FormEvent.ONCHANGE);
        // the "active"-toggle button
        fi = uifactory.addToggleButton(FT_NAME_PREFIX_TGL + handlerName, "&nbsp;", propTableFlc, null, null);
        if (usrPropCfgMng.getUserPropertiesConfigObject().isActiveHandler(handler))
            fi.toggleOn();
        else
            fi.toggleOff();
        if (!UsrPropCfgManager.canBeDeactivated(handler))
            fi.setEnabled(false);
        fi.setUserObject(handler);
        rowToggleButtonsMap.put(handlerName, fi);
        // the "translate" link
        if (isPropertyHandlerTranslated(handler)) {
            translateLink = uifactory.addFormLink(FT_NAME_PREFIX_TRANSL + handlerName, "upc.edittranslate", "label", propTableFlc, Link.LINK);
        } else {
            translateLink = uifactory.addFormLink(FT_NAME_PREFIX_TRANSL + handlerName, "upc.translate", "label", propTableFlc, Link.LINK);
            translateLink.setCustomEnabledLinkCSS("o_ochre");
        }
        translateLink.setUserObject(handler);
        // the "handler-config" link
        if (handlerConfigCtrlFactory.hasConfig(handler)) {
            handlerLink = uifactory.addFormLink(FT_NAME_PREFIX_HDNL + handlerName, "upc.hndlconfig", "label", propTableFlc, Link.LINK);
            handlerLink.setUserObject(handler);
        }
        // put the translation (in the current language) for the property
        translatedName = I18nManager.getInstance().getLocalizedString(UserPropertyHandler.class.getPackage().getName(), handler.i18nFormElementLabelKey(), null, getLocale(), true, true);
        uifactory.addStaticTextElement(FT_NAME_PREFIX_TRANSNAME + handlerName, (translatedName == null ? "-" : translatedName), propTableFlc);
    }
    propTableFlc.contextPut("rows", myHandlerList);
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 2 with FormToggle

use of org.olat.core.gui.components.form.flexible.elements.FormToggle in project OpenOLAT by OpenOLAT.

the class PortfolioFilterController method initTagFlc.

/**
 */
private void initTagFlc() {
    tagFlc.setLabel("filter.tag", null);
    tagAllBtn = uifactory.addToggleButton("filter.all", null, tagFlc, null, null);
    tagAllBtn.toggleOff();
    tagNoneBtn = uifactory.addToggleButton("filter.notag", null, tagFlc, null, null);
    Map<String, String> userTags = ePFMgr.getUsersMostUsedTags(getIdentity(), 8);
    int i = 1;
    tagCmpList = new ArrayList<FormToggle>();
    LinkedList<Entry<String, String>> sortEntrySet = new LinkedList<Entry<String, String>>(userTags.entrySet());
    Collections.sort(sortEntrySet, new Comparator<Entry<String, String>>() {

        public int compare(Entry<String, String> arg0, Entry<String, String> arg1) {
            return arg0.getValue().compareTo(arg1.getValue());
        }
    });
    List<String> allActiveTagToggles = new ArrayList<String>();
    for (Entry<String, String> entry : sortEntrySet) {
        String tag = entry.getValue();
        String tagText = StringHelper.escapeHtml(tag);
        String tagCmpName = TAG_CMP_IDENTIFIER + i;
        if (tagFlc.getComponent(tagCmpName) != null)
            tagFlc.remove(tagCmpName);
        FormToggle link = uifactory.addToggleButton(tagCmpName, tagText, tagFlc, null, null);
        link.setLabel("tag.one", new String[] { tagText });
        link.setUserObject(tag);
        if (!selectedTagsList.isEmpty() && selectedTagsList.contains(tag)) {
            link.toggleOn();
            allActiveTagToggles.add(tag);
        }
        tagCmpList.add(link);
        i++;
    }
    tagFlc.contextPut("tagCmpList", tagCmpList);
    tagEditBtn = uifactory.addToggleButton("filter.edit", null, tagFlc, null, null);
    tagEditBtn.toggleOff();
    if (!allActiveTagToggles.containsAll(selectedTagsList))
        tagEditBtn.toggleOn();
    if (selectedTagsList.isEmpty())
        tagAllBtn.toggleOn();
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle) LinkedList(java.util.LinkedList)

Example 3 with FormToggle

use of org.olat.core.gui.components.form.flexible.elements.FormToggle in project OpenOLAT by OpenOLAT.

the class PortfolioFilterController method initOrUpdateTypeFlc.

/**
 */
private void initOrUpdateTypeFlc(int limit) {
    typeFlc.setLabel("filter.view", null);
    typeAllBtn = uifactory.addToggleButton("filter.all", null, typeFlc, null, null);
    typeAllBtn.toggleOff();
    List<EPArtefactHandler<?>> handlers = portfolioModule.getAllAvailableArtefactHandlers();
    typeCmpList = new ArrayList<FormToggle>();
    int i = 0;
    List<String> allActiveTypeToggles = new ArrayList<String>();
    for (EPArtefactHandler<?> handler : handlers) {
        String handlerClass = PortfolioFilterController.HANDLER_PREFIX + handler.getClass().getSimpleName() + HANDLER_TITLE_SUFFIX;
        FormToggle link = (FormToggle) typeFlc.getFormComponent(handlerClass);
        if (link == null) {
            Translator handlerTrans = handler.getHandlerTranslator(getTranslator());
            typeFlc.setTranslator(handlerTrans);
            link = uifactory.addToggleButton(handlerClass, null, typeFlc, null, null);
            link.setUserObject(handler.getType());
        }
        if (selectedTypeList.contains(handler.getType())) {
            link.toggleOn();
            allActiveTypeToggles.add(handler.getType());
        } else {
            link.toggleOff();
        }
        typeCmpList.add(link);
        i++;
        if (i > limit)
            break;
    }
    typeFlc.contextPut("typeCmpList", typeCmpList);
    typeEditBtn = uifactory.addToggleButton("filter.edit", null, typeFlc, null, null);
    typeEditBtn.toggleOff();
    if (!allActiveTypeToggles.containsAll(selectedTypeList))
        typeEditBtn.toggleOn();
    if (selectedTypeList.isEmpty())
        typeAllBtn.toggleOn();
}
Also used : EPArtefactHandler(org.olat.portfolio.EPArtefactHandler) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle)

Example 4 with FormToggle

use of org.olat.core.gui.components.form.flexible.elements.FormToggle in project OpenOLAT by OpenOLAT.

the class UsrPropContextEditController method addTableRowComponents.

/**
 * adds tableRow-Components (Toggles and Links) for the given Handler
 *
 * @param handler The handler to create Components for
 * @param moveable if true, additional "up"/"down" Links will be rendered
 */
private void addTableRowComponents(UserPropertyHandler handler, boolean moveable) {
    List<FormItem> rowFormItemComponents = new ArrayList<FormItem>();
    final String handlername = handler.getName();
    final boolean isIncluded = context.contains(handler);
    final boolean isMandatory = context.isMandatoryUserProperty(handler);
    final boolean isAdminOnly = context.isForAdministrativeUserOnly(handler);
    final boolean isUserReadOnly = context.isUserViewReadOnly(handler);
    // put the translation (in the current language) for the property
    String translatedName = I18nManager.getInstance().getLocalizedString(UserPropertyHandler.class.getPackage().getName(), handler.i18nFormElementLabelKey(), null, getLocale(), true, true);
    uifactory.addStaticTextElement(FT_NAME_PREFIX_TRANS + handlername, (translatedName == null ? "-" : translatedName), contTableFlc);
    FormToggle ftMandatory = uifactory.addToggleButton(FT_NAME_PREFIX_MAND + handlername, "&nbsp;&nbsp;&nbsp;&nbsp;", contTableFlc, null, null);
    ftMandatory.setUserObject(handler);
    if (isMandatory)
        ftMandatory.toggleOn();
    else
        ftMandatory.toggleOff();
    if (!isIncluded) {
        ftMandatory.setEnabled(false);
        ftMandatory.setVisible(false);
    }
    FormToggle ftAdminonly = uifactory.addToggleButton(FT_NAME_PREFIX_ADMN + handlername, "&nbsp;&nbsp;&nbsp;&nbsp;", contTableFlc, null, null);
    ftAdminonly.setUserObject(handler);
    if (isAdminOnly)
        ftAdminonly.toggleOn();
    else
        ftAdminonly.toggleOff();
    if (!isIncluded) {
        ftAdminonly.setEnabled(false);
        ftAdminonly.setVisible(false);
    }
    FormToggle ftUserreadonly = uifactory.addToggleButton(FT_NAME_PREFIX_USR + handlername, "&nbsp;&nbsp;&nbsp;&nbsp;", contTableFlc, null, null);
    ftUserreadonly.setUserObject(handler);
    if (isUserReadOnly)
        ftUserreadonly.toggleOn();
    else
        ftUserreadonly.toggleOff();
    if (!isIncluded) {
        ftUserreadonly.setEnabled(false);
        ftUserreadonly.setVisible(false);
    }
    FormToggle ftInclude = uifactory.addToggleButton(FT_NAME_PREFIX_INCL + handlername, "&nbsp;&nbsp;&nbsp;&nbsp;", contTableFlc, null, null);
    ftInclude.setUserObject(handler);
    if (isIncluded) {
        ftInclude.toggleOn();
        includedPropertiesCount++;
    } else
        ftInclude.toggleOff();
    // up/down links
    FormLink fl_up = uifactory.addFormLink(FT_NAME_PREFIX_MUP + handlername, " ", null, contTableFlc, Link.NONTRANSLATED);
    fl_up.setIconLeftCSS("o_icon o_icon_move_up o_icon-lg");
    fl_up.setUserObject(handler);
    FormLink fl_down = uifactory.addFormLink(FT_NAME_PREFIX_MDN + handlername, " ", null, contTableFlc, Link.NONTRANSLATED);
    fl_down.setIconRightCSS("o_icon o_icon_move_down o_icon-lg");
    fl_down.setUserObject(handler);
    if (!moveable) {
        fl_up.setEnabled(false);
        fl_up.setVisible(false);
        fl_down.setEnabled(false);
        fl_down.setVisible(false);
    }
    rowFormItemComponents.add(ftMandatory);
    rowFormItemComponents.add(ftAdminonly);
    rowFormItemComponents.add(ftUserreadonly);
    rowFormItemComponents.add(fl_up);
    rowFormItemComponents.add(fl_down);
    rowToggleButtonsMap.put(handlername, rowFormItemComponents);
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 5 with FormToggle

use of org.olat.core.gui.components.form.flexible.elements.FormToggle in project openolat by klemens.

the class UsrPropCfgTableController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    UserPropertyHandler handler = (UserPropertyHandler) source.getUserObject();
    if (source instanceof FormToggle) {
        FormToggle toggle = (FormToggle) source;
        if (toggle.isOn()) {
            usrPropCfgMng.getUserPropertiesConfigObject().setHandlerAsActive(handler, true);
            usrPropCfgMng.saveUserPropertiesConfig();
        } else {
            deactPropertyYesNoCtrl = activateYesNoDialog(ureq, translate("upc.deact_confirmationtitle"), translate("upc.deact_confirmationtext"), deactPropertyYesNoCtrl);
            deactPropertyYesNoCtrl.setUserObject(handler);
        }
    } else if (source instanceof SingleSelection) {
        SingleSelection groupSel = (SingleSelection) source;
        handler.setGroup(groupSel.getSelectedKey());
        usrPropCfgMng.saveUserPropertiesConfig();
    } else if (source instanceof FormLink) {
        String itemname = source.getName();
        if (itemname.startsWith(FT_NAME_PREFIX_TRANSL)) {
            // open the singlekeyTranslator-controller callout
            String key2Translate1 = handler.i18nFormElementLabelKey();
            String key2Translate2 = handler.i18nColumnDescriptorLabelKey();
            String[] keys2Translate = { key2Translate1, key2Translate2 };
            singleKeyTrnsCtrl = new SingleKeyTranslatorController(ureq, getWindowControl(), keys2Translate, UserPropertyHandler.class);
            listenTo(singleKeyTrnsCtrl);
            removeAsListenerAndDispose(translatorCallout);
            translatorCallout = new CloseableCalloutWindowController(ureq, getWindowControl(), singleKeyTrnsCtrl.getInitialComponent(), (FormLink) source, "Translate:: " + key2Translate1, false, null);
            listenTo(translatorCallout);
            translatorCallout.activate();
        } else if (itemname.startsWith(FT_NAME_PREFIX_HDNL)) {
            handlerConfigCtrl = handlerConfigCtrlFactory.getConfigController(ureq, getWindowControl(), handler);
            listenTo(handlerConfigCtrl);
            if (handlerConfigCtrl.getInitialComponent() != null) {
                handlerPopupCtr = new CloseableModalController(getWindowControl(), "Save", handlerConfigCtrl.getInitialComponent(), true, translate("upc.handlerconfigtitle"), false);
                handlerPopupCtr.activate();
            }
        }
    }
}
Also used : SingleKeyTranslatorController(org.olat.core.util.i18n.ui.SingleKeyTranslatorController) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) CloseableCalloutWindowController(org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController) FormToggle(org.olat.core.gui.components.form.flexible.elements.FormToggle) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

FormToggle (org.olat.core.gui.components.form.flexible.elements.FormToggle)16 ArrayList (java.util.ArrayList)10 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)6 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)4 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 CloseableCalloutWindowController (org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 Translator (org.olat.core.gui.translator.Translator)2 SingleKeyTranslatorController (org.olat.core.util.i18n.ui.SingleKeyTranslatorController)2 EPArtefactHandler (org.olat.portfolio.EPArtefactHandler)2