use of org.compiere.grid.ed.CityVO in project adempiere by adempiere.
the class WAutoCompleterCity method fillList.
public void fillList() {
// Carlos Ruiz - globalqss - improve to avoid going to the database on every keystroke
m_cities.clear();
m_citiesShow.clear();
ArrayList<Object> params = new ArrayList<Object>();
final StringBuffer sql = new StringBuffer("SELECT cy.C_City_ID, cy.Name, cy.C_Region_ID, r.Name" + " FROM C_City cy" + " LEFT OUTER JOIN C_Region r ON (r.C_Region_ID=cy.C_Region_ID)" + " WHERE cy.AD_Client_ID IN (0,?)");
params.add(getAD_Client_ID());
if (getC_Region_ID() > 0) {
sql.append(" AND cy.C_Region_ID=?");
params.add(getC_Region_ID());
}
if (getC_Country_ID() > 0) {
sql.append(" AND cy.C_Country_ID=?");
params.add(getC_Country_ID());
}
sql.append(" ORDER BY cy.Name, r.Name");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql.toString(), null);
DB.setParameters(pstmt, params);
rs = pstmt.executeQuery();
int i = 0;
while (rs.next()) {
CityVO vo = new CityVO(rs.getInt(1), rs.getString(2), rs.getInt(3), rs.getString(4));
m_cities.add(vo);
if (i <= m_maxRows) {
m_citiesShow.add(vo);
} else if (i == m_maxRows + 1 && i > 0) {
m_citiesShow.add(ITEM_More);
}
i++;
}
} catch (SQLException e) {
throw new DBException(e, sql.toString());
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
refreshData("");
}
use of org.compiere.grid.ed.CityVO in project adempiere by adempiere.
the class WAutoCompleterCity method refreshData.
public void refreshData(String val) {
String search = val;
if (m_city != null && m_city.CityName.compareTo(search) != 0) {
setCity(null);
}
m_citiesShow.clear();
this.removeAllItems();
this.setDict(null);
this.setDescription(null);
boolean truncated = false;
search = search.toUpperCase();
int i = 0;
for (CityVO vo : m_cities) {
if (vo.CityName.toUpperCase().startsWith(search)) {
if (i > 0 && i == m_maxRows + 1) {
m_citiesShow.add(ITEM_More);
truncated = true;
break;
}
m_citiesShow.add(vo);
i++;
}
}
//if there is no city on the list return false, to not show the popup
if (m_citiesShow.isEmpty()) {
return;
} else {
CityVO city = (CityVO) m_citiesShow.get(0);
if (city.CityName.equalsIgnoreCase(search)) {
m_city = city;
return;
}
}
//return false to not show any popup
if (!truncated && m_citiesShow.size() == 1 && m_city != null && m_citiesShow.get(0).equals(this.m_city)) {
return;
}
String[] cityValues = new String[m_citiesShow.size()];
String[] cityDesc = new String[m_citiesShow.size()];
i = 0;
for (CityVO vo : m_citiesShow) {
cityValues[i] = vo.CityName;
cityDesc[i] = vo.RegionName;
i++;
}
//
this.removeAllItems();
this.setDict(cityValues);
this.setDescription(cityDesc);
}
use of org.compiere.grid.ed.CityVO in project adempiere by adempiere.
the class WAutoCompleterCity method onEvent.
public void onEvent(Event event) throws Exception {
System.out.println("Event: " + event.getName());
event.toString();
int index = this.getSelectedIndex();
System.out.println("Index = " + index);
if (index >= 0) {
CityVO city = (CityVO) m_citiesShow.get(index);
if (event == null || city.equals(ITEM_More)) {
setCity(null);
return;
}
setCity(city);
Env.setContext(Env.getCtx(), m_windowNo, Env.TAB_INFO, "C_Region_ID", String.valueOf(city.C_Region_ID));
this.setText(city.CityName);
}
}
Aggregations