Search in sources :

Example 16 with MCountry

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

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