/** Retrieve item types and fill in the item types combo box. */
 private void init() {
   Response res = ClientUtils.getData("loadItemTypes", new GridParams());
   Domain d = new Domain("ITEM_TYPES");
   if (!res.isError()) {
     ItemTypeVO vo = null;
     list = ((VOListResponse) res).getRows();
     for (int i = 0; i < list.size(); i++) {
       vo = (ItemTypeVO) list.get(i);
       d.addDomainPair(vo.getProgressiveHie02ITM02(), vo.getDescriptionSYS10());
     }
   }
   controlHierarchy.setDomain(d);
   controlHierarchy
       .getComboBox()
       .addItemListener(
           new ItemListener() {
             public void itemStateChanged(ItemEvent e) {
               if (e.getStateChange() == e.SELECTED) {
                 ItemTypeVO typeVO = (ItemTypeVO) list.get(controlHierarchy.getSelectedIndex());
                 treePanel.setCompanyCode(typeVO.getCompanyCodeSys01ITM02());
                 treePanel.setProgressiveHIE02((BigDecimal) controlHierarchy.getValue());
                 DetailSupplierVO vo =
                     (DetailSupplierVO) supplierPanel.getVOModel().getValueObject();
                 treePanel.setCompanyCode(vo.getCompanyCodeSys01REG04());
                 treePanel.reloadTree();
                 itemsGrid.clearData();
               }
             }
           });
   if (d.getDomainPairList().length == 1) controlHierarchy.getComboBox().setSelectedIndex(0);
   else controlHierarchy.getComboBox().setSelectedIndex(-1);
 }
 /**
  * Method invoked when pressing import all items button: it add all items to the supplier items
  * collection.
  */
 void impAllItemsButton_actionPerformed(ActionEvent e) {
   DetailSupplierVO vo = (DetailSupplierVO) supplierPanel.getVOModel().getValueObject();
   SupplierItemVO itemVO = new SupplierItemVO();
   itemVO.setCompanyCodeSys01PUR02(vo.getCompanyCodeSys01REG04());
   itemVO.setProgressiveReg04PUR02(vo.getProgressiveREG04());
   itemVO.setProgressiveHie02PUR02((BigDecimal) controlHierarchy.getValue());
   Response res = ClientUtils.getData("importAllItemsToSupplier", itemVO);
   if (!res.isError()) itemsGrid.reloadData();
 }
  /**
   * Method invoked when the user has clicked on save button and the grid is in EDIT mode.
   *
   * @param rowNumbers row indexes related to the changed rows
   * @param oldPersistentObjects old value objects, previous the changes
   * @param persistentObjects value objects relatied to the changed rows
   * @return an ErrorResponse value object in case of errors, VOListResponse if the operation is
   *     successfully completed
   */
  public Response updateRecords(
      int[] rowNumbers, ArrayList oldPersistentObjects, ArrayList persistentObjects)
      throws Exception {
    Response response = null;
    ItemDiscountVO vo = null;
    for (int i = 0; i < persistentObjects.size(); i++) {
      vo = (ItemDiscountVO) persistentObjects.get(i);
      response = validateDiscount(vo);
      if (response.isError()) return response;
    }

    response =
        ClientUtils.getData(
            "updateItemDiscounts", new ArrayList[] {oldPersistentObjects, persistentObjects});
    return response;
  }
  /**
   * Method invoked when the user has clicked on save button and the grid is in INSERT mode.
   *
   * @param rowNumbers row indexes related to the new rows to save
   * @param newValueObjects list of new value objects to save
   * @return an ErrorResponse value object in case of errors, VOListResponse if the operation is
   *     successfully completed
   */
  public Response insertRecords(int[] rowNumbers, ArrayList newValueObjects) throws Exception {
    ItemDiscountVO vo = null;
    Response response = null;
    DetailItemVO itemVO = (DetailItemVO) frame.getFormPanel().getVOModel().getValueObject();

    for (int i = 0; i < newValueObjects.size(); i++) {
      vo = (ItemDiscountVO) newValueObjects.get(i);
      response = validateDiscount(vo);
      if (response.isError()) return response;

      vo.setCompanyCodeSys01SAL03(itemVO.getCompanyCodeSys01ITM01());
      vo.setItemCodeItm01SAL04(itemVO.getItemCodeITM01());
    }

    response = ClientUtils.getData("insertItemDiscounts", newValueObjects);
    return response;
  }
  /**
   * Callback method invoked when the user has clicked on the insert button
   *
   * @param valueObject empty value object just created: the user can manage it to fill some
   *     attribute values
   */
  public void createValueObject(ValueObject valueObject) throws Exception {
    ItemDiscountVO vo = (ItemDiscountVO) valueObject;
    vo.setMinQtySAL03(new BigDecimal(1));
    vo.setMultipleQtySAL03(Boolean.FALSE);

    DetailItemVO itemVO = (DetailItemVO) frame.getFormPanel().getVOModel().getValueObject();
    itemVO.setCompanyCodeSys01ITM01(itemVO.getCompanyCodeSys01());
    Response res = ClientUtils.getData("loadCompany", itemVO.getCompanyCodeSys01());
    if (!res.isError()) {
      OrganizationVO compVO = (OrganizationVO) ((VOResponse) res).getVo();
      if (compVO.getCurrencyCodeReg03() != null && !compVO.getCurrencyCodeReg03().equals("")) {
        vo.setCurrencyCodeReg03SAL03(compVO.getCurrencyCodeReg03());
        frame
            .getColCurrencyCode()
            .forceValidate(
                frame.getDiscountsGrid().getSelectedRow() == -1
                    ? 0
                    : frame.getDiscountsGrid().getSelectedRow());
      }
    }
  }