void dynDepartament() {
    KeyNamePair cat = (KeyNamePair) categoryCombo.getSelectedItem();
    departmentCombo.removeActionListener(this);
    departmentCombo.removeAllItems();

    String sql = "SELECT XX_VMR_DEPARTMENT_ID, VALUE||'-'||NAME " + " FROM XX_VMR_DEPARTMENT ";

    if (cat != null && cat.getKey() != -1) {
      sql += " WHERE XX_VMR_CATEGORY_ID = " + cat.getKey();
    }
    sql += " ORDER BY VALUE||'-'||NAME ";
    sql = MRole.getDefault().addAccessSQL(sql, "", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();

      departmentCombo.addItem(new KeyNamePair(-1, null));
      while (rs.next()) {
        departmentCombo.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
      }
      rs.close();
      pstmt.close();

      departmentCombo.addActionListener(this);
      departmentCombo.setEnabled(true);
      departmentCombo.setEditable(true);
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  }
Ejemplo n.º 2
0
  /** Dynanmic Init & fill fields - Called when Country changes! */
  private void initLocation() {
    // Kenos
    fCity.setPreferredSize(new Dimension(225, 25));
    fCountry.setPreferredSize(new Dimension(225, 25));
    //

    MCountry country = m_location.getCountry();
    log.fine(
        country.getName()
            + ", Region="
            + country.isHasRegion()
            + " "
            + country.getDisplaySequence()
            + ", C_Location_ID="
            + m_location.getC_Location_ID());
    //	new Region
    if (m_location.getC_Country_ID() != s_oldCountry_ID && country.isHasRegion()) {
      fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), country.getC_Country_ID()));
      if (m_location.getRegion() != null) fRegion.setSelectedItem(m_location.getRegion());
      /*else
      	if(m_location.getCountry().getC_Country_ID() == 139 && m_location.getAD_Org_ID() != 0){
      		int C_Location_ID = MOrgInfo.get(Env.getCtx(),m_location.getAD_Org_ID()).getC_Location_ID();
      		if (C_Location_ID != 0)
      		{
      			MLocation location =
      				new MLocation(Env.getCtx(), C_Location_ID, null);
      			MRegion region = new MRegion(Env.getCtx(), location.getC_Region_ID(), null);
      			fRegion.setSelectedItem(region);
      			m_location.setRegion(region);
      			//	refrseh
      			fRegion.requestFocus();	//	allows to use Keybord selection
      		}
      	}
      */
      // Kenos
      fRegion.addActionListener(this);
      //
      lRegion.setText(country.getRegionName());
      s_oldCountry_ID = m_location.getC_Country_ID();
    }
    // Kenos// Faire
    if (m_location.getCountry().isHasRegion()
        && m_location.getRegion() != null
        && m_location.getCountry().getC_Country_ID() == 139) // 139 = Brasil
    {
      fCity.setEditable(false);
      fCity.removeAllItems();
      fCity = new CComboBox(getCCity());
      if (m_location.getC_City_ID() != 0)
        fCity.setSelectedItem(new MCity(Env.getCtx(), m_location.getC_City_ID(), null));
    } else {
      fCity.removeAllItems();
      fCity.setEditable(true);
      fCity.setSelectedItem(m_location.getCity());
    }
    // Kenos

    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridy = 0; // 	line
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.insets = fieldInsets;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0;
    gbc.weighty = 0;

    mainPanel.add(Box.createVerticalStrut(5), gbc); // 	top gap

    int line = 1;
    addLine(line++, lAddress1, fAddress1);
    addLine(line++, lAddress2, fAddress2);
    addLine(line++, lAddress3, fAddress3);
    addLine(line++, lAddress4, fAddress4);

    //  sequence of City Postal Region - @P@ @C@ - @C@, @R@ @P@
    String ds = country.getDisplaySequence();
    if (ds == null || ds.length() == 0) {
      log.log(Level.SEVERE, "DisplaySequence empty - " + country);
      ds = ""; // 	@C@,  @P@
    }
    StringTokenizer st = new StringTokenizer(ds, "@", false);
    while (st.hasMoreTokens()) {
      String s = st.nextToken();
      if (s.startsWith("C")) addLine(line++, lCity, fCity);
      else if (s.startsWith("P")) addLine(line++, lPostal, fPostal);
      else if (s.startsWith("A")) addLine(line++, lPostalAdd, fPostalAdd);
      else if (s.startsWith("R") && m_location.getCountry().isHasRegion())
        addLine(line++, lRegion, fRegion);
    }
    //  Country Last
    addLine(line++, lCountry, fCountry);

    //	Fill it
    if (m_location.getC_Location_ID() != 0) {
      fAddress1.setText(m_location.getAddress1());
      fAddress2.setText(m_location.getAddress2());
      fAddress3.setText(m_location.getAddress3());
      fAddress4.setText(m_location.getAddress4());
      // fCity.setText(m_location.getCity()); - Kenos (linha comentada)
      fPostal.setText(m_location.getPostal());
      fPostalAdd.setText(m_location.getPostal_Add());
      if (m_location.getCountry().isHasRegion()) {
        lRegion.setText(m_location.getCountry().getRegionName());
        fRegion.setSelectedItem(m_location.getRegion());
      }
      fCountry.setSelectedItem(country);
    }

    //	Update UI
    pack();
  } //	initLocation