Пример #1
0
  /**
   * Get edited Value (MLocation) for GoogleMaps
   *
   * @param MLocation location
   * @return String address
   */
  private String getGoogleMapsLocation(MLocation location) {

    MRegion region = new MRegion(Env.getCtx(), location.getC_Region_ID(), null);
    String address = "";
    address = address + (location.getAddress1() != null ? location.getAddress1() + ", " : "");
    address = address + (location.getAddress2() != null ? location.getAddress2() + ", " : "");
    address = address + (location.getCity() != null ? location.getCity() + ", " : "");
    address = address + (region.getName() != null ? region.getName() + ", " : "");
    address = address + (location.getCountryName() != null ? location.getCountryName() : "");

    return address.replace(" ", "+");
  }
Пример #2
0
 /**
  * Get Country (cached)
  *
  * @param ctx context
  * @param C_Region_ID ID
  * @return Country
  */
 public static MRegion get(Ctx ctx, int C_Region_ID) {
   if (s_regions.isEmpty()) loadAllRegions(ctx);
   String key = String.valueOf(C_Region_ID);
   MRegion r = s_regions.get(ctx, key);
   if (r != null) return r;
   r = new MRegion(ctx, C_Region_ID, null);
   if (r.getC_Region_ID() == C_Region_ID) {
     s_regions.put(key, r);
     return r;
   }
   return null;
 } //	get
Пример #3
0
 /**
  * Return Array of Regions of Country
  *
  * @param ctx context
  * @param C_Country_ID country
  * @return MRegion Array
  */
 public static MRegion[] getRegions(Ctx ctx, int C_Country_ID) {
   if (s_regions.isEmpty()) loadAllRegions(ctx);
   ArrayList<MRegion> list = new ArrayList<MRegion>();
   Iterator<MRegion> it = s_regions.values().iterator();
   while (it.hasNext()) {
     MRegion r = it.next();
     if (r.getC_Country_ID() == C_Country_ID) list.add(r);
   }
   //  Sort it
   MRegion[] retValue = new MRegion[list.size()];
   list.toArray(retValue);
   Arrays.sort(retValue, new MRegion(ctx, 0, null));
   return retValue;
 } //	getRegions
Пример #4
0
  /**
   * Load Regions (cached)
   *
   * @param ctx context
   */
  private static void loadAllRegions(Ctx ctx) {
    String sql = "SELECT * FROM C_Region WHERE IsActive='Y'";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, (Trx) null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        MRegion r = new MRegion(ctx, rs, null);
        s_regions.put(String.valueOf(r.getC_Region_ID()), r);
        if (r.isDefault()) s_default = r;
      }
    } catch (SQLException e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }

    s_log.fine(s_regions.size() + " - default=" + s_default);
  } //	loadAllRegions
Пример #5
0
  /** OK - check for changes (save them) & Exit */
  private void 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()); Kenos (linha comentada)
    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);
      m_location.setRegionName(r.getName());
    } else {
      m_location.setC_Region_ID(0);
      m_location.setRegionName(null);
    }

    // BEGIN fernandom @ faire.com.br
    // SET C_City_ID
    if (fCity.getSelectedItem() != null) {
      Object oo = fCity.getSelectedItem();
      if (oo instanceof MCity) {
        MCity city = (MCity) fCity.getSelectedItem();
        m_location.setC_City_ID(city.getC_City_ID());
        m_location.setCity(city.getName());
      } else {
        m_location.setCity((String) fCity.getSelectedItem()); // Kenos
        m_location.setC_City_ID(0);
      }
    }
    // END

    //	Save changes
    m_location.set_TrxName(null);
    m_location.save();
  } //	actionOK
Пример #6
0
  /**
   * Constructor
   *
   * @param frame parent
   * @param title title (field name)
   * @param location Model Location
   */
  public VLocationDialog(Frame frame, String title, MLocation location) {
    super(frame, title, true);
    try {
      jbInit();
    } catch (Exception ex) {
      log.log(Level.SEVERE, ex.getMessage());
    }
    m_location = location;
    if (m_location == null) {
      m_location = m_tempLocation;
    }

    //	Overwrite title
    if (m_location.getC_Location_ID() == 0) setTitle(Msg.getMsg(Env.getCtx(), "LocationNew"));
    else setTitle(Msg.getMsg(Env.getCtx(), "LocationUpdate"));

    //	Current Country
    // MCountry.setDisplayLanguage(Env.getAD_Language(Env.getCtx()));
    fCountry = new CComboBox(MCountry.getCountries(Env.getCtx()));
    fCountry.setSelectedItem(m_location.getCountry());
    m_origCountry_ID = m_location.getC_Country_ID();
    //	Current Region
    fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), m_origCountry_ID));
    if (m_location.getCountry().isHasRegion())
      lRegion.setText(m_location.getCountry().getRegionName()); // 	name for region
    fRegion.setSelectedItem(m_location.getRegion());

    // Kenos - Faire
    //	Current City
    if (m_location.getC_Region_ID() != 0) {
      fCity = new CComboBox(getCCity());
      fCity.setSelectedItem(new MCity(Env.getCtx(), m_location.getC_City_ID(), null));
    } else fCity = new CComboBox();

    //
    initLocation();
    fCountry.addActionListener(this);
    // Kenos
    fRegion.addActionListener(this);
    //
    AEnv.positionCenterWindow(frame, this);
  } //	VLocationDialog
Пример #7
0
  /**
   * ActionListener
   *
   * @param e ActionEvent
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
      if (fAddress1.isMandatory() && ((((String) fAddress1.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else if (fAddress2.isMandatory() && ((((String) fAddress2.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else if (fAddress3.isMandatory() && ((((String) fAddress3.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else if (fPostal.isMandatory() && ((((String) fPostal.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else {
        action_OK();
        m_change = true;
        dispose();
      }
    } else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
      m_change = false;
      dispose();
    } else if (e.getSource() == fCountry) {
      //	Country Changed - display in new Format
      //	Modifier for Mouse selection is 16  - for any key selection 0
      MCountry c = (MCountry) fCountry.getSelectedItem();
      m_location.setCountry(c);
      //	refrseh
      mainPanel.removeAll();
      initLocation();
      fCountry.requestFocus(); // 	allows to use Keybord selection
    }
    // Kenos
    else if (e.getSource() == fRegion) {
      //	Modifier for Mouse selection is 16  - for any key selection 0
      MRegion r = (MRegion) fRegion.getSelectedItem();
      m_location.setRegion(r);
      //	refrseh
      mainPanel.removeAll();
      initLocation();
      fRegion.requestFocus(); // 	allows to use Keybord selection
    }
    // Kenos
    else if (e.getSource() == toLink) {
      String urlString = GOOGLE_MAPS_URL_PREFIX + getGoogleMapsLocation(m_location);
      String message = null;

      try {
        new URL(urlString);
        Env.startBrowser(urlString);
      } catch (Exception ex) {
        message = ex.getMessage();
        ADialog.warn(0, this, "URLnotValid", message);
      }
    } else if (e.getSource() == toRoute) {
      int AD_Org_ID = Env.getAD_Org_ID(Env.getCtx());
      if (AD_Org_ID != 0) {
        MOrgInfo orgInfo = MOrgInfo.get(Env.getCtx(), AD_Org_ID, null);
        MLocation orgLocation = new MLocation(Env.getCtx(), orgInfo.getC_Location_ID(), null);

        String urlString =
            GOOGLE_MAPS_ROUTE_PREFIX
                + GOOGLE_SOURCE_ADDRESS
                + getGoogleMapsLocation(orgLocation)
                + // org
                GOOGLE_DESTINATION_ADDRESS
                + getGoogleMapsLocation(m_location); // partner
        String message = null;
        try {
          new URL(urlString);
          Env.startBrowser(urlString);
        } catch (Exception ex) {
          message = ex.getMessage();
          ADialog.warn(0, this, "URLnotValid", message);
        }
      }
    } else if (e.getSource() == getAddress) {
      if (fPostal != null && !fPostal.getText().equals("")) {
        if (!fAddress1.getText().equals("")
            || !fAddress2.getText().equals("")
            || !fAddress3.getText().equals("")
            || !fAddress4.getText().equals("")
            || fCity.getSelectedIndex() > 0) {
          String warningMsg = "O endereço atual será substituido. Deseja continuar?";
          String warningTitle = "Aviso";
          int response =
              JOptionPane.showConfirmDialog(
                  null, warningMsg, warningTitle, JOptionPane.YES_NO_OPTION);
          if (response == JOptionPane.NO_OPTION) return;
        }

        WebServiceCep cep = WebServiceCep.searchCep(fPostal.getText());
        if (cep.wasSuccessful()) {
          MRegion[] regions = MRegion.getRegions(Env.getCtx(), 139);
          for (MRegion r : regions)
            if (r.getName() != null && r.getName().equals(cep.getUf())) {
              fRegion.setSelectedItem(r);
              break;
            }
          fCity.setSelectedItem(cep.getCidade());
          fAddress1.setText(cep.getLogradouroType() + " " + cep.getLogradouro());
          fAddress3.setText(cep.getBairro());
          if (cep.getCep().length() == 8)
            fPostal.setText(cep.getCep().substring(0, 5) + "-" + cep.getCep().substring(5));
          else fPostal.setText(cep.getCep());
        } else if (cep.getResulCode() == 0)
          JOptionPane.showMessageDialog(null, "CEP não encontrado na base de dados.");
        else if (cep.getResulCode() == 14)
          JOptionPane.showMessageDialog(
              null, "Não foi possível fazer a busca. (Possível problema com a Internet).");
        else JOptionPane.showMessageDialog(null, "Erro ao fazer a busca.");
      } else JOptionPane.showMessageDialog(null, "Preencha o CEP.");
    }
  } //	actionPerformed
Пример #8
0
  /** Dynanmic Init & fill fields - Called when Country changes! */
  private void initLocation() {
    // Kenos
    fCity.setPreferredSize(new Dimension(225, 25));
    fCountry.setPreferredSize(new Dimension(225, 25));
    //

    MCountry country = m_location.getCountry();
    log.fine(
        country.getName()
            + ", Region="
            + country.isHasRegion()
            + " "
            + country.getDisplaySequence()
            + ", C_Location_ID="
            + m_location.getC_Location_ID());
    //	new Region
    if (m_location.getC_Country_ID() != s_oldCountry_ID && country.isHasRegion()) {
      fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), country.getC_Country_ID()));
      if (m_location.getRegion() != null) fRegion.setSelectedItem(m_location.getRegion());
      /*else
      	if(m_location.getCountry().getC_Country_ID() == 139 && m_location.getAD_Org_ID() != 0){
      		int C_Location_ID = MOrgInfo.get(Env.getCtx(),m_location.getAD_Org_ID()).getC_Location_ID();
      		if (C_Location_ID != 0)
      		{
      			MLocation location =
      				new MLocation(Env.getCtx(), C_Location_ID, null);
      			MRegion region = new MRegion(Env.getCtx(), location.getC_Region_ID(), null);
      			fRegion.setSelectedItem(region);
      			m_location.setRegion(region);
      			//	refrseh
      			fRegion.requestFocus();	//	allows to use Keybord selection
      		}
      	}
      */
      // Kenos
      fRegion.addActionListener(this);
      //
      lRegion.setText(country.getRegionName());
      s_oldCountry_ID = m_location.getC_Country_ID();
    }
    // Kenos// Faire
    if (m_location.getCountry().isHasRegion()
        && m_location.getRegion() != null
        && m_location.getCountry().getC_Country_ID() == 139) // 139 = Brasil
    {
      fCity.setEditable(false);
      fCity.removeAllItems();
      fCity = new CComboBox(getCCity());
      if (m_location.getC_City_ID() != 0)
        fCity.setSelectedItem(new MCity(Env.getCtx(), m_location.getC_City_ID(), null));
    } else {
      fCity.removeAllItems();
      fCity.setEditable(true);
      fCity.setSelectedItem(m_location.getCity());
    }
    // Kenos

    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridy = 0; // 	line
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.insets = fieldInsets;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0;
    gbc.weighty = 0;

    mainPanel.add(Box.createVerticalStrut(5), gbc); // 	top gap

    int line = 1;
    addLine(line++, lAddress1, fAddress1);
    addLine(line++, lAddress2, fAddress2);
    addLine(line++, lAddress3, fAddress3);
    addLine(line++, lAddress4, fAddress4);

    //  sequence of City Postal Region - @P@ @C@ - @C@, @R@ @P@
    String ds = country.getDisplaySequence();
    if (ds == null || ds.length() == 0) {
      log.log(Level.SEVERE, "DisplaySequence empty - " + country);
      ds = ""; // 	@C@,  @P@
    }
    StringTokenizer st = new StringTokenizer(ds, "@", false);
    while (st.hasMoreTokens()) {
      String s = st.nextToken();
      if (s.startsWith("C")) addLine(line++, lCity, fCity);
      else if (s.startsWith("P")) addLine(line++, lPostal, fPostal);
      else if (s.startsWith("A")) addLine(line++, lPostalAdd, fPostalAdd);
      else if (s.startsWith("R") && m_location.getCountry().isHasRegion())
        addLine(line++, lRegion, fRegion);
    }
    //  Country Last
    addLine(line++, lCountry, fCountry);

    //	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()); - Kenos (linha comentada)
      fPostal.setText(m_location.getPostal());
      fPostalAdd.setText(m_location.getPostal_Add());
      if (m_location.getCountry().isHasRegion()) {
        lRegion.setText(m_location.getCountry().getRegionName());
        fRegion.setSelectedItem(m_location.getRegion());
      }
      fCountry.setSelectedItem(country);
    }

    //	Update UI
    pack();
  } //	initLocation
Пример #9
0
 /**
  * Test / Load
  *
  * @param args
  */
 public static void main(String[] args) {
   Compiere.startup(true);
   /**
    * To add your regions, complete the code below. Please make sure that the file is converted via
    * the Java utility native2ascii - i.e. all seven bit code with /u0000 unicode stuff
    */
   int C_Country_ID = 216; // 	Japan
   MCountry country = new MCountry(Env.getCtx(), C_Country_ID, null);
   // Hokkaido
   MRegion temp = new MRegion(country, "\u5317\u6d77\u9053");
   temp.setDescription("\u5317\u6d77\u9053(Hokkaido)");
   temp.save();
   // Aomori
   temp = new MRegion(country, "\u9752\u68ee\u770c");
   temp.setDescription("\u9752\u68ee\u770c(Aomori)");
   temp.save();
   // Iwate
   temp = new MRegion(country, "\u5ca9\u624b\u770c");
   temp.setDescription("\u5ca9\u624b\u770c(Iwate)");
   temp.save();
   // Miyagi
   temp = new MRegion(country, "\u5bae\u57ce\u770c");
   temp.setDescription("\u5bae\u57ce\u770c(Miyagi)");
   temp.save();
   // Akita
   temp = new MRegion(country, "\u79cb\u7530\u770c");
   temp.setDescription("\u79cb\u7530\u770c(Akita)");
   temp.save();
   // Yamagata
   temp = new MRegion(country, "\u5c71\u5f62\u770c");
   temp.setDescription("\u5c71\u5f62\u770c(Yamagata)");
   temp.save();
   // Fukushima
   temp = new MRegion(country, "\u798f\u5cf6\u770c");
   temp.setDescription("\u798f\u5cf6\u770c(Fukushima)");
   temp.save();
   // Ibaraki
   temp = new MRegion(country, "\u8328\u57ce\u770c");
   temp.setDescription("\u8328\u57ce\u770c(Ibaraki)");
   temp.save();
   // Gunma
   temp = new MRegion(country, "\u7fa4\u99ac\u770c");
   temp.setDescription("\u7fa4\u99ac\u770c(Gunma)");
   temp.save();
   // Saitama
   temp = new MRegion(country, "\u57fc\u7389\u770c");
   temp.setDescription("\u57fc\u7389\u770c(Saitama)");
   temp.save();
   // Chiba
   temp = new MRegion(country, "\u5343\u8449\u770c");
   temp.setDescription("\u5343\u8449\u770c(Chiba)");
   temp.save();
   // Tokyo
   temp = new MRegion(country, "\u6771\u4eac\u90fd");
   temp.setDescription("\u6771\u4eac\u90fd(Tokyo)");
   temp.save();
   // Kanagawa
   temp = new MRegion(country, "\u795e\u5948\u5ddd\u770c");
   temp.setDescription("\u795e\u5948\u5ddd\u770c(Kanagawa)");
   temp.save();
   // Niigata
   temp = new MRegion(country, "\u65b0\u6f5f\u770c");
   temp.setDescription("\u65b0\u6f5f\u770c(Niigata)");
   temp.save();
   // Toyama
   temp = new MRegion(country, "\u5bcc\u5c71\u770c");
   temp.setDescription("\u5bcc\u5c71\u770c(Toyama)");
   temp.save();
   // Ishikawa
   temp = new MRegion(country, "\u77f3\u5ddd\u770c");
   temp.setDescription("\u77f3\u5ddd\u770c(Ishikawa)");
   temp.save();
   // Fukui
   temp = new MRegion(country, "\u798f\u4e95\u770c");
   temp.setDescription("\u798f\u4e95\u770c(Fukui)");
   temp.save();
   // Yamanashi
   temp = new MRegion(country, "\u5c71\u68a8\u770c");
   temp.setDescription("\u5c71\u68a8\u770c(Yamanashi)");
   temp.save();
   // Gifu
   temp = new MRegion(country, "\u5c90\u961c\u770c");
   temp.setDescription("\u5c90\u961c\u770c(Gifu)");
   temp.save();
   // Shizuoka
   temp = new MRegion(country, "\u9759\u5ca1\u770c");
   temp.setDescription("\u9759\u5ca1\u770c(Shizuoka)");
   temp.save();
   // Aichi
   temp = new MRegion(country, "\u611b\u77e5\u770c");
   temp.setDescription("\u611b\u77e5\u770c(Aichi)");
   temp.save();
   // Mie
   temp = new MRegion(country, "\u4e09\u91cd\u770c");
   temp.setDescription("\u4e09\u91cd\u770c(Mie)");
   temp.save();
   // Siga
   temp = new MRegion(country, "\u6ecb\u8cc0\u770c");
   temp.setDescription("\u6ecb\u8cc0\u770c(Siga)");
   temp.save();
   // Kyoto
   temp = new MRegion(country, "\u4eac\u90fd\u5e9c");
   temp.setDescription("\u4eac\u90fd\u5e9c(Kyoto)");
   temp.save();
   // Osaka
   temp = new MRegion(country, "\u5927\u962a\u5e9c");
   temp.setDescription("\u5927\u962a\u5e9c(Osaka)");
   temp.save();
   // Hyogo
   temp = new MRegion(country, "\u5175\u5eab\u770c");
   temp.setDescription("\u5175\u5eab\u770c(Hyogo)");
   temp.save();
   // Nara
   temp = new MRegion(country, "\u5948\u826f\u770c");
   temp.setDescription("\u5948\u826f\u770c(Nara)");
   temp.save();
   // Wakayama
   temp = new MRegion(country, "\u548c\u6b4c\u5c71\u770c");
   temp.setDescription("\u548c\u6b4c\u5c71\u770c(Wakayama)");
   temp.save();
   // Tottori
   temp = new MRegion(country, "\u9ce5\u53d6\u770c");
   temp.setDescription("\u9ce5\u53d6\u770c(Tottori)");
   temp.save();
   // Shimane
   temp = new MRegion(country, "\u5cf6\u6839\u770c");
   temp.setDescription("\u5cf6\u6839\u770c(Shimane)");
   temp.save();
   // Okayama
   temp = new MRegion(country, "\u5ca1\u5c71\u770c");
   temp.setDescription("\u5ca1\u5c71\u770c(Okayama)");
   temp.save();
   // Hiroshima
   temp = new MRegion(country, "\u5e83\u5cf6\u770c");
   temp.setDescription("\u5e83\u5cf6\u770c(Hiroshima)");
   temp.save();
   // Yamaguchi
   temp = new MRegion(country, "\u5c71\u53e3\u770c");
   temp.setDescription("\u5c71\u53e3\u770c(Yamaguchi)");
   temp.save();
   // Tokushima
   temp = new MRegion(country, "\u5fb3\u5cf6\u770c");
   temp.setDescription("\u5fb3\u5cf6\u770c(Tokushima)");
   temp.save();
   // Kagawa
   temp = new MRegion(country, "\u9999\u5ddd\u770c");
   temp.setDescription("\u9999\u5ddd\u770c(Kagawa)");
   temp.save();
   // Ehime
   temp = new MRegion(country, "\u611b\u5a9b\u770c");
   temp.setDescription("\u611b\u5a9b\u770c(Ehime)");
   temp.save();
   // Kouchi
   temp = new MRegion(country, "\u9ad8\u77e5\u770c");
   temp.setDescription("\u9ad8\u77e5\u770c(Kouchi)");
   temp.save();
   // Fukuoka
   temp = new MRegion(country, "\u798f\u5ca1\u770c");
   temp.setDescription("\u798f\u5ca1\u770c(Fukuoka)");
   temp.save();
   // Saga
   temp = new MRegion(country, "\u4f50\u8cc0\u770c");
   temp.setDescription("\u4f50\u8cc0\u770c(Saga)");
   temp.save();
   // Nagasaki
   temp = new MRegion(country, "\u9577\u5d0e\u770c");
   temp.setDescription("\u9577\u5d0e\u770c(Nagasaki)");
   temp.save();
   // Kumamoto
   temp = new MRegion(country, "\u718a\u672c\u770c");
   temp.setDescription("\u718a\u672c\u770c(Kumamoto)");
   temp.save();
   // Ohita
   temp = new MRegion(country, "\u5927\u5206\u770c");
   temp.setDescription("\u5927\u5206\u770c(Ohita)");
   temp.save();
   // Miyasaki
   temp = new MRegion(country, "\u5bae\u5d0e\u770c");
   temp.setDescription("\u5bae\u5d0e\u770c(Miyasaki)");
   temp.save();
   // Kagoshima
   temp = new MRegion(country, "\u9e7f\u5150\u5cf6\u770c");
   temp.setDescription("\u9e7f\u5150\u5cf6\u770c(Kagoshima)");
   temp.save();
   // Okinawa
   temp = new MRegion(country, "\u6c96\u7e04\u770c");
   temp.setDescription("\u6c96\u7e04\u770c(Okinawa)");
   temp.save();
 } //	main