Example #1
0
  /**
   * @param obj ValueObject related to the current row
   * @param colIndex TableModel column index
   * @return Object contained into the TableModel at the specified column and ValueObject
   */
  public final Object getField(ValueObject obj, int colIndex) {
    try {
      Method[] m = (Method[]) voGetterMethods.get(getFieldName(colIndex));
      if (m == null)
        Logger.error(
            this.getClass().getName(),
            "getField",
            "No getter method for index "
                + colIndex
                + " and attribute name '"
                + getFieldName(colIndex)
                + "'.",
            null);

      for (int i = 0; i < m.length - 1; i++) {
        obj = (ValueObject) m[i].invoke(obj, new Object[0]);
        if (obj == null) {
          if (grids.getGridControl() == null || !grids.getGridControl().isCreateInnerVO())
            return null;
          else obj = (ValueObject) m[i].getReturnType().newInstance();
        }
      }

      return m[m.length - 1].invoke(obj, new Object[0]);
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }
Example #2
0
 /**
  * @param colIndex TableModel column index
  * @return TableCellEditor for the specified column
  */
 public final TableCellEditor getCellEditor(int colIndex) {
   try {
     return colProperties[colIndex].getCellEditor(tableContainer, grids);
   } catch (Exception ex) {
     ex.printStackTrace();
     return null;
   }
 }
  public SaleCreditDocFrame(SaleCreditDocController controller) {
    this.controller = controller;
    try {
      jbInit();
      setSize(750, 630);
      setMinimumSize(new Dimension(750, 630));
      setTitle(ClientSettings.getInstance().getResources().getResource("credit note"));

      //      CustomizedControls customizedControls = new
      // CustomizedControls(tabbedPane,headerFormPanel,ApplicationConsts.ID_SALE_ESTIMATE);

      //
      // saleCustomerHeadPanel1.getCustomerDataLocator().getLookupFrameParams().put(ApplicationConsts.SUBJECT_TYPE,ApplicationConsts.SUBJECT_PEOPLE_CUSTOMER);
      //
      // saleCustomerHeadPanel1.getCustomerDataLocator().getLookupValidationParameters().put(ApplicationConsts.SUBJECT_TYPE,ApplicationConsts.SUBJECT_PEOPLE_CUSTOMER);

      init();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #4
0
 /**
  * @param colIndex TableModel column index
  * @return column type
  */
 public final Class getFieldClass(int colIndex) {
   try {
     Method[] m = (Method[]) voGetterMethods.get(getFieldName(colIndex));
     if (m == null)
       Logger.error(
           this.getClass().getName(),
           "getField",
           "No getter method for index "
               + colIndex
               + " and attribute name '"
               + getFieldName(colIndex)
               + "'.",
           null);
     return m[m.length - 1].getReturnType();
   } catch (Exception ex) {
     ex.printStackTrace();
     return String.class;
   }
 }
  /** Load data from server and construct panel content. */
  public final void reloadData(DocumentsFrame frame) {
    try {
      // remove all panel content...
      clearData();
      frame.getGrid().getOtherGridParams().put(ApplicationConsts.PROPERTIES_FILTER, filters);

      // retrieve customized input controls list...
      GridParams gridParams = new GridParams();
      DefaultMutableTreeNode node = frame.getHierarTreePanel().getSelectedNode();
      if (node != null) {
        HierarchyLevelVO vo = (HierarchyLevelVO) node.getUserObject();
        HierarchyLevelVO root =
            (HierarchyLevelVO) ((DefaultMutableTreeNode) node.getRoot()).getUserObject();
        gridParams
            .getOtherGridParams()
            .put(ApplicationConsts.PROGRESSIVE_HIE01, vo.getProgressiveHIE01());
        gridParams
            .getOtherGridParams()
            .put(ApplicationConsts.ROOT_PROGRESSIVE_HIE01, root.getProgressiveHIE01());
      } else gridParams.getOtherGridParams().remove(ApplicationConsts.PROGRESSIVE_HIE01);
      gridParams
          .getOtherGridParams()
          .put(
              ApplicationConsts.PROGRESSIVE_HIE02,
              frame.getHierarTreePanel().getProgressiveHIE02());
      gridParams.getOtherGridParams().put(ApplicationConsts.LOAD_ANCIENTS, Boolean.TRUE);
      Response res = ClientUtils.getData("loadLevelProperties", gridParams);
      if (res.isError()) {
        JOptionPane.showMessageDialog(
            ClientUtils.getParentFrame(this),
            ClientSettings.getInstance().getResources().getResource("Error while loading data")
                + ":\n"
                + res.getErrorMessage(),
            ClientSettings.getInstance().getResources().getResource("Loading Data Error"),
            JOptionPane.ERROR_MESSAGE);
        return;
      }
      ArrayList rows = ((VOListResponse) res).getRows();
      if (rows.size() > 0) {
        // adding customized input controls...
        LevelPropertyVO inputControlInfo = null;
        int row = 0;
        int col = 0;
        LabelControl labelControl = null;
        TextControl textControl = null;
        DateControl dateControl = null;
        NumericControl numericControl = null;
        for (int i = 0; i < rows.size(); i++) {
          inputControlInfo = (LevelPropertyVO) rows.get(i);
          labelControl = new LabelControl();
          labelControl.setText(inputControlInfo.getDescriptionSYS10());
          innerPanel.add(
              labelControl,
              new GridBagConstraints(
                  col++,
                  row,
                  1,
                  1,
                  0.0,
                  0.0,
                  GridBagConstraints.WEST,
                  GridBagConstraints.NONE,
                  new Insets(5, 5, 5, 5),
                  0,
                  0));

          if (inputControlInfo.getPropertyTypeDOC21().equals(ApplicationConsts.TYPE_TEXT)) {
            textControl = new TextControl();
            textControl.setMaxCharacters(255);
            textControl.setLinkLabel(labelControl);
            innerPanel.add(
                textControl,
                new GridBagConstraints(
                    col,
                    row,
                    1,
                    1,
                    1.0,
                    0.0,
                    GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL,
                    new Insets(5, 5, 5, 15),
                    0,
                    0));
            textControl.addFocusListener(new ControlFocusListener(inputControlInfo, textControl));
          } else if (inputControlInfo.getPropertyTypeDOC21().equals(ApplicationConsts.TYPE_DATE)) {
            dateControl = new DateControl();
            dateControl.setLinkLabel(labelControl);
            innerPanel.add(
                dateControl,
                new GridBagConstraints(
                    col,
                    row,
                    1,
                    1,
                    1.0,
                    0.0,
                    GridBagConstraints.WEST,
                    GridBagConstraints.NONE,
                    new Insets(5, 5, 5, 15),
                    0,
                    0));
            dateControl.addFocusListener(new ControlFocusListener(inputControlInfo, dateControl));
          } else if (inputControlInfo.getPropertyTypeDOC21().equals(ApplicationConsts.TYPE_NUM)) {
            numericControl = new NumericControl();
            numericControl.setDecimals(5);
            numericControl.setLinkLabel(labelControl);
            innerPanel.add(
                numericControl,
                new GridBagConstraints(
                    col,
                    row,
                    1,
                    1,
                    1.0,
                    0.0,
                    GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL,
                    new Insets(5, 5, 5, 15),
                    0,
                    0));
            numericControl.addFocusListener(
                new ControlFocusListener(inputControlInfo, numericControl));
          }

          col++;
          if (col >= 2) {
            innerPanel.add(
                new JPanel(),
                new GridBagConstraints(
                    col,
                    row,
                    1,
                    1,
                    1.0,
                    0.0,
                    GridBagConstraints.WEST,
                    GridBagConstraints.HORIZONTAL,
                    new Insets(5, 5, 5, 5),
                    0,
                    0));
            row++;
            col = 0;
          }
        }
        row++;
        innerPanel.add(
            new JPanel(),
            new GridBagConstraints(
                col,
                row,
                1,
                1,
                0.0,
                0.0,
                GridBagConstraints.WEST,
                GridBagConstraints.NONE,
                new Insets(5, 5, 5, 5),
                0,
                0));

        innerPanel.add(
            new JPanel(),
            new GridBagConstraints(
                0,
                row,
                1,
                1,
                0.0,
                1.0,
                GridBagConstraints.WEST,
                GridBagConstraints.VERTICAL,
                new Insets(5, 5, 5, 5),
                0,
                0));
        this.revalidate();
        this.repaint();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  /**
   * This method must be overridden by the subclass to retrieve data and return the valorized value
   * object.
   *
   * @param valueObjectClass value object class
   * @return a VOResponse object if data loading is successfully completed, or an ErrorResponse
   *     object if an error occours
   */
  public Response loadData(Class valueObjectClass) {
    try {
      // since this method could be invoked also when selecting another row on the linked grid,
      // the pk attribute must be recalculated from the grid...
      int row = gridFrame.getGrid().getSelectedRow();
      if (row != -1) {
        GridEmpVO gridVO =
            (GridEmpVO) gridFrame.getGrid().getVOListTableModel().getObjectForRow(row);
        pk = gridVO.getEmpCode();
      }

      String sql =
          "select EMP.EMP_CODE,EMP.FIRST_NAME, EMP.LAST_NAME,EMP.DEPT_CODE,DEPT.DESCRIPTION,EMP.TASK_CODE,TASKS.DESCRIPTION,EMP.SEX,EMP.HIRE_DATE,EMP.SALARY,EMP.NOTE "
              + "from EMP,DEPT,TASKS where EMP.DEPT_CODE=DEPT.DEPT_CODE and EMP.TASK_CODE=TASKS.TASK_CODE and EMP.EMP_CODE='"
              + pk
              + "'";

      // mapping between attributes and database fields...
      Map attribute2dbField = new HashMap();
      attribute2dbField.put("empCode", "EMP.EMP_CODE");
      attribute2dbField.put("firstName", "EMP.FIRST_NAME");
      attribute2dbField.put("lastName", "EMP.LAST_NAME");
      attribute2dbField.put("deptCode", "EMP.DEPT_CODE");
      attribute2dbField.put("deptDescription", "DEPT.DESCRIPTION");
      attribute2dbField.put("taskCode", "EMP.TASK_CODE");
      attribute2dbField.put("taskDescription", "TASKS.DESCRIPTION");
      attribute2dbField.put("sex", "EMP.SEX");
      attribute2dbField.put("hireDate", "EMP.HIRE_DATE");
      attribute2dbField.put("salary", "EMP.SALARY");
      attribute2dbField.put("note", "EMP.NOTE");

      return QueryUtil.getQuery(
          conn,
          sql,
          new ArrayList(), // list of values linked to "?" parameters in sql
          attribute2dbField,
          EmpVO.class, // v.o. to dinamically create for each row...
          "Y",
          "N",
          true // log query...
          );
    } catch (Exception ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    }

    /*
        // an alternative way: you can define your own business logic to retrieve data and adding filtering/sorting conditions at hand...
        Statement stmt = null;
        try {
          stmt = conn.createStatement();
          ResultSet rset = stmt.executeQuery(
            "select EMP.EMP_CODE,EMP.FIRST_NAME, EMP.LAST_NAME,EMP.DEPT_CODE,DEPT.DESCRIPTION,EMP.TASK_CODE,TASKS.DESCRIPTION,EMP.SEX,EMP.HIRE_DATE,EMP.SALARY,EMP.NOTE "+
            "from EMP,DEPT,TASKS where EMP.DEPT_CODE=DEPT.DEPT_CODE and EMP.TASK_CODE=TASKS.TASK_CODE and EMP.EMP_CODE='"+pk+"'"
          );
          if (rset.next()) {
            EmpVO vo = new EmpVO();
            vo.setEmpCode(rset.getString(1));
            vo.setFirstName(rset.getString(2));
            vo.setLastName(rset.getString(3));
            vo.setDeptCode(rset.getString(4));
            vo.setDeptDescription(rset.getString(5));
            vo.setTaskCode(rset.getString(6));
            vo.setTaskDescription(rset.getString(7));
            vo.setSex(rset.getString(8));
            vo.setHireDate(rset.getDate(9));
            vo.setSalary(rset.getBigDecimal(10));
            vo.setNote(rset.getString(11));
            return new VOResponse(vo);
          }
          else
            return new ErrorResponse("No data found.");
        }
        catch (SQLException ex) {
          ex.printStackTrace();
          return new ErrorResponse(ex.getMessage());
        }
        finally {
          try {
            stmt.close();
          }
          catch (SQLException ex1) {
          }
        }
    */
  }
Example #7
0
  /**
   * This method must be overridden by the subclass to retrieve data and return the valorized value
   * object.
   *
   * @param valueObjectClass value object class
   * @return a VOResponse object if data loading is successfully completed, or an ErrorResponse
   *     object if an error occours
   */
  public Response loadData(Class valueObjectClass) {
    Statement stmt = null;
    try {
      // since this method could be invoked also when selecting another row on the linked grid,
      // the pk attribute must be recalculated from the grid...
      int row = gridFrame.getGrid().getSelectedRow();
      if (row != -1) {
        TestVO gridVO = (TestVO) gridFrame.getGrid().getVOListTableModel().getObjectForRow(row);
        pk = gridVO.getStringValue();
      }

      stmt = conn.createStatement();
      ResultSet rset =
          stmt.executeQuery(
              "select DEMO4.TEXT,DEMO4.DECNUM,DEMO4.CURRNUM,DEMO4.THEDATE,DEMO4.COMBO,DEMO4.CHECK_BOX,DEMO4.RADIO,DEMO4.CODE,"
                  + "DEMO4_LOOKUP.DESCRCODE,DEMO4.TA,DEMO4.FORMATTED_TEXT,DEMO4.URI,DEMO4.LINK_LABEL,DEMO4.YEAR,DEMO4.FILENAME "
                  + "from DEMO4,DEMO4_LOOKUP where TEXT='"
                  + pk
                  + "' and DEMO4.CODE=DEMO4_LOOKUP.CODE");
      if (rset.next()) {
        DetailTestVO vo = new DetailTestVO();
        vo.setCheckValue(
            rset.getObject(6) == null || !rset.getObject(6).equals("Y")
                ? Boolean.FALSE
                : Boolean.TRUE);
        vo.setCombo(new ComboVO());
        vo.getCombo().setCode(rset.getString(5));

        // this is a simplification: in a real situation combo v.o. will be retrieved from the
        // database...
        Domain d = ClientSettings.getInstance().getDomain("ORDERSTATE");
        if (vo.getCombo().getCode().equals("O")) vo.getCombo().setDescription("opened");
        else if (vo.getCombo().getCode().equals("S")) vo.getCombo().setDescription("sospended");
        else if (vo.getCombo().getCode().equals("D")) vo.getCombo().setDescription("delivered");
        else if (vo.getCombo().getCode().equals("C")) vo.getCombo().setDescription("closed");

        vo.setCurrencyValue(rset.getBigDecimal(3));
        vo.setDateValue(rset.getDate(4));
        vo.setNumericValue(rset.getBigDecimal(2));
        vo.setRadioButtonValue(
            rset.getObject(7) == null || !rset.getObject(7).equals("Y")
                ? Boolean.FALSE
                : Boolean.TRUE);
        vo.setStringValue(rset.getString(1));
        vo.setLookupValue(rset.getString(8));
        vo.setDescrLookupValue(rset.getString(9));
        vo.setTaValue(rset.getString(10));
        vo.setFormattedTextValue(rset.getString(11));
        vo.setUri(rset.getString(12));
        vo.setLinkLabel(rset.getString(13));
        vo.setYear(rset.getBigDecimal(14));
        vo.setFilename(rset.getString(15));
        vo.setTooltipURI(vo.getUri());

        try {
          if (vo.getFilename() != null) {
            File f = new File(vo.getFilename());
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
            byte[] bytes = new byte[(int) f.length()];
            in.read(bytes);
            in.close();
            vo.setFile(bytes);
          }
        } catch (Exception ex) {
          ex.printStackTrace();
        }

        stmt.close();
        stmt = conn.createStatement();
        rset =
            stmt.executeQuery(
                "select DEMO4_LIST_VALUES.CODE from DEMO4_LIST_VALUES where TEXT='" + pk + "'");
        ArrayList codes = new ArrayList();
        while (rset.next()) {
          codes.add(rset.getString(1));
        }
        vo.setListValues(codes);

        return new VOResponse(vo);
      } else return new ErrorResponse("No data found.");
    } catch (SQLException ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    } finally {
      try {
        stmt.close();
      } catch (Exception ex1) {
      }
    }
  }
Example #8
0
  /**
   * Method called by the Form panel to update existing data.
   *
   * @param oldPersistentObject original value object, previous to the changes
   * @param persistentObject value object to save
   * @return an ErrorResponse value object in case of errors, VOResponse if the operation is
   *     successfully completed
   */
  public Response updateRecord(ValueObject oldPersistentObject, ValueObject persistentObject)
      throws Exception {
    PreparedStatement stmt = null;
    try {
      stmt =
          conn.prepareStatement(
              "update DEMO4 set TEXT=?,DECNUM=?,CURRNUM=?,THEDATE=?,COMBO=?,CHECK_BOX=?,RADIO=?,CODE=?,TA=?,FORMATTED_TEXT=?,URI=?,LINK_LABEL=?,YEAR=?,FILENAME=? where TEXT=?");
      DetailTestVO vo = (DetailTestVO) persistentObject;
      DetailTestVO oldVO = (DetailTestVO) oldPersistentObject;
      stmt.setObject(
          6, vo.getCheckValue() == null || !vo.getCheckValue().booleanValue() ? "N" : "Y");
      stmt.setString(5, vo.getCombo().getCode());
      stmt.setBigDecimal(3, vo.getCurrencyValue());
      stmt.setDate(4, vo.getDateValue());
      stmt.setBigDecimal(2, vo.getNumericValue());
      stmt.setObject(
          7,
          vo.getRadioButtonValue() == null || !vo.getRadioButtonValue().booleanValue() ? "N" : "Y");
      stmt.setString(1, vo.getStringValue());
      stmt.setString(8, vo.getLookupValue());
      stmt.setString(9, vo.getTaValue());
      stmt.setString(10, vo.getFormattedTextValue());
      stmt.setString(11, vo.getUri());
      stmt.setString(12, vo.getLinkLabel());
      stmt.setBigDecimal(13, vo.getYear());
      stmt.setString(14, vo.getFilename());
      stmt.setString(15, oldVO.getStringValue());
      stmt.execute();

      stmt.close();
      stmt = conn.prepareStatement("delete from DEMO4_LIST_VALUES where TEXT=?");
      stmt.setString(1, pk);
      stmt.execute();

      if (vo.getListValues() != null) {
        stmt.close();
        stmt = conn.prepareStatement("insert into DEMO4_LIST_VALUES(TEXT,CODE) values(?,?)");

        for (int i = 0; i < vo.getListValues().size(); i++) {
          stmt.setString(1, pk);
          stmt.setString(2, vo.getListValues().get(i).toString());
          stmt.execute();
        }
      }

      try {
        if (vo.getFilename() != null && vo.getFile() != null) {
          File f = new File(vo.getFilename());
          BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
          out.write(vo.getFile());
          out.close();
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }

      // this instruction is no more needed: the grid has been linked to the Form (see Form.linkGrid
      // method...)
      //      gridFrame.reloadData();
      return new VOResponse(vo);
    } catch (SQLException ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    } finally {
      try {
        stmt.close();
        conn.commit();
      } catch (SQLException ex1) {
      }
    }
  }
  /**
   * Constructor called by sale doc header frames.
   *
   * @param form sale doc header form
   * @param showDocRefLookup <code>true</code> to show combo+lookup used to select a linked document
   *     (e.g. a sale document in an invoice document); <code>false</code> to hide combo+lookup and
   *     show doc. ref. nr. input control
   * @param showSectional <code>true</code> to show the sectional field (for invoice documents);
   *     <code>false</code> to hide that field
   */
  public SaleIdHeadPanel(Form form, boolean showDocRefLookup, boolean showSectional) {
    this.showDocRefLookup = showDocRefLookup;
    this.showSectional = showSectional;
    try {
      jbInit();

      // doc. ref. lookup...
      docRefDataLocator.setGridMethodName("loadSaleDocs");
      docRefDataLocator.setValidationMethodName("validateSaleDocNumber");

      controlDocRifLookup.setLookupController(docRefController);
      docRefController.setForm(form);
      docRefController.setLookupDataLocator(docRefDataLocator);
      docRefController.setFrameTitle("documents");
      docRefController.setLookupValueObjectClassName(
          "org.jallinone.sales.documents.java.GridSaleDocVO");
      docRefController.addLookup2ParentLink("companyCodeSys01DOC01", "companyCodeSys01Doc01DOC01");
      docRefController.addLookup2ParentLink("docTypeDOC01", "docTypeDoc01DOC01");
      docRefController.addLookup2ParentLink("docYearDOC01", "docYearDoc01DOC01");
      docRefController.addLookup2ParentLink("docNumberDOC01", "docNumberDoc01DOC01");
      docRefController.addLookup2ParentLink("docSequenceDOC01", "docSequenceDoc01DOC01");
      docRefController.setAllColumnVisible(false);
      docRefController.setDomainColumn("docTypeDOC01", "SALE_DOC_TYPE");
      docRefController.setPreferredWidthColumn("docStateDOC01", 60);
      docRefController.setPreferredWidthColumn("docTypeDOC01", 60);
      docRefController.setPreferredWidthColumn("docYearDOC01", 60);
      docRefController.setPreferredWidthColumn("docSequenceDOC01", 90);
      docRefController.setPreferredWidthColumn("name_1REG04", 150);
      docRefController.setPreferredWidthColumn("name_2REG04", 140);
      docRefController.setPreferredWidthColumn("docDateDOC01", 80);

      docRefController.setSortedColumn("companyCodeSys01DOC01", "ASC", 1);
      docRefController.setSortedColumn("docTypeDOC01", "ASC", 2);
      docRefController.setSortedColumn("docYearDOC01", "ASC", 3);
      docRefController.setSortedColumn("docSequenceDOC01", "ASC", 4);

      docRefController.setVisibleColumn("companyCodeSys01DOC01", true);
      docRefController.setVisibleColumn("docTypeDOC01", true);
      docRefController.setVisibleColumn("docYearDOC01", true);
      docRefController.setVisibleColumn("docSequenceDOC01", true);
      docRefController.setVisibleColumn("name_1REG04", true);
      docRefController.setVisibleColumn("name_2REG04", true);
      docRefController.setVisibleColumn("docDateDOC01", true);
      docRefController.setFramePreferedSize(new Dimension(700, 500));

      docRefController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {}

            public void beforeLookupAction(ValueObject parentVO) {
              docRefDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.DOC_TYPE, controlDocTypeRef.getValue());
              docRefDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.DOC_TYPE, controlDocTypeRef.getValue());
              // filter sale documents having state confirmed, i.e. not yet invoiced, except for
              // sale desk docs...
              if (ApplicationConsts.SALE_DESK_DOC_TYPE.equals(controlDocTypeRef.getValue())) {
                docRefDataLocator
                    .getLookupFrameParams()
                    .put(ApplicationConsts.DOC_STATE, ApplicationConsts.CLOSED);
                docRefDataLocator
                    .getLookupValidationParameters()
                    .put(ApplicationConsts.DOC_STATE, ApplicationConsts.CLOSED);
              } else {
                docRefDataLocator
                    .getLookupFrameParams()
                    .put(ApplicationConsts.DOC_STATE, ApplicationConsts.CONFIRMED);
                docRefDataLocator
                    .getLookupValidationParameters()
                    .put(ApplicationConsts.DOC_STATE, ApplicationConsts.CONFIRMED);
              }
            }

            public void forceValidate() {}
          });

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public SupplierDetailFrame(final SupplierController controller) {
    try {
      jbInit();
      setSize(750, 550);
      setMinimumSize(new Dimension(750, 550));

      supplierPanel.setFormController(controller);
      supplierPanel.setInsertButton(insertButton);
      supplierPanel.setEditButton(editButton);
      supplierPanel.setReloadButton(reloadButton);
      supplierPanel.setDeleteButton(deleteButton);
      supplierPanel.setSaveButton(saveButton);
      supplierPanel.setFunctionId("PUR01");
      organizationPanel.setFunctionId("PUR01");

      // link the parent grid to the current Form...
      HashSet pk = new HashSet();
      pk.add("companyCodeSys01REG04");
      pk.add("progressiveREG04");
      supplierPanel.linkGrid(
          controller.getGridFrame().getGrid(), pk, true, true, true, navigatorBar);

      // banks lookup...
      bankDataLocator.setGridMethodName("loadBanks");
      bankDataLocator.setValidationMethodName("validateBankCode");
      controlBank.setLookupController(bankController);
      controlBank.setControllerMethodName("getBanksList");
      bankController.setLookupDataLocator(bankDataLocator);
      bankController.setFrameTitle("banks");
      bankController.setLookupValueObjectClassName("org.jallinone.registers.bank.java.BankVO");
      bankController.addLookup2ParentLink("bankCodeREG12", "bankCodeReg12PUR01");
      bankController.addLookup2ParentLink("descriptionREG12", "descriptionREG12");
      bankController.setAllColumnVisible(false);
      bankController.setVisibleColumn("bankCodeREG12", true);
      bankController.setVisibleColumn("descriptionREG12", true);
      bankController.setPreferredWidthColumn("descriptionREG12", 200);
      new CustomizedColumns(new BigDecimal(232), bankController);

      // payments lookup...
      payDataLocator.setGridMethodName("loadPayments");
      payDataLocator.setValidationMethodName("validatePaymentCode");
      controlPayment.setLookupController(payController);
      controlPayment.setControllerMethodName("getPaymentsList");
      payController.setLookupDataLocator(payDataLocator);
      payController.setFrameTitle("payments");
      payController.setLookupValueObjectClassName(
          "org.jallinone.registers.payments.java.PaymentVO");
      payController.addLookup2ParentLink("paymentCodeREG10", "paymentCodeReg10PUR01");
      payController.addLookup2ParentLink("descriptionSYS10", "paymentDescriptionSYS10");
      payController.setAllColumnVisible(false);
      payController.setVisibleColumn("paymentCodeREG10", true);
      payController.setVisibleColumn("descriptionSYS10", true);
      payController.setPreferredWidthColumn("descriptionSYS10", 200);
      new CustomizedColumns(new BigDecimal(212), payController);
      payController.addLookupListener(
          new LookupListener() {

            public void beforeLookupAction(
                org.openswing.swing.message.receive.java.ValueObject parentVO) {
              DetailSupplierVO vo = (DetailSupplierVO) parentVO;
              payDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, vo.getCompanyCodeSys01REG04());
              payDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, vo.getCompanyCodeSys01REG04());
            }

            public void codeChanged(
                org.openswing.swing.message.receive.java.ValueObject parentVO,
                Collection parentChangedAttributes) {}

            public void codeValidated(boolean validated) {}

            public void forceValidate() {}
          });

      // items lookup...
      itemDataLocator.setGridMethodName("loadItems");
      itemDataLocator.setValidationMethodName("validateItemCode");
      colItemCode.setLookupController(itemController);
      colItemCode.setControllerMethodName("getItemsList");
      itemController.setLookupDataLocator(itemDataLocator);
      itemController.setFrameTitle("items");
      itemController.setLookupValueObjectClassName("org.jallinone.items.java.GridItemVO");
      itemController.addLookup2ParentLink("companyCodeSys01ITM01", "companyCodeSys01PUR02");
      itemController.addLookup2ParentLink("itemCodeITM01", "itemCodeItm01PUR02");
      itemController.addLookup2ParentLink("descriptionSYS10", "descriptionSYS10");
      itemController.setAllColumnVisible(false);
      itemController.setVisibleColumn("itemCodeITM01", true);
      itemController.setVisibleColumn("descriptionSYS10", true);
      itemController.setPreferredWidthColumn("descriptionSYS10", 200);
      new CustomizedColumns(ApplicationConsts.ID_ITEMS_GRID, itemController);
      itemController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {
              GridItemVO vo = (GridItemVO) itemController.getLookupVO();
              if (vo.getItemCodeITM01() != null) {
                SupplierItemVO supplierVO = (SupplierItemVO) parentVO;
                supplierVO.setSupplierItemCodePUR02(vo.getItemCodeITM01());
              }
            }

            public void beforeLookupAction(ValueObject parentVO) {}

            public void forceValidate() {}
          });

      // purchase um lookup...
      umDataLocator.setGridMethodName("loadMeasures");
      umDataLocator.setValidationMethodName("validateMeasureCode");
      colUmCode.setLookupController(umController);
      colUmCode.setControllerMethodName("getMeasureUnitsList");
      umController.setLookupDataLocator(umDataLocator);
      umController.setFrameTitle("measures");
      umController.setLookupValueObjectClassName("org.jallinone.registers.measure.java.MeasureVO");
      umController.addLookup2ParentLink("umCodeREG02", "umCodeReg02PUR02");
      umController.addLookup2ParentLink("decimalsREG02", "decimalsREG02");
      umController.setAllColumnVisible(false);
      umController.setVisibleColumn("umCodeREG02", true);
      umController.setVisibleColumn("decimalsREG02", true);
      new CustomizedColumns(ApplicationConsts.ID_UM_GRID, umController);
      umController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {
              MeasureVO vo = (MeasureVO) umController.getLookupVO();
              if (vo.getUmCodeREG02() != null) {
                colMinQty.setDecimals(vo.getDecimalsREG02().intValue());
                colMultipleQty.setDecimals(vo.getDecimalsREG02().intValue());
                SupplierItemVO supplierVO = (SupplierItemVO) parentVO;
                if (supplierVO.getMinPurchaseQtyPUR02() != null)
                  supplierVO.setMinPurchaseQtyPUR02(
                      supplierVO
                          .getMinPurchaseQtyPUR02()
                          .setScale(vo.getDecimalsREG02().intValue(), BigDecimal.ROUND_HALF_UP));
                if (supplierVO.getMultipleQtyPUR02() != null)
                  supplierVO.setMultipleQtyPUR02(
                      supplierVO
                          .getMultipleQtyPUR02()
                          .setScale(vo.getDecimalsREG02().intValue(), BigDecimal.ROUND_HALF_UP));
              }
            }

            public void beforeLookupAction(ValueObject parentVO) {}

            public void forceValidate() {}
          });

      itemsGrid.setController(new SupplierItemsController(this));
      itemsGrid.setGridDataLocator(itemsGridDataLocator);
      itemsGridDataLocator.setServerMethodName("loadSupplierItems");

      treePanel.addHierarTreeListener(
          new HierarTreeListener() {

            public void loadDataCompleted(boolean error) {
              if (treePanel.getTree().getRowCount() > 0) treePanel.getTree().setSelectionRow(0);
              if (treePanel.getTree().getSelectionPath() != null)
                controller.leftClick(
                    (DefaultMutableTreeNode)
                        treePanel.getTree().getSelectionPath().getLastPathComponent());
            }
          });

      treePanel.setTreeController(controller);
      treePanel.setFunctionId("PUR01");

      init();

      itemsGrid.enableDrag(ApplicationConsts.ID_SUPPLIER_ITEMS_GRID.toString());

      // debit account code lookup...
      controlDebitsCode.setLookupController(debitController);
      controlDebitsCode.setControllerMethodName("getAccounts");
      debitController.setLookupDataLocator(debitDataLocator);
      debitDataLocator.setGridMethodName("loadAccounts");
      debitDataLocator.setValidationMethodName("validateAccountCode");
      debitController.setFrameTitle("accounts");
      debitController.setAllowTreeLeafSelectionOnly(false);
      debitController.setLookupValueObjectClassName(
          "org.jallinone.accounting.accounts.java.AccountVO");
      debitController.addLookup2ParentLink("accountCodeACC02", "debitAccountCodeAcc02PUR01");
      debitController.addLookup2ParentLink("descriptionSYS10", "debitAccountDescrPUR01");
      debitController.setFramePreferedSize(new Dimension(400, 400));
      debitController.setAllColumnVisible(false);
      debitController.setVisibleColumn("accountCodeACC02", true);
      debitController.setVisibleColumn("descriptionSYS10", true);
      debitController.setFilterableColumn("accountCodeACC02", true);
      debitController.setFilterableColumn("descriptionSYS10", true);
      debitController.setSortedColumn("accountCodeACC02", "ASC", 1);
      debitController.setSortableColumn("accountCodeACC02", true);
      debitController.setSortableColumn("descriptionSYS10", true);
      debitController.setPreferredWidthColumn("accountCodeACC02", 100);
      debitController.setPreferredWidthColumn("descriptionSYS10", 290);
      debitController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {}

            public void beforeLookupAction(ValueObject parentVO) {
              debitDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
              debitDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
            }

            public void forceValidate() {}
          });

      // costs account code lookup...
      controlCostsCode.setLookupController(costsController);
      controlCostsCode.setControllerMethodName("getAccounts");
      costsController.setLookupDataLocator(costsDataLocator);
      costsDataLocator.setGridMethodName("loadAccounts");
      costsDataLocator.setValidationMethodName("validateAccountCode");
      costsController.setFrameTitle("accounts");
      costsController.setAllowTreeLeafSelectionOnly(false);
      costsController.setLookupValueObjectClassName(
          "org.jallinone.accounting.accounts.java.AccountVO");
      costsController.addLookup2ParentLink("accountCodeACC02", "costsAccountCodeAcc02PUR01");
      costsController.addLookup2ParentLink("descriptionSYS10", "costsAccountDescrPUR01");
      costsController.setFramePreferedSize(new Dimension(400, 400));
      costsController.setAllColumnVisible(false);
      costsController.setVisibleColumn("accountCodeACC02", true);
      costsController.setVisibleColumn("descriptionSYS10", true);
      costsController.setFilterableColumn("accountCodeACC02", true);
      costsController.setFilterableColumn("descriptionSYS10", true);
      costsController.setSortedColumn("accountCodeACC02", "ASC", 1);
      costsController.setSortableColumn("accountCodeACC02", true);
      costsController.setSortableColumn("descriptionSYS10", true);
      costsController.setPreferredWidthColumn("accountCodeACC02", 100);
      costsController.setPreferredWidthColumn("descriptionSYS10", 290);
      costsController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {}

            public void beforeLookupAction(ValueObject parentVO) {
              costsDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
              costsDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
            }

            public void forceValidate() {}
          });

      CustomizedControls customizedControls =
          new CustomizedControls(tabbedPane, supplierPanel, ApplicationConsts.ID_SUPPLIER_GRID);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #11
0
  /**
   * Analyze class fields and fill in "voSetterMethods","voGetterMethods","indexes",reverseIndexes"
   * attributes.
   *
   * @param prefix e.g. "attrx.attry."
   * @param parentMethods getter methods of parent v.o.
   * @param classType class to analyze
   */
  private void analyzeClassFields(String prefix, Method[] parentMethods, Class classType) {
    try {
      if (prefix.split("\\.").length > ClientSettings.MAX_NR_OF_LOOPS_IN_ANALYZE_VO) return;

      // retrieve all getter and setter methods defined in the specified value object...
      String attributeName = null;
      Method[] methods = classType.getMethods();
      String aName = null;
      for (int i = 0; i < methods.length; i++) {
        attributeName = methods[i].getName();

        if (attributeName.startsWith("get")
            && methods[i].getParameterTypes().length == 0
            && ValueObject.class.isAssignableFrom(methods[i].getReturnType())) {
          aName = getAttributeName(attributeName, classType);
          Method[] newparentMethods = new Method[parentMethods.length + 1];
          System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length);
          newparentMethods[parentMethods.length] = methods[i];
          analyzeClassFields(prefix + aName + ".", newparentMethods, methods[i].getReturnType());
        }

        if (attributeName.startsWith("get")
            && methods[i].getParameterTypes().length == 0
            && (methods[i].getReturnType().equals(String.class)
                || methods[i].getReturnType().equals(Long.class)
                || methods[i].getReturnType().equals(Long.TYPE)
                || methods[i].getReturnType().equals(Float.class)
                || methods[i].getReturnType().equals(Float.TYPE)
                || methods[i].getReturnType().equals(Short.class)
                || methods[i].getReturnType().equals(Short.TYPE)
                || methods[i].getReturnType().equals(Double.class)
                || methods[i].getReturnType().equals(Double.TYPE)
                || methods[i].getReturnType().equals(BigDecimal.class)
                || methods[i].getReturnType().equals(java.util.Date.class)
                || methods[i].getReturnType().equals(java.sql.Date.class)
                || methods[i].getReturnType().equals(java.sql.Timestamp.class)
                || methods[i].getReturnType().equals(Integer.class)
                || methods[i].getReturnType().equals(Integer.TYPE)
                || methods[i].getReturnType().equals(Character.class)
                || methods[i].getReturnType().equals(Boolean.class)
                || methods[i].getReturnType().equals(boolean.class)
                || methods[i].getReturnType().equals(ImageIcon.class)
                || methods[i].getReturnType().equals(Icon.class)
                || methods[i].getReturnType().equals(byte[].class)
                || methods[i].getReturnType().equals(Object.class)
                || ValueObject.class.isAssignableFrom(methods[i].getReturnType()))) {
          attributeName = getAttributeName(attributeName, classType);
          //          try {
          //            if
          // (classType.getMethod("set"+attributeName.substring(0,1).toUpperCase()+attributeName.substring(1),new Class[]{methods[i].getReturnType()})!=null)
          Method[] newparentMethods = new Method[parentMethods.length + 1];
          System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length);
          newparentMethods[parentMethods.length] = methods[i];
          voGetterMethods.put(prefix + attributeName, newparentMethods);
          //          } catch (NoSuchMethodException ex) {
          //          }
        } else if (attributeName.startsWith("is")
            && methods[i].getParameterTypes().length == 0
            && (methods[i].getReturnType().equals(Boolean.class)
                || methods[i].getReturnType().equals(boolean.class))) {
          attributeName = getAttributeName(attributeName, classType);
          Method[] newparentMethods = new Method[parentMethods.length + 1];
          System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length);
          newparentMethods[parentMethods.length] = methods[i];
          voGetterMethods.put(prefix + attributeName, newparentMethods);
        } else if (attributeName.startsWith("set") && methods[i].getParameterTypes().length == 1) {
          attributeName = getAttributeName(attributeName, classType);
          try {
            if (classType.getMethod(
                    "get"
                        + attributeName.substring(0, 1).toUpperCase()
                        + attributeName.substring(1),
                    new Class[0])
                != null) {
              Method[] newparentMethods = new Method[parentMethods.length + 1];
              System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length);
              newparentMethods[parentMethods.length] = methods[i];
              voSetterMethods.put(prefix + attributeName, newparentMethods);
            }
          } catch (NoSuchMethodException ex) {
            try {
              if (classType.getMethod(
                      "is"
                          + attributeName.substring(0, 1).toUpperCase()
                          + attributeName.substring(1),
                      new Class[0])
                  != null) {
                Method[] newparentMethods = new Method[parentMethods.length + 1];
                System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length);
                newparentMethods[parentMethods.length] = methods[i];
                voSetterMethods.put(prefix + attributeName, newparentMethods);
              }
            } catch (NoSuchMethodException exx) {
            }
          }
        }
      }

      // fill in indexes with the colProperties indexes first; after them, it will be added the
      // other indexes (of attributes not mapped with grid column...)
      HashSet alreadyAdded = new HashSet();
      int i = 0;
      for (i = 0; i < colProperties.length; i++) {
        indexes.put(new Integer(i), colProperties[i].getColumnName());
        reverseIndexes.put(colProperties[i].getColumnName(), new Integer(i));
        alreadyAdded.add(colProperties[i].getColumnName());
      }
      Enumeration en = voGetterMethods.keys();
      while (en.hasMoreElements()) {
        attributeName = en.nextElement().toString();
        if (!alreadyAdded.contains(attributeName)) {
          indexes.put(new Integer(i), attributeName);
          reverseIndexes.put(attributeName, new Integer(i));
          i++;
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #12
0
  /**
   * @param obj ValueObject where updating the value for the specified attribute (identified by
   *     colunm index)
   * @param attributeName attribute name
   * @param value new Object to set onto ValueObject
   */
  public final void setField(ValueObject obj, String attributeName, Object value) {
    try {
      Method[] getter = ((Method[]) voGetterMethods.get(attributeName));
      Method[] setter = ((Method[]) voSetterMethods.get(attributeName));
      if (getter == null)
        Logger.error(
            this.getClass().getName(),
            "setField",
            "No getter method for attribute name '" + attributeName + "'.",
            null);
      if (setter == null)
        Logger.error(
            this.getClass().getName(),
            "setField",
            "No setter method for attribute name '" + attributeName + "'.",
            null);

      if (value != null
          && (value instanceof Number || !value.equals("") && value instanceof String)) {
        if (!getter[getter.length - 1].getReturnType().equals(value.getClass())) {
          Class attrType = getter[getter.length - 1].getReturnType();
          if (attrType.equals(Integer.class) || attrType.equals(Integer.TYPE))
            value = new Integer(Double.valueOf(value.toString()).intValue());
          else if (attrType.equals(Double.class) || attrType.equals(Double.TYPE))
            value = new Double(value.toString());
          else if (attrType.equals(BigDecimal.class)) value = new BigDecimal(value.toString());
          else if (attrType.equals(Long.class) || attrType.equals(Long.TYPE))
            value = new Long(Double.valueOf(value.toString()).longValue());
          else if (attrType.equals(Short.class) || attrType.equals(Short.TYPE))
            value = new Short(Double.valueOf(value.toString()).shortValue());
          else if (attrType.equals(Float.class) || attrType.equals(Float.TYPE))
            value = new Float(Double.valueOf(value.toString()).floatValue());
        }
      } else if (value != null && value.equals("")) {
        if (!getter[getter.length - 1].getReturnType().equals(value.getClass())) value = null;
      }
      // test date compatibility...
      if (value != null && value.getClass().equals(java.util.Date.class)) {
        if (setter[setter.length - 1].getParameterTypes()[0].equals(java.sql.Date.class))
          value = new java.sql.Date(((java.util.Date) value).getTime());
        else if (setter[setter.length - 1].getParameterTypes()[0].equals(java.sql.Timestamp.class))
          value = new java.sql.Timestamp(((java.util.Date) value).getTime());
      }

      // retrieve inner v.o.: if not present then maybe create it, according to "createInnerVO"
      // property...
      Method[] m = (Method[]) voGetterMethods.get(attributeName);
      if (m == null)
        Logger.error(
            this.getClass().getName(),
            "setField",
            "No getter method for attribute name '" + attributeName + "'.",
            null);
      Object oldObj = obj;
      String auxAttr;
      for (int i = 0; i < m.length - 1; i++) {
        oldObj = obj;
        obj = (ValueObject) m[i].invoke(oldObj, new Object[0]);
        if (obj == null) {
          if (grids.getGridControl() == null || !grids.getGridControl().isCreateInnerVO()) return;
          else {
            obj = (ValueObject) m[i].getReturnType().newInstance();
            String[] attrs = attributeName.split("\\.");

            auxAttr = "";
            for (int k = 0; k <= i; k++) auxAttr += attrs[k] + ".";
            auxAttr = auxAttr.substring(0, auxAttr.length() - 1);
            Method aux = ((Method[]) voSetterMethods.get(auxAttr))[i];
            aux.invoke(oldObj, new Object[] {obj});
          }
        }
      }

      // avoid to set null for primitive types!
      if (value == null && setter[setter.length - 1].getParameterTypes()[0].equals(Long.TYPE))
        setter[setter.length - 1].invoke(obj, new Object[] {new Long(0)});
      if (value == null && setter[setter.length - 1].getParameterTypes()[0].equals(Integer.TYPE))
        setter[setter.length - 1].invoke(obj, new Object[] {new Integer(0)});
      if (value == null && setter[setter.length - 1].getParameterTypes()[0].equals(Short.TYPE))
        setter[setter.length - 1].invoke(obj, new Object[] {new Short((short) 0)});
      if (value == null && setter[setter.length - 1].getParameterTypes()[0].equals(Float.TYPE))
        setter[setter.length - 1].invoke(obj, new Object[] {new Float(0)});
      if (value == null && setter[setter.length - 1].getParameterTypes()[0].equals(Double.TYPE))
        setter[setter.length - 1].invoke(obj, new Object[] {new Double(0)});
      if (value == null && setter[setter.length - 1].getParameterTypes()[0].equals(Boolean.TYPE))
        setter[setter.length - 1].invoke(obj, new Object[] {Boolean.FALSE});
      else setter[setter.length - 1].invoke(obj, new Object[] {value});
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }