* 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.sql.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
import javax.sql.RowSet;
import javax.swing.JComponent;
import org.compiere.model.*; import org.compiere.model.*;
import org.compiere.util.*; import org.compiere.util.*;
@ -864,6 +868,41 @@ public class MPrintFormat extends X_AD_PrintFormat
} }
//end vpj-cd e-evolution //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 * 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 */ /** Logging */
private static CLogger s_log = CLogger.getCLogger(Env.class); 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 * Exit System
@ -96,54 +100,59 @@ public final class Env
public static void reset (boolean finalCall) public static void reset (boolean finalCall)
{ {
s_log.info("finalCall=" + finalCall); s_log.info("finalCall=" + finalCall);
closeWindows(); if (Ini.isClient())
// Dismantle windows
/**
for (int i = 0; i < s_windows.size(); i++)
{ {
Container win = (Container)s_windows.get(i); closeWindows();
if (win.getClass().getName().endsWith("AMenu")) // Null pointer
; // Dismantle windows
else if (win instanceof Window) /**
((Window)win).dispose(); for (int i = 0; i < s_windows.size(); i++)
else {
win.removeAll(); Container win = (Container)s_windows.get(i);
} if (win.getClass().getName().endsWith("AMenu")) // Null pointer
**/ ;
//bug [ 1574630 ] else if (win instanceof Window)
if (s_windows.size() > 0) { ((Window)win).dispose();
if (!finalCall) { else
Container c = s_windows.get(0); win.removeAll();
s_windows.clear(); }
createWindowNo(c); **/
} else { //bug [ 1574630 ]
s_windows.clear(); if (s_windows.size() > 0) {
if (!finalCall) {
Container c = s_windows.get(0);
s_windows.clear();
createWindowNo(c);
} else {
s_windows.clear();
}
} }
} }
// Clear all Context // Clear all Context
if (finalCall) if (finalCall)
s_ctx.clear(); getCtx().clear();
else // clear window context only else // clear window context only
{ {
Object[] keys = s_ctx.keySet().toArray(); Object[] keys = getCtx().keySet().toArray();
for (int i = 0; i < keys.length; i++) for (int i = 0; i < keys.length; i++)
{ {
String tag = keys[i].toString(); String tag = keys[i].toString();
if (Character.isDigit(tag.charAt(0))) if (Character.isDigit(tag.charAt(0)))
s_ctx.remove(keys[i]); getCtx().remove(keys[i]);
} }
} }
// Cache // Cache
CacheMgt.get().reset(); CacheMgt.get().reset();
DB.closeTarget(); if (Ini.isClient())
DB.closeTarget();
// Reset Role Access // Reset Role Access
if (!finalCall) if (!finalCall)
{ {
DB.setDBTarget(CConnection.get()); if (Ini.isClient())
MRole defaultRole = MRole.getDefault(s_ctx, false); DB.setDBTarget(CConnection.get());
MRole defaultRole = MRole.getDefault(getCtx(), false);
if (defaultRole != null) if (defaultRole != null)
defaultRole.loadAccess(true); // Reload defaultRole.loadAccess(true); // Reload
} }
@ -153,7 +162,6 @@ public final class Env
/************************************************************************** /**************************************************************************
* Application Context * Application Context
*/ */
private static Properties s_ctx = new Properties();
/** WindowNo for Find */ /** WindowNo for Find */
public static final int WINDOW_FIND = 1110; public static final int WINDOW_FIND = 1110;
/** WinowNo for MLookup */ /** WinowNo for MLookup */
@ -172,7 +180,7 @@ public final class Env
*/ */
public static final Properties getCtx() public static final Properties getCtx()
{ {
return s_ctx; return contextProvider.getContext();
} // getCtx } // getCtx
/** /**
@ -183,8 +191,8 @@ public final class Env
{ {
if (ctx == null) if (ctx == null)
throw new IllegalArgumentException ("Require Context"); throw new IllegalArgumentException ("Require Context");
s_ctx.clear(); getCtx().clear();
s_ctx = ctx; getCtx().putAll(ctx);
} // setCtx } // setCtx
/** /**
@ -1064,7 +1072,8 @@ public final class Env
MLookupCache.cacheReset(WindowNo); MLookupCache.cacheReset(WindowNo);
// MLocator.cacheReset(WindowNo); // MLocator.cacheReset(WindowNo);
// //
removeWindow(WindowNo); if (Ini.isClient())
removeWindow(WindowNo);
} // clearWinContext } // clearWinContext
/** /**
@ -1230,7 +1239,7 @@ public final class Env
*/ */
public static void clearWinContext(int WindowNo) public static void clearWinContext(int WindowNo)
{ {
clearWinContext (s_ctx, WindowNo); clearWinContext (getCtx(), WindowNo);
} // clearWinContext } // clearWinContext
/** /**
@ -1238,7 +1247,7 @@ public final class Env
*/ */
public static void clearContext() public static void clearContext()
{ {
s_ctx.clear(); getCtx().clear();
} // clearContext } // clearContext
@ -1363,42 +1372,7 @@ public final class Env
public static void startBrowser (String url) public static void startBrowser (String url)
{ {
s_log.info(url); s_log.info(url);
// OS command contextProvider.showURL(url);
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);
}
}
} // startBrowser } // startBrowser
/** /**
@ -1495,7 +1469,7 @@ public final class Env
} // showWindow } // showWindow
/** /**
* Clode Windows * Clode Windows.
*/ */
static void closeWindows () static void closeWindows ()
{ {
@ -1589,7 +1563,7 @@ public final class Env
static static
{ {
// Set English as default Language // Set English as default Language
s_ctx.put(LANGUAGE, Language.getBaseAD_Language()); getCtx().put(LANGUAGE, Language.getBaseAD_Language());
} // static } // static
} // Env } // Env