* Add hook to allow Env to work in a multi user environment, i.e servlet base UI

* Refactoring - move business logic code from AReport to MPrintFormat
This commit is contained in:
Heng Sin Low 2007-06-19 03:16:56 +00:00
parent 8691c4d36c
commit 6dd45a2ed6
4 changed files with 203 additions and 75 deletions

View File

@ -19,6 +19,10 @@ package org.compiere.print;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.sql.RowSet;
import javax.swing.JComponent;
import org.compiere.model.*;
import org.compiere.util.*;
@ -864,6 +868,41 @@ public class MPrintFormat extends X_AD_PrintFormat
}
//end vpj-cd e-evolution
/**
* @param AD_Table_ID
* @param AD_Client_ID use -1 to retrieve from all client
* @param trxName
*/
public static RowSet getAccessiblePrintFormats (int AD_Table_ID, int AD_Client_ID, String trxName)
{
RowSet rowSet = null;
String sql = "SELECT AD_PrintFormat_ID, Name, AD_Client_ID "
+ "FROM AD_PrintFormat "
+ "WHERE AD_Table_ID=? AND IsTableBased='Y' ";
if (AD_Client_ID >= 0)
{
sql = sql + " AND AD_Client_ID = ? ";
}
sql = sql + "ORDER BY AD_Client_ID DESC, IsDefault DESC, Name"; // Own First
//
sql = MRole.getDefault().addAccessSQL (
sql, "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
try
{
CPreparedStatement pstmt = DB.prepareStatement(sql, trxName);
pstmt.setInt(1, AD_Table_ID);
if (AD_Client_ID >= 0)
pstmt.setInt(2, AD_Client_ID);
rowSet = pstmt.getRowSet();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
}
return rowSet;
}
/**************************************************************************
* Test

View File

@ -0,0 +1,32 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*
* Copyright (C) 2007 Low Heng Sin hengsin@avantz.com
* _____________________________________________
*****************************************************************************/
package org.compiere.util;
import java.util.Properties;
/**
*
* @author Low Heng Sin
*
*/
public interface ContextProvider {
public Properties getContext();
public void showURL(String url);
}

View File

@ -0,0 +1,83 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*
* Copyright (C) 2007 Low Heng Sin hengsin@avantz.com
* _____________________________________________
*****************************************************************************/
package org.compiere.util;
import java.util.Properties;
/**
*
* @author Low Heng Sin
*
*/
public class DefaultContextProvider implements ContextProvider {
/** Logging */
private static CLogger s_log = CLogger.getCLogger(DefaultContextProvider.class);
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) {
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);
}
}
}
}

View File

@ -46,9 +46,13 @@ public final class Env
/** Logging */
private static CLogger s_log = CLogger.getCLogger(Env.class);
private static String UNIX_BROWSER = "netscape";
private static ContextProvider contextProvider = new DefaultContextProvider();
private static String MAC_BROWSER = "open";
public static void setContextProvider(ContextProvider provider)
{
contextProvider = provider;
getCtx().put(LANGUAGE, Language.getBaseAD_Language());
}
/**
* Exit System
@ -96,6 +100,8 @@ public final class Env
public static void reset (boolean finalCall)
{
s_log.info("finalCall=" + finalCall);
if (Ini.isClient())
{
closeWindows();
// Dismantle windows
@ -121,29 +127,32 @@ public final class Env
s_windows.clear();
}
}
}
// Clear all Context
if (finalCall)
s_ctx.clear();
getCtx().clear();
else // clear window context only
{
Object[] keys = s_ctx.keySet().toArray();
Object[] keys = getCtx().keySet().toArray();
for (int i = 0; i < keys.length; i++)
{
String tag = keys[i].toString();
if (Character.isDigit(tag.charAt(0)))
s_ctx.remove(keys[i]);
getCtx().remove(keys[i]);
}
}
// Cache
CacheMgt.get().reset();
if (Ini.isClient())
DB.closeTarget();
// Reset Role Access
if (!finalCall)
{
if (Ini.isClient())
DB.setDBTarget(CConnection.get());
MRole defaultRole = MRole.getDefault(s_ctx, false);
MRole defaultRole = MRole.getDefault(getCtx(), false);
if (defaultRole != null)
defaultRole.loadAccess(true); // Reload
}
@ -153,7 +162,6 @@ public final class Env
/**************************************************************************
* Application Context
*/
private static Properties s_ctx = new Properties();
/** WindowNo for Find */
public static final int WINDOW_FIND = 1110;
/** WinowNo for MLookup */
@ -172,7 +180,7 @@ public final class Env
*/
public static final Properties getCtx()
{
return s_ctx;
return contextProvider.getContext();
} // getCtx
/**
@ -183,8 +191,8 @@ public final class Env
{
if (ctx == null)
throw new IllegalArgumentException ("Require Context");
s_ctx.clear();
s_ctx = ctx;
getCtx().clear();
getCtx().putAll(ctx);
} // setCtx
/**
@ -1064,6 +1072,7 @@ public final class Env
MLookupCache.cacheReset(WindowNo);
// MLocator.cacheReset(WindowNo);
//
if (Ini.isClient())
removeWindow(WindowNo);
} // clearWinContext
@ -1230,7 +1239,7 @@ public final class Env
*/
public static void clearWinContext(int WindowNo)
{
clearWinContext (s_ctx, WindowNo);
clearWinContext (getCtx(), WindowNo);
} // clearWinContext
/**
@ -1238,7 +1247,7 @@ public final class Env
*/
public static void clearContext()
{
s_ctx.clear();
getCtx().clear();
} // clearContext
@ -1363,42 +1372,7 @@ public final class Env
public static void startBrowser (String url)
{
s_log.info(url);
// OS command
String cmd = "rundll32 url.dll,FileProtocolHandler ";
if (!isWindows()){
if(isMac())
cmd = MAC_BROWSER + " ";
else
cmd = UNIX_BROWSER + " ";
}
//
String execute = cmd + url;
try
{
Runtime.getRuntime().exec(execute);
return;
}
catch (Exception e)
{
if (isWindows())
s_log.severe(execute + " - " + e);
}
//try firefox
if (!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);
}
}
contextProvider.showURL(url);
} // startBrowser
/**
@ -1495,7 +1469,7 @@ public final class Env
} // showWindow
/**
* Clode Windows
* Clode Windows.
*/
static void closeWindows ()
{
@ -1589,7 +1563,7 @@ public final class Env
static
{
// Set English as default Language
s_ctx.put(LANGUAGE, Language.getBaseAD_Language());
getCtx().put(LANGUAGE, Language.getBaseAD_Language());
} // static
} // Env