Package org.jallinone.variants.java

Examples of org.jallinone.variants.java.VariantsMatrixVO


  private void initGrid(VariantsItemDescriptor itemVO) {

    Response res = ClientUtils.getData("loadProductVariantsMatrix",itemVO);
    if (!res.isError()) {
      // retrieve grid descriptor...
      final VariantsMatrixVO vo = (VariantsMatrixVO)((VOResponse)res).getVo();

      // create grid...
      grid = new GridControl();
      grid.setController(new GridController() {


        /**
         * 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/new rows
         * @param oldPersistentObjects old value objects, previous the changes; it can contains null objects, in case of new inserted rows
         * @param persistentObjects value objects related to the changed/new 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 res = ClientUtils.getData("updateVariantMinStocks",new Object[]{vo,getCells()});
          if (res.isError())
            return res;
          return new VOListResponse(persistentObjects,false,persistentObjects.size());
        }

      });
      grid.setGridDataLocator(new GridDataLocator() {

        public Response loadData(int action, int startIndex,
                                 Map filteredColumns,
                                 ArrayList currentSortedColumns,
                                 ArrayList currentSortedVersusColumns,
                                 Class valueObjectType, Map otherGridParams) {
          VariantsMatrixVO matrixVO = (VariantsMatrixVO)otherGridParams.get(ApplicationConsts.VARIANTS_MATRIX_VO);
          return ClientUtils.getData("loadVariantMinStocks",matrixVO);
        }

      });
      //gridDataLocator.setServerMethodName(serverGridMethodName);
View Full Code Here


  private void initGrid(VariantsItemDescriptor itemVO) {

    Response res = ClientUtils.getData("loadProductVariantsMatrix",itemVO);
    if (!res.isError()) {
      // retrieve grid descriptor...
      final VariantsMatrixVO vo = (VariantsMatrixVO)((VOResponse)res).getVo();

      // create grid...
      grid = new GridControl();
      grid.setController(new GridController() {


        /**
         * 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/new rows
         * @param oldPersistentObjects old value objects, previous the changes; it can contains null objects, in case of new inserted rows
         * @param persistentObjects value objects related to the changed/new 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 res = ClientUtils.getData("updateVariantBarcodes",new Object[]{vo,getCells()});
          if (res.isError())
            return res;
          return new VOListResponse(persistentObjects,false,persistentObjects.size());
        }

      });
      grid.setGridDataLocator(new GridDataLocator() {

        public Response loadData(int action, int startIndex,
                                 Map filteredColumns,
                                 ArrayList currentSortedColumns,
                                 ArrayList currentSortedVersusColumns,
                                 Class valueObjectType, Map otherGridParams) {
          VariantsMatrixVO matrixVO = (VariantsMatrixVO)otherGridParams.get(ApplicationConsts.VARIANTS_MATRIX_VO);
          return ClientUtils.getData("loadVariantBarcodes",matrixVO);
        }

      });
      //gridDataLocator.setServerMethodName(serverGridMethodName);
View Full Code Here

  public VOListResponse loadVariantsPrices(GridParams params,String serverLanguageId,String username) throws Throwable {
    Connection conn = null;
    try {
      if (this.conn==null) conn = getConn(); else conn = this.conn;

      VariantsMatrixVO matrixVO = (VariantsMatrixVO)params.getOtherGridParams().get(ApplicationConsts.VARIANTS_MATRIX_VO);
      ItemPK itemPK = matrixVO.getItemPK();
      String priceListCode = (String)params.getOtherGridParams().get(ApplicationConsts.PRICELIST);

      String sql =
            "select SAL11_VARIANTS_PRICES.COMPANY_CODE_SYS01,SAL11_VARIANTS_PRICES.PRICELIST_CODE_SAL01,"+
            "SAL11_VARIANTS_PRICES.ITEM_CODE_ITM01,SAL11_VARIANTS_PRICES.VALUE,SAL11_VARIANTS_PRICES.START_DATE,SAL11_VARIANTS_PRICES.END_DATE,"+
            "A.DESCRIPTION,ITM01_ITEMS.PROGRESSIVE_HIE02,"+
            "SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM06,SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM11,"+
            "SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM07,SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM12,"+
            "SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM08,SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM13,"+
            "SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM09,SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM14,"+
            "SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM10,SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM15 "+
            " from SAL11_VARIANTS_PRICES,SYS10_COMPANY_TRANSLATIONS A,ITM01_ITEMS where "+
            "SAL11_VARIANTS_PRICES.COMPANY_CODE_SYS01=ITM01_ITEMS.COMPANY_CODE_SYS01 and "+
            "SAL11_VARIANTS_PRICES.ITEM_CODE_ITM01=ITM01_ITEMS.ITEM_CODE and "+
            "ITM01_ITEMS.COMPANY_CODE_SYS01=A.COMPANY_CODE_SYS01 and "+
            "ITM01_ITEMS.PROGRESSIVE_SYS10=A.PROGRESSIVE and "+
            "A.LANGUAGE_CODE=? and SAL11_VARIANTS_PRICES.COMPANY_CODE_SYS01=? and ITM01_ITEMS.ENABLED='Y' and "+
            "SAL11_VARIANTS_PRICES.PRICELIST_CODE_SAL01=? and "+
            "SAL11_VARIANTS_PRICES.ITEM_CODE_ITM01=?";

      Map attribute2dbField = new HashMap();
      attribute2dbField.put("companyCodeSys01SAL11","SAL11_VARIANTS_PRICES.COMPANY_CODE_SYS01");
      attribute2dbField.put("pricelistCodeSal01SAL11","SAL11_VARIANTS_PRICES.PRICELIST_CODE_SAL01");
      attribute2dbField.put("itemCodeItm01SAL11","SAL11_VARIANTS_PRICES.ITEM_CODE_ITM01");
      attribute2dbField.put("valueSAL11","SAL11_VARIANTS_PRICES.VALUE");
      attribute2dbField.put("startDateSAL11","SAL11_VARIANTS_PRICES.START_DATE");
      attribute2dbField.put("endDateSAL11","SAL11_VARIANTS_PRICES.END_DATE");
      attribute2dbField.put("itemDescriptionSYS10","A.DESCRIPTION");
      attribute2dbField.put("pricelistDescriptionSYS10","B.DESCRIPTION");
      attribute2dbField.put("progressiveHie02ITM01","ITM01_ITEMS.PROGRESSIVE_HIE02");

      attribute2dbField.put("variantTypeItm06SAL11","SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM06");
      attribute2dbField.put("variantCodeItm11SAL11","SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM11");
      attribute2dbField.put("variantTypeItm07SAL11","SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM07");
      attribute2dbField.put("variantCodeItm12SAL11","SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM12");
      attribute2dbField.put("variantTypeItm08SAL11","SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM08");
      attribute2dbField.put("variantCodeItm13SAL11","SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM13");
      attribute2dbField.put("variantTypeItm09SAL11","SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM09");
      attribute2dbField.put("variantCodeItm14SAL11","SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM14");
      attribute2dbField.put("variantTypeItm10SAL11","SAL11_VARIANTS_PRICES.VARIANT_TYPE_ITM10");
      attribute2dbField.put("variantCodeItm15SAL11","SAL11_VARIANTS_PRICES.VARIANT_CODE_ITM15");

      ArrayList values = new ArrayList();
      values.add(serverLanguageId);
      values.add(itemPK.getCompanyCodeSys01ITM01());
      values.add(priceListCode);
      values.add(itemPK.getItemCodeITM01());


      // read ALL from SAL11 table...
      Response res = QueryUtil.getQuery(
          conn,
          new UserSessionParameters(username),
          sql,
          values,
          attribute2dbField,
          VariantsPriceVO.class,
          "Y",
          "N",
          null,
          new GridParams(),
          true
      );

      if (res.isError())
        throw new Exception(res.getErrorMessage());


      java.util.List rows = ((VOListResponse)res).getRows();


      // convert the records list in matrix format...
      ArrayList matrixRows = new ArrayList();
      VariantsPriceVO vo = null;
      CustomValueObject customVO = null;
      VariantsMatrixRowVO rowVO = null;
      VariantsMatrixColumnVO colVO = null;
      HashMap indexes = new HashMap();
      for(int i=0;i<matrixVO.getRowDescriptors().length;i++) {
        rowVO = (VariantsMatrixRowVO)matrixVO.getRowDescriptors()[i];

        customVO = new CustomValueObject();
        customVO.setAttributeNameS0(rowVO.getRowDescription());
        matrixRows.add(customVO);
        indexes.put(
          VariantsMatrixUtils.getVariantType(matrixVO,rowVO)+" "+VariantsMatrixUtils.getVariantCode(matrixVO,rowVO),
          customVO
        );
      }
      VariantNameVO varVO = (VariantNameVO)matrixVO.getManagedVariants()[0];
      for(int i=0;i<rows.size();i++) {
        vo = (VariantsPriceVO)rows.get(i);

        if (varVO.getTableName().equals("ITM11_VARIANTS_1")) {
          customVO = (CustomValueObject)indexes.get(vo.getVariantTypeItm06SAL11()+" "+vo.getVariantCodeItm11SAL11());
        }
        else if (varVO.getTableName().equals("ITM12_VARIANTS_2")) {
          customVO = (CustomValueObject)indexes.get(vo.getVariantTypeItm07SAL11()+" "+vo.getVariantCodeItm12SAL11());
        }
        else if (varVO.getTableName().equals("ITM13_VARIANTS_3")) {
          customVO = (CustomValueObject)indexes.get(vo.getVariantTypeItm08SAL11()+" "+vo.getVariantCodeItm13SAL11());
        }
        else if (varVO.getTableName().equals("ITM14_VARIANTS_4")) {
          customVO = (CustomValueObject)indexes.get(vo.getVariantTypeItm09SAL11()+" "+vo.getVariantCodeItm14SAL11());
        }
        else if (varVO.getTableName().equals("ITM15_VARIANTS_5")) {
          customVO = (CustomValueObject)indexes.get(vo.getVariantTypeItm10SAL11()+" "+vo.getVariantCodeItm15SAL11());
        }

        if (matrixVO.getColumnDescriptors().length==0) {
          customVO.setAttributeNameN0(vo.getValueSAL11());
        }
        else {

          for(int j=0;j<matrixVO.getColumnDescriptors().length;j++) {
            colVO = (VariantsMatrixColumnVO)matrixVO.getColumnDescriptors()[j];
            if ((varVO.getTableName().equals("ITM11_VARIANTS_1")?true:colVO.getVariantCodeITM11().equals(vo.getVariantCodeItm11SAL11())) &&
                (varVO.getTableName().equals("ITM12_VARIANTS_2")?true:colVO.getVariantCodeITM12().equals(vo.getVariantCodeItm12SAL11())) &&
                (varVO.getTableName().equals("ITM13_VARIANTS_3")?true:colVO.getVariantCodeITM13().equals(vo.getVariantCodeItm13SAL11())) &&
                (varVO.getTableName().equals("ITM14_VARIANTS_4")?true:colVO.getVariantCodeITM14().equals(vo.getVariantCodeItm14SAL11())) &&
                (varVO.getTableName().equals("ITM15_VARIANTS_5")?true:colVO.getVariantCodeITM15().equals(vo.getVariantCodeItm15SAL11())) &&
View Full Code Here

    try {
      if (this.conn==null) conn = getConn(); else conn = this.conn;
      bean.setConn(conn);

      // create VariantsMatrixVO v.o.
      VariantsMatrixVO matrixVO = new VariantsMatrixVO();
      matrixVO.setDecimals(itemVO.getDecimalsREG02().intValue());
      matrixVO.setItemPK(new ItemPK(itemVO.getCompanyCodeSys01(),itemVO.getItemCodeItm01()));

      // retrieve variants descriptors...
      String sql =
          "select ITM21_VARIANTS.COMPANY_CODE_SYS01,ITM21_VARIANTS.TABLE_NAME,ITM21_VARIANTS.PROGRESSIVE_SYS10,"+
          "SYS10_COMPANY_TRANSLATIONS.DESCRIPTION,ITM21_VARIANTS.USE_VARIANT_TYPE "+
          "from ITM21_VARIANTS,SYS10_COMPANY_TRANSLATIONS where "+
          "ITM21_VARIANTS.COMPANY_CODE_SYS01=SYS10_COMPANY_TRANSLATIONS.COMPANY_CODE_SYS01 and "+
          "ITM21_VARIANTS.PROGRESSIVE_SYS10=SYS10_COMPANY_TRANSLATIONS.PROGRESSIVE and "+
          "SYS10_COMPANY_TRANSLATIONS.LANGUAGE_CODE=? and "+
          "ITM21_VARIANTS.COMPANY_CODE_SYS01=?";
      Map attribute2dbField = new HashMap();
      attribute2dbField.put("companyCodeSys01ITM21","ITM21_VARIANTS.COMPANY_CODE_SYS01");
      attribute2dbField.put("tableName","ITM21_VARIANTS.TABLE_NAME");
      attribute2dbField.put("descriptionSYS10","SYS10_COMPANY_TRANSLATIONS.DESCRIPTION");
      attribute2dbField.put("progressiveSys10ITM21","ITM21_VARIANTS.PROGRESSIVE_SYS10");
      attribute2dbField.put("useVariantTypeITM21","ITM21_VARIANTS.USE_VARIANT_TYPE");
      ArrayList values = new ArrayList();
      values.add(serverLanguageId);
      values.add(itemVO.getCompanyCodeSys01());
      Response answer = QueryUtil.getQuery(
          conn,
          new UserSessionParameters(username),
          sql,
          values,
          attribute2dbField,
          VariantNameVO.class,
          "Y",
          "N",
          null,
          new GridParams(),
          true
      );
      if (answer.isError())
        throw new Exception(answer.getErrorMessage());
      List variants = ((VOListResponse)answer).getRows();

      // define managedVariants...
      ArrayList managedVariants = new ArrayList();
      if (Boolean.TRUE.equals(itemVO.getUseVariant1ITM01()))
        managedVariants.add(variants.get(0));
      if (Boolean.TRUE.equals(itemVO.getUseVariant2ITM01()))
        managedVariants.add(variants.get(1));
      if (Boolean.TRUE.equals(itemVO.getUseVariant3ITM01()))
        managedVariants.add(variants.get(2));
      if (Boolean.TRUE.equals(itemVO.getUseVariant4ITM01()))
        managedVariants.add(variants.get(3));
      if (Boolean.TRUE.equals(itemVO.getUseVariant5ITM01()))
        managedVariants.add(variants.get(4));
      matrixVO.setManagedVariants((VariantNameVO[])managedVariants.toArray(new VariantNameVO[managedVariants.size()]));

      // define rows and cols...
      ArrayList rows = new ArrayList();
      ArrayList cols = new ArrayList();

      // retrieve product variants, for each managed variant...
      GridParams gridParams = new GridParams();
      VariantNameVO varVO = null;
      ArrayList[] tmp = new ArrayList[managedVariants.size()-1];
      boolean[] tmpSameVarType = new boolean[managedVariants.size()-1];
      boolean sameVarType = true;
      ItemVariantVO variantVO = null;
      String currVarType = null;
      for(int i=0;i<managedVariants.size();i++) {
        varVO = (VariantNameVO)managedVariants.get(i);
        gridParams.getOtherGridParams().put(ApplicationConsts.ITEM_PK,matrixVO.getItemPK());
        gridParams.getOtherGridParams().put(ApplicationConsts.TABLE_NAME,varVO.getTableName());
        //gridParams.getOtherGridParams().put(ApplicationConsts.VARIANT_TYPE,null); //???
        answer = bean.loadItemVariants(gridParams,serverLanguageId,username);
        if (answer.isError())
          throw new Exception(answer.getErrorMessage());
        // list of all variant's elements (not only the ones associated to the current item
        // ("selected" attribute establishes which ones are associated to the current item...)
        ArrayList vos = new ArrayList(((VOListResponse)answer).getRows());

        sameVarType = true;
        currVarType = null;
        for(int k=0;k<vos.size();k++) {
          variantVO = (ItemVariantVO)vos.get(k);
          if (!Boolean.TRUE.equals(variantVO.getSelected()))
              continue;
          if (currVarType!=null && !currVarType.equals(variantVO.getVariantType())) {
            sameVarType = false;
            break;
          }
          else
            currVarType = variantVO.getVariantType();
        }

        if (i==0) {
          for(int k=0;k<vos.size();k++) {
            variantVO = (ItemVariantVO)vos.get(k);
            if (!Boolean.TRUE.equals(variantVO.getSelected()))
                continue;

            VariantsMatrixRowVO rowVO = new VariantsMatrixRowVO();
            setVariantDescription(variantVO,rowVO,sameVarType);
            setVariantTypeAndCode(variantVO,rowVO);
            rows.add(rowVO);
          }
        }
        else {
          tmpSameVarType[i-1] = sameVarType;
          tmp[i-1] = vos; // es. i=1 (color),tmp[0]=[red,black,orange...]
                          // es. i=2 (drop), tmp[1]=[short,medium,...]
        }
      }

      // create combinations of "tmp"...
      if (managedVariants.size()>1)
        createCombinations(managedVariants,tmp,tmpSameVarType,cols,0,null);

      matrixVO.setRowDescriptors((VariantsMatrixRowVO[])rows.toArray(new VariantsMatrixRowVO[rows.size()]));
      matrixVO.setColumnDescriptors((VariantsMatrixColumnVO[])cols.toArray(new VariantsMatrixColumnVO[cols.size()]));

      return matrixVO;
    }
    catch (Throwable ex) {
      Logger.error(username,this.getClass().getName(),"getVariantsMatrix","Error while fetching the variants matrix",ex);
View Full Code Here

  public final void initGrid(VariantsItemDescriptor lookupVO) {

    Response res = ClientUtils.getData(serverMatrixMethodName,lookupVO);
    if (!res.isError()) {
      // retrieve grid descriptor...
      VariantsMatrixVO vo = (VariantsMatrixVO)((VOResponse)res).getVo();

      // create grid...
      grid = new GridControl();
      grid.getOtherGridParams().putAll(otherGridParams);
      grid.setController(new GridController() {

        /**
         * @param grid grid
         * @param row selected row index
         * @param attributeName attribute name that identifies the selected grid column
         * @return <code>true</code> if the selected cell is editable, <code>false</code> otherwise
         */
        public boolean isCellEditable(GridControl grid,int row,String attributeName) {
          int col = grid.getTable().getGrid().getColumnIndex(attributeName);
          if (col<1)
            return false;
          if (barcodeVO!=null) {
            return grid.getVOListTableModel().getValueAt(row,grid.getVOListTableModel().findColumn(attributeName))!=null;
            //return getCells()[row][col-1]!=null;
          }
          return grid.isFieldEditable(row,attributeName);
        }


        /**
         * Callback method invoked when the data loading is completed.
         * @param error <code>true</code> if data loading has terminated with errors, <code>false</code> otherwise
         */
        public void loadDataCompleted(boolean error) {
          if (barcodeVO!=null) {
            updateMatrixWithBarcode();
            grid.setMode(Consts.EDIT);
          }
          else if (snVO!=null)
            updateMatrixWithSN();
          else {
            grid.setMode(Consts.EDIT);
          }

          if (variantsPanelController!=null)
            variantsPanelController.loadDataCompleted(error);

          grid.revalidate();
          grid.repaint();
        }

        public boolean validateCell(int rowNumber,String attributeName,Object oldValue,Object newValue) {
          try {
            onValidating = true;

            if (variantsPanelController!=null)
              if (!variantsPanelController.validateCell(rowNumber,grid.getTable().getGrid().getColumnIndex(attributeName),attributeName,(Number)oldValue,(Number)newValue))
                return false;

            if (newValue!=null && ((Number)newValue).doubleValue()<=0)
              return false;

            if (newValue!=null) {
                BigDecimal correctValue = controller.validateQty((BigDecimal)newValue);
                if (!correctValue.equals(newValue))
                  // in case of multiple qty not correct...
                  return false;
            }
            SwingUtilities.invokeLater(new Runnable() {

              public void run() {
                BigDecimal tot = new BigDecimal(0);
                for(int i=0;i<grid.getVOListTableModel().getRowCount();i++)
                  for(int k=1;k<grid.getTable().getGrid().getColumnCount();k++)
                    if (grid.getVOListTableModel().getValueAt(i,k)!=null)
                      tot = tot.add((BigDecimal)grid.getVOListTableModel().getValueAt(i,k));
                if (tot.doubleValue()==0)
                  controlQty.setText("");
                else {
                  controlQty.setEnabled(true);
                  controlQty.setValue(tot);

                  FocusListener[] ll = controlQty.getBindingComponent().getFocusListeners();
                  for(int i=0;i<ll.length;i++)
                    ll[i].focusLost(new FocusEvent(controlQty,FocusEvent.FOCUS_LOST));

                  controller.qtyUpdated(tot);
                  controlQty.setEnabled(false);
                }

              }

            });

            return true;
          }
          catch (Exception ex) {
            ex.printStackTrace();
            return false;
          }
          finally {
            onValidating = false;
          }
        }

      });


      // set grid's data locator...
      if (serverGridMethodName!=null && !serverGridMethodName.equals("")) {
        ServerGridDataLocator gridDataLocator = new ServerGridDataLocator();
        gridDataLocator.setServerMethodName(serverGridMethodName);
        grid.setGridDataLocator(gridDataLocator);
      }
      else
        grid.setGridDataLocator(new GridDataLocator() {

          public Response loadData(int action, int startIndex,
                                   Map filteredColumns,
                                   ArrayList currentSortedColumns,
                                   ArrayList currentSortedVersusColumns,
                                   Class valueObjectType, Map otherGridParams) {
            VariantsMatrixVO matrixVO = (VariantsMatrixVO)otherGridParams.get(ApplicationConsts.VARIANTS_MATRIX_VO);
            ArrayList rows = new ArrayList();
            CustomValueObject vo = null;
            VariantsMatrixRowVO rowVO = null;
            for(int i=0;i<matrixVO.getRowDescriptors().length;i++) {
              rowVO = (VariantsMatrixRowVO)matrixVO.getRowDescriptors()[i];

              vo = new CustomValueObject();
              vo.setAttributeNameS0(rowVO.getRowDescription());
              rows.add(vo);
            }
View Full Code Here

TOP

Related Classes of org.jallinone.variants.java.VariantsMatrixVO

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.