use of org.compiere.model.MRegion in project adempiere by adempiere.
the class WLocation method getRegion.
// getRegion
/**
* Get Region Pick-List
*
* @param location localion model
* @param ws window status
* @return Select field with Region
*/
private select getRegion(MLocation location, WWindowStatus ws) {
MRegion[] regions = MRegion.getRegions(location.getCtx(), location.getC_Country_ID());
int comp = location.getC_Region_ID();
if (comp == 0)
comp = Env.getContextAsInt(ws.ctx, "C_Region_ID");
option[] options = new option[regions.length];
for (int i = 0; i < regions.length; i++) {
options[i] = new option(String.valueOf(regions[i].getC_Region_ID()));
options[i].addElement(regions[i].getName());
if (comp == regions[i].getC_Region_ID())
options[i].setSelected(true);
}
select select = new select(P_C_REGION_ID, options);
return select;
}
use of org.compiere.model.MRegion in project adempiere by adempiere.
the class VLocationDialog method actionPerformed.
/**
* ActionListener
* @param e ActionEvent
*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
inOKAction = true;
if (m_location.getCountry().isHasRegion() && fRegion.getSelectedItem() == null) {
if (fCityAutoCompleter.getC_Region_ID() > 0 && fCityAutoCompleter.getC_Region_ID() != m_location.getC_Region_ID()) {
fRegion.setSelectedItem(MRegion.get(Env.getCtx(), fCityAutoCompleter.getC_Region_ID()));
m_location.setRegion(MRegion.get(Env.getCtx(), fCityAutoCompleter.getC_Region_ID()));
}
}
String msg = validate_OK();
if (msg != null) {
ADialog.error(0, this, "FillMandatory", Msg.parseTranslation(Env.getCtx(), msg));
inOKAction = false;
return;
}
if (action_OK()) {
m_change = true;
dispose();
} else {
ADialog.error(m_WindowNo, this, "CityNotFound");
}
inOKAction = false;
} else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
m_change = false;
dispose();
} else // Country Changed - display in new Format
if (e.getSource() == fCountry) {
inCountryAction = true;
// Modifier for Mouse selection is 16 - for any key selection 0
MCountry c = (MCountry) fCountry.getSelectedItem();
m_location.setCountry(c);
initLocation();
// allows to use Keyboard selection
fCountry.requestFocus();
inCountryAction = false;
} else // Region Changed
if (e.getSource() == fRegion) {
if (inCountryAction || inOKAction)
return;
MRegion r = (MRegion) fRegion.getSelectedItem();
m_location.setRegion(r);
m_location.setC_City_ID(0);
m_location.setCity(null);
initLocation();
// allows to use Keyboard selection
fRegion.requestFocus();
} else if (e.getSource() == fOnline) {
// check to see if we have a postcode lookup plugin for this country
MCountry c = (MCountry) fCountry.getSelectedItem();
if (c.isPostcodeLookup()) {
lookupPostcode(c, fPostal.getText());
}
} else if (e.getSource() == bUrl) {
Env.startBrowser(DefaultContextProvider.GOOGLE_MAPS_URL_PREFIX + getCurrentLocation());
}
}
use of org.compiere.model.MRegion in project adempiere by adempiere.
the class VLocationDialog method getCurrentLocation.
/**
* Get edited Value (MLocation)
* @return location
*/
private String getCurrentLocation() {
m_location.setAddress1(fAddress1.getText());
m_location.setAddress2(fAddress2.getText());
m_location.setAddress3(fAddress3.getText());
m_location.setAddress4(fAddress4.getText());
m_location.setCity(fCity.getText());
m_location.setPostal(fPostal.getText());
m_location.setPostal_Add(fPostalAdd.getText());
// Country/Region
MCountry c = (MCountry) fCountry.getSelectedItem();
m_location.setCountry(c);
if (m_location.getCountry().isHasRegion()) {
MRegion r = (MRegion) fRegion.getSelectedItem();
m_location.setRegion(r);
} else
m_location.setC_Region_ID(0);
return m_location.toString().replace(" ", "%");
}
use of org.compiere.model.MRegion in project adempiere by adempiere.
the class VLocationDialog method action_OK.
/**
* OK - check for changes (save them) & Exit
*/
private boolean action_OK() {
m_location.setAddress1(fAddress1.getText());
m_location.setAddress2(fAddress2.getText());
m_location.setAddress3(fAddress3.getText());
m_location.setAddress4(fAddress4.getText());
m_location.setCity(fCity.getText());
m_location.setC_City_ID(fCityAutoCompleter.getC_City_ID());
m_location.setPostal(fPostal.getText());
m_location.setPostal_Add(fPostalAdd.getText());
// Country/Region
MCountry c = (MCountry) fCountry.getSelectedItem();
m_location.setCountry(c);
if (m_location.getCountry().isHasRegion()) {
MRegion r = (MRegion) fRegion.getSelectedItem();
m_location.setRegion(r);
} else
m_location.setC_Region_ID(0);
// Save changes
if (m_location.save()) {
return true;
} else {
return false;
}
}
use of org.compiere.model.MRegion in project adempiere by adempiere.
the class VLocationDialog method initLocation.
// jbInit
/**
* Dynamic Init & fill fields - Called when Country changes!
*/
private void initLocation() {
MCountry country = m_location.getCountry();
log.fine(country.getName() + ", Region=" + country.isHasRegion() + " " + country.getCaptureSequence() + ", C_Location_ID=" + m_location.getC_Location_ID());
// new Country
if (country.getC_Country_ID() != s_oldCountry_ID) {
fRegion.removeAllItems();
if (country.isHasRegion()) {
for (MRegion region : MRegion.getRegions(Env.getCtx(), country.getC_Country_ID())) {
fRegion.addItem(region);
}
if (m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName) != null && m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName).trim().length() > 0)
lRegion.setText(m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName));
else
lRegion.setText(Msg.getMsg(Env.getCtx(), "Region"));
}
s_oldCountry_ID = m_location.getC_Country_ID();
}
if (m_location.getC_Region_ID() > 0 && m_location.getC_Region().getC_Country_ID() == country.getC_Country_ID()) {
fRegion.setSelectedItem(m_location.getC_Region());
} else {
fRegion.setSelectedItem(null);
m_location.setC_Region_ID(0);
}
if (country.isHasRegion() && m_location.getC_Region_ID() > 0) {
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_Region_ID", String.valueOf(m_location.getC_Region_ID()));
} else {
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_Region_ID", "0");
}
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_Country_ID", String.valueOf(country.get_ID()));
fCityAutoCompleter.fillList();
gbc.anchor = GridBagConstraints.NORTHWEST;
// line
gbc.gridy = 0;
gbc.gridx = 0;
gbc.gridwidth = 1;
gbc.insets = fieldInsets;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0;
gbc.weighty = 0;
mainPanel.removeAll();
// top gap
mainPanel.add(Box.createVerticalStrut(5), gbc);
int line = 1;
// sequence of City Postal Region - @P@ @C@ - @C@, @R@ @P@
String ds = country.getCaptureSequence();
if (ds == null || ds.length() == 0) {
log.log(Level.SEVERE, "CaptureSequence empty - " + country);
// @C@, @P@
ds = "";
}
isCityMandatory = false;
isRegionMandatory = false;
isAddress1Mandatory = false;
isAddress2Mandatory = false;
isAddress3Mandatory = false;
isAddress4Mandatory = false;
isPostalMandatory = false;
isPostalAddMandatory = false;
StringTokenizer st = new StringTokenizer(ds, "@", false);
while (st.hasMoreTokens()) {
String s = st.nextToken();
if (s.startsWith("CO")) {
// Country Last
addLine(line++, lCountry, fCountry);
// disable online if this country doesn't have post code lookup
if (m_location.getCountry().isPostcodeLookup()) {
addLine(line++, lOnline, fOnline);
}
} else if (s.startsWith("A1")) {
addLine(line++, lAddress1, fAddress1);
isAddress1Mandatory = s.endsWith("!");
} else if (s.startsWith("A2")) {
addLine(line++, lAddress2, fAddress2);
isAddress2Mandatory = s.endsWith("!");
} else if (s.startsWith("A3")) {
addLine(line++, lAddress3, fAddress3);
isAddress3Mandatory = s.endsWith("!");
} else if (s.startsWith("A4")) {
addLine(line++, lAddress4, fAddress4);
isAddress4Mandatory = s.endsWith("!");
} else if (s.startsWith("C")) {
addLine(line++, lCity, fCity);
isCityMandatory = s.endsWith("!");
} else if (s.startsWith("P")) {
addLine(line++, lPostal, fPostal);
isPostalMandatory = s.endsWith("!");
} else if (s.startsWith("A")) {
addLine(line++, lPostalAdd, fPostalAdd);
isPostalAddMandatory = s.endsWith("!");
} else if (s.startsWith("R") && m_location.getCountry().isHasRegion()) {
addLine(line++, lRegion, fRegion);
isRegionMandatory = s.endsWith("!");
}
}
// 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());
fPostal.setText(m_location.getPostal());
fPostalAdd.setText(m_location.getPostal_Add());
if (m_location.getCountry().isHasRegion()) {
if (m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName) != null && m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName).trim().length() > 0)
lRegion.setText(m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName));
else
lRegion.setText(Msg.getMsg(Env.getCtx(), "Region"));
fRegion.setSelectedItem(m_location.getRegion());
}
if (!fCountry.getSelectedItem().equals(country))
fCountry.setSelectedItem(country);
}
// Update UI
pack();
}
Aggregations