Search in sources :

Example 11 with MRegion

use of org.compiere.model.MRegion 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 12 with MRegion

use of org.compiere.model.MRegion 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 13 with MRegion

use of org.compiere.model.MRegion 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)

Example 14 with MRegion

use of org.compiere.model.MRegion in project adempiere by adempiere.

the class WLocationDialog method initLocation.

private void initLocation() {
    if (mainPanel.getRows() != null)
        mainPanel.getRows().getChildren().clear();
    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 (m_location.getC_Country_ID() != s_oldCountry_ID) {
        lstRegion.getChildren().clear();
        if (country.isHasRegion()) {
            lstRegion.appendItem("", null);
            for (MRegion region : MRegion.getRegions(Env.getCtx(), country.getC_Country_ID())) {
                lstRegion.appendItem(region.getName(), region);
            }
            if (m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName) != null && m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName).trim().length() > 0)
                lblRegion.setValue(m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName));
            else
                lblRegion.setValue(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()) {
        setRegion();
    } else {
        lstRegion.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()));
    txtCity.fillList();
    //      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
            addComponents((Row) lstCountry.getParent());
        // TODO: Add Online
        // if (m_location.getCountry().isPostcodeLookup()) {
        // addLine(line++, lOnline, fOnline);
        // }
        } else if (s.startsWith("A1")) {
            addComponents((Row) txtAddress1.getParent());
            isAddress1Mandatory = s.endsWith("!");
        } else if (s.startsWith("A2")) {
            addComponents((Row) txtAddress2.getParent());
            isAddress2Mandatory = s.endsWith("!");
        } else if (s.startsWith("A3")) {
            addComponents((Row) txtAddress3.getParent());
            isAddress3Mandatory = s.endsWith("!");
        } else if (s.startsWith("A4")) {
            addComponents((Row) txtAddress4.getParent());
            isAddress4Mandatory = s.endsWith("!");
        } else if (s.startsWith("C")) {
            addComponents((Row) txtCity.getParent());
            isCityMandatory = s.endsWith("!");
        } else if (s.startsWith("P")) {
            addComponents((Row) txtPostal.getParent());
            isPostalMandatory = s.endsWith("!");
        } else if (s.startsWith("A")) {
            addComponents((Row) txtPostalAdd.getParent());
            isPostalAddMandatory = s.endsWith("!");
        } else if (s.startsWith("R") && m_location.getCountry().isHasRegion()) {
            addComponents((Row) lstRegion.getParent());
            isRegionMandatory = s.endsWith("!");
        }
    }
    //      Fill it
    if (m_location.getC_Location_ID() != 0) {
        txtAddress1.setText(m_location.getAddress1());
        txtAddress2.setText(m_location.getAddress2());
        txtAddress3.setText(m_location.getAddress3());
        txtAddress4.setText(m_location.getAddress4());
        txtCity.setText(m_location.getCity());
        txtPostal.setText(m_location.getPostal());
        txtPostalAdd.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)
                lblRegion.setValue(m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName));
            else
                lblRegion.setValue(Msg.getMsg(Env.getCtx(), "Region"));
            setRegion();
        }
        setCountry();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) MCountry(org.compiere.model.MCountry) Row(org.adempiere.webui.component.Row) MRegion(org.compiere.model.MRegion)

Aggregations

MRegion (org.compiere.model.MRegion)14 MCountry (org.compiere.model.MCountry)9 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)3 StringTokenizer (java.util.StringTokenizer)2 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)2 Postcode (com.akunagroup.uk.postcode.Postcode)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 HttpSession (javax.servlet.http.HttpSession)1 Row (org.adempiere.webui.component.Row)1 MLocation (org.compiere.model.MLocation)1 CComboBoxEditable (org.compiere.swing.CComboBoxEditable)1 LookupValue (pl.x3E.adInterface.LookupValue)1 LookupValues (pl.x3E.adInterface.LookupValues)1