Package org.olat.group.ui.run

Source Code of org.olat.group.ui.run.BusinessGroupSendToChooserForm

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.group.ui.run;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.olat.basesecurity.Manager;
import org.olat.basesecurity.ManagerFactory;
import org.olat.basesecurity.SecurityGroup;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.RadioButtonGroupElement;
import org.olat.core.gui.formelements.StaticMultipleSelectionElement;
import org.olat.core.gui.formelements.VisibilityDependsOnSelectionRule;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.group.BusinessGroup;
import org.olat.group.properties.BusinessGroupPropertyManager;

/**
* Description: <BR>
* TODO: Class Description for BusinessGroupSendToChooserForm
* <P>
*
* @author patrick
*/

public class BusinessGroupSendToChooserForm extends Form {

  private BusinessGroup businessGroup;
  // Owner
  private List<Long> selectedOwnerKeys;
  private StaticMultipleSelectionElement multiSelectionOwnerKeys;
  private RadioButtonGroupElement radioButtonOwner;
  // Participator
  private List<Long> selectedPartipKeys;
  private StaticMultipleSelectionElement multiSelectionPartipKeys;
  private RadioButtonGroupElement radioButtonPartip;
  // Waiting
  private List<Long> selectedWaitingKeys;
  private StaticMultipleSelectionElement multiSelectionWaitingKeys;
  private RadioButtonGroupElement radioButtonWaiting;
  private boolean showChooseOwners;
  private boolean showChoosePartips;
  private boolean isAdmin;
 
  public final static String NLS_RADIO_ALL = "all";
  private final static String NLS_RADIO_NOTHING = "nothing";
  public final static String NLS_RADIO_CHOOSE = "choose";

  /**
   * @param name
   * @param translator
   */
  public BusinessGroupSendToChooserForm(String name, Translator translator, BusinessGroup businessGroup, boolean isAdmin) {
    super(name, translator);
    this.businessGroup = businessGroup;
    // check 'members can see owners' and 'members can see participators'
    BusinessGroupPropertyManager bgpm = new BusinessGroupPropertyManager(businessGroup);
    this.showChooseOwners = bgpm.showOwners();
    this.showChoosePartips = bgpm.showPartips();
    this.isAdmin = isAdmin;
   
    Manager scrtMngr = ManagerFactory.getManager();
    VisibilityDependsOnSelectionRule rule;
   
    if (!isRightGroup()) {
      if (isMultiSelectionOwnerKeys()) {
        String[] radioKeysOwners = { NLS_RADIO_ALL, NLS_RADIO_NOTHING, NLS_RADIO_CHOOSE };
        String[] radioValuesOwners = { translator.translate("sendtochooser.form.radio.owners.all"),
            translator.translate("sendtochooser.form.radio.owners.nothing"), translator.translate("sendtochooser.form.radio.owners.choose") };
        radioButtonOwner = new RadioButtonGroupElement(true, "sendtochooser.form.radio.owners", radioKeysOwners, radioValuesOwners);
        radioButtonOwner.select(NLS_RADIO_ALL, true);

        // Owner MultiSelection
        SecurityGroup owners = businessGroup.getOwnerGroup();
        List<Identity> ownerList = scrtMngr.getIdentitiesOfSecurityGroup(owners);
        String[] keysOwner = new String[ownerList.size()];
        String[] valuesOwner = new String[ownerList.size()];
        for (int i = 0; i < ownerList.size(); i++) {
          keysOwner[i] = ownerList.get(i).getKey().toString();
          valuesOwner[i] = ownerList.get(i).getName().toString();
        }
        multiSelectionOwnerKeys = new StaticMultipleSelectionElement(null, keysOwner, valuesOwner, ownerList.size() > 0 ? true : false);

        addFormElement("radioButtonOwner", radioButtonOwner);
        addFormElement("multiSelectionOwnerKeys", multiSelectionOwnerKeys);

        // rule owner
        rule = new VisibilityDependsOnSelectionRule(radioButtonOwner, multiSelectionOwnerKeys, "choose", true, null, true);
        addVisibilityDependsOnSelectionRule(rule);
      } else {
        String[] radioKeysOwners = { NLS_RADIO_ALL, NLS_RADIO_NOTHING };
        String[] radioValuesOwners = { translator.translate("sendtochooser.form.radio.owners.all"),
            translator.translate("sendtochooser.form.radio.owners.nothing") };
        radioButtonOwner = new RadioButtonGroupElement(true, "sendtochooser.form.radio.owners", radioKeysOwners, radioValuesOwners);
        radioButtonOwner.select(NLS_RADIO_ALL, true);

        addFormElement("radioButtonOwner", radioButtonOwner);
      }
    }
    if (isMultiSelectionPartipKeys()) {
      if (isRightGroup()) {
        String[] radioKeysPartip = { NLS_RADIO_ALL, NLS_RADIO_CHOOSE };
        String[] radioValuesPartip = { translator.translate("sendtochooser.form.radio.partip.rightgroup.all"), translator.translate("sendtochooser.form.radio.partip.rightgroup.choose") };
        radioButtonPartip = new RadioButtonGroupElement(true, "sendtochooser.form.radio.rightgroup", radioKeysPartip, radioValuesPartip);
        radioButtonPartip.select(NLS_RADIO_ALL, true);
        // Participator MultiSelection
        SecurityGroup participants = businessGroup.getPartipiciantGroup();
        List<Identity> participantsList = scrtMngr.getIdentitiesOfSecurityGroup(participants);
        String[] keysPartip = new String[participantsList.size()];
        String[] valuesPartip = new String[participantsList.size()];
        for (int i = 0; i < participantsList.size(); i++) {
          keysPartip[i] = participantsList.get(i).getKey().toString();
          valuesPartip[i] = participantsList.get(i).getName().toString();
        }
        multiSelectionPartipKeys = new StaticMultipleSelectionElement(null, keysPartip, valuesPartip, participantsList.size() > 0 ? true
            : false);
        addFormElement("radioButtonPartip", radioButtonPartip);
        addFormElement("multiSelectionPartipKeys", multiSelectionPartipKeys);
        // rule partips
        rule = new VisibilityDependsOnSelectionRule(radioButtonPartip, multiSelectionPartipKeys, "choose", true, null, true);
        addVisibilityDependsOnSelectionRule(rule);
      } else {
        String[] radioKeysPartip = { NLS_RADIO_ALL, NLS_RADIO_NOTHING, NLS_RADIO_CHOOSE };
        String[] radioValuesPartip = { translator.translate("sendtochooser.form.radio.partip.all"),
            translator.translate("sendtochooser.form.radio.partip.nothing"), translator.translate("sendtochooser.form.radio.partip.choose") };
        radioButtonPartip = new RadioButtonGroupElement(true, "sendtochooser.form.radio.partip", radioKeysPartip, radioValuesPartip);
        radioButtonPartip.select(NLS_RADIO_ALL, true);
        // Participator MultiSelection
        SecurityGroup participants = businessGroup.getPartipiciantGroup();
        List<Identity> participantsList = scrtMngr.getIdentitiesOfSecurityGroup(participants);
        String[] keysPartip = new String[participantsList.size()];
        String[] valuesPartip = new String[participantsList.size()];
        for (int i = 0; i < participantsList.size(); i++) {
          keysPartip[i] = participantsList.get(i).getKey().toString();
          valuesPartip[i] = participantsList.get(i).getName().toString();
        }
        multiSelectionPartipKeys = new StaticMultipleSelectionElement(null, keysPartip, valuesPartip, participantsList.size() > 0 ? true
            : false);
        addFormElement("radioButtonPartip", radioButtonPartip);
        addFormElement("multiSelectionPartipKeys", multiSelectionPartipKeys);
        // rule partips
        rule = new VisibilityDependsOnSelectionRule(radioButtonPartip, multiSelectionPartipKeys, "choose", true, null, true);
        addVisibilityDependsOnSelectionRule(rule);
      }
    } else {
      if (isRightGroup()) {
        String[] radioKeysPartip = { NLS_RADIO_ALL };
        String[] radioValuesPartip = { translator.translate("sendtochooser.form.radio.partip.all.rightgroup") };
        radioButtonPartip = new RadioButtonGroupElement(true, "sendtochooser.form.radio.partip.rightgroup", radioKeysPartip, radioValuesPartip);
        radioButtonPartip.select(NLS_RADIO_ALL, true);
        addFormElement("radioButtonPartip", radioButtonPartip);
      } else {
        String[] radioKeysPartip = { NLS_RADIO_ALL, NLS_RADIO_NOTHING };
        String[] radioValuesPartip = { translator.translate("sendtochooser.form.radio.partip.all"),
            translator.translate("sendtochooser.form.radio.partip.nothing") };
        radioButtonPartip = new RadioButtonGroupElement(true, "sendtochooser.form.radio.partip", radioKeysPartip, radioValuesPartip);
        radioButtonPartip.select(NLS_RADIO_ALL, true);
        addFormElement("radioButtonPartip", radioButtonPartip);
      }
    }   

    if ( isAdmin && businessGroup.getWaitingListEnabled().booleanValue()) {
      String[] radioKeysWaitings = { NLS_RADIO_ALL, NLS_RADIO_NOTHING, NLS_RADIO_CHOOSE };
      String[] radioValuesWaitings = {translator.translate("sendtochooser.form.radio.waitings.all"), translator.translate("sendtochooser.form.radio.waitings.nothing"), translator.translate("sendtochooser.form.radio.waitings.choose")};
      radioButtonWaiting = new RadioButtonGroupElement(true, "sendtochooser.form.radio.waitings", radioKeysWaitings, radioValuesWaitings);
      radioButtonWaiting.select(NLS_RADIO_ALL, true);
     
      // Waitings MultiSelection
      SecurityGroup waitingList = businessGroup.getWaitingGroup();
      List<Identity> waitingListIdentities = scrtMngr.getIdentitiesOfSecurityGroup(waitingList);
      String[] keysWaiting = new String[waitingListIdentities.size()];
      String[] valuesWaiting = new String[waitingListIdentities.size()];
      for (int i = 0; i < waitingListIdentities.size(); i++) {
        keysWaiting[i] = waitingListIdentities.get(i).getKey().toString();
        valuesWaiting[i] = waitingListIdentities.get(i).getName().toString();
      }
      multiSelectionWaitingKeys = new StaticMultipleSelectionElement(null, keysWaiting, valuesWaiting, waitingListIdentities.size()>0?true:false);
      // WaitingList is enabled => show checkbox
      addFormElement("radioButtonWaiting", radioButtonWaiting);
      addFormElement("multiSelectionWaitingKeys", multiSelectionWaitingKeys);
     
      // rule waitings
      rule = new VisibilityDependsOnSelectionRule(radioButtonWaiting, multiSelectionWaitingKeys, "choose", true, null, true);
      addVisibilityDependsOnSelectionRule(rule);
    }
    setCancelButton();
    addSubmitKey("sendtochooser.form.submit");
  }
 
  /**
   * @param businessGroup
   * @return
   */
  private boolean isRightGroup() {
    return this.businessGroup.getType().equals(businessGroup.TYPE_RIGHTGROUP);
  }

  /**
   * @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest)
   */
  public boolean validate() {
    if (businessGroup.getWaitingListEnabled().booleanValue()) {
      // there is a waiting list checkbox
      if ((radioButtonOwner!=null && radioButtonOwner.isSelected(0))
          || radioButtonPartip.isSelected(0)
          || radioButtonWaiting.isSelected(0)
          || (isMultiSelectionOwnerKeys() ? (radioButtonOwner!=null && radioButtonOwner.isSelected(2) && multiSelectionOwnerKeys.getSelectedKeys().size() > 0 ? true : false) : false)
          || (isMultiSelectionPartipKeys() ? (radioButtonPartip.isSelected(2) && multiSelectionPartipKeys.getSelectedKeys().size() > 0 ? true : false) : false)
          || (radioButtonWaiting.isSelected(2) && multiSelectionWaitingKeys.getSelectedKeys().size() > 0 ? true : false)) {
        return true;
      } else {
        radioButtonWaiting.setErrorKey("sendtochooser.form.error.nonselected");
        return false;
      }
    } else {
      if (isRightGroup()) {
        if (radioButtonPartip.isSelected(0)
            || (isMultiSelectionPartipKeys() ? (radioButtonPartip.isSelected(1) && multiSelectionPartipKeys.getSelectedKeys().size() > 0 ? true
                : false)
                : false)) {
          return true;
        } else {
          radioButtonPartip.setErrorKey("sendtochooser.form.error.nonselected");
          return false;
        }
      } else {
        if ((radioButtonOwner!=null && radioButtonOwner.isSelected(0))
            || radioButtonPartip.isSelected(0)
            || (isMultiSelectionOwnerKeys() ? (radioButtonOwner!=null && radioButtonOwner.isSelected(2) && multiSelectionOwnerKeys.getSelectedKeys().size() > 0 ? true
                : false)
                : false)
            || (isMultiSelectionPartipKeys() ? (radioButtonPartip.isSelected(2) && multiSelectionPartipKeys.getSelectedKeys().size() > 0 ? true
                : false)
                : false)) {
          return true;
        } else {
          radioButtonPartip.setErrorKey("sendtochooser.form.error.nonselected");
          return false;
        }
      }
    }
  }

  /**
   * @return true if owner is checked
   */
  public String ownerChecked() {
    return radioButtonOwner == null?BusinessGroupSendToChooserForm.NLS_RADIO_NOTHING:radioButtonOwner.getSelectedKey();
  }

  /**
   * @return true if participant is checked
   */
  public String participantChecked() {
    return radioButtonPartip.getSelectedKey();
  }

  /**
   * @return true if waiting-list is checked
   */
  public String waitingListChecked() {
    return radioButtonWaiting.getSelectedKey();
  }
 
  /**
   * @return
   */
  private boolean isMultiSelectionOwnerKeys() {
    return isAdmin ? true : showChooseOwners;
  }
 
  /**
   * @return
   */
  private boolean isMultiSelectionPartipKeys() {
    return isAdmin ? true : showChoosePartips;
  }

  /**
   * @return
   */
  public List<Long> getSelectedOwnerKeys() {
    Set selectedKeys = multiSelectionOwnerKeys.getSelectedKeys();
    List<Long> selectedKeysLong = new ArrayList<Long>();
    for (Object key : selectedKeys) {
      selectedKeysLong.add(Long.parseLong(key.toString()));
    }
    return selectedKeysLong;
  }
 
  /**
   * @return
   */
  public List<Long> getSelectedPartipKeys() {
    Set selectedKeys = multiSelectionPartipKeys.getSelectedKeys();
    List<Long> selectedKeysLong = new ArrayList<Long>();
    for (Object key : selectedKeys) {
      selectedKeysLong.add(Long.parseLong(key.toString()));
    }
    return selectedKeysLong;
  }
 
  /**
   * @return
   */
  public List<Long> getSelectedWaitingKeys() {
    Set selectedKeys = multiSelectionWaitingKeys.getSelectedKeys();
    List<Long> selectedKeysLong = new ArrayList<Long>();
    for (Object key : selectedKeys) {
      selectedKeysLong.add(Long.parseLong(key.toString()));
    }
    return selectedKeysLong;
  }
 
  /**
   * @return
   */
  public StaticMultipleSelectionElement getMultiSelectionOwnerKeys() {
    return multiSelectionOwnerKeys;
  }

  /**
   * @param multiSelectionOwnerKeys
   */
  public void setMultiSelectionOwnerKeys(StaticMultipleSelectionElement multiSelectionOwnerKeys) {
    this.multiSelectionOwnerKeys = multiSelectionOwnerKeys;
  }

  /**
   * @return
   */
  public StaticMultipleSelectionElement getMultiSelectionPartipKeys() {
    return multiSelectionPartipKeys;
  }

  /**
   * @param multiSelectionPartipKeys
   */
  public void setMultiSelectionPartipKeys(StaticMultipleSelectionElement multiSelectionPartipKeys) {
    this.multiSelectionPartipKeys = multiSelectionPartipKeys;
  }

  /**
   * @return
   */
  public StaticMultipleSelectionElement getMultiSelectionWaitingKeys() {
    return multiSelectionWaitingKeys;
  }

  /**
   * @param multiSelectionWaitingKeys
   */
  public void setMultiSelectionWaitingKeys(StaticMultipleSelectionElement multiSelectionWaitingKeys) {
    this.multiSelectionWaitingKeys = multiSelectionWaitingKeys;
  }

}
TOP

Related Classes of org.olat.group.ui.run.BusinessGroupSendToChooserForm

TOP
Copyright © 2018 www.massapi.com. 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.