use of org.compiere.model.MCountry in project adempiere by adempiere.
the class LocationTag method getCountries.
// doEndTag
/**
* Get Country Options.
* Add Regions for selected country
* Set Default
* @param loc MLocation
* @param C_Country_ID default country
* @return array of country options
*/
private option[] getCountries(MLocation loc, int C_Country_ID) {
MCountry[] countries = MCountry.getCountries(loc.getCtx());
option[] options = new option[countries.length];
m_country = null;
//
for (int i = 0; i < countries.length; i++) {
options[i] = new option(String.valueOf(countries[i].getC_Country_ID()));
options[i].addElement(Util.maskHTML(countries[i].getName()));
if (countries[i].getC_Country_ID() == C_Country_ID) {
m_country = countries[i];
options[i].setSelected(true);
}
}
//
return options;
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class WLocation method getCountry.
// fillform
/**
* Get Country Pick-List
*
* @param location location model
* @param ws window status
* @return Select Field with Countries
*/
private select getCountry(MLocation location, WWindowStatus ws) {
MCountry[] countries = MCountry.getCountries(location.getCtx());
int comp = location.getC_Country_ID();
if (comp == 0)
comp = Env.getContextAsInt(ws.ctx, "C_Country_ID");
option[] options = new option[countries.length];
for (int i = 0; i < countries.length; i++) {
options[i] = new option(String.valueOf(countries[i].getC_Country_ID()));
options[i].addElement(countries[i].getName());
if (comp == countries[i].getC_Country_ID())
options[i].setSelected(true);
}
select select = new select(P_C_COUNTRY_ID, options);
return select;
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class WLocationDialog method getCurrentLocation.
/**
* Get edited Value (MLocation)
* @return location
*/
private String getCurrentLocation() {
m_location.setAddress1(txtAddress1.getText());
m_location.setAddress2(txtAddress2.getText());
m_location.setAddress3(txtAddress3.getText());
m_location.setAddress4(txtAddress4.getText());
m_location.setCity(txtCity.getText());
m_location.setPostal(txtPostal.getText());
m_location.setPostal_Add(txtPostalAdd.getText());
// Country/Region
MCountry c = (MCountry) lstCountry.getSelectedItem().getValue();
m_location.setCountry(c);
if (m_location.getCountry().isHasRegion()) {
MRegion r = (MRegion) lstRegion.getSelectedItem().getValue();
m_location.setRegion(r);
} else
m_location.setC_Region_ID(0);
return m_location.toString().replace(" ", "%");
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class WLocationDialog method action_OK.
/**
* OK - check for changes (save them) & Exit
*/
private boolean action_OK() {
m_location.setAddress1(txtAddress1.getValue());
m_location.setAddress2(txtAddress2.getValue());
m_location.setAddress3(txtAddress3.getValue());
m_location.setAddress4(txtAddress4.getValue());
m_location.setC_City_ID(txtCity.getC_City_ID());
m_location.setCity(txtCity.getValue());
m_location.setPostal(txtPostal.getValue());
// Country/Region
MCountry country = (MCountry) lstCountry.getSelectedItem().getValue();
m_location.setCountry(country);
if (country.isHasRegion() && lstRegion.getSelectedItem() != null) {
MRegion r = (MRegion) lstRegion.getSelectedItem().getValue();
m_location.setRegion(r);
} else {
m_location.setC_Region_ID(0);
}
// Save chnages
if (m_location.save()) {
return true;
} else {
return false;
}
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class WLocationDialog method onEvent.
public void onEvent(Event event) throws Exception {
if (btnOk.equals(event.getTarget())) {
inOKAction = true;
if (m_location.getCountry().isHasRegion() && lstRegion.getSelectedItem() == null) {
if (txtCity.getC_Region_ID() > 0 && txtCity.getC_Region_ID() != m_location.getC_Region_ID()) {
m_location.setRegion(MRegion.get(Env.getCtx(), txtCity.getC_Region_ID()));
setRegion();
}
}
String msg = validate_OK();
if (msg != null) {
FDialog.error(0, this, "FillMandatory", Msg.parseTranslation(Env.getCtx(), msg));
inOKAction = false;
return;
}
if (action_OK()) {
m_change = true;
inOKAction = false;
this.dispose();
} else {
FDialog.error(0, this, "CityNotFound");
}
inOKAction = false;
} else if (btnCancel.equals(event.getTarget())) {
m_change = false;
this.dispose();
} else // Country Changed - display in new Format
if (lstCountry.equals(event.getTarget())) {
inCountryAction = true;
MCountry c = (MCountry) lstCountry.getSelectedItem().getValue();
m_location.setCountry(c);
m_location.setC_City_ID(0);
m_location.setCity(null);
// refresh
initLocation();
inCountryAction = false;
} else // Region Changed
if (lstRegion.equals(event.getTarget())) {
if (inCountryAction || inOKAction)
return;
MRegion r = (MRegion) lstRegion.getSelectedItem().getValue();
m_location.setRegion(r);
m_location.setC_City_ID(0);
m_location.setCity(null);
// refresh
initLocation();
} else if (btnUrl.equals(event.getTarget())) {
Env.startBrowser(DefaultContextProvider.GOOGLE_MAPS_URL_PREFIX + getCurrentLocation());
m_change = false;
this.dispose();
}
}
Aggregations