Package org.olat.core.gui.components.form.flexible

Examples of org.olat.core.gui.components.form.flexible.FormItemDependencyRule


    String key = dispatchFormItem.getName();
    if(dependencyRules.containsKey(key)){
      Map<String, FormItemDependencyRule> ruleSet = dependencyRules.get(key);
      Collection<FormItemDependencyRule> rules = ruleSet.values();
      for (Iterator iter = rules.iterator(); iter.hasNext();) {
        FormItemDependencyRule tmp = (FormItemDependencyRule)iter.next();
        if (tmp.applyRule(this)) this.setDirty(true);
      }
    }
   
  }
View Full Code Here


    // Rule1: hide variant when country is empty
    Set<FormItem> hideItems = new HashSet<FormItem>();
    RulesFactory.createHideRule(newCountry, "", hideItems, formLayout);
    hideItems.add(newVariant);
    // Rule 2: show variant when country is not empty
    FormItemDependencyRule showRule = new FormItemDependencyRuleImpl(newCountry, ".{2}", hideItems, FormItemDependencyRuleImpl.MAKE_VISIBLE) {
      @Override
      protected boolean doesTrigger() {
        TextElement te = (TextElement) this.triggerElement;
        String val = te.getValue();
        //
View Full Code Here

   * @return The rule
   * @see    DependencyRuleApplayable
   */
  public static FormItemDependencyRule createCustomRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets,
      FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.CUSTOM);
    formLayout.addDependencyRule(fidr);
    return fidr;
  }
View Full Code Here

   * @param formLayout
   * @return
   */
  public static FormItemDependencyRule createResetRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets,
      FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.RESET);
    formLayout.addDependencyRule(fidr);
    return fidr;
  }
View Full Code Here

   * @param targets
   * @return
   */
  public static FormItemDependencyRule createHideRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets,
      FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.MAKE_INVISIBLE);
    formLayout.addDependencyRule(fidr);
    return fidr;
  }
View Full Code Here

   * @param targets
   * @return
   */
  public static FormItemDependencyRule createShowRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets,
      FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.MAKE_VISIBLE);
    formLayout.addDependencyRule(fidr);
    return fidr;
  }
View Full Code Here

   * @param targets
   * @return
   */
  public static FormItemDependencyRule createReadOnlyRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets,
      FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.MAKE_READONLY);
    formLayout.addDependencyRule(fidr);
    return fidr;
  }
View Full Code Here

   * @param targets
   * @return
   */
  public static FormItemDependencyRule createWritableRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets,
      FormItemContainer formLayout) {
    FormItemDependencyRule fidr = createRule(triggerElement, triggerValue, targets, FormItemDependencyRuleImpl.MAKE_WRITABLE);
    formLayout.addDependencyRule(fidr);
    return fidr;
  }
View Full Code Here

   * @param targets
   * @param type
   * @return
   */
  private static FormItemDependencyRule createRule(FormItem triggerElement, Object triggerValue, Set<FormItem> targets, int type) {
    FormItemDependencyRule retVal = null;
    //
    if (triggerElement instanceof SingleSelection) {
      retVal = new SingleSelectionTriggerdDependencyRule((SingleSelection) triggerElement, (String) triggerValue, targets, type);
    } else if (triggerElement instanceof MultipleSelectionElement) {
      retVal = new MultiSelectionTriggerdDependencyRule((MultipleSelectionElement) triggerElement, (String) triggerValue, targets, type);
View Full Code Here

        }
      }
    };
   
    // show elements dependent on other values set.
    FormItemDependencyRule hideClearDateSwitchDeps = RulesFactory.createCustomRule(dateSwitch, null, dependenciesDateSwitch, formLayout);
    hideClearDateSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {
      @SuppressWarnings("unused")
      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() > || isSelectedNodeDeleted()));
                       
        boolean atLeastOneOn = dateSwitch.getSelectedKeys().size() == 1 || groupSwitch.getSelectedKeys().size() == 1 || assessmentSwitch.getSelectedKeys().size() == 1|| (attributeSwitch != null && attributeSwitch.getSelectedKeys().size()==1);
        if(!applyRulesForCoach.isEnabled() && atLeastOneOn){
          //not enabled AND at least another dependent on
          applyRulesForCoach.setEnabled(true);
        }else if(!atLeastOneOn){
          //enabled (or not) AND not at least another dependent on
          applyRulesForCoach.setEnabled(false);
          applyRulesForCoach.select("ison", true);
        }
      }
    });
    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() > || isSelectedNodeDeleted()));
               
        if(!applyRulesForCoach.isEnabled()){
          applyRulesForCoach.setEnabled(true);
        }
      }
    });
   
    if (ShibbolethModule.isEnableShibbolethLogins()) {
      FormItemDependencyRule hideClearAttibuteSwitchDeps = RulesFactory.createCustomRule(attributeSwitch, null, dependenciesAttributeSwitch, formLayout);
     
      hideClearAttibuteSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {
        @SuppressWarnings("unused")
        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();
          }
          boolean atLeastOneOn = dateSwitch.getSelectedKeys().size() == 1 || groupSwitch.getSelectedKeys().size() == 1 || assessmentSwitch.getSelectedKeys().size() == 1||attributeSwitch.getSelectedKeys().size()==1;
          if(!applyRulesForCoach.isEnabled() && atLeastOneOn){
            //not enabled AND at least another dependent on
            applyRulesForCoach.setEnabled(true);
          }else if(!atLeastOneOn){
            //enabled (or not) AND not at least another dependent on
            applyRulesForCoach.setEnabled(false);
            applyRulesForCoach.select("ison", true);
          }
        }
      });
     
      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();
          }
          if(!applyRulesForCoach.isEnabled()){
            applyRulesForCoach.setEnabled(true);
          }
        }
      });
    }
 
    //
    // enable textfields and subworkflow-start-links if groups is yes
    // disable it otherwise
    final Set<FormItem> dependenciesGroupSwitch = new HashSet<FormItem>() {
      {
        add(groupSubContainer);
        add(easyAreaTE);
        add(chooseAreasLink);
        add(createAreasLink);
        add(easyGroupTE);
        add(chooseGroupsLink);
        add(createGroupsLink);
      }
    };
    FormItemDependencyRule hideClearGroupSwitchDeps = RulesFactory.createCustomRule(groupSwitch, null, dependenciesGroupSwitch, formLayout);
    hideClearGroupSwitchDeps.setDependencyRuleApplayable(new DependencyRuleApplayable() {
      @SuppressWarnings("unused")
      public void apply(FormItem triggerElement, Object triggerVal, Set<FormItem> targets) {
        easyAreaTE.setValue("");
        easyGroupTE.setValue("");
        easyAreaTE.setVisible(false);
        easyGroupTE.setVisible(false);
        chooseAreasLink.setVisible(false);
        createAreasLink.setVisible(false);
        chooseGroupsLink.setVisible(false);
        createGroupsLink.setVisible(false);
        easyAreaTE.clearError();
        easyGroupTE.clearError();
        groupSwitch.clearError();
        groupSubContainer.setVisible(false);       
        if (ShibbolethModule.isEnableShibbolethLogins()) {
          attributeSwitch.clearError();
        }
        easyGroupTE.setFocus(false);
       
        //assessment switch only enabled if nodes to be selected
        boolean coachExclIsOn = coachExclusive.getSelectedKeys().size() == 1;
        assessmentSwitch.setEnabled(!coachExclIsOn && (nodeIdentList.size() > || isSelectedNodeDeleted()));
                               
        boolean atLeastOneOn = dateSwitch.getSelectedKeys().size() == 1 || groupSwitch.getSelectedKeys().size() == 1 || assessmentSwitch.getSelectedKeys().size() == 1||(attributeSwitch != null && attributeSwitch.getSelectedKeys().size()==1);
        if(!applyRulesForCoach.isEnabled() && atLeastOneOn){
          applyRulesForCoach.setEnabled(true);
        }else if(!atLeastOneOn){
          //enabled (or not) AND not at least another dependent on
          applyRulesForCoach.setEnabled(false);
          applyRulesForCoach.select("ison", true);
        }
      }
    });
    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) {

        easyGroupTE.setFocus(true);
       
        //assessment switch only enabled if nodes to be selected
        assessmentSwitch.setEnabled((nodeIdentList.size() > || isSelectedNodeDeleted()));
               
        if(!applyRulesForCoach.isEnabled()){
          applyRulesForCoach.setEnabled(true);
        }
      }
    });
   
    // 
    // dependencies of assessment switch
    final Set<FormItem> assessDeps = new HashSet<FormItem>() {
      {
        add(assessmentTypeSwitch);
        add(nodePassed);
        add(cutValue);
        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();

        if(!applyRulesForCoach.isEnabled()){
          applyRulesForCoach.setEnabled(true);
        }
      }
    });

    // 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);

        boolean atLeastOneOn = dateSwitch.getSelectedKeys().size() == 1 || groupSwitch.getSelectedKeys().size() == 1 || assessmentSwitch.getSelectedKeys().size() == 1||(attributeSwitch != null && attributeSwitch.getSelectedKeys().size()==1);
        if(!applyRulesForCoach.isEnabled() && atLeastOneOn){
          applyRulesForCoach.setEnabled(true);
        }else if(!atLeastOneOn){
          //enabled (or not) AND not at least another dependent on
          applyRulesForCoach.setEnabled(false);
          applyRulesForCoach.select("ison", true);
        }
      }
    });

    final Set<FormItem> assessTypeDeps = new HashSet<FormItem>() {
      {
        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>() {
      {
        addAll(dependenciesDateSwitch);
        addAll(dependenciesGroupSwitch);
        addAll(assessDeps);
        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);
        easyAreaTE.setValue("");
        easyGroupTE.setValue("");
        assessmentSwitch.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();
        }
        //opposite meaning! see creation of applyRulesForCoach
        applyRulesForCoach.select("ison", true);
        applyRulesForCoach.setEnabled(false);
        // 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>() {
      {
        add(dateSwitch);
        add(groupSwitch);
        add(assessmentSwitch);
        add(applyRulesForCoach);
        if (ShibbolethModule.isEnableShibbolethLogins()) {
          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
View Full Code Here

TOP

Related Classes of org.olat.core.gui.components.form.flexible.FormItemDependencyRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.