IDEMPIERE-147 GoogleMap to show Locators (ZK)

* Implement same approach for zkwebui
http://jira.idempiere.com/browse/IDEMPIERE-147
This commit is contained in:
Carlos Ruiz 2012-02-11 14:11:49 -05:00
parent 4e7a7291d4
commit 42b25f7f8b
3 changed files with 91 additions and 29 deletions

View File

@ -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 //BEGIN fernandinho/ricardo - http://jira.idempiere.com/browse/IDEMPIERE-147
public static String LOCATION_MAPS_URL_PREFIX = MSysConfig.getValue("LOCATION_MAPS_URL_PREFIX"); 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()); + " OR C_LocTo_ID=" + getC_Location_ID() + ")", get_TrxName());
return success; return success;
} // afterSave } // 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 } // MLocation

View File

@ -23,7 +23,6 @@ import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -483,12 +482,11 @@ public class VLocationDialog extends CDialog
//BEGIN fernandinho/ricardo //BEGIN fernandinho/ricardo
else if (e.getSource() == toLink) 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; String message = null;
try try
{ {
new URL(urlString);
Env.startBrowser(urlString); Env.startBrowser(urlString);
} }
catch (Exception ex) catch (Exception ex)
@ -505,12 +503,11 @@ public class VLocationDialog extends CDialog
MLocation orgLocation = new MLocation(Env.getCtx(),orgInfo.getC_Location_ID(),null); MLocation orgLocation = new MLocation(Env.getCtx(),orgInfo.getC_Location_ID(),null);
String urlString = MLocation.LOCATION_MAPS_ROUTE_PREFIX + String urlString = MLocation.LOCATION_MAPS_ROUTE_PREFIX +
MLocation.LOCATION_MAPS_SOURCE_ADDRESS + getGoogleMapsLocation(orgLocation) + //org MLocation.LOCATION_MAPS_SOURCE_ADDRESS + orgLocation.getGoogleMapsLocation() + //org
MLocation.LOCATION_MAPS_DESTINATION_ADDRESS + getGoogleMapsLocation(m_location); //partner MLocation.LOCATION_MAPS_DESTINATION_ADDRESS + m_location.getGoogleMapsLocation(); //partner
String message = null; String message = null;
try try
{ {
new URL(urlString);
Env.startBrowser(urlString); Env.startBrowser(urlString);
} }
catch (Exception ex) 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 } // VLocationDialog

View File

@ -21,6 +21,7 @@
package org.adempiere.webui.window; package org.adempiere.webui.window;
import java.net.URI;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -38,10 +39,13 @@ import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.compiere.model.MCountry; import org.compiere.model.MCountry;
import org.compiere.model.MLocation; import org.compiere.model.MLocation;
import org.compiere.model.MOrgInfo;
import org.compiere.model.MRegion; import org.compiere.model.MRegion;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; 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.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; 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 * https://sourceforge.net/tracker/?func=detail&aid=2995212&group_id=176962&atid=955896
* *
* @TODO: Implement fOnline button present in swing client * @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 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;"; private static final String LABEL_STYLE = "white-space: nowrap;";
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(WLocationDialog.class); private static CLogger log = CLogger.getCLogger(WLocationDialog.class);
@ -113,6 +119,15 @@ public class WLocationDialog extends Window implements EventListener
private boolean inCountryAction; private boolean inCountryAction;
private boolean inOKAction; 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) public WLocationDialog(String title, MLocation location)
{ {
m_location = location; m_location = location;
@ -224,6 +239,11 @@ public class WLocationDialog extends Window implements EventListener
btnCancel.setImage("/images/Cancel16.png"); btnCancel.setImage("/images/Cancel16.png");
btnCancel.addEventListener(Events.ON_CLICK,this); 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 = GridFactory.newGridLayout();
mainPanel.setStyle("padding:5px"); mainPanel.setStyle("padding:5px");
} }
@ -266,6 +286,16 @@ public class WLocationDialog extends Window implements EventListener
pnlCountry.appendChild(lblCountry.rightAlign()); pnlCountry.appendChild(lblCountry.rightAlign());
pnlCountry.appendChild(lstCountry); 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(); Panel pnlButton = new Panel();
pnlButton.appendChild(btnOk); pnlButton.appendChild(btnOk);
pnlButton.appendChild(btnCancel); pnlButton.appendChild(btnCancel);
@ -273,6 +303,8 @@ public class WLocationDialog extends Window implements EventListener
pnlButton.setStyle("text-align:right"); pnlButton.setStyle("text-align:right");
this.appendChild(mainPanel); this.appendChild(mainPanel);
if (MLocation.LOCATION_MAPS_URL_PREFIX != null || MLocation.LOCATION_MAPS_ROUTE_PREFIX != null)
this.appendChild(pnlLinks);
this.appendChild(pnlButton); this.appendChild(pnlButton);
} }
/** /**
@ -496,6 +528,38 @@ public class WLocationDialog extends Window implements EventListener
m_change = false; m_change = false;
this.dispose(); 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 // Country Changed - display in new Format
else if (lstCountry.equals(event.getTarget())) else if (lstCountry.equals(event.getTarget()))
{ {
@ -601,4 +665,5 @@ public class WLocationDialog extends Window implements EventListener
} }
super.dispose(); super.dispose();
} }
} }