diff --git a/base/src/org/compiere/print/MPrintFormat.java b/base/src/org/compiere/print/MPrintFormat.java index c32e7ca500..49737dc1ca 100644 --- a/base/src/org/compiere/print/MPrintFormat.java +++ b/base/src/org/compiere/print/MPrintFormat.java @@ -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.*; @@ -863,6 +867,41 @@ public class MPrintFormat extends X_AD_PrintFormat return retValue; } //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; + } /************************************************************************** diff --git a/base/src/org/compiere/util/ContextProvider.java b/base/src/org/compiere/util/ContextProvider.java new file mode 100644 index 0000000000..752067b0a6 --- /dev/null +++ b/base/src/org/compiere/util/ContextProvider.java @@ -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); + +} diff --git a/base/src/org/compiere/util/DefaultContextProvider.java b/base/src/org/compiere/util/DefaultContextProvider.java new file mode 100644 index 0000000000..49460e0f7a --- /dev/null +++ b/base/src/org/compiere/util/DefaultContextProvider.java @@ -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); + } + } + + } + +} diff --git a/base/src/org/compiere/util/Env.java b/base/src/org/compiere/util/Env.java index e729338c37..a729e7973a 100644 --- a/base/src/org/compiere/util/Env.java +++ b/base/src/org/compiere/util/Env.java @@ -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,54 +100,59 @@ public final class Env public static void reset (boolean finalCall) { s_log.info("finalCall=" + finalCall); - closeWindows(); - - // Dismantle windows - /** - for (int i = 0; i < s_windows.size(); i++) + if (Ini.isClient()) { - Container win = (Container)s_windows.get(i); - if (win.getClass().getName().endsWith("AMenu")) // Null pointer - ; - else if (win instanceof Window) - ((Window)win).dispose(); - else - win.removeAll(); - } - **/ - //bug [ 1574630 ] - if (s_windows.size() > 0) { - if (!finalCall) { - Container c = s_windows.get(0); - s_windows.clear(); - createWindowNo(c); - } else { - s_windows.clear(); + closeWindows(); + + // Dismantle windows + /** + for (int i = 0; i < s_windows.size(); i++) + { + Container win = (Container)s_windows.get(i); + if (win.getClass().getName().endsWith("AMenu")) // Null pointer + ; + else if (win instanceof Window) + ((Window)win).dispose(); + else + win.removeAll(); + } + **/ + //bug [ 1574630 ] + 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 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(); - DB.closeTarget(); + if (Ini.isClient()) + DB.closeTarget(); // Reset Role Access if (!finalCall) { - DB.setDBTarget(CConnection.get()); - MRole defaultRole = MRole.getDefault(s_ctx, false); + if (Ini.isClient()) + DB.setDBTarget(CConnection.get()); + 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,7 +1072,8 @@ public final class Env MLookupCache.cacheReset(WindowNo); // MLocator.cacheReset(WindowNo); // - removeWindow(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 \ No newline at end of file