Search in sources :

Example 11 with MCountry

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;
}
Also used : MCountry(org.compiere.model.MCountry) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 12 with MCountry

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;
}
Also used : MCountry(org.compiere.model.MCountry) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 13 with MCountry

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(" ", "%");
}
Also used : MCountry(org.compiere.model.MCountry) MRegion(org.compiere.model.MRegion)

Example 14 with MCountry

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;
    }
}
Also used : MCountry(org.compiere.model.MCountry) MRegion(org.compiere.model.MRegion)

Example 15 with MCountry

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();
    }
}
Also used : MCountry(org.compiere.model.MCountry) MRegion(org.compiere.model.MRegion)

Aggregations

MCountry (org.compiere.model.MCountry)16 MRegion (org.compiere.model.MRegion)9 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)3 Properties (java.util.Properties)2 StringTokenizer (java.util.StringTokenizer)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)2 MCurrency (org.compiere.model.MCurrency)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ServletException (javax.servlet.ServletException)1 HttpSession (javax.servlet.http.HttpSession)1 Row (org.adempiere.webui.component.Row)1 MCity (org.compiere.model.MCity)1 MLanguage (org.compiere.model.MLanguage)1 MLocation (org.compiere.model.MLocation)1 MSetup (org.compiere.model.MSetup)1 Query (org.compiere.model.Query)1