IDEMPIERE-147 GoogleMap to show Locators (Improvements)

* make it configurable (to allow using other services like yahoo, bing, mapquest
* use java6 syntax to open proper configured browser
* fix NPE found on CityAutoCompleter
* refactor constant definitions to use sysconfig and move to MLocation to reuse on zk webui
http://jira.idempiere.com/browse/IDEMPIERE-147
This commit is contained in:
Carlos Ruiz 2012-02-11 14:09:25 -05:00
parent 9ade9b5bfa
commit 4e7a7291d4
6 changed files with 111 additions and 61 deletions

View File

@ -0,0 +1,46 @@
-- Feb 11, 2012 12:12:21 PM COT
-- IDEMPIERE-147 GoogleMap to show Locators
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200004,'D','S','LOCATION_MAPS_URL_PREFIX','http://local.google.com/maps?q=','URL to indicate the preferred maps service',0,0,TO_DATE('2012-02-11 12:12:19','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2012-02-11 12:12:19','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:13:04 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200005,'D','S','LOCATION_MAPS_ROUTE_PREFIX','http://maps.google.com/maps?f=d&geocode=','URL to indicate the preferred maps routing service',0,0,TO_DATE('2012-02-11 12:13:03','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2012-02-11 12:13:03','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:13:50 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200006,'D','S','LOCATION_MAPS_SOURCE_ADDRESS','&saddr=','Prefix for source address used by the preferred maps routing service',0,0,TO_DATE('2012-02-11 12:13:49','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2012-02-11 12:13:49','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:14:07 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200007,'D','S','LOCATION_MAPS_DESTINATION_ADDRESS','&daddr=','Prefix for destination address used by the preferred maps routing service',0,0,TO_DATE('2012-02-11 12:14:07','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2012-02-11 12:14:07','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:14:42 PM COT
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,Value,IsActive,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,Created,UpdatedBy) VALUES ('I','Map',200001,'D','Map','Y',TO_DATE('2012-02-11 12:14:41','YYYY-MM-DD HH24:MI:SS'),0,0,100,TO_DATE('2012-02-11 12:14:41','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Feb 11, 2012 12:14:42 PM COT
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200001 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Feb 11, 2012 12:14:50 PM COT
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Mapa',Updated=TO_DATE('2012-02-11 12:14:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=200001 AND AD_Language LIKE 'es%'
;
-- Feb 11, 2012 12:15:06 PM COT
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,Value,IsActive,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,Created,UpdatedBy) VALUES ('I','Route',200002,'D','Route','Y',TO_DATE('2012-02-11 12:15:05','YYYY-MM-DD HH24:MI:SS'),0,0,100,TO_DATE('2012-02-11 12:15:05','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Feb 11, 2012 12:15:06 PM COT
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200002 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Feb 11, 2012 12:15:12 PM COT
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Ruta',Updated=TO_DATE('2012-02-11 12:15:12','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=200002 AND AD_Language LIKE 'es%'
;
UPDATE AD_System
SET LastMigrationScriptApplied='817_IDEMPIERE-147.sql'
WHERE LastMigrationScriptApplied<'817_IDEMPIERE-147.sql'
OR LastMigrationScriptApplied IS NULL
;

View File

@ -0,0 +1,46 @@
-- Feb 11, 2012 12:12:21 PM COT
-- IDEMPIERE-147 GoogleMap to show Locators
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200004,'D','S','LOCATION_MAPS_URL_PREFIX','http://local.google.com/maps?q=','URL to indicate the preferred maps service',0,0,TO_TIMESTAMP('2012-02-11 12:12:19','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2012-02-11 12:12:19','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:13:04 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200005,'D','S','LOCATION_MAPS_ROUTE_PREFIX','http://maps.google.com/maps?f=d&geocode=','URL to indicate the preferred maps routing service',0,0,TO_TIMESTAMP('2012-02-11 12:13:03','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2012-02-11 12:13:03','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:13:50 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200006,'D','S','LOCATION_MAPS_SOURCE_ADDRESS','&saddr=','Prefix for source address used by the preferred maps routing service',0,0,TO_TIMESTAMP('2012-02-11 12:13:49','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2012-02-11 12:13:49','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:14:07 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Name,Value,Description,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive) VALUES (200007,'D','S','LOCATION_MAPS_DESTINATION_ADDRESS','&daddr=','Prefix for destination address used by the preferred maps routing service',0,0,TO_TIMESTAMP('2012-02-11 12:14:07','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2012-02-11 12:14:07','YYYY-MM-DD HH24:MI:SS'),100,100,'Y')
;
-- Feb 11, 2012 12:14:42 PM COT
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,Value,IsActive,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,Created,UpdatedBy) VALUES ('I','Map',200001,'D','Map','Y',TO_TIMESTAMP('2012-02-11 12:14:41','YYYY-MM-DD HH24:MI:SS'),0,0,100,TO_TIMESTAMP('2012-02-11 12:14:41','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Feb 11, 2012 12:14:42 PM COT
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200001 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Feb 11, 2012 12:14:50 PM COT
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Mapa',Updated=TO_TIMESTAMP('2012-02-11 12:14:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=200001 AND AD_Language LIKE 'es%'
;
-- Feb 11, 2012 12:15:06 PM COT
INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,Value,IsActive,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,Created,UpdatedBy) VALUES ('I','Route',200002,'D','Route','Y',TO_TIMESTAMP('2012-02-11 12:15:05','YYYY-MM-DD HH24:MI:SS'),0,0,100,TO_TIMESTAMP('2012-02-11 12:15:05','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Feb 11, 2012 12:15:06 PM COT
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200002 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;
-- Feb 11, 2012 12:15:12 PM COT
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Ruta',Updated=TO_TIMESTAMP('2012-02-11 12:15:12','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=200002 AND AD_Language LIKE 'es%'
;
UPDATE AD_System
SET LastMigrationScriptApplied='817_IDEMPIERE-147.sql'
WHERE LastMigrationScriptApplied<'817_IDEMPIERE-147.sql'
OR LastMigrationScriptApplied IS NULL
;

View File

@ -49,8 +49,13 @@ public class MLocation extends X_C_Location implements Comparator
/**
*
*/
private static final long serialVersionUID = -1326655776792201217L;
private static final long serialVersionUID = 8556443338866862468L;
//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_ROUTE_PREFIX = MSysConfig.getValue("LOCATION_MAPS_ROUTE_PREFIX");
public static String LOCATION_MAPS_SOURCE_ADDRESS = MSysConfig.getValue("LOCATION_MAPS_SOURCE_ADDRESS");
public static String LOCATION_MAPS_DESTINATION_ADDRESS = MSysConfig.getValue("LOCATION_MAPS_DESTINATION_ADDRESS");
/**
* Get Location from Cache

View File

@ -30,55 +30,11 @@ public class DefaultContextProvider implements ContextProvider {
private static Properties s_ctx = new Properties();
private static String UNIX_BROWSER = "netscape";
private static String MAC_BROWSER = "open";
public Properties getContext() {
return s_ctx;
}
public void showURL(String url) {
/* JAVA5 */
if (!Ini.isClient()) return;
// OS command
String cmd = "rundll32 url.dll,FileProtocolHandler ";
if (!Env.isWindows()){
if(Env.isMac())
cmd = MAC_BROWSER + " ";
else
cmd = UNIX_BROWSER + " ";
}
//
String execute = cmd + url;
try
{
Runtime.getRuntime().exec(execute);
return;
}
catch (Exception e)
{
if (Env.isWindows())
s_log.severe(execute + " - " + e);
}
//try firefox
if (!Env.isWindows() && !("firefox".equals(UNIX_BROWSER)))
{
UNIX_BROWSER = "firefox";
cmd = UNIX_BROWSER + " ";
execute = cmd + url;
try
{
Runtime.getRuntime().exec(execute);
}
catch (Exception e)
{
s_log.severe(execute + " - " + e);
}
}
/* JAVA6 *
try {
java.net.URI uri = new java.net.URI(url);
java.awt.Desktop.getDesktop().browse(uri);
@ -86,7 +42,6 @@ public class DefaultContextProvider implements ContextProvider {
catch (Exception e) {
s_log.warning(e.getLocalizedMessage());
}
/**/
}
}

View File

@ -228,7 +228,7 @@ public class CityAutoCompleter extends AutoCompleter
public void mouseClicked(MouseEvent e)
{
if(e == null || listBox.getSelectedValue().equals(ITEM_More))
if (e == null || listBox == null || listBox.getSelectedValue() == null || listBox.getSelectedValue().equals(ITEM_More))
{
setCity(null);
return;

View File

@ -79,7 +79,7 @@ public class VLocationDialog extends CDialog
/**
*
*/
private static final long serialVersionUID = 6952838437136830975L;
private static final long serialVersionUID = -5915071456635949972L;
/** Lookup result header */
private Object[] header = null;
@ -194,16 +194,10 @@ public class VLocationDialog extends CDialog
private boolean inCountryAction;
private boolean inOKAction;
//BEGIN fernandinho/ricardo - http://jira.idempiere.com/browse/IDEMPIERE-147
public static String GOOGLE_MAPS_URL_PREFIX = "http://local.google.com/maps?q=";
public static String GOOGLE_MAPS_ROUTE_PREFIX = "http://maps.google.com/maps?f=d&geocode=";
public static String GOOGLE_SOURCE_ADDRESS = "&saddr=";
public static String GOOGLE_DESTINATION_ADDRESS = "&daddr=";
/** The "route" key */
private static final String TO_ROUTE = "Route";
private static final String TO_ROUTE = Msg.getMsg(Env.getCtx(), "Route");
/** The "to link" key */
private static final String TO_LINK = "Map";
private static final String TO_LINK = Msg.getMsg(Env.getCtx(), "Map");
private JButton toLink = new JButton();
private JButton toRoute = new JButton();
@ -230,11 +224,15 @@ public class VLocationDialog extends CDialog
toLink.addActionListener(this);
toLink.setMargin(ConfirmPanel.s_insets);
confirmPanel.addComponent(toLink);
if (MLocation.LOCATION_MAPS_URL_PREFIX == null)
toLink.setVisible(false);
toRoute.setText(TO_ROUTE);
toRoute.addActionListener(this);
toRoute.setMargin(ConfirmPanel.s_insets);
confirmPanel.addComponent(toRoute);
if (MLocation.LOCATION_MAPS_ROUTE_PREFIX == null)
toRoute.setVisible(false);
//END
//
@ -485,7 +483,7 @@ public class VLocationDialog extends CDialog
//BEGIN fernandinho/ricardo
else if (e.getSource() == toLink)
{
String urlString = GOOGLE_MAPS_URL_PREFIX + getGoogleMapsLocation(m_location);
String urlString = MLocation.LOCATION_MAPS_URL_PREFIX + getGoogleMapsLocation(m_location);
String message = null;
try
@ -506,9 +504,9 @@ public class VLocationDialog extends CDialog
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 urlString = MLocation.LOCATION_MAPS_ROUTE_PREFIX +
MLocation.LOCATION_MAPS_SOURCE_ADDRESS + getGoogleMapsLocation(orgLocation) + //org
MLocation.LOCATION_MAPS_DESTINATION_ADDRESS + getGoogleMapsLocation(m_location); //partner
String message = null;
try
{