Search in sources :

Example 1 with DependencyRuleApplayable

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

the class ConditionConfigEasyController method addRules.

/**
 * you may find here now the complexest rule set ever use in OLAT<br>
 * This form has a 5 switches<br>
 * <ul>
 * <li>[] 1 Learners only</li>
 * <li>[] 2 Date dependent</li>
 * <li>[] 3 Group dependent</li>
 * <li>[] 4 Assess dependent</li>
 * <li>[] 5 Apply rules also to coaches</li>
 * </ul>
 * enable [1] this greys out all others<br>
 * if one of [2] [3] or [4] is selected -> [5] becomes selectable<br>
 * selecting [2] [3] or [4] opens their respective subconfiguration<br>
 * "[2] date dependent" shows an end and startdate where at least one must be
 * selected and the start date must be before the enddate.<br>
 * "[3] group dependent" shows a group or area input field. which takes group
 * or area names comma separated. the form evaluates if the areas or groups
 * exists, and if not, a quick fix is provided to create the missing groups/areas.
 * furthermore there is a "choose" button to choose groups/areas. This choose
 * button is named "create" if there are no groups or areas to choose from. If
 * create is clicked a create group/area workflow is started directly. If some
 * comma separated values are in the input field, it allows to create them at
 * once. At least an area or groupname must be specified, and all the specified
 * names must exist.<br>
 * "[4] assessment " allows to choose a node and to define a cut value or if
 * it should be checked for passed.<br>
 * To accomplish all the hiding, disabling, enabling, resetting to initial values
 * the following rules are added. this may look confusing, and it is confusing.
 * It took quite some days and testing until to get it right.
 * @param formLayout
 */
private void addRules(FormItemContainer formLayout) {
    // disable date choosers if date switch is set to no
    // enable it otherwise.
    final Set<FormItem> dependenciesDateSwitch = new HashSet<FormItem>();
    dependenciesDateSwitch.add(toDate);
    dependenciesDateSwitch.add(fromDate);
    dependenciesDateSwitch.add(dateSubContainer);
    final Set<FormItem> dependenciesAttributeSwitch = new HashSet<FormItem>();
    // only add when initialized. is null when shibboleth module is not enabled
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        dependenciesAttributeSwitch.add(attributeBconnector);
    }
    // show elements dependent on other values set.
    FormItemDependencyRule hideClearDateSwitchDeps = RulesFactory.createCustomRule(dateSwitch, null, dependenciesDateSwitch, formLayout);
    hideClearDateSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            toDate.setDate(null);
            toDate.setVisible(false);
            fromDate.setDate(null);
            fromDate.setVisible(false);
            toDate.clearError();
            fromDate.clearError();
            dateSwitch.clearError();
            dateSubContainer.setVisible(false);
            fromDate.setFocus(false);
            /*
				 * special rules for apply rules for coach and for assessment dependent
				 */
            // assessment switch only enabled if nodes to be selected
            boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
            assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    RulesFactory.createShowRule(dateSwitch, "ison", dependenciesDateSwitch, formLayout);
    FormItemDependencyRule toggleApplyRule = RulesFactory.createCustomRule(dateSwitch, "ison", dependenciesDateSwitch, formLayout);
    toggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            fromDate.setFocus(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        FormItemDependencyRule hideClearAttibuteSwitchDeps = RulesFactory.createCustomRule(attributeSwitch, null, dependenciesAttributeSwitch, formLayout);
        hideClearAttibuteSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

            public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
                attributeSwitch.clearError();
                attributeBconnector.select(BCON_VAL_AND, true);
                attributeBconnector.setVisible(false);
                if (attribteRowAdderSubform != null) {
                    attribteRowAdderSubform.cleanUp();
                }
                showOrHideApplyRulesForCoach();
            }
        });
        RulesFactory.createShowRule(attributeSwitch, "ison", dependenciesAttributeSwitch, formLayout);
        FormItemDependencyRule attributeSwitchtoggleApplyRule = RulesFactory.createCustomRule(attributeSwitch, "ison", dependenciesAttributeSwitch, formLayout);
        attributeSwitchtoggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

            public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
                attributeBconnector.setVisible(true);
                if (attribteRowAdderSubform != null) {
                    attribteRowAdderSubform.init();
                }
                showOrHideApplyRulesForCoach();
            }
        });
    }
    // 
    // enable textfields and subworkflow-start-links if groups is yes
    // disable it otherwise
    final Set<FormItem> dependenciesGroupSwitch = new HashSet<FormItem>();
    dependenciesGroupSwitch.add(groupSubContainer);
    FormItemDependencyRule hideClearGroupSwitchDeps = RulesFactory.createCustomRule(groupSwitch, null, dependenciesGroupSwitch, formLayout);
    hideClearGroupSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            easyAreaList.clearError();
            easyGroupList.clearError();
            groupSwitch.clearError();
            groupSubContainer.setVisible(false);
            if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
                attributeSwitch.clearError();
            }
            easyGroupList.setFocus(false);
            // assessment switch only enabled if nodes to be selected
            boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
            assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    RulesFactory.createShowRule(groupSwitch, "ison", dependenciesGroupSwitch, formLayout);
    toggleApplyRule = RulesFactory.createCustomRule(groupSwitch, "ison", dependenciesGroupSwitch, formLayout);
    toggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            easyGroupList.setFocus(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    // 
    // dependencies of assessment switch
    final Set<FormItem> assessDeps = new HashSet<FormItem>();
    assessDeps.add(assessmentTypeSwitch);
    assessDeps.add(nodePassed);
    assessDeps.add(cutValue);
    assessDeps.add(assessSubContainer);
    // show elements dependent on other values set.
    FormItemDependencyRule showAssessmentSwitchDeps = RulesFactory.createCustomRule(assessmentSwitch, "ison", assessDeps, formLayout);
    showAssessmentSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            boolean cutValueVisibility = assessmentTypeSwitch.getSelectedKey().equals(NODEPASSED_VAL_SCORE);
            assessSubContainer.setVisible(true);
            assessmentTypeSwitch.setVisible(true);
            nodePassed.setVisible(true);
            cutValue.setVisible(cutValueVisibility);
            assessmentSwitch.clearError();
            cutValue.clearError();
            nodePassed.clearError();
            showOrHideApplyRulesForCoach();
        }
    });
    // hide elements and reset values.
    FormItemDependencyRule hideResetAssessmentSwitchDeps = RulesFactory.createCustomRule(assessmentSwitch, null, assessDeps, formLayout);
    hideResetAssessmentSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            assessSubContainer.setVisible(false);
            assessmentTypeSwitch.select(NODEPASSED_VAL_PASSED, true);
            assessmentTypeSwitch.setVisible(false);
            nodePassed.select(NO_NODE_SELECTED_IDENTIFYER, true);
            nodePassed.setVisible(false);
            cutValue.setIntValue(0);
            cutValue.setVisible(false);
            showOrHideApplyRulesForCoach();
        }
    });
    final Set<FormItem> assessTypeDeps = new HashSet<FormItem>();
    assessTypeDeps.add(cutValue);
    RulesFactory.createHideRule(assessmentTypeSwitch, NODEPASSED_VAL_PASSED, assessTypeDeps, assessSubContainer);
    RulesFactory.createShowRule(assessmentTypeSwitch, NODEPASSED_VAL_SCORE, assessTypeDeps, assessSubContainer);
    // 
    // 
    final Set<FormItem> dependenciesCoachExclusiveReadonly = new HashSet<FormItem>();
    dependenciesCoachExclusiveReadonly.addAll(dependenciesDateSwitch);
    dependenciesCoachExclusiveReadonly.addAll(dependenciesGroupSwitch);
    dependenciesCoachExclusiveReadonly.addAll(assessDeps);
    dependenciesCoachExclusiveReadonly.addAll(dependenciesAttributeSwitch);
    // coach exclusive switch rules
    // -> custom rule implementation because it is not a simple hide / show rule
    // while disabling reset the elements
    FormItemDependencyRule disableAndResetOthers = RulesFactory.createCustomRule(coachExclusive, "ison", dependenciesCoachExclusiveReadonly, formLayout);
    disableAndResetOthers.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            // disable and remove checkbox selection
            // uncheck and disable checkboxes
            dateSwitch.select("ison", false);
            groupSwitch.select("ison", false);
            assessmentSwitch.select("ison", false);
            dateSwitch.setEnabled(false);
            toDate.setDate(null);
            fromDate.setDate(null);
            groupSwitch.setEnabled(false);
            easyAreaList.setValue("");
            easyAreaList.setUserObject(new ArrayList<Long>());
            easyGroupList.setValue("");
            easyGroupList.setUserObject(new ArrayList<Long>());
            assessmentSwitch.setEnabled(false);
            assessmentMode.select("ison", false);
            assessmentMode.setEnabled(false);
            // disable the shibboleth attributes switch and reset the row subform
            if (attributeSwitch != null) {
                attributeSwitch.select("ison", false);
                attributeSwitch.setEnabled(false);
                attribteRowAdderSubform.cleanUp();
                attributeSwitch.clearError();
            }
            showOrHideApplyRulesForCoach();
            // hide (e.g. remove) general erros
            dateSwitch.clearError();
            groupSwitch.clearError();
            assessmentSwitch.clearError();
            // all dependent elements become invisible
            for (Iterator<FormItem> iter = dependenciesCoachExclusiveReadonly.iterator(); iter.hasNext(); ) {
                FormItem element = iter.next();
                element.setVisible(false);
            }
        }
    });
    // two rules to bring them back visible and also checkable
    // dependencies of assessment switch
    final Set<FormItem> switchesOnly = new HashSet<FormItem>();
    switchesOnly.add(dateSwitch);
    switchesOnly.add(groupSwitch);
    switchesOnly.add(assessmentSwitch);
    switchesOnly.add(applyRulesForCoach);
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        switchesOnly.add(attributeSwitch);
    }
    FormItemDependencyRule enableOthers = RulesFactory.createCustomRule(coachExclusive, null, switchesOnly, formLayout);
    enableOthers.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        private boolean firedDuringInit = true;

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            dateSwitch.setEnabled(true);
            groupSwitch.setEnabled(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            assessmentMode.setEnabled(true);
            // default is a checked disabled apply rules for coach
            if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
                attributeSwitch.setEnabled(true);
            }
            if (!firedDuringInit) {
                showOrHideApplyRulesForCoach();
            }
            firedDuringInit = false;
        }
    });
    // 
    // dependencies of assessment mode
    final Set<FormItem> assessModeDeps = new HashSet<FormItem>();
    // show elements dependent on other values set.
    FormItemDependencyRule showAssessmentModeDeps = RulesFactory.createCustomRule(assessmentMode, "ison", assessModeDeps, formLayout);
    showAssessmentModeDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            showOrHideApplyRulesForCoach();
        }
    });
    // hide elements and reset values.
    FormItemDependencyRule hideResetAssessmentModeDeps = RulesFactory.createCustomRule(assessmentMode, null, assessModeDeps, formLayout);
    hideResetAssessmentModeDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            showOrHideApplyRulesForCoach();
        }
    });
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule) DependencyRuleApplayable(org.olat.core.gui.components.form.flexible.DependencyRuleApplayable) HashSet(java.util.HashSet)

Example 2 with DependencyRuleApplayable

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

the class ConditionConfigEasyController method addRules.

/**
 * you may find here now the complexest rule set ever use in OLAT<br>
 * This form has a 5 switches<br>
 * <ul>
 * <li>[] 1 Learners only</li>
 * <li>[] 2 Date dependent</li>
 * <li>[] 3 Group dependent</li>
 * <li>[] 4 Assess dependent</li>
 * <li>[] 5 Apply rules also to coaches</li>
 * </ul>
 * enable [1] this greys out all others<br>
 * if one of [2] [3] or [4] is selected -> [5] becomes selectable<br>
 * selecting [2] [3] or [4] opens their respective subconfiguration<br>
 * "[2] date dependent" shows an end and startdate where at least one must be
 * selected and the start date must be before the enddate.<br>
 * "[3] group dependent" shows a group or area input field. which takes group
 * or area names comma separated. the form evaluates if the areas or groups
 * exists, and if not, a quick fix is provided to create the missing groups/areas.
 * furthermore there is a "choose" button to choose groups/areas. This choose
 * button is named "create" if there are no groups or areas to choose from. If
 * create is clicked a create group/area workflow is started directly. If some
 * comma separated values are in the input field, it allows to create them at
 * once. At least an area or groupname must be specified, and all the specified
 * names must exist.<br>
 * "[4] assessment " allows to choose a node and to define a cut value or if
 * it should be checked for passed.<br>
 * To accomplish all the hiding, disabling, enabling, resetting to initial values
 * the following rules are added. this may look confusing, and it is confusing.
 * It took quite some days and testing until to get it right.
 * @param formLayout
 */
private void addRules(FormItemContainer formLayout) {
    // disable date choosers if date switch is set to no
    // enable it otherwise.
    final Set<FormItem> dependenciesDateSwitch = new HashSet<FormItem>();
    dependenciesDateSwitch.add(toDate);
    dependenciesDateSwitch.add(fromDate);
    dependenciesDateSwitch.add(dateSubContainer);
    final Set<FormItem> dependenciesAttributeSwitch = new HashSet<FormItem>();
    // only add when initialized. is null when shibboleth module is not enabled
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        dependenciesAttributeSwitch.add(attributeBconnector);
    }
    // show elements dependent on other values set.
    FormItemDependencyRule hideClearDateSwitchDeps = RulesFactory.createCustomRule(dateSwitch, null, dependenciesDateSwitch, formLayout);
    hideClearDateSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            toDate.setDate(null);
            toDate.setVisible(false);
            fromDate.setDate(null);
            fromDate.setVisible(false);
            toDate.clearError();
            fromDate.clearError();
            dateSwitch.clearError();
            dateSubContainer.setVisible(false);
            fromDate.setFocus(false);
            /*
				 * special rules for apply rules for coach and for assessment dependent
				 */
            // assessment switch only enabled if nodes to be selected
            boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
            assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    RulesFactory.createShowRule(dateSwitch, "ison", dependenciesDateSwitch, formLayout);
    FormItemDependencyRule toggleApplyRule = RulesFactory.createCustomRule(dateSwitch, "ison", dependenciesDateSwitch, formLayout);
    toggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            fromDate.setFocus(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        FormItemDependencyRule hideClearAttibuteSwitchDeps = RulesFactory.createCustomRule(attributeSwitch, null, dependenciesAttributeSwitch, formLayout);
        hideClearAttibuteSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

            public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
                attributeSwitch.clearError();
                attributeBconnector.select(BCON_VAL_AND, true);
                attributeBconnector.setVisible(false);
                if (attribteRowAdderSubform != null) {
                    attribteRowAdderSubform.cleanUp();
                }
                showOrHideApplyRulesForCoach();
            }
        });
        RulesFactory.createShowRule(attributeSwitch, "ison", dependenciesAttributeSwitch, formLayout);
        FormItemDependencyRule attributeSwitchtoggleApplyRule = RulesFactory.createCustomRule(attributeSwitch, "ison", dependenciesAttributeSwitch, formLayout);
        attributeSwitchtoggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

            public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
                attributeBconnector.setVisible(true);
                if (attribteRowAdderSubform != null) {
                    attribteRowAdderSubform.init();
                }
                showOrHideApplyRulesForCoach();
            }
        });
    }
    // 
    // enable textfields and subworkflow-start-links if groups is yes
    // disable it otherwise
    final Set<FormItem> dependenciesGroupSwitch = new HashSet<FormItem>();
    dependenciesGroupSwitch.add(groupSubContainer);
    FormItemDependencyRule hideClearGroupSwitchDeps = RulesFactory.createCustomRule(groupSwitch, null, dependenciesGroupSwitch, formLayout);
    hideClearGroupSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            easyAreaList.clearError();
            easyGroupList.clearError();
            groupSwitch.clearError();
            groupSubContainer.setVisible(false);
            if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
                attributeSwitch.clearError();
            }
            easyGroupList.setFocus(false);
            // assessment switch only enabled if nodes to be selected
            boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
            assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    RulesFactory.createShowRule(groupSwitch, "ison", dependenciesGroupSwitch, formLayout);
    toggleApplyRule = RulesFactory.createCustomRule(groupSwitch, "ison", dependenciesGroupSwitch, formLayout);
    toggleApplyRule.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            easyGroupList.setFocus(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            showOrHideApplyRulesForCoach();
        }
    });
    // 
    // dependencies of assessment switch
    final Set<FormItem> assessDeps = new HashSet<FormItem>();
    assessDeps.add(assessmentTypeSwitch);
    assessDeps.add(nodePassed);
    assessDeps.add(cutValue);
    assessDeps.add(assessSubContainer);
    // show elements dependent on other values set.
    FormItemDependencyRule showAssessmentSwitchDeps = RulesFactory.createCustomRule(assessmentSwitch, "ison", assessDeps, formLayout);
    showAssessmentSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            boolean cutValueVisibility = assessmentTypeSwitch.getSelectedKey().equals(NODEPASSED_VAL_SCORE);
            assessSubContainer.setVisible(true);
            assessmentTypeSwitch.setVisible(true);
            nodePassed.setVisible(true);
            cutValue.setVisible(cutValueVisibility);
            assessmentSwitch.clearError();
            cutValue.clearError();
            nodePassed.clearError();
            showOrHideApplyRulesForCoach();
        }
    });
    // hide elements and reset values.
    FormItemDependencyRule hideResetAssessmentSwitchDeps = RulesFactory.createCustomRule(assessmentSwitch, null, assessDeps, formLayout);
    hideResetAssessmentSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            assessSubContainer.setVisible(false);
            assessmentTypeSwitch.select(NODEPASSED_VAL_PASSED, true);
            assessmentTypeSwitch.setVisible(false);
            nodePassed.select(NO_NODE_SELECTED_IDENTIFYER, true);
            nodePassed.setVisible(false);
            cutValue.setIntValue(0);
            cutValue.setVisible(false);
            showOrHideApplyRulesForCoach();
        }
    });
    final Set<FormItem> assessTypeDeps = new HashSet<FormItem>();
    assessTypeDeps.add(cutValue);
    RulesFactory.createHideRule(assessmentTypeSwitch, NODEPASSED_VAL_PASSED, assessTypeDeps, assessSubContainer);
    RulesFactory.createShowRule(assessmentTypeSwitch, NODEPASSED_VAL_SCORE, assessTypeDeps, assessSubContainer);
    // 
    // 
    final Set<FormItem> dependenciesCoachExclusiveReadonly = new HashSet<FormItem>();
    dependenciesCoachExclusiveReadonly.addAll(dependenciesDateSwitch);
    dependenciesCoachExclusiveReadonly.addAll(dependenciesGroupSwitch);
    dependenciesCoachExclusiveReadonly.addAll(assessDeps);
    dependenciesCoachExclusiveReadonly.addAll(dependenciesAttributeSwitch);
    // coach exclusive switch rules
    // -> custom rule implementation because it is not a simple hide / show rule
    // while disabling reset the elements
    FormItemDependencyRule disableAndResetOthers = RulesFactory.createCustomRule(coachExclusive, "ison", dependenciesCoachExclusiveReadonly, formLayout);
    disableAndResetOthers.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            // disable and remove checkbox selection
            // uncheck and disable checkboxes
            dateSwitch.select("ison", false);
            groupSwitch.select("ison", false);
            assessmentSwitch.select("ison", false);
            dateSwitch.setEnabled(false);
            toDate.setDate(null);
            fromDate.setDate(null);
            groupSwitch.setEnabled(false);
            easyAreaList.setValue("");
            easyAreaList.setUserObject(new ArrayList<Long>());
            easyGroupList.setValue("");
            easyGroupList.setUserObject(new ArrayList<Long>());
            assessmentSwitch.setEnabled(false);
            assessmentMode.select("ison", false);
            assessmentMode.setEnabled(false);
            // disable the shibboleth attributes switch and reset the row subform
            if (attributeSwitch != null) {
                attributeSwitch.select("ison", false);
                attributeSwitch.setEnabled(false);
                attribteRowAdderSubform.cleanUp();
                attributeSwitch.clearError();
            }
            showOrHideApplyRulesForCoach();
            // hide (e.g. remove) general erros
            dateSwitch.clearError();
            groupSwitch.clearError();
            assessmentSwitch.clearError();
            // all dependent elements become invisible
            for (Iterator<FormItem> iter = dependenciesCoachExclusiveReadonly.iterator(); iter.hasNext(); ) {
                FormItem element = iter.next();
                element.setVisible(false);
            }
        }
    });
    // two rules to bring them back visible and also checkable
    // dependencies of assessment switch
    final Set<FormItem> switchesOnly = new HashSet<FormItem>();
    switchesOnly.add(dateSwitch);
    switchesOnly.add(groupSwitch);
    switchesOnly.add(assessmentSwitch);
    switchesOnly.add(applyRulesForCoach);
    if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
        switchesOnly.add(attributeSwitch);
    }
    FormItemDependencyRule enableOthers = RulesFactory.createCustomRule(coachExclusive, null, switchesOnly, formLayout);
    enableOthers.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        private boolean firedDuringInit = true;

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            dateSwitch.setEnabled(true);
            groupSwitch.setEnabled(true);
            // assessment switch only enabled if nodes to be selected
            assessmentSwitch.setEnabled((nodeIdentList.size() > 0 || isSelectedNodeDeleted()));
            assessmentMode.setEnabled(true);
            // default is a checked disabled apply rules for coach
            if (shibbolethModule.isEnableShibbolethCourseEasyConfig()) {
                attributeSwitch.setEnabled(true);
            }
            if (!firedDuringInit) {
                showOrHideApplyRulesForCoach();
            }
            firedDuringInit = false;
        }
    });
    // 
    // dependencies of assessment mode
    final Set<FormItem> assessModeDeps = new HashSet<FormItem>();
    // show elements dependent on other values set.
    FormItemDependencyRule showAssessmentModeDeps = RulesFactory.createCustomRule(assessmentMode, "ison", assessModeDeps, formLayout);
    showAssessmentModeDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            showOrHideApplyRulesForCoach();
        }
    });
    // hide elements and reset values.
    FormItemDependencyRule hideResetAssessmentModeDeps = RulesFactory.createCustomRule(assessmentMode, null, assessModeDeps, formLayout);
    hideResetAssessmentModeDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {

        public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
            showOrHideApplyRulesForCoach();
        }
    });
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormItemDependencyRule(org.olat.core.gui.components.form.flexible.FormItemDependencyRule) DependencyRuleApplayable(org.olat.core.gui.components.form.flexible.DependencyRuleApplayable) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 DependencyRuleApplayable (org.olat.core.gui.components.form.flexible.DependencyRuleApplayable)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 FormItemDependencyRule (org.olat.core.gui.components.form.flexible.FormItemDependencyRule)2