diff --git a/org.adempiere.base/src/org/compiere/model/MLocation.java b/org.adempiere.base/src/org/compiere/model/MLocation.java index 0f246b335e..9f518b6a75 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLocation.java @@ -49,7 +49,7 @@ public class MLocation extends X_C_Location implements Comparator /** * */ - private static final long serialVersionUID = 8556443338866862468L; + private static final long serialVersionUID = 7655032871533297438L; //BEGIN fernandinho/ricardo - http://jira.idempiere.com/browse/IDEMPIERE-147 public static String LOCATION_MAPS_URL_PREFIX = MSysConfig.getValue("LOCATION_MAPS_URL_PREFIX"); @@ -656,5 +656,24 @@ public class MLocation extends X_C_Location implements Comparator + " OR C_LocTo_ID=" + getC_Location_ID() + ")", get_TrxName()); return success; } // afterSave - + + /** + * Get edited Value (MLocation) for GoogleMaps + * @author Fernandinho/Ricardo + * @param MLocation location + * @return String address + */ + public String getGoogleMapsLocation() { + + MRegion region = new MRegion(Env.getCtx(), getC_Region_ID(), get_TrxName()); + String address = ""; + address = address + (getAddress1() != null ? getAddress1() + ", " : ""); + address = address + (getAddress2() != null ? getAddress2() + ", " : ""); + address = address + (getCity() != null ? getCity() + ", " : ""); + address = address + (region.getName() != null ? region.getName() + ", " : ""); + address = address + (getCountryName() != null ? getCountryName() : ""); + + return address.replace(" ", "+"); + } + } // MLocation diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java index a8124b1ddd..b885867839 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java @@ -23,7 +23,6 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.net.URL; import java.util.HashMap; import java.util.Iterator; import java.util.Set; @@ -483,12 +482,11 @@ public class VLocationDialog extends CDialog //BEGIN fernandinho/ricardo else if (e.getSource() == toLink) { - String urlString = MLocation.LOCATION_MAPS_URL_PREFIX + getGoogleMapsLocation(m_location); + String urlString = MLocation.LOCATION_MAPS_URL_PREFIX + m_location.getGoogleMapsLocation(); String message = null; try { - new URL(urlString); Env.startBrowser(urlString); } catch (Exception ex) @@ -505,12 +503,11 @@ public class VLocationDialog extends CDialog MLocation orgLocation = new MLocation(Env.getCtx(),orgInfo.getC_Location_ID(),null); String urlString = MLocation.LOCATION_MAPS_ROUTE_PREFIX + - MLocation.LOCATION_MAPS_SOURCE_ADDRESS + getGoogleMapsLocation(orgLocation) + //org - MLocation.LOCATION_MAPS_DESTINATION_ADDRESS + getGoogleMapsLocation(m_location); //partner + MLocation.LOCATION_MAPS_SOURCE_ADDRESS + orgLocation.getGoogleMapsLocation() + //org + MLocation.LOCATION_MAPS_DESTINATION_ADDRESS + m_location.getGoogleMapsLocation(); //partner String message = null; try { - new URL(urlString); Env.startBrowser(urlString); } catch (Exception ex) @@ -764,24 +761,5 @@ public class VLocationDialog extends CDialog } } - - /** - * Get edited Value (MLocation) for GoogleMaps - * @author Fernandinho/Ricardo - * @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(" ", "+"); - } } // VLocationDialog diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java index 8b03370fbc..2239feba28 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java @@ -21,6 +21,7 @@ package org.adempiere.webui.window; +import java.net.URI; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; @@ -38,10 +39,13 @@ import org.adempiere.webui.component.Textbox; import org.adempiere.webui.component.Window; import org.compiere.model.MCountry; import org.compiere.model.MLocation; +import org.compiere.model.MOrgInfo; import org.compiere.model.MRegion; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.zkoss.zhtml.A; +import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -58,14 +62,16 @@ import org.zkoss.zk.ui.event.Events; * https://sourceforge.net/tracker/?func=detail&aid=2995212&group_id=176962&atid=955896 * * @TODO: Implement fOnline button present in swing client - * + * @contributors - Carlos Ruiz / globalqss + * - Show GoogleMap on Location Dialog (integrate approach from Fernandinho) + * - http://jira.idempiere.com/browse/IDEMPIERE-147 **/ public class WLocationDialog extends Window implements EventListener { /** * */ - private static final long serialVersionUID = 6892969005447776082L; + private static final long serialVersionUID = -8511642461845783366L; private static final String LABEL_STYLE = "white-space: nowrap;"; /** Logger */ private static CLogger log = CLogger.getCLogger(WLocationDialog.class); @@ -113,6 +119,15 @@ public class WLocationDialog extends Window implements EventListener private boolean inCountryAction; private boolean inOKAction; + /** The "route" key */ + private static final String TO_ROUTE = Msg.getMsg(Env.getCtx(), "Route"); + /** The "to link" key */ + private static final String TO_LINK = Msg.getMsg(Env.getCtx(), "Map"); + + private Button toLink; + private Button toRoute; + //END + public WLocationDialog(String title, MLocation location) { m_location = location; @@ -224,6 +239,11 @@ public class WLocationDialog extends Window implements EventListener btnCancel.setImage("/images/Cancel16.png"); btnCancel.addEventListener(Events.ON_CLICK,this); + toLink = new Button(TO_LINK); + toLink.addEventListener(Events.ON_CLICK,this); + toRoute = new Button(TO_ROUTE); + toRoute.addEventListener(Events.ON_CLICK,this); + mainPanel = GridFactory.newGridLayout(); mainPanel.setStyle("padding:5px"); } @@ -266,6 +286,16 @@ public class WLocationDialog extends Window implements EventListener pnlCountry.appendChild(lblCountry.rightAlign()); pnlCountry.appendChild(lstCountry); + Panel pnlLinks = new Panel(); + pnlLinks.appendChild(toLink); + if (MLocation.LOCATION_MAPS_URL_PREFIX == null) + toLink.setVisible(false); + pnlLinks.appendChild(toRoute); + if (MLocation.LOCATION_MAPS_ROUTE_PREFIX == null) + toRoute.setVisible(false); + pnlLinks.setWidth("100%"); + pnlLinks.setStyle("text-align:left"); + Panel pnlButton = new Panel(); pnlButton.appendChild(btnOk); pnlButton.appendChild(btnCancel); @@ -273,6 +303,8 @@ public class WLocationDialog extends Window implements EventListener pnlButton.setStyle("text-align:right"); this.appendChild(mainPanel); + if (MLocation.LOCATION_MAPS_URL_PREFIX != null || MLocation.LOCATION_MAPS_ROUTE_PREFIX != null) + this.appendChild(pnlLinks); this.appendChild(pnlButton); } /** @@ -496,6 +528,38 @@ public class WLocationDialog extends Window implements EventListener m_change = false; this.dispose(); } + else if (toLink.equals(event.getTarget())) + { + String urlString = MLocation.LOCATION_MAPS_URL_PREFIX + m_location.getGoogleMapsLocation(); + String message = null; + try { + Executions.getCurrent().sendRedirect(urlString, "_blank"); + } + catch (Exception e) { + message = e.getMessage(); + FDialog.warn(0, this, "URLnotValid", message); + } + } + else if (toRoute.equals(event.getTarget())) + { + 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 = MLocation.LOCATION_MAPS_ROUTE_PREFIX + + MLocation.LOCATION_MAPS_SOURCE_ADDRESS + orgLocation.getGoogleMapsLocation() + //org + MLocation.LOCATION_MAPS_DESTINATION_ADDRESS + m_location.getGoogleMapsLocation(); //partner + String message = null; + try { + Executions.getCurrent().sendRedirect(urlString, "_blank"); + } + catch (Exception e) { + message = e.getMessage(); + FDialog.warn(0, this, "URLnotValid", message); + } + } + } // Country Changed - display in new Format else if (lstCountry.equals(event.getTarget())) { @@ -601,4 +665,5 @@ public class WLocationDialog extends Window implements EventListener } super.dispose(); } + }